@graphql-eslint/eslint-plugin 4.3.0 → 4.4.0-alpha-20241207210859-41eb4549764dc0314b5bd4f257ea6667b178540e

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (110) hide show
  1. package/cjs/cache.js +6 -2
  2. package/cjs/configs/operations-all.js +2 -2
  3. package/cjs/configs/schema-all.js +2 -2
  4. package/cjs/configs/schema-recommended.js +1 -1
  5. package/cjs/documents.js +13 -7
  6. package/cjs/estree-converter/converter.js +17 -8
  7. package/cjs/estree-converter/utils.js +22 -9
  8. package/cjs/graphql-config.js +13 -6
  9. package/cjs/index.d.cts +18 -4
  10. package/cjs/meta.js +1 -1
  11. package/cjs/parser.js +36 -9
  12. package/cjs/processor.js +48 -20
  13. package/cjs/rules/alphabetize/index.js +99 -47
  14. package/cjs/rules/description-style/index.js +10 -6
  15. package/cjs/rules/graphql-js-validation.js +142 -108
  16. package/cjs/rules/index.d.cts +18 -4
  17. package/cjs/rules/input-name/index.js +51 -38
  18. package/cjs/rules/lone-executable-definition/index.js +15 -6
  19. package/cjs/rules/match-document-filename/index.d.cts +4 -3
  20. package/cjs/rules/match-document-filename/index.js +63 -37
  21. package/cjs/rules/naming-convention/index.d.cts +6 -10
  22. package/cjs/rules/naming-convention/index.js +179 -82
  23. package/cjs/rules/no-anonymous-operations/index.js +8 -5
  24. package/cjs/rules/no-deprecated/index.js +27 -13
  25. package/cjs/rules/no-duplicate-fields/index.js +15 -8
  26. package/cjs/rules/no-hashtag-description/index.js +18 -10
  27. package/cjs/rules/no-one-place-fragments/index.js +17 -10
  28. package/cjs/rules/no-root-type/index.js +15 -8
  29. package/cjs/rules/no-scalar-result-type-on-mutation/index.js +20 -12
  30. package/cjs/rules/no-typename-prefix/index.js +25 -21
  31. package/cjs/rules/no-unreachable-types/index.js +34 -17
  32. package/cjs/rules/no-unused-fields/index.js +56 -30
  33. package/cjs/rules/relay-arguments/index.js +31 -13
  34. package/cjs/rules/relay-connection-types/index.js +31 -9
  35. package/cjs/rules/relay-edge-types/index.js +84 -41
  36. package/cjs/rules/relay-page-info/index.js +31 -14
  37. package/cjs/rules/require-deprecation-date/index.js +20 -9
  38. package/cjs/rules/require-deprecation-reason/index.js +8 -5
  39. package/cjs/rules/require-description/index.d.cts +79 -13
  40. package/cjs/rules/require-description/index.js +67 -49
  41. package/cjs/rules/require-field-of-type-query-in-mutation-result/index.js +21 -10
  42. package/cjs/rules/require-import-fragment/index.js +20 -11
  43. package/cjs/rules/require-nullable-fields-with-oneof/index.js +12 -5
  44. package/cjs/rules/require-nullable-result-in-root/index.js +32 -27
  45. package/cjs/rules/require-selections/index.js +88 -46
  46. package/cjs/rules/require-type-pattern-with-oneof/index.js +14 -10
  47. package/cjs/rules/selection-set-depth/index.js +19 -10
  48. package/cjs/rules/strict-id-in-types/index.js +32 -19
  49. package/cjs/rules/unique-enum-value-names/index.js +4 -3
  50. package/cjs/rules/unique-fragment-name/index.js +25 -18
  51. package/cjs/rules/unique-operation-name/index.js +5 -5
  52. package/cjs/schema.js +14 -8
  53. package/cjs/siblings.js +60 -32
  54. package/cjs/utils.js +23 -9
  55. package/esm/cache.js +6 -2
  56. package/esm/configs/operations-all.js +2 -2
  57. package/esm/configs/schema-all.js +2 -2
  58. package/esm/configs/schema-recommended.js +1 -1
  59. package/esm/documents.js +13 -7
  60. package/esm/estree-converter/converter.js +17 -8
  61. package/esm/estree-converter/utils.js +22 -9
  62. package/esm/graphql-config.js +13 -6
  63. package/esm/index.d.ts +18 -4
  64. package/esm/meta.js +1 -1
  65. package/esm/parser.js +36 -9
  66. package/esm/processor.js +48 -20
  67. package/esm/rules/alphabetize/index.js +99 -47
  68. package/esm/rules/description-style/index.js +10 -6
  69. package/esm/rules/graphql-js-validation.js +142 -108
  70. package/esm/rules/index.d.ts +18 -4
  71. package/esm/rules/input-name/index.js +51 -38
  72. package/esm/rules/lone-executable-definition/index.js +15 -6
  73. package/esm/rules/match-document-filename/index.d.ts +4 -3
  74. package/esm/rules/match-document-filename/index.js +63 -37
  75. package/esm/rules/naming-convention/index.d.ts +6 -10
  76. package/esm/rules/naming-convention/index.js +179 -82
  77. package/esm/rules/no-anonymous-operations/index.js +8 -5
  78. package/esm/rules/no-deprecated/index.js +27 -13
  79. package/esm/rules/no-duplicate-fields/index.js +15 -8
  80. package/esm/rules/no-hashtag-description/index.js +18 -10
  81. package/esm/rules/no-one-place-fragments/index.js +17 -10
  82. package/esm/rules/no-root-type/index.js +15 -8
  83. package/esm/rules/no-scalar-result-type-on-mutation/index.js +20 -12
  84. package/esm/rules/no-typename-prefix/index.js +25 -21
  85. package/esm/rules/no-unreachable-types/index.js +34 -17
  86. package/esm/rules/no-unused-fields/index.js +56 -30
  87. package/esm/rules/relay-arguments/index.js +31 -13
  88. package/esm/rules/relay-connection-types/index.js +31 -9
  89. package/esm/rules/relay-edge-types/index.js +84 -41
  90. package/esm/rules/relay-page-info/index.js +31 -14
  91. package/esm/rules/require-deprecation-date/index.js +20 -9
  92. package/esm/rules/require-deprecation-reason/index.js +8 -5
  93. package/esm/rules/require-description/index.d.ts +79 -13
  94. package/esm/rules/require-description/index.js +67 -49
  95. package/esm/rules/require-field-of-type-query-in-mutation-result/index.js +21 -10
  96. package/esm/rules/require-import-fragment/index.js +20 -11
  97. package/esm/rules/require-nullable-fields-with-oneof/index.js +12 -5
  98. package/esm/rules/require-nullable-result-in-root/index.js +32 -27
  99. package/esm/rules/require-selections/index.js +88 -46
  100. package/esm/rules/require-type-pattern-with-oneof/index.js +14 -10
  101. package/esm/rules/selection-set-depth/index.js +19 -10
  102. package/esm/rules/strict-id-in-types/index.js +32 -19
  103. package/esm/rules/unique-enum-value-names/index.js +4 -3
  104. package/esm/rules/unique-fragment-name/index.js +25 -18
  105. package/esm/rules/unique-operation-name/index.js +5 -5
  106. package/esm/schema.js +15 -8
  107. package/esm/siblings.js +60 -32
  108. package/esm/utils.js +23 -9
  109. package/index.browser.js +1871 -1160
  110. package/package.json +1 -1
