Skip to content

Commit 6b4e20c

Browse files
authored
fix no-unreachable-types ignore types from directive arguments with request locations (#1469)
1 parent 5779329 commit 6b4e20c

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

.changeset/honest-yaks-trade.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-eslint/eslint-plugin': patch
3+
---
4+
5+
fix `no-unreachable-types` ignore types from directive arguments with request locations

packages/plugin/src/rules/no-unreachable-types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ function getReachableTypes(schema: GraphQLSchema): ReachableTypes {
9898
for (const node of schema.getDirectives()) {
9999
if (node.locations.some(location => RequestDirectiveLocations.has(location))) {
100100
reachableTypes.add(node.name);
101+
for (const arg of node.args) {
102+
const argTypeName = 'name' in arg.type && arg.type.name;
103+
if (argTypeName) {
104+
reachableTypes.add(argTypeName);
105+
}
106+
}
101107
}
102108
}
103109

packages/plugin/tests/no-unreachable-types.spec.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,17 @@ ruleTester.runGraphQLTests('no-unreachable-types', rule, {
148148
type Query
149149
`),
150150
},
151+
{
152+
name: 'should ignore types from directive arguments with request locations',
153+
...useSchema(/* GraphQL */ `
154+
enum Enum {
155+
A
156+
B
157+
}
158+
directive @q(arg: Enum = A) on QUERY
159+
type Query
160+
`),
161+
},
151162
],
152163
invalid: [
153164
{

0 commit comments

Comments
 (0)