Skip to content

Commit

Permalink
Handle recursive input types when pruning schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
mdlavin committed Sep 11, 2020
1 parent 65b41f0 commit 42156d1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
3 changes: 1 addition & 2 deletions packages/utils/src/prune.ts
Expand Up @@ -167,6 +167,7 @@ function visitInputType(
}

pruningContext.unusedTypes[type.name] = false;
visitedTypes[type.name] = true;

if (isInputObjectType(type)) {
const fields = type.getFields();
Expand All @@ -176,8 +177,6 @@ function visitInputType(
visitInputType(visitedTypes, pruningContext, namedType);
});
}

visitedTypes[type.name] = true;
}

function visitTypes(pruningContext: PruningContext, schema: GraphQLSchema): void {
Expand Down
18 changes: 18 additions & 0 deletions packages/utils/tests/prune.test.ts
@@ -0,0 +1,18 @@
import { buildSchema } from 'graphql';

import { pruneSchema } from '../src/prune';

describe('prune', () => {
test('can handle recursive input types', () => {
const schema = buildSchema(`
input Input {
moreInput: Input
}
type Query {
someQuery(input: Input): Boolean
}
`);
pruneSchema(schema);
});
});

0 comments on commit 42156d1

Please sign in to comment.