Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix no-unreachable-types to consider wrapped request directive argument types #2721

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading