import type { GraphQLFieldResolver } from 'graphql'; import SchemaBuilder, { BasePlugin, mapInputFields, type PothosInputFieldConfig, type PothosOutputFieldConfig, type SchemaTypes, } from '../src'; const pluginName = 'removedArgsTestPlugin' as keyof PothosSchemaTypes.Plugins; class RemovingPlugin extends BasePlugin { seenArgs: Record[] = []; override onInputFieldConfig(field: PothosInputFieldConfig) { return field.name === 'removed' ? null : field; } override wrapResolve( resolve: GraphQLFieldResolver, config: PothosOutputFieldConfig, ) { this.seenArgs.push(config.args); mapInputFields(config.args, this.buildCache, () => null); return resolve; } } SchemaBuilder.registerPlugin(pluginName, RemovingPlugin as never); describe('arguments removed by onInputFieldConfig', () => { it('omits removed args from the config passed to resolver wrappers', () => { const builder = new SchemaBuilder({ plugins: [pluginName] }); builder.queryType({ fields: (t) => ({ value: t.string({ args: { removed: t.arg.string(), kept: t.arg.string(), }, resolve: () => 'ok', }), }), }); const schema = builder.toSchema(); const field = schema.getQueryType()!.getFields().value; expect(field.args.map((arg) => arg.name)).toEqual(['kept']); const configArgs = (field.extensions as { pothosConfig: PothosOutputFieldConfig }) .pothosConfig.args; expect(Object.keys(configArgs)).toEqual(['kept']); expect(Object.values(configArgs)).not.toContain(null); }); });