Skip to content

Commit

Permalink
fix no-unreachable-types ignore types from directive arguments with…
Browse files Browse the repository at this point in the history
… request locations (#1469)
  • Loading branch information
dimaMachina committed Feb 26, 2023
1 parent 5779329 commit 6b4e20c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/honest-yaks-trade.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-eslint/eslint-plugin': patch
---

fix `no-unreachable-types` ignore types from directive arguments with request locations
6 changes: 6 additions & 0 deletions packages/plugin/src/rules/no-unreachable-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ function getReachableTypes(schema: GraphQLSchema): ReachableTypes {
for (const node of schema.getDirectives()) {
if (node.locations.some(location => RequestDirectiveLocations.has(location))) {
reachableTypes.add(node.name);
for (const arg of node.args) {
const argTypeName = 'name' in arg.type && arg.type.name;
if (argTypeName) {
reachableTypes.add(argTypeName);
}
}
}
}

Expand Down
11 changes: 11 additions & 0 deletions packages/plugin/tests/no-unreachable-types.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,17 @@ ruleTester.runGraphQLTests('no-unreachable-types', rule, {
type Query
`),
},
{
name: 'should ignore types from directive arguments with request locations',
...useSchema(/* GraphQL */ `
enum Enum {
A
B
}
directive @q(arg: Enum = A) on QUERY
type Query
`),
},
],
invalid: [
{
Expand Down

0 comments on commit 6b4e20c

Please sign in to comment.