@@ -8,57 +8,60 @@ import {
8
8
  requireGraphQLSchema,
9
9
  TYPES_KINDS
10
10
  } from "../../utils.js";
11
- const RULE_ID = "require-description", ALLOWED_KINDS = [
11
+ const RULE_ID = "require-description";
12
+ const ALLOWED_KINDS = [
12
13
  ...TYPES_KINDS,
13
14
  Kind.DIRECTIVE_DEFINITION,
14
15
  Kind.FIELD_DEFINITION,
15
16
  Kind.INPUT_VALUE_DEFINITION,
16
17
  Kind.ENUM_VALUE_DEFINITION,
17
18
  Kind.OPERATION_DEFINITION
18
- ], schema = {
19
+ ];
20
+ const entries = /* @__PURE__ */ Object.create(null);
21
+ for (const kind of [...ALLOWED_KINDS].sort()) {
22
+ let description = `> [!NOTE]
23
+ >
24
+ > Read more about this kind on [spec.graphql.org](https://spec.graphql.org/October2021/#${kind}).`;
25
+ if (kind === Kind.OPERATION_DEFINITION) {
26
+ description += [
27
+ "",
28
+ "",
29
+ "> [!WARNING]",
30
+ ">",
31
+ '> You must use only comment syntax `#` and not description syntax `"""` or `"`.'
32
+ ].join("\n");
33
+ }
34
+ entries[kind] = { type: "boolean", description };
35
+ }
36
+ const schema = {
19
37
  type: "array",
20
38
  minItems: 1,
21
39
  maxItems: 1,
22
40
  items: {
23
41
  type: "object",
24
- additionalProperties: !1,
42
+ additionalProperties: false,
25
43
  minProperties: 1,
26
44
  properties: {
27
45
  types: {
28
46
  type: "boolean",
29
- enum: [!0],
47
+ enum: [true],
30
48
  description: `Includes:
31
- ${TYPES_KINDS.map((kind) => `- \`${kind}\``).join(`
32
- `)}`
49
+ ${TYPES_KINDS.map((kind) => `- \`${kind}\``).join("\n")}`
33
50
  },
34
51
  rootField: {
35
52
  type: "boolean",
36
- enum: [!0],
53
+ enum: [true],
37
54
  description: "Definitions within `Query`, `Mutation`, and `Subscription` root types."
38
55
  },
39
56
  ignoredSelectors: {
40
57
  ...ARRAY_DEFAULT_OPTIONS,
41
- description: ["Ignore specific selectors", eslintSelectorsTip].join(`
42
- `)
58
+ description: ["Ignore specific selectors", eslintSelectorsTip].join("\n")
43
59
  },
44
- ...Object.fromEntries(
45
- [...ALLOWED_KINDS].sort().map((kind) => {
46
- let description = `> [!NOTE]
47
- >
48
- > Read more about this kind on [spec.graphql.org](https://spec.graphql.org/October2021/#${kind}).`;
49
- return kind === Kind.OPERATION_DEFINITION && (description += [
50
- "",
51
- "",
52
- "> [!WARNING]",
53
- ">",
54
- '> You must use only comment syntax `#` and not description syntax `"""` or `"`.'
55
- ].join(`
56
- `)), [kind, { type: "boolean", description }];
57
- })
58
- )
60
+ ...entries
59
61
  }
