fix: skip visiting directive arguments when collecting usage (#1224)

This commit is contained in:
Ryan Perry-Nguyen 2023-02-10 06:52:53 -05:00 committed by GitHub
parent de7ba835e4
commit cf14c18d6e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 0 deletions

View file

@ -0,0 +1,5 @@
---
'@graphql-hive/client': minor
---
skip directive arguments during usage collection

View file

@ -379,6 +379,12 @@ export function createCollector({
collectInputType(resolveTypeName(inputType));
}
},
Directive(node) {
return {
...node,
arguments: [],
};
},
Argument(node) {
const parent = typeInfo.getParentType()!;
const field = typeInfo.getFieldDef()!;

View file

@ -195,6 +195,34 @@ test('collect arguments', async () => {
expect(info.fields).toContain(`Query.projects.filter`);
});
test('skips argument directives', async () => {
const collect = createCollector({
schema,
max: 1,
});
const info = collect(
parse(/* GraphQL */ `
query getProjects($limit: Int!, $type: ProjectType!, $includeName: Boolean!) {
projects(filter: { pagination: { limit: $limit }, type: $type }) {
id
...NestedFragment
}
}
fragment NestedFragment on Project {
...IncludeNameFragment @include(if: $includeName)
}
fragment IncludeNameFragment on Project {
name
}
`),
{},
).value;
expect(info.fields).toContain(`Query.projects.filter`);
});
test('collect used-only input fields', async () => {
const collect = createCollector({
schema,