Skip to content

Commit

Permalink
fix: skip visiting directive arguments when collecting usage (#1224)
Browse files Browse the repository at this point in the history
  • Loading branch information
rperryng authored Feb 10, 2023
1 parent de7ba83 commit cf14c18
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/many-jobs-perform.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-hive/client': minor
---

skip directive arguments during usage collection
6 changes: 6 additions & 0 deletions packages/libraries/client/src/internal/usage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()!;
Expand Down
28 changes: 28 additions & 0 deletions packages/libraries/client/tests/usage-collector.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit cf14c18

Please sign in to comment.