Skip to content

Commit

Permalink
fix(filterSchema): provide actual type name for root field (#5931)
Browse files Browse the repository at this point in the history
* fix(filterSchema): provide actual type name for root field

* add changeset
  • Loading branch information
henryqdineen committed Mar 11, 2024
1 parent d4395dd commit baf3c28
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/warm-ducks-smash.md
@@ -0,0 +1,5 @@
---
"@graphql-tools/utils": patch
---

fix filterSchema argument filter for schema with non-default root types
2 changes: 1 addition & 1 deletion packages/utils/src/filterSchema.ts
Expand Up @@ -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];
}
}
Expand Down
29 changes: 29 additions & 0 deletions packages/utils/tests/filterSchema.test.ts
Expand Up @@ -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']);
});
});

0 comments on commit baf3c28

Please sign in to comment.