Skip to content

Commit 73b1087

Browse files
authored
fix TypeError: Cannot read properties of undefined (reading 'kind') for require-nullable-result-in-root rule (#1665)
1 parent baf0c46 commit 73b1087

File tree

6 files changed

+391
-2068
lines changed

6 files changed

+391
-2068
lines changed

.changeset/lovely-otters-watch.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@graphql-eslint/eslint-plugin': patch
3+
---
4+
5+
fix `TypeError: Cannot read properties of undefined (reading 'kind')` for
6+
`require-nullable-result-in-root` rule

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"chalk": "4.1.2",
3232
"dedent": "0.7.0",
3333
"enquirer": "2.3.6",
34-
"eslint": "8.38.0",
34+
"eslint": "8.41.0",
3535
"eslint-plugin-eslint-plugin": "5.0.7",
3636
"eslint-plugin-tailwindcss": "3.12.0",
3737
"husky": "8.0.3",
@@ -49,7 +49,7 @@
4949
},
5050
"pnpm": {
5151
"patchedDependencies": {
52-
"eslint@8.38.0": "patches/[email protected]",
52+
"eslint@8.41.0": "patches/[email protected]",
5353
5454
5555
"@vitest/[email protected]": "patches/@[email protected]"

packages/plugin/src/rules/require-nullable-result-in-root.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ export const rule: GraphQLESLintRule = {
6363
continue;
6464
const name = field.gqlType.gqlType.name.value;
6565
const type = schema.getType(name);
66-
const resultType = type ? getNodeName(type.astNode as any) : '';
66+
const resultType = type?.astNode ? getNodeName(type.astNode as any) : type?.name;
6767

6868
context.report({
6969
node: field.gqlType,
7070
messageId: RULE_ID,
7171
data: {
72-
resultType,
72+
resultType: resultType || '',
7373
rootType: getNodeName(node),
7474
},
7575
suggest: [

packages/plugin/tests/__snapshots__/require-nullable-result-in-root.spec.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,35 @@ exports[`Invalid #1 1`] = `
2727
6 | }
2828
`;
2929

30+
exports[`should work with default scalars 1`] = `
31+
#### ⌨️ Code
32+
33+
1 | type MySubscription
34+
2 | extend type MySubscription {
35+
3 | foo: Boolean!
36+
4 | }
37+
5 | schema {
38+
6 | subscription: MySubscription
39+
7 | }
40+
41+
#### ❌ Error
42+
43+
2 | extend type MySubscription {
44+
> 3 | foo: Boolean!
45+
| ^^^^^^^ Unexpected non-null result Boolean in type "MySubscription"
46+
4 | }
47+
48+
#### 💡 Suggestion: Make Boolean nullable
49+
50+
1 | type MySubscription
51+
2 | extend type MySubscription {
52+
3 | foo: Boolean
53+
4 | }
54+
5 | schema {
55+
6 | subscription: MySubscription
56+
7 | }
57+
`;
58+
3059
exports[`should work with extend query 1`] = `
3160
#### ⌨️ Code
3261

packages/plugin/tests/require-nullable-result-in-root.spec.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,18 @@ ruleTester.runGraphQLTests('require-nullable-result-in-root', rule, {
5353
`),
5454
errors: 1,
5555
},
56+
{
57+
name: 'should work with default scalars',
58+
...useSchema(/* GraphQL */ `
59+
type MySubscription
60+
extend type MySubscription {
61+
foo: Boolean!
62+
}
63+
schema {
64+
subscription: MySubscription
65+
}
66+
`),
67+
errors: 1,
68+
},
5669
],
5770
});

0 commit comments

Comments
 (0)