diff --git a/.changeset/popular-radios-sleep.md b/.changeset/popular-radios-sleep.md new file mode 100644 index 00000000000..211fa5d870d --- /dev/null +++ b/.changeset/popular-radios-sleep.md @@ -0,0 +1,5 @@ +--- +'@graphql-eslint/eslint-plugin': patch +--- + +fix `no-unreachable-types` to consider wrapped request directive argument types diff --git a/packages/plugin/src/rules/no-unreachable-types/index.test.ts b/packages/plugin/src/rules/no-unreachable-types/index.test.ts index 7bc14453e52..a458e49f837 100644 --- a/packages/plugin/src/rules/no-unreachable-types/index.test.ts +++ b/packages/plugin/src/rules/no-unreachable-types/index.test.ts @@ -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({ diff --git a/packages/plugin/src/rules/no-unreachable-types/index.ts b/packages/plugin/src/rules/no-unreachable-types/index.ts index f771437f053..32ea8165d97 100644 --- a/packages/plugin/src/rules/no-unreachable-types/index.ts +++ b/packages/plugin/src/rules/no-unreachable-types/index.ts @@ -2,6 +2,7 @@ import { ASTNode, ASTVisitor, DirectiveLocation, + getNamedType, GraphQLSchema, isInterfaceType, Kind, @@ -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); } } }