@graphql-eslint/eslint-plugin 4.0.0-alpha-20230801163310-8bc4340 → 4.0.0-alpha-20230810155929-e89edf7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (222) hide show
  1. package/README.md +2 -0
  2. package/cjs/cache.js +10 -19
  3. package/cjs/configs/index.d.ts +42 -16
  4. package/cjs/configs/index.js +10 -19
  5. package/cjs/configs/operations-all.d.ts +4 -3
  6. package/cjs/configs/operations-all.js +5 -4
  7. package/cjs/configs/operations-recommended.d.ts +3 -1
  8. package/cjs/configs/operations-recommended.js +3 -1
  9. package/cjs/configs/schema-all.d.ts +6 -1
  10. package/cjs/configs/schema-all.js +5 -2
  11. package/cjs/configs/schema-recommended.d.ts +19 -1
  12. package/cjs/configs/schema-recommended.js +22 -2
  13. package/cjs/documents.js +17 -32
  14. package/cjs/estree-converter/converter.js +14 -27
  15. package/cjs/estree-converter/index.js +4 -7
  16. package/cjs/estree-converter/types.js +3 -5
  17. package/cjs/estree-converter/utils.d.ts +2 -3
  18. package/cjs/estree-converter/utils.js +15 -45
  19. package/cjs/flat-configs.d.ts +59 -12
  20. package/cjs/flat-configs.js +9 -14
  21. package/cjs/graphql-config.d.ts +4 -3
  22. package/cjs/graphql-config.js +23 -44
  23. package/cjs/index.d.ts +10 -4
  24. package/cjs/index.js +8 -16
  25. package/cjs/parser.d.ts +4 -3
  26. package/cjs/parser.js +38 -45
  27. package/cjs/processor.d.ts +5 -1
  28. package/cjs/processor.js +25 -57
  29. package/cjs/rules/alphabetize.d.ts +6 -16
  30. package/cjs/rules/alphabetize.js +60 -132
  31. package/cjs/rules/description-style.d.ts +4 -3
  32. package/cjs/rules/description-style.js +11 -18
  33. package/cjs/rules/graphql-js-validation.d.ts +4 -3
  34. package/cjs/rules/graphql-js-validation.js +151 -225
  35. package/cjs/rules/index.d.ts +15 -13
  36. package/cjs/rules/index.js +8 -45
  37. package/cjs/rules/input-name.d.ts +4 -3
  38. package/cjs/rules/input-name.js +43 -59
  39. package/cjs/rules/lone-executable-definition.d.ts +6 -5
  40. package/cjs/rules/lone-executable-definition.js +14 -28
  41. package/cjs/rules/match-document-filename.d.ts +4 -3
  42. package/cjs/rules/match-document-filename.js +39 -70
  43. package/cjs/rules/naming-convention.d.ts +4 -3
  44. package/cjs/rules/naming-convention.js +56 -74
  45. package/cjs/rules/no-anonymous-operations.d.ts +4 -3
  46. package/cjs/rules/no-anonymous-operations.js +11 -18
  47. package/cjs/rules/no-deprecated.d.ts +4 -3
  48. package/cjs/rules/no-deprecated.js +15 -29
  49. package/cjs/rules/no-duplicate-fields.d.ts +4 -3
  50. package/cjs/rules/no-duplicate-fields.js +13 -23
  51. package/cjs/rules/no-hashtag-description.d.ts +4 -3
  52. package/cjs/rules/no-hashtag-description.js +16 -29
  53. package/cjs/rules/no-one-place-fragments.d.ts +4 -3
  54. package/cjs/rules/no-one-place-fragments.js +17 -29
  55. package/cjs/rules/no-root-type.d.ts +4 -3
  56. package/cjs/rules/no-root-type.js +15 -25
  57. package/cjs/rules/no-scalar-result-type-on-mutation.d.ts +4 -3
  58. package/cjs/rules/no-scalar-result-type-on-mutation.js +18 -30
  59. package/cjs/rules/no-typename-prefix.d.ts +4 -3
  60. package/cjs/rules/no-typename-prefix.js +26 -33
  61. package/cjs/rules/no-unreachable-types.d.ts +4 -3
  62. package/cjs/rules/no-unreachable-types.js +25 -47
  63. package/cjs/rules/no-unused-fields.d.ts +4 -3
  64. package/cjs/rules/no-unused-fields.js +24 -49
  65. package/cjs/rules/relay-arguments.d.ts +4 -3
  66. package/cjs/rules/relay-arguments.js +20 -43
  67. package/cjs/rules/relay-connection-types.d.ts +4 -3
  68. package/cjs/rules/relay-connection-types.js +14 -45
  69. package/cjs/rules/relay-edge-types.d.ts +4 -3
  70. package/cjs/rules/relay-edge-types.js +48 -99
  71. package/cjs/rules/relay-page-info.d.ts +4 -3
  72. package/cjs/rules/relay-page-info.js +21 -44
  73. package/cjs/rules/require-deprecation-date.d.ts +4 -3
  74. package/cjs/rules/require-deprecation-date.js +15 -31
  75. package/cjs/rules/require-deprecation-reason.d.ts +4 -3
  76. package/cjs/rules/require-deprecation-reason.js +12 -20
  77. package/cjs/rules/require-description.d.ts +4 -3
  78. package/cjs/rules/require-description.js +39 -65
  79. package/cjs/rules/require-field-of-type-query-in-mutation-result.d.ts +4 -3
  80. package/cjs/rules/require-field-of-type-query-in-mutation-result.js +16 -31
  81. package/cjs/rules/require-import-fragment.d.ts +4 -3
  82. package/cjs/rules/require-import-fragment.js +22 -40
  83. package/cjs/rules/require-nullable-fields-with-oneof.d.ts +4 -3
  84. package/cjs/rules/require-nullable-fields-with-oneof.js +11 -22
  85. package/cjs/rules/require-nullable-result-in-root.d.ts +4 -3
  86. package/cjs/rules/require-nullable-result-in-root.js +34 -44
  87. package/cjs/rules/{require-id-when-available.d.ts → require-selections.d.ts} +4 -3
  88. package/cjs/rules/require-selections.js +198 -0
  89. package/cjs/rules/require-type-pattern-with-oneof.d.ts +4 -3
  90. package/cjs/rules/require-type-pattern-with-oneof.js +15 -23
  91. package/cjs/rules/selection-set-depth.d.ts +4 -3
  92. package/cjs/rules/selection-set-depth.js +18 -34
  93. package/cjs/rules/strict-id-in-types.d.ts +4 -3
  94. package/cjs/rules/strict-id-in-types.js +25 -43
  95. package/cjs/rules/{no-case-insensitive-enum-values-duplicates.d.ts → unique-enum-value-names.d.ts} +4 -3
  96. package/cjs/rules/{no-case-insensitive-enum-values-duplicates.js → unique-enum-value-names.js} +16 -21
  97. package/cjs/rules/unique-fragment-name.d.ts +3 -2
  98. package/cjs/rules/unique-fragment-name.js +24 -36
  99. package/cjs/rules/unique-operation-name.d.ts +4 -3
  100. package/cjs/rules/unique-operation-name.js +10 -12
  101. package/cjs/schema.d.ts +4 -3
  102. package/cjs/schema.js +14 -27
  103. package/cjs/siblings.d.ts +24 -8
  104. package/cjs/siblings.js +42 -82
  105. package/cjs/types.d.ts +74 -7
  106. package/cjs/types.js +3 -5
  107. package/cjs/utils.d.ts +3 -2
  108. package/cjs/utils.js +27 -44
  109. package/esm/cache.js +4 -8
  110. package/esm/{chunk-BMTV3EA2.js → chunk-U3TKCM4X.js} +1 -1
  111. package/esm/configs/index.d.mts +42 -16
  112. package/esm/configs/index.js +4 -4
  113. package/esm/configs/operations-all.d.mts +4 -3
  114. package/esm/configs/operations-all.js +6 -5
  115. package/esm/configs/operations-recommended.d.mts +3 -1
  116. package/esm/configs/operations-recommended.js +4 -2
  117. package/esm/configs/schema-all.d.mts +6 -1
  118. package/esm/configs/schema-all.js +6 -3
  119. package/esm/configs/schema-recommended.d.mts +19 -1
  120. package/esm/configs/schema-recommended.js +23 -3
  121. package/esm/configs/{relay.js → schema-relay.js} +4 -4
  122. package/esm/documents.js +10 -17
  123. package/esm/estree-converter/converter.js +9 -18
  124. package/esm/estree-converter/utils.d.mts +2 -3
  125. package/esm/estree-converter/utils.js +11 -38
  126. package/esm/flat-configs.d.mts +59 -12
  127. package/esm/flat-configs.js +4 -5
  128. package/esm/graphql-config.d.mts +4 -3
  129. package/esm/graphql-config.js +18 -34
  130. package/esm/index.d.mts +10 -4
  131. package/esm/index.js +1 -1
  132. package/esm/parser.d.mts +4 -3
  133. package/esm/parser.js +33 -27
  134. package/esm/processor.d.mts +5 -1
  135. package/esm/processor.js +21 -46
  136. package/esm/rules/alphabetize.d.mts +6 -16
  137. package/esm/rules/alphabetize.js +53 -118
  138. package/esm/rules/description-style.d.mts +4 -3
  139. package/esm/rules/description-style.js +7 -11
  140. package/esm/rules/graphql-js-validation.d.mts +4 -3
  141. package/esm/rules/graphql-js-validation.js +178 -218
  142. package/esm/rules/index.d.mts +15 -13
  143. package/esm/rules/index.js +5 -5
  144. package/esm/rules/input-name.d.mts +4 -3
  145. package/esm/rules/input-name.js +39 -52
  146. package/esm/rules/lone-executable-definition.d.mts +6 -5
  147. package/esm/rules/lone-executable-definition.js +10 -20
  148. package/esm/rules/match-document-filename.d.mts +4 -3
  149. package/esm/rules/match-document-filename.js +35 -61
  150. package/esm/rules/naming-convention.d.mts +4 -3
  151. package/esm/rules/naming-convention.js +51 -65
  152. package/esm/rules/no-anonymous-operations.d.mts +4 -3
  153. package/esm/rules/no-anonymous-operations.js +6 -9
  154. package/esm/rules/no-deprecated.d.mts +4 -3
  155. package/esm/rules/no-deprecated.js +10 -20
  156. package/esm/rules/no-duplicate-fields.d.mts +4 -3
  157. package/esm/rules/no-duplicate-fields.js +9 -16
  158. package/esm/rules/no-hashtag-description.d.mts +4 -3
  159. package/esm/rules/no-hashtag-description.js +11 -20
  160. package/esm/rules/no-one-place-fragments.d.mts +4 -3
  161. package/esm/rules/no-one-place-fragments.js +12 -19
  162. package/esm/rules/no-root-type.d.mts +4 -3
  163. package/esm/rules/no-root-type.js +11 -18
  164. package/esm/rules/no-scalar-result-type-on-mutation.d.mts +4 -3
  165. package/esm/rules/no-scalar-result-type-on-mutation.js +13 -21
  166. package/esm/rules/no-typename-prefix.d.mts +4 -3
  167. package/esm/rules/no-typename-prefix.js +22 -26
  168. package/esm/rules/no-unreachable-types.d.mts +4 -3
  169. package/esm/rules/no-unreachable-types.js +18 -33
  170. package/esm/rules/no-unused-fields.d.mts +4 -3
  171. package/esm/rules/no-unused-fields.js +19 -40
  172. package/esm/rules/relay-arguments.d.mts +4 -3
  173. package/esm/rules/relay-arguments.js +15 -34
  174. package/esm/rules/relay-connection-types.d.mts +4 -3
  175. package/esm/rules/relay-connection-types.js +10 -38
  176. package/esm/rules/relay-edge-types.d.mts +4 -3
  177. package/esm/rules/relay-edge-types.js +43 -89
  178. package/esm/rules/relay-page-info.d.mts +4 -3
  179. package/esm/rules/relay-page-info.js +16 -34
  180. package/esm/rules/require-deprecation-date.d.mts +4 -3
  181. package/esm/rules/require-deprecation-date.js +10 -22
  182. package/esm/rules/require-deprecation-reason.d.mts +4 -3
  183. package/esm/rules/require-deprecation-reason.js +7 -11
  184. package/esm/rules/require-description.d.mts +4 -3
  185. package/esm/rules/require-description.js +34 -55
  186. package/esm/rules/require-field-of-type-query-in-mutation-result.d.mts +4 -3
  187. package/esm/rules/require-field-of-type-query-in-mutation-result.js +11 -22
  188. package/esm/rules/require-import-fragment.d.mts +4 -3
  189. package/esm/rules/require-import-fragment.js +14 -26
  190. package/esm/rules/require-nullable-fields-with-oneof.d.mts +4 -3
  191. package/esm/rules/require-nullable-fields-with-oneof.js +6 -13
  192. package/esm/rules/require-nullable-result-in-root.d.mts +4 -3
  193. package/esm/rules/require-nullable-result-in-root.js +29 -35
  194. package/esm/rules/{require-id-when-available.d.mts → require-selections.d.mts} +4 -3
  195. package/esm/rules/{require-id-when-available.js → require-selections.js} +43 -80
  196. package/esm/rules/require-type-pattern-with-oneof.d.mts +4 -3
  197. package/esm/rules/require-type-pattern-with-oneof.js +11 -16
  198. package/esm/rules/selection-set-depth.d.mts +4 -3
  199. package/esm/rules/selection-set-depth.js +11 -20
  200. package/esm/rules/strict-id-in-types.d.mts +4 -3
  201. package/esm/rules/strict-id-in-types.js +20 -34
  202. package/esm/rules/{no-case-insensitive-enum-values-duplicates.d.mts → unique-enum-value-names.d.mts} +4 -3
  203. package/esm/rules/{no-case-insensitive-enum-values-duplicates.js → unique-enum-value-names.js} +8 -9
  204. package/esm/rules/unique-fragment-name.d.mts +3 -2
  205. package/esm/rules/unique-fragment-name.js +20 -27
  206. package/esm/rules/unique-operation-name.d.mts +4 -3
  207. package/esm/rules/unique-operation-name.js +6 -5
  208. package/esm/schema.d.mts +4 -3
  209. package/esm/schema.js +7 -12
  210. package/esm/siblings.d.mts +24 -8
  211. package/esm/siblings.js +37 -73
  212. package/esm/types.d.mts +74 -7
  213. package/esm/utils.d.mts +3 -2
  214. package/esm/utils.js +20 -31
  215. package/index.browser.mjs +5323 -0
  216. package/package.json +8 -13
  217. package/cjs/rules/require-id-when-available.js +0 -241
  218. package/cjs/types-8d5f4ae0.d.ts +0 -107
  219. package/esm/types-ace77d86.d.ts +0 -107
  220. /package/cjs/configs/{relay.d.ts → schema-relay.d.ts} +0 -0
  221. /package/cjs/configs/{relay.js → schema-relay.js} +0 -0
  222. /package/esm/configs/{relay.d.mts → schema-relay.d.mts} +0 -0
