Skip to content

Commit

Permalink
fix TypeError: Cannot read properties of undefined (reading 'kind')
Browse files Browse the repository at this point in the history
… for `require-nullable-result-in-root` rule (#1665)
  • Loading branch information
dimaMachina committed May 23, 2023
1 parent baf0c46 commit 73b1087
Show file tree
Hide file tree
Showing 6 changed files with 391 additions and 2,068 deletions.
6 changes: 6 additions & 0 deletions .changeset/lovely-otters-watch.md
@@ -0,0 +1,6 @@
---
'@graphql-eslint/eslint-plugin': patch
---

fix `TypeError: Cannot read properties of undefined (reading 'kind')` for
`require-nullable-result-in-root` rule
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -31,7 +31,7 @@
"chalk": "4.1.2",
"dedent": "0.7.0",
"enquirer": "2.3.6",
"eslint": "8.38.0",
"eslint": "8.41.0",
"eslint-plugin-eslint-plugin": "5.0.7",
"eslint-plugin-tailwindcss": "3.12.0",
"husky": "8.0.3",
Expand All @@ -49,7 +49,7 @@
},
"pnpm": {
"patchedDependencies": {
"eslint@8.38.0": "patches/eslint@8.31.0.patch",
"eslint@8.41.0": "patches/eslint@8.31.0.patch",
"eslint-plugin-eslint-plugin@5.0.7": "patches/eslint-plugin-eslint-plugin@5.0.6.patch",
"json-schema-to-markdown@1.1.1": "patches/json-schema-to-markdown@1.1.1.patch",
"@vitest/runner@0.30.1": "patches/@vitest__runner@0.28.4.patch"
Expand Down
4 changes: 2 additions & 2 deletions packages/plugin/src/rules/require-nullable-result-in-root.ts
Expand Up @@ -63,13 +63,13 @@ export const rule: GraphQLESLintRule = {
continue;
const name = field.gqlType.gqlType.name.value;
const type = schema.getType(name);
const resultType = type ? getNodeName(type.astNode as any) : '';
const resultType = type?.astNode ? getNodeName(type.astNode as any) : type?.name;

context.report({
node: field.gqlType,
messageId: RULE_ID,
data: {
resultType,
resultType: resultType || '',
rootType: getNodeName(node),
},
suggest: [
Expand Down
Expand Up @@ -27,6 +27,35 @@ exports[`Invalid #1 1`] = `
6 | }
`;

exports[`should work with default scalars 1`] = `
#### ⌨️ Code

1 | type MySubscription
2 | extend type MySubscription {
3 | foo: Boolean!
4 | }
5 | schema {
6 | subscription: MySubscription
7 | }

#### ❌ Error

2 | extend type MySubscription {
> 3 | foo: Boolean!
| ^^^^^^^ Unexpected non-null result Boolean in type "MySubscription"
4 | }

#### 💡 Suggestion: Make Boolean nullable

1 | type MySubscription
2 | extend type MySubscription {
3 | foo: Boolean
4 | }
5 | schema {
6 | subscription: MySubscription
7 | }
`;

exports[`should work with extend query 1`] = `
#### ⌨️ Code

Expand Down
13 changes: 13 additions & 0 deletions packages/plugin/tests/require-nullable-result-in-root.spec.ts
Expand Up @@ -53,5 +53,18 @@ ruleTester.runGraphQLTests('require-nullable-result-in-root', rule, {
`),
errors: 1,
},
{
name: 'should work with default scalars',
...useSchema(/* GraphQL */ `
type MySubscription
extend type MySubscription {
foo: Boolean!
}
schema {
subscription: MySubscription
}
`),
errors: 1,
},
],
});

0 comments on commit 73b1087

Please sign in to comment.