Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(filterSchema): provide actual type name for root field #5931

Merged
merged 2 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/warm-ducks-smash.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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']);
});
});
Loading