60
62
  }
61
- }, rule = {
63
+ };
64
+ const rule = {
62
65
  meta: {
63
66
  docs: {
64
67
  category: "Schema",
@@ -67,7 +70,7 @@ ${TYPES_KINDS.map((kind) => `- \`${kind}\``).join(`
67
70
  examples: [
68
71
  {
69
72
  title: "Incorrect",
70
- usage: [{ types: !0, FieldDefinition: !0 }],
73
+ usage: [{ types: true, FieldDefinition: true }],
71
74
  code: (
72
75
  /* GraphQL */
73
76
  `
@@ -79,7 +82,7 @@ ${TYPES_KINDS.map((kind) => `- \`${kind}\``).join(`
79
82
  },
80
83
  {
81
84
  title: "Correct",
82
- usage: [{ types: !0, FieldDefinition: !0 }],
85
+ usage: [{ types: true, FieldDefinition: true }],
83
86
  code: (
84
87
  /* GraphQL */
85
88
  `
@@ -97,7 +100,7 @@ ${TYPES_KINDS.map((kind) => `- \`${kind}\``).join(`
97
100
  },
98
101
  {
99
102
  title: "Correct",
100
- usage: [{ OperationDefinition: !0 }],
103
+ usage: [{ OperationDefinition: true }],
101
104
  code: (
102
105
  /* GraphQL */
103
106
  `
@@ -110,7 +113,7 @@ ${TYPES_KINDS.map((kind) => `- \`${kind}\``).join(`
110
113
  },
111
114
  {
112
115
  title: "Correct",
113
- usage: [{ rootField: !0 }],
116
+ usage: [{ rootField: true }],
114
117
  code: (
115
118
  /* GraphQL */
116
119
  `
@@ -158,12 +161,12 @@ ${TYPES_KINDS.map((kind) => `- \`${kind}\``).join(`
158
161
  ],
159
162
  configOptions: [
160
163
  {
161
- types: !0,
162
- [Kind.DIRECTIVE_DEFINITION]: !0,
163
- rootField: !0
164
+ types: true,
165
+ [Kind.DIRECTIVE_DEFINITION]: true,
166
+ rootField: true
164
167
  }
165
168
  ],
166
- recommended: !0
169
+ recommended: true
167
170
  },
168
171
  type: "suggestion",
169
172
  messages: {
@@ -172,11 +175,18 @@ ${TYPES_KINDS.map((kind) => `- \`${kind}\``).join(`
172
175
  schema
173
176
  },
174
177
  create(context) {
175
- const { types, rootField, ignoredSelectors = [], ...restOptions } = context.options[0] || {}, kinds = new Set(types ? TYPES_KINDS : []);
176
- for (const [kind, isEnabled] of Object.entries(restOptions))
177
- isEnabled ? kinds.add(kind) : kinds.delete(kind);
178
+ const { types, rootField, ignoredSelectors = [], ...restOptions } = context.options[0] || {};
179
+ const kinds = new Set(types ? TYPES_KINDS : []);
180
+ for (const [kind, isEnabled] of Object.entries(restOptions)) {
181
+ if (isEnabled) {
182
+ kinds.add(kind);
183
+ } else {
184
+ kinds.delete(kind);
185
+ }
186
+ }
178
187
  if (rootField) {
179
- const schema2 = requireGraphQLSchema(RULE_ID, context), rootTypeNames = getRootTypeNames(schema2);
188
+ const schema2 = requireGraphQLSchema(RULE_ID, context);
189
+ const rootTypeNames = getRootTypeNames(schema2);
180
190
  kinds.add(
181
191
  `:matches(ObjectTypeDefinition, ObjectTypeExtension)[name.value=/^(${[
182
192
  ...rootTypeNames
@@ -184,27 +194,35 @@ ${TYPES_KINDS.map((kind) => `- \`${kind}\``).join(`
184
194
  );
185
195
  }
186
196
  let selector = `:matches(${[...kinds]})`;
187
- for (const str of ignoredSelectors)
197
+ for (const str of ignoredSelectors) {
188
198
  selector += `:not(${str})`;
199
+ }
189
200
  return {
190
201
  [selector](node) {
191
202
  let description = "";
192
203
  const isOperation = node.kind === Kind.OPERATION_DEFINITION;
193
204
  if (isOperation) {
194
- const rawNode = node.rawNode(), { prev, line } = rawNode.loc.startToken;
205
+ const rawNode = node.rawNode();
206
+ const { prev, line } = rawNode.loc.startToken;
195
207
  if (prev?.kind === TokenKind.COMMENT) {
196
- const value = prev.value.trim(), linesBefore = line - prev.line;
197
- !value.startsWith("eslint") && linesBefore === 1 && (description = value);
208
+ const value = prev.value.trim();
209
+ const linesBefore = line - prev.line;
210
+ if (!value.startsWith("eslint") && linesBefore === 1) {
211
+ description = value;
212
+ }
198
213
  }
199
- } else
214
+ } else {
200
215
  description = node.description?.value.trim() || "";
201
- description.length === 0 && context.report({
202
- loc: isOperation ? getLocation(node.loc.start, node.operation) : node.name.loc,
203
- messageId: RULE_ID,
204
- data: {
205
- nodeName: getNodeName(node)
206
- }
207
- });
216
+ }
217
+ if (description.length === 0) {
218
+ context.report({
219
+ loc: isOperation ? getLocation(node.loc.start, node.operation) : node.name.loc,
220
+ messageId: RULE_ID,
221
+ data: {
222
+ nodeName: getNodeName(node)
223
+ }
224
+ });
225
+ }
208
226
  }
209
227
  };
210
228
  }
@@ -1,13 +1,14 @@
1
1
  import { isObjectType } from "graphql";
2
2
  import { getTypeName, requireGraphQLSchema } from "../../utils.js";
3
- const RULE_ID = "require-field-of-type-query-in-mutation-result", rule = {
3
+ const RULE_ID = "require-field-of-type-query-in-mutation-result";
4
+ const rule = {
4
5
  meta: {
5
6
  type: "suggestion",
6
7
  docs: {
7
8
  category: "Schema",
8
9
  description: "Allow the client in one round-trip not only to call mutation but also to get a wagon of data to update their application.\n> Currently, no errors are reported for result type `union`, `interface` and `scalar`.",
9
10
  url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
10
- requiresSchema: !0,
11
+ requiresSchema: true,
11
12
  examples: [
12
13
  {
13
14
  title: "Incorrect",
@@ -47,16 +48,26 @@ const RULE_ID = "require-field-of-type-query-in-mutation-result", rule = {
47
48
  schema: []
48
49
  },
49
50
  create(context) {
50
- const schema = requireGraphQLSchema(RULE_ID, context), mutationType = schema.getMutationType(), queryType = schema.getQueryType();
51
- return !mutationType || !queryType ? {} : {
52
- [`:matches(ObjectTypeDefinition, ObjectTypeExtension)[name.value=${mutationType.name}] > FieldDefinition > .gqlType Name`](node) {
53
- const typeName = node.value, graphQLType = schema.getType(typeName);
51
+ const schema = requireGraphQLSchema(RULE_ID, context);
52
+ const mutationType = schema.getMutationType();
53
+ const queryType = schema.getQueryType();
54
+ if (!mutationType || !queryType) {
55
+ return {};
56
+ }
57
+ const selector = `:matches(ObjectTypeDefinition, ObjectTypeExtension)[name.value=${mutationType.name}] > FieldDefinition > .gqlType Name`;
58
+ return {
59
+ [selector](node) {
60
+ const typeName = node.value;
61
+ const graphQLType = schema.getType(typeName);
54
62
  if (isObjectType(graphQLType)) {
55
63
  const { fields } = graphQLType.astNode;
56
- fields?.some((field) => getTypeName(field) === queryType.name) || context.report({
57
- node,
58
- message: `Mutation result type "${graphQLType.name}" must contain field of type "${queryType.name}"`
59
- });
64
+ const hasQueryType = fields?.some((field) => getTypeName(field) === queryType.name);
65
+ if (!hasQueryType) {
66
+ context.report({
67
+ node,
68
+ message: `Mutation result type "${graphQLType.name}" must contain field of type "${queryType.name}"`
69
+ });
70
+ }
60
71
  }
61
72
  }
62
73
  };
@@ -1,6 +1,8 @@
1
1
  import path from "node:path";
2
2
  import { requireGraphQLOperations, slash } from "../../utils.js";
3
- const RULE_ID = "require-import-fragment", SUGGESTION_ID = "add-import-expression", rule = {
3
+ const RULE_ID = "require-import-fragment";
4
+ const SUGGESTION_ID = "add-import-expression";
5
+ const rule = {
4
6
  meta: {
5
7
  type: "suggestion",
6
8
  docs: {
@@ -64,9 +66,9 @@ const RULE_ID = "require-import-fragment", SUGGESTION_ID = "add-import-expressio
64
66
  )
65
67
  }
66
68
  ],
67
- requiresSiblings: !0
69
+ requiresSiblings: true
68
70
  },
69
- hasSuggestions: !0,
71
+ hasSuggestions: true,
70
72
  messages: {
71
73
  [RULE_ID]: 'Expected "{{fragmentName}}" fragment to be imported.',
72
74
  [SUGGESTION_ID]: 'Add import expression for "{{fragmentName}}".'
@@ -74,24 +76,31 @@ const RULE_ID = "require-import-fragment", SUGGESTION_ID = "add-import-expressio
74
76
  schema: []
75
77
  },
76
78
  create(context) {
77
- const comments = context.getSourceCode().getAllComments(), siblings = requireGraphQLOperations(RULE_ID, context), filePath = context.filename;
79
+ const comments = context.getSourceCode().getAllComments();
80
+ const siblings = requireGraphQLOperations(RULE_ID, context);
81
+ const filePath = context.filename;
78
82
  return {
79
83
  "FragmentSpread > .name"(node) {
80
- const fragmentName = node.value, fragmentsFromSiblings = siblings.getFragment(fragmentName);
84
+ const fragmentName = node.value;
85
+ const fragmentsFromSiblings = siblings.getFragment(fragmentName);
81
86
  for (const comment of comments) {
82
- if (comment.type !== "Line" || !new RegExp(
87
+ if (comment.type !== "Line") continue;
88
+ const isPossibleImported = new RegExp(
83
89
  `^\\s*import\\s+(${fragmentName}\\s+from\\s+)?['"]`
84
- ).test(comment.value)) continue;
90
+ ).test(comment.value);
91
+ if (!isPossibleImported) continue;
85
92
  const extractedImportPath = comment.value.match(/(["'])((?:\1|.)*?)\1/)?.[2];
86
93
  if (!extractedImportPath) continue;
87
94
  const importPath = path.join(filePath, "..", extractedImportPath);
88
- if (fragmentsFromSiblings.some(
95
+ const hasInSiblings = fragmentsFromSiblings.some(
89
96
  (source) => source.filePath === importPath
90
- )) return;
97
+ );
98
+ if (hasInSiblings) return;
91
99
  }
92
- if (fragmentsFromSiblings.some(
100
+ const fragmentInSameFile = fragmentsFromSiblings.some(
93
101
  (source) => source.filePath === filePath
94
- )) return;
102
+ );
103
+ if (fragmentInSameFile) return;
95
104
  const suggestedFilePaths = fragmentsFromSiblings.length ? fragmentsFromSiblings.map(
96
105
  (o) => (
97
106
  // Use always forward slash for suggested import path
@@ -1,6 +1,7 @@
1
1
  import { Kind } from "graphql";
2
2
  import { getNodeName } from "../../utils.js";
3
- const RULE_ID = "require-nullable-fields-with-oneof", rule = {
3
+ const RULE_ID = "require-nullable-fields-with-oneof";
4
+ const rule = {
4
5
  meta: {
5
6
  type: "suggestion",
6
7
  docs: {
@@ -42,16 +43,22 @@ const RULE_ID = "require-nullable-fields-with-oneof", rule = {
42
43
  create(context) {
43
44
  return {
44
45
  "Directive[name.value=oneOf]"({ parent }) {
45
- if ([
46
+ const isTypeOrInput = [
46
47
  Kind.OBJECT_TYPE_DEFINITION,
47
48
  Kind.INPUT_OBJECT_TYPE_DEFINITION
48
- ].includes(parent.kind))
49
- for (const field of parent.fields || [])
50
- field.gqlType.kind === Kind.NON_NULL_TYPE && context.report({
49
+ ].includes(parent.kind);
50
+ if (!isTypeOrInput) {
51
+ return;
52
+ }
53
+ for (const field of parent.fields || []) {
54
+ if (field.gqlType.kind === Kind.NON_NULL_TYPE) {
55
+ context.report({
51
56
  node: field.name,
52
57
  messageId: RULE_ID,
53
58
  data: { nodeName: getNodeName(field) }
54
59
  });
60
+ }
61
+ }
55
62
  }
56
63
  };
57
64
  }
@@ -1,14 +1,15 @@
1
1
  import { Kind } from "graphql";
2
2
  import { getNodeName, requireGraphQLSchema } from "../../utils.js";
3
- const RULE_ID = "require-nullable-result-in-root", rule = {
3
+ const RULE_ID = "require-nullable-result-in-root";
4
+ const rule = {
4
5
  meta: {
5
6
  type: "suggestion",
6
- hasSuggestions: !0,
7
+ hasSuggestions: true,
7
8
  docs: {
8
9
  category: "Schema",
9
10
  description: "Require nullable fields in root types.",
10
11
  url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
11
- requiresSchema: !0,
12
+ requiresSchema: true,
12
13
  examples: [
13
14
  {
14
15
  title: "Incorrect",
@@ -42,34 +43,38 @@ const RULE_ID = "require-nullable-result-in-root", rule = {
42
43
  schema: []
43
44
  },
44
45
  create(context) {
45
- const schema = requireGraphQLSchema(RULE_ID, context), rootTypeNames = new Set(
46
+ const schema = requireGraphQLSchema(RULE_ID, context);
47
+ const rootTypeNames = new Set(
46
48
  [schema.getQueryType(), schema.getMutationType()].filter((v) => !!v).map((type) => type.name)
47
- ), sourceCode = context.getSourceCode();
49
+ );
50
+ const sourceCode = context.getSourceCode();
48
51
  return {
49
52
  "ObjectTypeDefinition,ObjectTypeExtension"(node) {
50
- if (rootTypeNames.has(node.name.value))
51
- for (const field of node.fields || []) {
52
- if (field.gqlType.type !== Kind.NON_NULL_TYPE || field.gqlType.gqlType.type !== Kind.NAMED_TYPE)
53
- continue;
54
- const name = field.gqlType.gqlType.name.value, type = schema.getType(name), resultType = type?.astNode ? getNodeName(type.astNode) : type?.name;
55
- context.report({
56
- node: field.gqlType,
57
- messageId: RULE_ID,
58
- data: {
59
- resultType: resultType || "",
60
- rootType: getNodeName(node)
61
- },
62
- suggest: [
63
- {
64
- desc: `Make ${resultType} nullable`,
65
- fix(fixer) {
66
- const text = sourceCode.getText(field.gqlType);
67
- return fixer.replaceText(field.gqlType, text.replace("!", ""));
68
- }
53
+ if (!rootTypeNames.has(node.name.value)) return;
54
+ for (const field of node.fields || []) {
55
+ if (field.gqlType.type !== Kind.NON_NULL_TYPE || field.gqlType.gqlType.type !== Kind.NAMED_TYPE)
56
+ continue;
57
+ const name = field.gqlType.gqlType.name.value;
58
+ const type = schema.getType(name);
59
+ const resultType = type?.astNode ? getNodeName(type.astNode) : type?.name;
60
+ context.report({
61
+ node: field.gqlType,
62
+ messageId: RULE_ID,
63
+ data: {
64
+ resultType: resultType || "",
65
+ rootType: getNodeName(node)
66
+ },
67
+ suggest: [
68
+ {
69
+ desc: `Make ${resultType} nullable`,
70
+ fix(fixer) {
71
+ const text = sourceCode.getText(field.gqlType);
72
+ return fixer.replaceText(field.gqlType, text.replace("!", ""));
69
73
  }
70
- ]
71
- });
72
- }
74
+ }
75
+ ]
76
+ });
77
+ }
73
78
  }
74
79
  };
75
80
  }