@@ -1,4 +1,4 @@
1
- import "../chunk-BMTV3EA2.js";
1
+ import "../chunk-U3TKCM4X.js";
2
2
  import { getRootTypeNames } from "@graphql-tools/utils";
3
3
  import { Kind, TokenKind } from "graphql";
4
4
  import {
@@ -7,28 +7,27 @@ import {
7
7
  requireGraphQLSchemaFromContext,
8
8
  TYPES_KINDS
9
9
  } from "../utils.js";
10
- const RULE_ID = "require-description";
11
- const ALLOWED_KINDS = [
10
+ const RULE_ID = "require-description", ALLOWED_KINDS = [
12
11
  ...TYPES_KINDS,
13
12
  Kind.DIRECTIVE_DEFINITION,
14
13
  Kind.FIELD_DEFINITION,
15
14
  Kind.INPUT_VALUE_DEFINITION,
16
15
  Kind.ENUM_VALUE_DEFINITION,
17
16
  Kind.OPERATION_DEFINITION
18
- ];
19
- const schema = {
17
+ ], schema = {
20
18
  type: "array",
21
19
  minItems: 1,
22
20
  maxItems: 1,
23
21
  items: {
24
22
  type: "object",
25
- additionalProperties: false,
23
+ additionalProperties: !1,
26
24
  minProperties: 1,
27
25
  properties: {
28
26
  types: {
29
27
  type: "boolean",
30
28
  description: `Includes:
31
- ${TYPES_KINDS.map((kind) => `- \`${kind}\``).join("\n")}`
29
+ ${TYPES_KINDS.map((kind) => `- \`${kind}\``).join(`
30
+ `)}`
32
31
  },
33
32
  rootField: {
34
33
  type: "boolean",
@@ -37,16 +36,12 @@ ${TYPES_KINDS.map((kind) => `- \`${kind}\``).join("\n")}`
37
36
  ...Object.fromEntries(
38
37
  [...ALLOWED_KINDS].sort().map((kind) => {
39
38
  let description = `Read more about this kind on [spec.graphql.org](https://spec.graphql.org/October2021/#${kind}).`;
40
- if (kind === Kind.OPERATION_DEFINITION) {
41
- description += '\n> You must use only comment syntax `#` and not description syntax `"""` or `"`.';
42
- }
43
- return [kind, { type: "boolean", description }];
39
+ return kind === Kind.OPERATION_DEFINITION && (description += '\n> You must use only comment syntax `#` and not description syntax `"""` or `"`.'), [kind, { type: "boolean", description }];
44
40
  })
