diff --git a/.changeset/chilled-apricots-allow.md b/.changeset/chilled-apricots-allow.md new file mode 100644 index 0000000000..4650a5588c --- /dev/null +++ b/.changeset/chilled-apricots-allow.md @@ -0,0 +1,5 @@ +--- +'@graphql-tools/utils': patch +--- + +pruneSchema will no longer removed used input object type. diff --git a/packages/utils/src/prune.ts b/packages/utils/src/prune.ts index 4ef14743a1..d774564e5c 100644 --- a/packages/utils/src/prune.ts +++ b/packages/utils/src/prune.ts @@ -139,7 +139,7 @@ function visitQueue(queue: string[], schema: GraphQLSchema, visited: Set } 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 } diff --git a/packages/utils/tests/prune.test.ts b/packages/utils/tests/prune.test.ts index 91834ca873..07c7f8542a 100644 --- a/packages/utils/tests/prune.test.ts +++ b/packages/utils/tests/prune.test.ts @@ -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 {