Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Corrected check for object type and added test to validate used input…
… type is not pruned (#4406)
  • Loading branch information
tlivings committed Apr 19, 2022
1 parent 435af04 commit 31a33e2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/chilled-apricots-allow.md
@@ -0,0 +1,5 @@
---
'@graphql-tools/utils': patch
---

pruneSchema will no longer removed used input object type.
2 changes: 1 addition & 1 deletion packages/utils/src/prune.ts
Expand Up @@ -139,7 +139,7 @@ function visitQueue(queue: string[], schema: GraphQLSchema, visited: Set<string>
}

for (const [, field] of entries) {
if (isInputObjectType(type)) {
if (isObjectType(type)) {
for (const arg of field.args) {
queue.push(getNamedType(arg.type).name); // Visit arg types
}
Expand Down
14 changes: 14 additions & 0 deletions packages/utils/tests/prune.test.ts
Expand Up @@ -86,6 +86,20 @@ describe('pruneSchema', () => {
expect(result.getType('CustomScalar')).toBeDefined();
});

test('does not remove used input objects', () => {
const schema = buildSchema(/* GraphQL */ `
input UsedInput {
value: String
}
type Query {
foo(input: UsedInput): Boolean
}
`);
const result = pruneSchema(schema);
expect(result.getType('UsedInput')).toBeDefined();
});

test('removes unused input objects', () => {
const schema = buildSchema(/* GraphQL */ `
input Unused {
Expand Down

0 comments on commit 31a33e2

Please sign in to comment.