45
41
  )
46
42
  }
47
43
  }
48
- };
49
- const rule = {
44
+ }, rule = {
50
45
  meta: {
51
46
  docs: {
52
47
  category: "Schema",
@@ -55,7 +50,7 @@ const rule = {
55
50
  examples: [
56
51
  {
57
52
  title: "Incorrect",
58
- usage: [{ types: true, FieldDefinition: true }],
53
+ usage: [{ types: !0, FieldDefinition: !0 }],
59
54
  code: (
60
55
  /* GraphQL */
61
56
  `
@@ -67,7 +62,7 @@ const rule = {
67
62
  },
68
63
  {
69
64
  title: "Correct",
70
- usage: [{ types: true, FieldDefinition: true }],
65
+ usage: [{ types: !0, FieldDefinition: !0 }],
71
66
  code: (
72
67
  /* GraphQL */
73
68
  `
@@ -85,7 +80,7 @@ const rule = {
85
80
  },
86
81
  {
87
82
  title: "Correct",
88
- usage: [{ OperationDefinition: true }],
83
+ usage: [{ OperationDefinition: !0 }],
89
84
  code: (
90
85
  /* GraphQL */
91
86
  `
@@ -98,7 +93,7 @@ const rule = {
98
93
  },
99
94
  {
100
95
  title: "Correct",
101
- usage: [{ rootField: true }],
96
+ usage: [{ rootField: !0 }],
102
97
  code: (
103
98
  /* GraphQL */
104
99
  `
@@ -116,12 +111,12 @@ const rule = {
116
111
  ],
117
112
  configOptions: [
118
113
  {
119
- types: true,
120
- [Kind.DIRECTIVE_DEFINITION]: true
121
- // rootField: true TODO enable in graphql-eslint v4
114
+ types: !0,
115
+ [Kind.DIRECTIVE_DEFINITION]: !0,
116
+ rootField: !0
122
117
  }
123
118
  ],
124
- recommended: true
119
+ recommended: !0
125
120
  },
126
121
  type: "suggestion",
127
122
  messages: {
@@ -130,52 +125,36 @@ const rule = {
130
125
  schema
131
126
  },
132
127
  create(context) {
133
- const { types, rootField, ...restOptions } = context.options[0] || {};
134
- const kinds = new Set(types ? TYPES_KINDS : []);
135
- for (const [kind, isEnabled] of Object.entries(restOptions)) {
136
- if (isEnabled) {
137
- kinds.add(kind);
138
- } else {
139
- kinds.delete(kind);
140
- }
141
- }
128
+ const { types, rootField, ...restOptions } = context.options[0] || {}, kinds = new Set(types ? TYPES_KINDS : []);
129
+ for (const [kind, isEnabled] of Object.entries(restOptions))
130
+ isEnabled ? kinds.add(kind) : kinds.delete(kind);
142
131
  if (rootField) {
143
- const schema2 = requireGraphQLSchemaFromContext(RULE_ID, context);
144
- const rootTypeNames = getRootTypeNames(schema2);
132
+ const schema2 = requireGraphQLSchemaFromContext(RULE_ID, context), rootTypeNames = getRootTypeNames(schema2);
145
133
  kinds.add(
146
134
  `:matches(ObjectTypeDefinition, ObjectTypeExtension)[name.value=/^(${[
147
135
  ...rootTypeNames
148
136
  ].join(",")})$/] > FieldDefinition`
149
137
  );
150
138
  }
151
- const selector = [...kinds].join(",");
152
139
  return {
153
- [selector](node) {
154
- var _a;
140
+ [[...kinds].join(",")](node) {
155
141
  let description = "";
156
142
  const isOperation = node.kind === Kind.OPERATION_DEFINITION;
157
143
  if (isOperation) {
158
- const rawNode = node.rawNode();
159
- const { prev, line } = rawNode.loc.startToken;
160
- if ((prev == null ? void 0 : prev.kind) === TokenKind.COMMENT) {
161
- const value = prev.value.trim();
162
- const linesBefore = line - prev.line;
163
- if (!value.startsWith("eslint") && linesBefore === 1) {
164
- description = value;
165
- }
144
+ const rawNode = node.rawNode(), { prev, line } = rawNode.loc.startToken;
145
+ if (prev?.kind === TokenKind.COMMENT) {
146
+ const value = prev.value.trim(), linesBefore = line - prev.line;
147
+ !value.startsWith("eslint") && linesBefore === 1 && (description = value);
166
148
  }
167
- } else {
168
- description = ((_a = node.description) == null ? void 0 : _a.value.trim()) || "";
169
- }
170
- if (description.length === 0) {
171
- context.report({
172
- loc: isOperation ? getLocation(node.loc.start, node.operation) : node.name.loc,
173
- messageId: RULE_ID,
174
- data: {
175
- nodeName: getNodeName(node)
176
- }
177
- });
178
- }
149
+ } else
150
+ description = node.description?.value.trim() || "";
151
+ description.length === 0 && context.report({
152
+ loc: isOperation ? getLocation(node.loc.start, node.operation) : node.name.loc,
153
+ messageId: RULE_ID,
154
+ data: {
155
+ nodeName: getNodeName(node)
156
+ }
157
+ });
179
158
  }
180
159
  };
181
160
  }
@@ -1,11 +1,12 @@
1
- import { f as GraphQLESLintRule } from '../types-ace77d86.js';
2
- import '@graphql-tools/utils';
1
+ import { GraphQLESLintRule } from '../types.mjs';
3
2
  import 'eslint';
4
3
  import 'estree';
5
4
  import 'graphql';
6
- import 'graphql-config';
7
5
  import 'json-schema-to-ts';
6
+ import '../siblings.mjs';
7
+ import '@graphql-tools/utils';
8
8
  import '../estree-converter/types.mjs';
9
+ import 'graphql-config';
9
10
 
10
11
  declare const rule: GraphQLESLintRule;
11
12
 
@@ -1,15 +1,14 @@
1
- import "../chunk-BMTV3EA2.js";
1
+ import "../chunk-U3TKCM4X.js";
2
2
  import { isObjectType } from "graphql";
3
3
  import { getTypeName, requireGraphQLSchemaFromContext } from "../utils.js";
4
- const RULE_ID = "require-field-of-type-query-in-mutation-result";
5
- const rule = {
4
+ const RULE_ID = "require-field-of-type-query-in-mutation-result", rule = {
6
5
  meta: {
7
6
  type: "suggestion",
8
7
  docs: {
9
8
  category: "Schema",
10
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`.",
11
10
  url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
12
- requiresSchema: true,
11
+ requiresSchema: !0,
13
12
  examples: [
14
13
  {
15
14
  title: "Incorrect",
@@ -49,26 +48,16 @@ const rule = {
49
48
  schema: []
50
49
  },
51
50
  create(context) {
52
- const schema = requireGraphQLSchemaFromContext(RULE_ID, context);
53
- const mutationType = schema.getMutationType();
54
- const queryType = schema.getQueryType();
55
- if (!mutationType || !queryType) {
56
- return {};
57
- }
58
- const selector = `:matches(ObjectTypeDefinition, ObjectTypeExtension)[name.value=${mutationType.name}] > FieldDefinition > .gqlType Name`;
59
- return {
60
- [selector](node) {
61
- const typeName = node.value;
62
- const graphQLType = schema.getType(typeName);
51
+ const schema = requireGraphQLSchemaFromContext(RULE_ID, context), mutationType = schema.getMutationType(), queryType = schema.getQueryType();
52
+ return !mutationType || !queryType ? {} : {
53
+ [`:matches(ObjectTypeDefinition, ObjectTypeExtension)[name.value=${mutationType.name}] > FieldDefinition > .gqlType Name`](node) {
54
+ const typeName = node.value, graphQLType = schema.getType(typeName);
63
55
  if (isObjectType(graphQLType)) {
64
56
  const { fields } = graphQLType.astNode;
65
- const hasQueryType = fields == null ? void 0 : fields.some((field) => getTypeName(field) === queryType.name);
66
- if (!hasQueryType) {
67
- context.report({
68
- node,
69
- message: `Mutation result type "${graphQLType.name}" must contain field of type "${queryType.name}"`
70
- });
71
- }
57
+ fields?.some((field) => getTypeName(field) === queryType.name) || context.report({
58
+ node,
59
+ message: `Mutation result type "${graphQLType.name}" must contain field of type "${queryType.name}"`
60
+ });
72
61
  }
73
62
  }
74
63
  };
@@ -1,11 +1,12 @@
1
- import { f as GraphQLESLintRule } from '../types-ace77d86.js';
2
- import '@graphql-tools/utils';
1
+ import { GraphQLESLintRule } from '../types.mjs';
3
2
  import 'eslint';
4
3
  import 'estree';
5
4
  import 'graphql';
6
- import 'graphql-config';
7
5
  import 'json-schema-to-ts';
6
+ import '../siblings.mjs';
7
+ import '@graphql-tools/utils';
8
8
  import '../estree-converter/types.mjs';
9
+ import 'graphql-config';
9
10
 
10
11
  declare const rule: GraphQLESLintRule;
11
12
 
@@ -1,9 +1,7 @@
1
- import "../chunk-BMTV3EA2.js";
2
- import path from "path";
1
+ import "../chunk-U3TKCM4X.js";
2
+ import path from "node:path";
3
3
  import { requireSiblingsOperations } from "../utils.js";
4
- const RULE_ID = "require-import-fragment";
5
- const SUGGESTION_ID = "add-import-expression";
6
- const rule = {
4
+ const RULE_ID = "require-import-fragment", SUGGESTION_ID = "add-import-expression", rule = {
7
5
  meta: {
8
6
  type: "suggestion",
9
7
  docs: {
@@ -67,10 +65,9 @@ const rule = {
67
65
  )
68
66
  }
69
67
  ],
70
- requiresSiblings: true,
71
- isDisabledForAllConfig: true
68
+ requiresSiblings: !0
72
69
  },
73
- hasSuggestions: true,
70
+ hasSuggestions: !0,
74
71
  messages: {
75
72
  [RULE_ID]: 'Expected "{{fragmentName}}" fragment to be imported.',
76
73
  [SUGGESTION_ID]: 'Add import expression for "{{fragmentName}}".'
@@ -78,36 +75,27 @@ const rule = {
78
75
  schema: []
79
76
  },
80
77
  create(context) {
81
- const comments = context.getSourceCode().getAllComments();
82
- const siblings = requireSiblingsOperations(RULE_ID, context);
83
- const filePath = context.getFilename();
78
+ const comments = context.getSourceCode().getAllComments(), siblings = requireSiblingsOperations(RULE_ID, context), filePath = context.filename;
84
79
  return {
85
80
  "FragmentSpread > .name"(node) {
86
- var _a;
87
- const fragmentName = node.value;
88
- const fragmentsFromSiblings = siblings.getFragment(fragmentName);
81
+ const fragmentName = node.value, fragmentsFromSiblings = siblings.getFragment(fragmentName);
89
82
  for (const comment of comments) {
90
- if (comment.type !== "Line")
91
- continue;
92
- const isPossibleImported = new RegExp(
83
+ if (comment.type !== "Line" || !new RegExp(
93
84
  `^\\s*import\\s+(${fragmentName}\\s+from\\s+)?['"]`
94
- ).test(comment.value);
95
- if (!isPossibleImported)
85
+ ).test(comment.value))
96
86
  continue;
97
- const extractedImportPath = (_a = comment.value.match(/(["'])((?:\1|.)*?)\1/)) == null ? void 0 : _a[2];
87
+ const extractedImportPath = comment.value.match(/(["'])((?:\1|.)*?)\1/)?.[2];
98
88
  if (!extractedImportPath)
99
89
  continue;
100
90
  const importPath = path.join(path.dirname(filePath), extractedImportPath);
101
- const hasInSiblings = fragmentsFromSiblings.some(
91
+ if (fragmentsFromSiblings.some(
102
92
  (source) => source.filePath === importPath
103
- );
104
- if (hasInSiblings)
93
+ ))
105
94
  return;
106
95
  }
107
- const fragmentInSameFile = fragmentsFromSiblings.some(
96
+ if (fragmentsFromSiblings.some(
108
97
  (source) => source.filePath === filePath
109
- );
110
- if (fragmentInSameFile)
98
+ ))
111
99
  return;
112
100
  const suggestedFilePaths = fragmentsFromSiblings.length ? fragmentsFromSiblings.map((o) => path.relative(path.dirname(filePath), o.filePath)) : ["CHANGE_ME.graphql"];
113
101
  context.report({
@@ -1,11 +1,12 @@
1
- import { f as GraphQLESLintRule } from '../types-ace77d86.js';
2
- import '@graphql-tools/utils';
1
+ import { GraphQLESLintRule } from '../types.mjs';
3
2
  import 'eslint';
4
3
  import 'estree';
5
4
  import 'graphql';
6
- import 'graphql-config';
7
5
  import 'json-schema-to-ts';
6
+ import '../siblings.mjs';
7
+ import '@graphql-tools/utils';
8
8
  import '../estree-converter/types.mjs';
9
+ import 'graphql-config';
9
10
 
10
11
  declare const rule: GraphQLESLintRule;
11
12
 
@@ -1,8 +1,7 @@
1
- import "../chunk-BMTV3EA2.js";
1
+ import "../chunk-U3TKCM4X.js";
2
2
  import { Kind } from "graphql";
3
3
  import { getNodeName } from "../utils.js";
4
- const RULE_ID = "require-nullable-fields-with-oneof";
5
- const rule = {
4
+ const RULE_ID = "require-nullable-fields-with-oneof", rule = {
6
5
  meta: {
7
6
  type: "suggestion",
8
7
  docs: {
@@ -44,22 +43,16 @@ const rule = {
44
43
  create(context) {
45
44
  return {
46
45
  "Directive[name.value=oneOf]"({ parent }) {
47
- const isTypeOrInput = [
46
+ if ([
48
47
  Kind.OBJECT_TYPE_DEFINITION,
49
48
  Kind.INPUT_OBJECT_TYPE_DEFINITION
50
- ].includes(parent.kind);
51
- if (!isTypeOrInput) {
52
- return;
53
- }
54
- for (const field of parent.fields || []) {
55
- if (field.gqlType.kind === Kind.NON_NULL_TYPE) {
56
- context.report({
49
+ ].includes(parent.kind))
50
+ for (const field of parent.fields || [])
51
+ field.gqlType.kind === Kind.NON_NULL_TYPE && context.report({
57
52
  node: field.name,
58
53
  messageId: RULE_ID,
59
54
  data: { nodeName: getNodeName(field) }
60
55
  });
61
- }
62
- }
63
56
  }
64
57
  };
65
58
  }
@@ -1,11 +1,12 @@
1
- import { f as GraphQLESLintRule } from '../types-ace77d86.js';
2
- import '@graphql-tools/utils';
1
+ import { GraphQLESLintRule } from '../types.mjs';
3
2
  import 'eslint';
4
3
  import 'estree';
5
4
  import 'graphql';
6
- import 'graphql-config';
7
5
  import 'json-schema-to-ts';
6
+ import '../siblings.mjs';
7
+ import '@graphql-tools/utils';
8
8
  import '../estree-converter/types.mjs';
9
+ import 'graphql-config';
9
10
 
10
11
  declare const rule: GraphQLESLintRule;
11
12
 
@@ -1,16 +1,15 @@
1
- import "../chunk-BMTV3EA2.js";
1
+ import "../chunk-U3TKCM4X.js";
2
2
  import { Kind } from "graphql";
3
3
  import { getNodeName, requireGraphQLSchemaFromContext, truthy } from "../utils.js";
4
- const RULE_ID = "require-nullable-result-in-root";
5
- const rule = {
4
+ const RULE_ID = "require-nullable-result-in-root", rule = {
6
5
  meta: {
7
6
  type: "suggestion",
8
- hasSuggestions: true,
7
+ hasSuggestions: !0,
9
8
  docs: {
10
9
  category: "Schema",
11
10
  description: "Require nullable fields in root types.",
12
11
  url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
13
- requiresSchema: true,
12
+ requiresSchema: !0,
14
13
  examples: [
15
14
  {
16
15
  title: "Incorrect",
@@ -44,39 +43,34 @@ const rule = {
44
43
  schema: []
45
44
  },
46
45
  create(context) {
47
- const schema = requireGraphQLSchemaFromContext(RULE_ID, context);
48
- const rootTypeNames = new Set(
49
- [schema.getQueryType(), schema.getMutationType(), schema.getSubscriptionType()].filter(truthy).map((type) => type.name)
50
- );
51
- const sourceCode = context.getSourceCode();
46
+ const schema = requireGraphQLSchemaFromContext(RULE_ID, context), rootTypeNames = new Set(
47
+ [schema.getQueryType(), schema.getMutationType()].filter(truthy).map((type) => type.name)
48
+ ), sourceCode = context.getSourceCode();
52
49
  return {
53
50
  "ObjectTypeDefinition,ObjectTypeExtension"(node) {
54
- if (!rootTypeNames.has(node.name.value))
55
- return;
56
- for (const field of node.fields || []) {
57
- if (field.gqlType.type !== Kind.NON_NULL_TYPE || field.gqlType.gqlType.type !== Kind.NAMED_TYPE)
58
- continue;
59
- const name = field.gqlType.gqlType.name.value;
60
- const type = schema.getType(name);
61
- const resultType = (type == null ? void 0 : type.astNode) ? getNodeName(type.astNode) : type == null ? void 0 : type.name;
62
- context.report({
63
- node: field.gqlType,
64
- messageId: RULE_ID,
65
- data: {
66
- resultType: resultType || "",
67
- rootType: getNodeName(node)
68
- },
69
- suggest: [
70
- {
71
- desc: `Make ${resultType} nullable`,
72
- fix(fixer) {
73
- const text = sourceCode.getText(field.gqlType);
74
- return fixer.replaceText(field.gqlType, text.replace("!", ""));
51
+ if (rootTypeNames.has(node.name.value))
52
+ for (const field of node.fields || []) {
53
+ if (field.gqlType.type !== Kind.NON_NULL_TYPE || field.gqlType.gqlType.type !== Kind.NAMED_TYPE)
54
+ continue;
55
+ const name = field.gqlType.gqlType.name.value, type = schema.getType(name), resultType = type?.astNode ? getNodeName(type.astNode) : type?.name;
56
+ context.report({
57
+ node: field.gqlType,
58
+ messageId: RULE_ID,
59
+ data: {
60
+ resultType: resultType || "",
61
+ rootType: getNodeName(node)
62
+ },
63
+ suggest: [
64
+ {
65
+ desc: `Make ${resultType} nullable`,
66
+ fix(fixer) {
67
+ const text = sourceCode.getText(field.gqlType);
68
+ return fixer.replaceText(field.gqlType, text.replace("!", ""));
69
+ }
75
70
  }
76
- }
77
- ]
78
- });
79
- }
71
+ ]
72
+ });
73
+ }
80
74
  }
81
75
  };
82
76
  }
@@ -1,11 +1,12 @@
1
1
  import { FromSchema } from 'json-schema-to-ts';
2
- import { f as GraphQLESLintRule } from '../types-ace77d86.js';
3
- import '@graphql-tools/utils';
2
+ import { GraphQLESLintRule } from '../types.mjs';
4
3
  import 'eslint';
5
4
  import 'estree';
6
5
  import 'graphql';
7
- import 'graphql-config';
6
+ import '../siblings.mjs';
7
+ import '@graphql-tools/utils';
8
8
  import '../estree-converter/types.mjs';
9
+ import 'graphql-config';
9
10
 
10
11
  declare const schema: {
11
12
  readonly definitions: {