Skip to content

Commit e854103

Browse files
committed
no-unreachable-types: fix handling wrapped request directive argument types
1 parent ff0ac30 commit e854103

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,22 @@ ruleTester.run('no-unreachable-types', rule, {
166166
type Query
167167
`,
168168
}),
169+
withSchema({
170+
name: 'should ignore types from directive arguments with request locations',
171+
code: /* GraphQL */ `
172+
scalar Scalar0
173+
scalar Scalar1
174+
scalar Scalar2
175+
scalar Scalar3
176+
scalar Scalar4
177+
directive @q(arg: Scalar0) on QUERY
178+
directive @w(arg: [Scalar1]) on QUERY
179+
directive @e(arg: [Scalar2]!) on QUERY
180+
directive @r(arg: [Scalar3!]) on QUERY
181+
directive @t(arg: [Scalar4!]!) on QUERY
182+
type Query
183+
`,
184+
}),
169185
],
170186
invalid: [
171187
withSchema({

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ import {
33
ASTVisitor,
44
DirectiveLocation,
55
GraphQLSchema,
6-
isInterfaceType,
76
Kind,
87
NameNode,
8+
getNamedType,
9+
isInterfaceType,
910
visit,
1011
} from 'graphql';
1112
import lowerCase from 'lodash.lowercase';
@@ -99,10 +100,7 @@ function getReachableTypes(schema: GraphQLSchema): ReachableTypes {
99100
if (node.locations.some(location => RequestDirectiveLocations.has(location))) {
100101
reachableTypes.add(node.name);
101102
for (const arg of node.args) {
102-
const argTypeName = 'name' in arg.type && arg.type.name;
103-
if (argTypeName) {
104-
reachableTypes.add(argTypeName);
105-
}
103+
reachableTypes.add(getNamedType(arg.type).name);
106104
}
107105
}
108106
}

0 commit comments

Comments
 (0)