From c5465ea0a5f229e436a0f07ce939ee5732b6ad88 Mon Sep 17 00:00:00 2001 From: Henry Dineen Date: Fri, 23 Feb 2024 12:47:15 -0500 Subject: [PATCH 1/2] fix(filterSchema): provide actual type name for root field --- packages/utils/src/filterSchema.ts | 2 +- packages/utils/tests/filterSchema.test.ts | 29 +++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/packages/utils/src/filterSchema.ts b/packages/utils/src/filterSchema.ts index 4360a6c0cca..1ab54f714cf 100644 --- a/packages/utils/src/filterSchema.ts +++ b/packages/utils/src/filterSchema.ts @@ -94,7 +94,7 @@ function filterRootFields( delete config.fields[fieldName]; } else if (argumentFilter && field.args) { for (const argName in field.args) { - if (!argumentFilter(operation, fieldName, argName, field.args[argName])) { + if (!argumentFilter(type.name, fieldName, argName, field.args[argName])) { delete field.args[argName]; } } diff --git a/packages/utils/tests/filterSchema.test.ts b/packages/utils/tests/filterSchema.test.ts index 73436defa05..617ebffdf86 100644 --- a/packages/utils/tests/filterSchema.test.ts +++ b/packages/utils/tests/filterSchema.test.ts @@ -236,4 +236,33 @@ describe('filterSchema', () => { ['field'].args.map(arg => arg.name), ).toEqual(['keep']); }); + + it('filters root field arguments for non-default query type', () => { + const schema = makeExecutableSchema({ + typeDefs: /* GraphQL */ ` + schema { + query: Root + } + type Root { + field(keep: String, omit: String): String + } + `, + }); + + const filtered = filterSchema({ + schema, + argumentFilter(typeName, fieldName, argName) { + if (typeName === 'Root' && fieldName === 'field' && argName === 'omit') { + return false; + } + return true; + }, + }); + + expect( + (filtered.getType('Root') as GraphQLObjectType) + .getFields() + ['field'].args.map(arg => arg.name), + ).toEqual(['keep']); + }); }); From 4a348b58d4cda6fd5ed6c0c47bbbe73c015b1969 Mon Sep 17 00:00:00 2001 From: Henry Dineen Date: Fri, 23 Feb 2024 13:15:42 -0500 Subject: [PATCH 2/2] add changeset --- .changeset/warm-ducks-smash.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/warm-ducks-smash.md diff --git a/.changeset/warm-ducks-smash.md b/.changeset/warm-ducks-smash.md new file mode 100644 index 00000000000..24e30d6073b --- /dev/null +++ b/.changeset/warm-ducks-smash.md @@ -0,0 +1,5 @@ +--- +"@graphql-tools/utils": patch +--- + +fix filterSchema argument filter for schema with non-default root types