Skip to content

Commit

Permalink
aa (#2721)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaMachina authored Nov 19, 2024
1 parent 710a4bb commit cda7929
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/popular-radios-sleep.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-eslint/eslint-plugin': patch
---

fix `no-unreachable-types` to consider wrapped request directive argument types
17 changes: 17 additions & 0 deletions packages/plugin/src/rules/no-unreachable-types/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,23 @@ ruleTester.run('no-unreachable-types', rule, {
type Query
`,
}),
withSchema({
name: 'should ignore types from directive arguments with request locations',
code: /* GraphQL */ `
scalar Scalar1
scalar Scalar2
scalar Scalar3
scalar Scalar4
scalar Scalar5
scalar Scalar6
directive @q(arg: Scalar1) on QUERY
directive @w(arg: Scalar2!) on QUERY
directive @e(arg: [Scalar3]) on QUERY
directive @r(arg: [Scalar4!]) on QUERY
directive @t(arg: [Scalar5]!) on QUERY
directive @y(arg: [Scalar6!]!) on QUERY
`,
}),
],
invalid: [
withSchema({
Expand Down
6 changes: 2 additions & 4 deletions packages/plugin/src/rules/no-unreachable-types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
ASTNode,
ASTVisitor,
DirectiveLocation,
getNamedType,
GraphQLSchema,
isInterfaceType,
Kind,
Expand Down Expand Up @@ -102,10 +103,7 @@ function getReachableTypes(schema: GraphQLSchema): ReachableTypes {
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);
}
reachableTypes.add(getNamedType(arg.type).name);
}
}
}
Expand Down

0 comments on commit cda7929

Please sign in to comment.