@graphql-eslint/eslint-plugin 3.19.3-alpha-20230702093957-98f7783 → 3.20.0-alpha-20230703154330-0d51273

Sign up to get free protection for your applications and to get access to all the features.
Files changed (302) hide show
  1. package/{typings → cjs}/cache.d.ts +3 -1
  2. package/cjs/cache.js +57 -26
  3. package/{typings → cjs}/configs/index.d.ts +3 -1
  4. package/cjs/configs/index.js +47 -14
  5. package/{typings → cjs}/configs/operations-all.d.ts +2 -1
  6. package/cjs/configs/operations-all.js +47 -30
  7. package/{typings → cjs}/configs/operations-recommended.d.ts +2 -1
  8. package/cjs/configs/operations-recommended.js +72 -55
  9. package/{typings → cjs}/configs/relay.d.ts +2 -1
  10. package/cjs/configs/relay.js +31 -11
  11. package/{typings → cjs}/configs/schema-all.d.ts +2 -1
  12. package/cjs/configs/schema-all.js +41 -24
  13. package/{typings → cjs}/configs/schema-recommended.d.ts +2 -1
  14. package/cjs/configs/schema-recommended.js +68 -51
  15. package/{typings → cjs}/documents.d.ts +4 -1
  16. package/cjs/documents.js +74 -43
  17. package/cjs/estree-converter/converter.d.ts +8 -0
  18. package/cjs/estree-converter/converter.js +80 -59
  19. package/cjs/estree-converter/index.d.ts +8 -0
  20. package/cjs/estree-converter/index.js +25 -5
  21. package/{typings → cjs}/estree-converter/types.d.ts +7 -5
  22. package/cjs/estree-converter/types.js +16 -0
  23. package/cjs/estree-converter/utils.d.ts +18 -0
  24. package/cjs/estree-converter/utils.js +119 -95
  25. package/{typings → cjs}/flat-configs.d.ts +12 -1
  26. package/cjs/flat-configs.js +56 -32
  27. package/cjs/graphql-config.d.ts +13 -0
  28. package/cjs/graphql-config.js +78 -47
  29. package/cjs/index.d.ts +22 -0
  30. package/cjs/index.js +50 -18
  31. package/cjs/parser.d.ts +12 -0
  32. package/cjs/parser.js +96 -76
  33. package/cjs/processor.d.ts +9 -0
  34. package/cjs/processor.js +119 -88
  35. package/{typings → cjs}/rules/alphabetize.d.ts +12 -4
  36. package/cjs/rules/alphabetize.js +337 -295
  37. package/{typings → cjs}/rules/description-style.d.ts +12 -4
  38. package/cjs/rules/description-style.js +96 -66
  39. package/cjs/rules/graphql-js-validation.d.ts +12 -0
  40. package/cjs/rules/graphql-js-validation.js +595 -433
  41. package/cjs/rules/index.d.ts +125 -0
  42. package/cjs/rules/index.js +97 -76
  43. package/{typings → cjs}/rules/input-name.d.ts +12 -4
  44. package/cjs/rules/input-name.js +153 -123
  45. package/{typings → cjs}/rules/lone-executable-definition.d.ts +12 -4
  46. package/cjs/rules/lone-executable-definition.js +101 -72
  47. package/{typings → cjs}/rules/match-document-filename.d.ts +14 -6
  48. package/cjs/rules/match-document-filename.js +229 -182
  49. package/{typings → cjs}/rules/naming-convention.d.ts +12 -4
  50. package/cjs/rules/naming-convention.js +380 -316
  51. package/cjs/rules/no-anonymous-operations.d.ts +12 -0
  52. package/cjs/rules/no-anonymous-operations.js +88 -57
  53. package/cjs/rules/no-case-insensitive-enum-values-duplicates.d.ts +12 -0
  54. package/cjs/rules/no-case-insensitive-enum-values-duplicates.js +82 -50
  55. package/cjs/rules/no-deprecated.d.ts +12 -0
  56. package/cjs/rules/no-deprecated.js +106 -75
  57. package/cjs/rules/no-duplicate-fields.d.ts +12 -0
  58. package/cjs/rules/no-duplicate-fields.js +116 -82
  59. package/cjs/rules/no-hashtag-description.d.ts +13 -0
  60. package/cjs/rules/no-hashtag-description.js +119 -82
  61. package/cjs/rules/no-one-place-fragments.d.ts +12 -0
  62. package/cjs/rules/no-one-place-fragments.js +88 -58
  63. package/{typings → cjs}/rules/no-root-type.d.ts +12 -4
  64. package/cjs/rules/no-root-type.js +101 -74
  65. package/cjs/rules/no-scalar-result-type-on-mutation.d.ts +12 -0
  66. package/cjs/rules/no-scalar-result-type-on-mutation.js +90 -60
  67. package/cjs/rules/no-typename-prefix.d.ts +12 -0
  68. package/cjs/rules/no-typename-prefix.js +88 -55
  69. package/cjs/rules/no-unreachable-types.d.ts +12 -0
  70. package/cjs/rules/no-unreachable-types.js +169 -134
  71. package/cjs/rules/no-unused-fields.d.ts +12 -0
  72. package/cjs/rules/no-unused-fields.js +117 -92
  73. package/{typings → cjs}/rules/relay-arguments.d.ts +12 -4
  74. package/cjs/rules/relay-arguments.js +136 -110
  75. package/cjs/rules/relay-connection-types.d.ts +13 -0
  76. package/cjs/rules/relay-connection-types.js +123 -94
  77. package/{typings → cjs}/rules/relay-edge-types.d.ts +12 -4
  78. package/cjs/rules/relay-edge-types.js +196 -179
  79. package/cjs/rules/relay-page-info.d.ts +12 -0
  80. package/cjs/rules/relay-page-info.js +108 -89
  81. package/{typings → cjs}/rules/require-deprecation-date.d.ts +12 -4
  82. package/cjs/rules/require-deprecation-date.js +143 -112
  83. package/cjs/rules/require-deprecation-reason.d.ts +12 -0
  84. package/cjs/rules/require-deprecation-reason.js +80 -46
  85. package/{typings → cjs}/rules/require-description.d.ts +13 -5
  86. package/cjs/rules/require-description.js +170 -132
  87. package/cjs/rules/require-field-of-type-query-in-mutation-result.d.ts +12 -0
  88. package/cjs/rules/require-field-of-type-query-in-mutation-result.js +81 -51
  89. package/{typings → cjs}/rules/require-id-when-available.d.ts +12 -4
  90. package/cjs/rules/require-id-when-available.js +196 -173
  91. package/cjs/rules/require-import-fragment.d.ts +12 -0
  92. package/cjs/rules/require-import-fragment.js +138 -88
  93. package/cjs/rules/require-nullable-fields-with-oneof.d.ts +12 -0
  94. package/cjs/rules/require-nullable-fields-with-oneof.js +80 -50
  95. package/cjs/rules/require-nullable-result-in-root.d.ts +12 -0
  96. package/cjs/rules/require-nullable-result-in-root.js +97 -68
  97. package/cjs/rules/require-type-pattern-with-oneof.d.ts +12 -0
  98. package/cjs/rules/require-type-pattern-with-oneof.js +70 -42
  99. package/{typings → cjs}/rules/selection-set-depth.d.ts +12 -4
  100. package/cjs/rules/selection-set-depth.js +147 -107
  101. package/{typings → cjs}/rules/strict-id-in-types.d.ts +12 -4
  102. package/cjs/rules/strict-id-in-types.js +143 -122
  103. package/cjs/rules/unique-fragment-name.d.ts +13 -0
  104. package/cjs/rules/unique-fragment-name.js +88 -62
  105. package/cjs/rules/unique-operation-name.d.ts +12 -0
  106. package/cjs/rules/unique-operation-name.js +65 -35
  107. package/cjs/schema.d.ts +12 -0
  108. package/cjs/schema.js +62 -30
  109. package/cjs/siblings.d.ts +8 -0
  110. package/cjs/siblings.js +124 -106
  111. package/cjs/testkit.d.ts +8 -0
  112. package/cjs/testkit.js +165 -144
  113. package/cjs/types-e3367e3c.d.ts +129 -0
  114. package/cjs/types.d.ts +8 -0
  115. package/cjs/types.js +16 -0
  116. package/cjs/utils.d.ts +44 -0
  117. package/cjs/utils.js +181 -124
  118. package/{typings/cache.d.cts → esm/cache.d.mts} +3 -1
  119. package/esm/cache.js +25 -23
  120. package/{typings/configs/index.d.cts → esm/configs/index.d.mts} +3 -1
  121. package/esm/configs/index.js +14 -11
  122. package/{typings/configs/operations-all.d.cts → esm/configs/operations-all.d.mts} +2 -1
  123. package/esm/configs/operations-all.js +28 -28
  124. package/{typings/configs/operations-recommended.d.cts → esm/configs/operations-recommended.d.mts} +2 -1
  125. package/esm/configs/operations-recommended.js +53 -53
  126. package/{typings/configs/relay.d.cts → esm/configs/relay.d.mts} +2 -1
  127. package/esm/configs/relay.js +12 -9
  128. package/{typings/configs/schema-all.d.cts → esm/configs/schema-all.d.mts} +2 -1
  129. package/esm/configs/schema-all.js +22 -22
  130. package/{typings/configs/schema-recommended.d.cts → esm/configs/schema-recommended.d.mts} +2 -1
  131. package/esm/configs/schema-recommended.js +49 -49
  132. package/{typings/documents.d.cts → esm/documents.d.mts} +4 -1
  133. package/esm/documents.js +41 -39
  134. package/esm/estree-converter/converter.d.mts +8 -0
  135. package/esm/estree-converter/converter.js +63 -57
  136. package/esm/estree-converter/index.d.mts +8 -0
  137. package/esm/estree-converter/index.js +3 -3
  138. package/{typings/estree-converter/types.d.cts → esm/estree-converter/types.d.mts} +7 -5
  139. package/esm/estree-converter/utils.d.mts +18 -0
  140. package/esm/estree-converter/utils.js +102 -93
  141. package/{typings/flat-configs.d.cts → esm/flat-configs.d.mts} +13 -2
  142. package/esm/flat-configs.js +33 -30
  143. package/esm/graphql-config.d.mts +13 -0
  144. package/esm/graphql-config.js +49 -44
  145. package/esm/index.d.mts +22 -0
  146. package/esm/index.js +18 -9
  147. package/esm/package.json +1 -1
  148. package/esm/parser.d.mts +12 -0
  149. package/esm/parser.js +64 -73
  150. package/esm/processor.d.mts +9 -0
  151. package/esm/processor.js +98 -86
  152. package/{typings/rules/alphabetize.d.cts → esm/rules/alphabetize.d.mts} +12 -4
  153. package/esm/rules/alphabetize.js +304 -290
  154. package/{typings/rules/description-style.d.cts → esm/rules/description-style.d.mts} +12 -4
  155. package/esm/rules/description-style.js +73 -64
  156. package/esm/rules/graphql-js-validation.d.mts +12 -0
  157. package/esm/rules/graphql-js-validation.js +580 -429
  158. package/esm/rules/index.d.mts +125 -0
  159. package/esm/rules/index.js +74 -74
  160. package/{typings/rules/input-name.d.cts → esm/rules/input-name.d.mts} +12 -4
  161. package/esm/rules/input-name.js +132 -121
  162. package/{typings/rules/lone-executable-definition.d.cts → esm/rules/lone-executable-definition.d.mts} +12 -4
  163. package/esm/rules/lone-executable-definition.js +78 -70
  164. package/{typings/rules/match-document-filename.d.cts → esm/rules/match-document-filename.d.mts} +14 -6
  165. package/esm/rules/match-document-filename.js +210 -180
  166. package/{typings/rules/naming-convention.d.cts → esm/rules/naming-convention.d.mts} +12 -4
  167. package/esm/rules/naming-convention.js +363 -314
  168. package/esm/rules/no-anonymous-operations.d.mts +12 -0
  169. package/esm/rules/no-anonymous-operations.js +65 -55
  170. package/esm/rules/no-case-insensitive-enum-values-duplicates.d.mts +12 -0
  171. package/esm/rules/no-case-insensitive-enum-values-duplicates.js +59 -48
  172. package/esm/rules/no-deprecated.d.mts +12 -0
  173. package/esm/rules/no-deprecated.js +83 -73
  174. package/esm/rules/no-duplicate-fields.d.mts +12 -0
  175. package/esm/rules/no-duplicate-fields.js +93 -80
  176. package/esm/rules/no-hashtag-description.d.mts +13 -0
  177. package/esm/rules/no-hashtag-description.js +95 -80
  178. package/esm/rules/no-one-place-fragments.d.mts +12 -0
  179. package/esm/rules/no-one-place-fragments.js +65 -56
  180. package/{typings/rules/no-root-type.d.cts → esm/rules/no-root-type.d.mts} +12 -4
  181. package/esm/rules/no-root-type.js +78 -72
  182. package/esm/rules/no-scalar-result-type-on-mutation.d.mts +12 -0
  183. package/esm/rules/no-scalar-result-type-on-mutation.js +67 -58
  184. package/esm/rules/no-typename-prefix.d.mts +12 -0
  185. package/esm/rules/no-typename-prefix.js +65 -53
  186. package/esm/rules/no-unreachable-types.d.mts +12 -0
  187. package/esm/rules/no-unreachable-types.js +141 -131
  188. package/esm/rules/no-unused-fields.d.mts +12 -0
  189. package/esm/rules/no-unused-fields.js +94 -90
  190. package/{typings/rules/relay-arguments.d.cts → esm/rules/relay-arguments.d.mts} +12 -4
  191. package/esm/rules/relay-arguments.js +113 -108
  192. package/esm/rules/relay-connection-types.d.mts +13 -0
  193. package/esm/rules/relay-connection-types.js +98 -91
  194. package/{typings/rules/relay-edge-types.d.cts → esm/rules/relay-edge-types.d.mts} +12 -4
  195. package/esm/rules/relay-edge-types.js +178 -177
  196. package/esm/rules/relay-page-info.d.mts +12 -0
  197. package/esm/rules/relay-page-info.js +84 -86
  198. package/{typings/rules/require-deprecation-date.d.cts → esm/rules/require-deprecation-date.d.mts} +12 -4
  199. package/esm/rules/require-deprecation-date.js +120 -110
  200. package/esm/rules/require-deprecation-reason.d.mts +12 -0
  201. package/esm/rules/require-deprecation-reason.js +57 -44
  202. package/{typings/rules/require-description.d.cts → esm/rules/require-description.d.mts} +13 -5
  203. package/esm/rules/require-description.js +151 -130
  204. package/esm/rules/require-field-of-type-query-in-mutation-result.d.mts +12 -0
  205. package/esm/rules/require-field-of-type-query-in-mutation-result.js +58 -49
  206. package/{typings/rules/require-id-when-available.d.cts → esm/rules/require-id-when-available.d.mts} +12 -4
  207. package/esm/rules/require-id-when-available.js +186 -171
  208. package/esm/rules/require-import-fragment.d.mts +12 -0
  209. package/esm/rules/require-import-fragment.js +105 -85
  210. package/esm/rules/require-nullable-fields-with-oneof.d.mts +12 -0
  211. package/esm/rules/require-nullable-fields-with-oneof.js +57 -48
  212. package/esm/rules/require-nullable-result-in-root.d.mts +12 -0
  213. package/esm/rules/require-nullable-result-in-root.js +74 -66
  214. package/esm/rules/require-type-pattern-with-oneof.d.mts +12 -0
  215. package/esm/rules/require-type-pattern-with-oneof.js +47 -40
  216. package/{typings/rules/selection-set-depth.d.cts → esm/rules/selection-set-depth.d.mts} +12 -4
  217. package/esm/rules/selection-set-depth.js +114 -104
  218. package/{typings/rules/strict-id-in-types.d.cts → esm/rules/strict-id-in-types.d.mts} +12 -4
  219. package/esm/rules/strict-id-in-types.js +125 -119
  220. package/esm/rules/unique-fragment-name.d.mts +13 -0
  221. package/esm/rules/unique-fragment-name.js +65 -60
  222. package/esm/rules/unique-operation-name.d.mts +12 -0
  223. package/esm/rules/unique-operation-name.js +42 -33
  224. package/esm/schema.d.mts +12 -0
  225. package/esm/schema.js +29 -26
  226. package/esm/siblings.d.mts +8 -0
  227. package/esm/siblings.js +105 -104
  228. package/esm/testkit.d.mts +8 -0
  229. package/esm/testkit.js +132 -141
  230. package/esm/types-2e1afd7c.d.ts +129 -0
  231. package/esm/types.d.mts +8 -0
  232. package/esm/utils.d.mts +44 -0
  233. package/esm/utils.js +138 -116
  234. package/package.json +40 -30
  235. package/typings/estree-converter/converter.d.cts +0 -3
  236. package/typings/estree-converter/converter.d.ts +0 -3
  237. package/typings/estree-converter/index.d.cts +0 -3
  238. package/typings/estree-converter/index.d.ts +0 -3
  239. package/typings/estree-converter/utils.d.cts +0 -13
  240. package/typings/estree-converter/utils.d.ts +0 -13
  241. package/typings/graphql-config.d.cts +0 -4
  242. package/typings/graphql-config.d.ts +0 -4
  243. package/typings/index.d.cts +0 -10
  244. package/typings/index.d.ts +0 -10
  245. package/typings/parser.d.cts +0 -2
  246. package/typings/parser.d.ts +0 -2
  247. package/typings/processor.d.cts +0 -6
  248. package/typings/processor.d.ts +0 -6
  249. package/typings/rules/graphql-js-validation.d.cts +0 -2
  250. package/typings/rules/graphql-js-validation.d.ts +0 -2
  251. package/typings/rules/index.d.cts +0 -111
  252. package/typings/rules/index.d.ts +0 -111
  253. package/typings/rules/no-anonymous-operations.d.cts +0 -2
  254. package/typings/rules/no-anonymous-operations.d.ts +0 -2
  255. package/typings/rules/no-case-insensitive-enum-values-duplicates.d.cts +0 -2
  256. package/typings/rules/no-case-insensitive-enum-values-duplicates.d.ts +0 -2
  257. package/typings/rules/no-deprecated.d.cts +0 -2
  258. package/typings/rules/no-deprecated.d.ts +0 -2
  259. package/typings/rules/no-duplicate-fields.d.cts +0 -2
  260. package/typings/rules/no-duplicate-fields.d.ts +0 -2
  261. package/typings/rules/no-hashtag-description.d.cts +0 -3
  262. package/typings/rules/no-hashtag-description.d.ts +0 -3
  263. package/typings/rules/no-one-place-fragments.d.cts +0 -2
  264. package/typings/rules/no-one-place-fragments.d.ts +0 -2
  265. package/typings/rules/no-scalar-result-type-on-mutation.d.cts +0 -2
  266. package/typings/rules/no-scalar-result-type-on-mutation.d.ts +0 -2
  267. package/typings/rules/no-typename-prefix.d.cts +0 -2
  268. package/typings/rules/no-typename-prefix.d.ts +0 -2
  269. package/typings/rules/no-unreachable-types.d.cts +0 -2
  270. package/typings/rules/no-unreachable-types.d.ts +0 -2
  271. package/typings/rules/no-unused-fields.d.cts +0 -2
  272. package/typings/rules/no-unused-fields.d.ts +0 -2
  273. package/typings/rules/relay-connection-types.d.cts +0 -4
  274. package/typings/rules/relay-connection-types.d.ts +0 -4
  275. package/typings/rules/relay-page-info.d.cts +0 -2
  276. package/typings/rules/relay-page-info.d.ts +0 -2
  277. package/typings/rules/require-deprecation-reason.d.cts +0 -2
  278. package/typings/rules/require-deprecation-reason.d.ts +0 -2
  279. package/typings/rules/require-field-of-type-query-in-mutation-result.d.cts +0 -2
  280. package/typings/rules/require-field-of-type-query-in-mutation-result.d.ts +0 -2
  281. package/typings/rules/require-import-fragment.d.cts +0 -2
  282. package/typings/rules/require-import-fragment.d.ts +0 -2
  283. package/typings/rules/require-nullable-fields-with-oneof.d.cts +0 -2
  284. package/typings/rules/require-nullable-fields-with-oneof.d.ts +0 -2
  285. package/typings/rules/require-nullable-result-in-root.d.cts +0 -2
  286. package/typings/rules/require-nullable-result-in-root.d.ts +0 -2
  287. package/typings/rules/require-type-pattern-with-oneof.d.cts +0 -2
  288. package/typings/rules/require-type-pattern-with-oneof.d.ts +0 -2
  289. package/typings/rules/unique-fragment-name.d.cts +0 -5
  290. package/typings/rules/unique-fragment-name.d.ts +0 -5
  291. package/typings/rules/unique-operation-name.d.cts +0 -2
  292. package/typings/rules/unique-operation-name.d.ts +0 -2
  293. package/typings/schema.d.cts +0 -3
  294. package/typings/schema.d.ts +0 -3
  295. package/typings/siblings.d.cts +0 -22
  296. package/typings/siblings.d.ts +0 -22
  297. package/typings/testkit.d.cts +0 -29
  298. package/typings/testkit.d.ts +0 -29
  299. package/typings/types.d.cts +0 -83
  300. package/typings/types.d.ts +0 -83
  301. package/typings/utils.d.cts +0 -40
  302. package/typings/utils.d.ts +0 -40
@@ -1,256 +1,308 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.GRAPHQL_JS_VALIDATIONS = void 0;
4
- const graphql_1 = require("graphql");
5
- const validate_js_1 = require("graphql/validation/validate.js");
6
- const utils_js_1 = require("../utils.js");
7
- function validateDocument({ context, schema = null, documentNode, rule, hasDidYouMeanSuggestions, }) {
8
- var _a;
9
- if (documentNode.definitions.length === 0) {
10
- return;
11
- }
12
- try {
13
- const validationErrors = schema
14
- ? (0, graphql_1.validate)(schema, documentNode, [rule])
15
- : (0, validate_js_1.validateSDL)(documentNode, null, [rule]);
16
- for (const error of validationErrors) {
17
- const { line, column } = error.locations[0];
18
- const sourceCode = context.getSourceCode();
19
- const { tokens } = sourceCode.ast;
20
- const token = tokens.find(token => token.loc.start.line === line && token.loc.start.column === column - 1);
21
- let loc = {
22
- line,
23
- column: column - 1,
24
- };
25
- if (token) {
26
- loc =
27
- // if cursor on `@` symbol than use next node
28
- token.type === '@'
29
- ? sourceCode.getNodeByRangeIndex(token.range[1] + 1).loc
30
- : token.loc;
31
- }
32
- const didYouMeanContent = (_a = error.message.match(/Did you mean (?<content>.*)\?$/)) === null || _a === void 0 ? void 0 : _a.groups.content;
33
- const matches = didYouMeanContent ? [...didYouMeanContent.matchAll(/"(?<name>[^"]*)"/g)] : [];
34
- context.report({
35
- loc,
36
- message: error.message,
37
- suggest: hasDidYouMeanSuggestions
38
- ? matches.map(match => {
39
- const { name } = match.groups;
40
- return {
41
- desc: `Rename to \`${name}\``,
42
- fix: fixer => fixer.replaceText(token, name),
43
- };
44
- })
45
- : [],
46
- });
47
- }
48
- }
49
- catch (error) {
50
- context.report({
51
- loc: utils_js_1.REPORT_ON_FIRST_CHARACTER,
52
- message: error.message,
53
- });
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var graphql_js_validation_exports = {};
20
+ __export(graphql_js_validation_exports, {
21
+ GRAPHQL_JS_VALIDATIONS: () => GRAPHQL_JS_VALIDATIONS
22
+ });
23
+ module.exports = __toCommonJS(graphql_js_validation_exports);
24
+ var import_graphql = require("graphql");
25
+ var import_validate = require("graphql/validation/validate.js");
26
+ var import_utils = require("../utils.js");
27
+ function validateDocument({
28
+ context,
29
+ schema = null,
30
+ documentNode,
31
+ rule,
32
+ hasDidYouMeanSuggestions
33
+ }) {
34
+ if (documentNode.definitions.length === 0) {
35
+ return;
36
+ }
37
+ try {
38
+ const validationErrors = schema ? (0, import_graphql.validate)(schema, documentNode, [rule]) : (0, import_validate.validateSDL)(documentNode, null, [rule]);
39
+ for (const error of validationErrors) {
40
+ const { line, column } = error.locations[0];
41
+ const sourceCode = context.getSourceCode();
42
+ const { tokens } = sourceCode.ast;
43
+ const token = tokens.find(
44
+ (token2) => token2.loc.start.line === line && token2.loc.start.column === column - 1
45
+ );
46
+ let loc = {
47
+ line,
48
+ column: column - 1
49
+ };
50
+ if (token) {
51
+ loc = // if cursor on `@` symbol than use next node
52
+ token.type === "@" ? sourceCode.getNodeByRangeIndex(token.range[1] + 1).loc : token.loc;
53
+ }
54
+ const didYouMeanContent = error.message.match(/Did you mean (?<content>.*)\?$/)?.groups.content;
55
+ const matches = didYouMeanContent ? [...didYouMeanContent.matchAll(/"(?<name>[^"]*)"/g)] : [];
56
+ context.report({
57
+ loc,
58
+ message: error.message,
59
+ suggest: hasDidYouMeanSuggestions ? matches.map((match) => {
60
+ const { name } = match.groups;
61
+ return {
62
+ desc: `Rename to \`${name}\``,
63
+ fix: (fixer) => fixer.replaceText(token, name)
64
+ };
65
+ }) : []
66
+ });
54
67
  }
68
+ } catch (error) {
69
+ context.report({
70
+ loc: import_utils.REPORT_ON_FIRST_CHARACTER,
71
+ message: error.message
72
+ });
73
+ }
55
74
  }
56
75
  const getFragmentDefsAndFragmentSpreads = (node) => {
57
- const fragmentDefs = new Set();
58
- const fragmentSpreads = new Set();
59
- const visitor = {
60
- FragmentDefinition(node) {
61
- fragmentDefs.add(node.name.value);
62
- },
63
- FragmentSpread(node) {
64
- fragmentSpreads.add(node.name.value);
65
- },
66
- };
67
- (0, graphql_1.visit)(node, visitor);
68
- return { fragmentDefs, fragmentSpreads };
76
+ const fragmentDefs = /* @__PURE__ */ new Set();
77
+ const fragmentSpreads = /* @__PURE__ */ new Set();
78
+ const visitor = {
79
+ FragmentDefinition(node2) {
80
+ fragmentDefs.add(node2.name.value);
81
+ },
82
+ FragmentSpread(node2) {
83
+ fragmentSpreads.add(node2.name.value);
84
+ }
85
+ };
86
+ (0, import_graphql.visit)(node, visitor);
87
+ return { fragmentDefs, fragmentSpreads };
69
88
  };
70
89
  const getMissingFragments = (node) => {
71
- const { fragmentDefs, fragmentSpreads } = getFragmentDefsAndFragmentSpreads(node);
72
- return [...fragmentSpreads].filter(name => !fragmentDefs.has(name));
90
+ const { fragmentDefs, fragmentSpreads } = getFragmentDefsAndFragmentSpreads(node);
91
+ return [...fragmentSpreads].filter((name) => !fragmentDefs.has(name));
73
92
  };
74
93
  const handleMissingFragments = ({ ruleId, context, node }) => {
75
- const missingFragments = getMissingFragments(node);
76
- if (missingFragments.length > 0) {
77
- const siblings = (0, utils_js_1.requireSiblingsOperations)(ruleId, context);
78
- const fragmentsToAdd = [];
79
- for (const fragmentName of missingFragments) {
80
- const [foundFragment] = siblings.getFragment(fragmentName).map(source => source.document);
81
- if (foundFragment) {
82
- fragmentsToAdd.push(foundFragment);
83
- }
84
- }
85
- if (fragmentsToAdd.length > 0) {
86
- // recall fn to make sure to add fragments inside fragments
87
- return handleMissingFragments({
88
- ruleId,
89
- context,
90
- node: {
91
- kind: graphql_1.Kind.DOCUMENT,
92
- definitions: [...node.definitions, ...fragmentsToAdd],
93
- },
94
- });
94
+ const missingFragments = getMissingFragments(node);
95
+ if (missingFragments.length > 0) {
96
+ const siblings = (0, import_utils.requireSiblingsOperations)(ruleId, context);
97
+ const fragmentsToAdd = [];
98
+ for (const fragmentName of missingFragments) {
99
+ const [foundFragment] = siblings.getFragment(fragmentName).map((source) => source.document);
100
+ if (foundFragment) {
101
+ fragmentsToAdd.push(foundFragment);
102
+ }
103
+ }
104
+ if (fragmentsToAdd.length > 0) {
105
+ return handleMissingFragments({
106
+ ruleId,
107
+ context,
108
+ node: {
109
+ kind: import_graphql.Kind.DOCUMENT,
110
+ definitions: [...node.definitions, ...fragmentsToAdd]
95
111
  }
112
+ });
96
113
  }
97
- return node;
114
+ }
115
+ return node;
98
116
  };
99
- const validationToRule = ({ ruleId, ruleName, getDocumentNode, schema = [], hasDidYouMeanSuggestions, }, docs) => {
100
- let ruleFn = null;
117
+ const validationToRule = ({
118
+ ruleId,
119
+ ruleName,
120
+ getDocumentNode,
121
+ schema = [],
122
+ hasDidYouMeanSuggestions
123
+ }, docs) => {
124
+ let ruleFn = null;
125
+ try {
126
+ ruleFn = require(`graphql/validation/rules/${ruleName}Rule`)[`${ruleName}Rule`];
127
+ } catch {
101
128
  try {
102
- ruleFn = require(`graphql/validation/rules/${ruleName}Rule`)[`${ruleName}Rule`];
129
+ ruleFn = require(`graphql/validation/rules/${ruleName}`)[`${ruleName}Rule`];
130
+ } catch {
131
+ ruleFn = require("graphql/validation")[`${ruleName}Rule`];
103
132
  }
104
- catch (_a) {
105
- try {
106
- ruleFn = require(`graphql/validation/rules/${ruleName}`)[`${ruleName}Rule`];
107
- }
108
- catch (_b) {
109
- ruleFn = require('graphql/validation')[`${ruleName}Rule`];
133
+ }
134
+ return {
135
+ [ruleId]: {
136
+ meta: {
137
+ docs: {
138
+ recommended: true,
139
+ ...docs,
140
+ graphQLJSRuleName: ruleName,
141
+ url: `https://the-guild.dev/graphql/eslint/rules/${ruleId}`,
142
+ description: `${docs.description}
143
+ > This rule is a wrapper around a \`graphql-js\` validation function.`
144
+ },
145
+ schema,
146
+ hasSuggestions: hasDidYouMeanSuggestions
147
+ },
148
+ create(context) {
149
+ if (!ruleFn) {
150
+ import_utils.logger.warn(
151
+ `Rule "${ruleId}" depends on a GraphQL validation rule "${ruleName}" but it's not available in the "graphql" version you are using. Skipping\u2026`
152
+ );
153
+ return {};
110
154
  }
155
+ return {
156
+ Document(node) {
157
+ const schema2 = docs.requiresSchema ? (0, import_utils.requireGraphQLSchemaFromContext)(ruleId, context) : null;
158
+ const documentNode = getDocumentNode ? getDocumentNode({ ruleId, context, node: node.rawNode() }) : node.rawNode();
159
+ validateDocument({
160
+ context,
161
+ schema: schema2,
162
+ documentNode,
163
+ rule: ruleFn,
164
+ hasDidYouMeanSuggestions
165
+ });
166
+ }
167
+ };
168
+ }
111
169
  }
112
- return {
113
- [ruleId]: {
114
- meta: {
115
- docs: {
116
- recommended: true,
117
- ...docs,
118
- graphQLJSRuleName: ruleName,
119
- url: `https://the-guild.dev/graphql/eslint/rules/${ruleId}`,
120
- description: `${docs.description}\n> This rule is a wrapper around a \`graphql-js\` validation function.`,
121
- },
122
- schema,
123
- hasSuggestions: hasDidYouMeanSuggestions,
124
- },
125
- create(context) {
126
- if (!ruleFn) {
127
- utils_js_1.logger.warn(`Rule "${ruleId}" depends on a GraphQL validation rule "${ruleName}" but it's not available in the "graphql" version you are using. Skipping…`);
128
- return {};
129
- }
130
- return {
131
- Document(node) {
132
- const schema = docs.requiresSchema
133
- ? (0, utils_js_1.requireGraphQLSchemaFromContext)(ruleId, context)
134
- : null;
135
- const documentNode = getDocumentNode
136
- ? getDocumentNode({ ruleId, context, node: node.rawNode() })
137
- : node.rawNode();
138
- validateDocument({
139
- context,
140
- schema,
141
- documentNode,
142
- rule: ruleFn,
143
- hasDidYouMeanSuggestions,
144
- });
145
- },
146
- };
147
- },
148
- },
149
- };
170
+ };
150
171
  };
151
- exports.GRAPHQL_JS_VALIDATIONS = Object.assign({}, validationToRule({
152
- ruleId: 'executable-definitions',
153
- ruleName: 'ExecutableDefinitions',
154
- }, {
155
- category: 'Operations',
156
- description: 'A GraphQL document is only valid for execution if all definitions are either operation or fragment definitions.',
157
- requiresSchema: true,
158
- }), validationToRule({
159
- ruleId: 'fields-on-correct-type',
160
- ruleName: 'FieldsOnCorrectType',
161
- hasDidYouMeanSuggestions: true,
162
- }, {
163
- category: 'Operations',
164
- description: 'A GraphQL document is only valid if all fields selected are defined by the parent type, or are an allowed meta field such as `__typename`.',
165
- requiresSchema: true,
166
- }), validationToRule({
167
- ruleId: 'fragments-on-composite-type',
168
- ruleName: 'FragmentsOnCompositeTypes',
169
- }, {
170
- category: 'Operations',
171
- description: 'Fragments use a type condition to determine if they apply, since fragments can only be spread into a composite type (object, interface, or union), the type condition must also be a composite type.',
172
- requiresSchema: true,
173
- }), validationToRule({
174
- ruleId: 'known-argument-names',
175
- ruleName: 'KnownArgumentNames',
176
- hasDidYouMeanSuggestions: true,
177
- }, {
178
- category: ['Schema', 'Operations'],
179
- description: 'A GraphQL field is only valid if all supplied arguments are defined by that field.',
180
- requiresSchema: true,
181
- }), validationToRule({
182
- ruleId: 'known-directives',
183
- ruleName: 'KnownDirectives',
184
- getDocumentNode({ context, node: documentNode }) {
172
+ const GRAPHQL_JS_VALIDATIONS = Object.assign(
173
+ {},
174
+ validationToRule(
175
+ {
176
+ ruleId: "executable-definitions",
177
+ ruleName: "ExecutableDefinitions"
178
+ },
179
+ {
180
+ category: "Operations",
181
+ description: "A GraphQL document is only valid for execution if all definitions are either operation or fragment definitions.",
182
+ requiresSchema: true
183
+ }
184
+ ),
185
+ validationToRule(
186
+ {
187
+ ruleId: "fields-on-correct-type",
188
+ ruleName: "FieldsOnCorrectType",
189
+ hasDidYouMeanSuggestions: true
190
+ },
191
+ {
192
+ category: "Operations",
193
+ description: "A GraphQL document is only valid if all fields selected are defined by the parent type, or are an allowed meta field such as `__typename`.",
194
+ requiresSchema: true
195
+ }
196
+ ),
197
+ validationToRule(
198
+ {
199
+ ruleId: "fragments-on-composite-type",
200
+ ruleName: "FragmentsOnCompositeTypes"
201
+ },
202
+ {
203
+ category: "Operations",
204
+ description: "Fragments use a type condition to determine if they apply, since fragments can only be spread into a composite type (object, interface, or union), the type condition must also be a composite type.",
205
+ requiresSchema: true
206
+ }
207
+ ),
208
+ validationToRule(
209
+ {
210
+ ruleId: "known-argument-names",
211
+ ruleName: "KnownArgumentNames",
212
+ hasDidYouMeanSuggestions: true
213
+ },
214
+ {
215
+ category: ["Schema", "Operations"],
216
+ description: "A GraphQL field is only valid if all supplied arguments are defined by that field.",
217
+ requiresSchema: true
218
+ }
219
+ ),
220
+ validationToRule(
221
+ {
222
+ ruleId: "known-directives",
223
+ ruleName: "KnownDirectives",
224
+ getDocumentNode({ context, node: documentNode }) {
185
225
  const { ignoreClientDirectives = [] } = context.options[0] || {};
186
226
  if (ignoreClientDirectives.length === 0) {
187
- return documentNode;
227
+ return documentNode;
188
228
  }
189
- const filterDirectives = (node) => {
190
- var _a;
191
- return ({
192
- ...node,
193
- directives: (_a = node.directives) === null || _a === void 0 ? void 0 : _a.filter(directive => !ignoreClientDirectives.includes(directive.name.value)),
194
- });
195
- };
196
- return (0, graphql_1.visit)(documentNode, {
197
- Field: filterDirectives,
198
- OperationDefinition: filterDirectives,
229
+ const filterDirectives = (node) => ({
230
+ ...node,
231
+ directives: node.directives?.filter(
232
+ (directive) => !ignoreClientDirectives.includes(directive.name.value)
233
+ )
199
234
  });
200
- },
201
- schema: {
202
- type: 'array',
235
+ return (0, import_graphql.visit)(documentNode, {
236
+ Field: filterDirectives,
237
+ OperationDefinition: filterDirectives
238
+ });
239
+ },
240
+ schema: {
241
+ type: "array",
203
242
  maxItems: 1,
204
243
  items: {
205
- type: 'object',
206
- additionalProperties: false,
207
- required: ['ignoreClientDirectives'],
208
- properties: {
209
- ignoreClientDirectives: utils_js_1.ARRAY_DEFAULT_OPTIONS,
210
- },
211
- },
244
+ type: "object",
245
+ additionalProperties: false,
246
+ required: ["ignoreClientDirectives"],
247
+ properties: {
248
+ ignoreClientDirectives: import_utils.ARRAY_DEFAULT_OPTIONS
249
+ }
250
+ }
251
+ }
212
252
  },
213
- }, {
214
- category: ['Schema', 'Operations'],
215
- description: 'A GraphQL document is only valid if all `@directive`s are known by the schema and legally positioned.',
216
- requiresSchema: true,
217
- examples: [
253
+ {
254
+ category: ["Schema", "Operations"],
255
+ description: "A GraphQL document is only valid if all `@directive`s are known by the schema and legally positioned.",
256
+ requiresSchema: true,
257
+ examples: [
218
258
  {
219
- title: 'Valid',
220
- usage: [{ ignoreClientDirectives: ['client'] }],
221
- code: /* GraphQL */ `
259
+ title: "Valid",
260
+ usage: [{ ignoreClientDirectives: ["client"] }],
261
+ code: (
262
+ /* GraphQL */
263
+ `
222
264
  {
223
265
  product {
224
266
  someClientField @client
225
267
  }
226
268
  }
227
- `,
228
- },
229
- ],
230
- }), validationToRule({
231
- ruleId: 'known-fragment-names',
232
- ruleName: 'KnownFragmentNames',
233
- getDocumentNode: handleMissingFragments,
234
- }, {
235
- category: 'Operations',
236
- description: 'A GraphQL document is only valid if all `...Fragment` fragment spreads refer to fragments defined in the same document.',
237
- requiresSchema: true,
238
- requiresSiblings: true,
239
- examples: [
269
+ `
270
+ )
271
+ }
272
+ ]
273
+ }
274
+ ),
275
+ validationToRule(
276
+ {
277
+ ruleId: "known-fragment-names",
278
+ ruleName: "KnownFragmentNames",
279
+ getDocumentNode: handleMissingFragments
280
+ },
281
+ {
282
+ category: "Operations",
283
+ description: "A GraphQL document is only valid if all `...Fragment` fragment spreads refer to fragments defined in the same document.",
284
+ requiresSchema: true,
285
+ requiresSiblings: true,
286
+ examples: [
240
287
  {
241
- title: 'Incorrect',
242
- code: /* GraphQL */ `
288
+ title: "Incorrect",
289
+ code: (
290
+ /* GraphQL */
291
+ `
243
292
  query {
244
293
  user {
245
294
  id
246
295
  ...UserFields # fragment not defined in the document
247
296
  }
248
297
  }
249
- `,
298
+ `
299
+ )
250
300
  },
251
301
  {
252
- title: 'Correct',
253
- code: /* GraphQL */ `
302
+ title: "Correct",
303
+ code: (
304
+ /* GraphQL */
305
+ `
254
306
  fragment UserFields on User {
255
307
  firstName
256
308
  lastName
@@ -262,11 +314,14 @@ exports.GRAPHQL_JS_VALIDATIONS = Object.assign({}, validationToRule({
262
314
  ...UserFields
263
315
  }
264
316
  }
265
- `,
317
+ `
318
+ )
266
319
  },
267
320
  {
268
- title: 'Correct (`UserFields` fragment located in a separate file)',
269
- code: /* GraphQL */ `
321
+ title: "Correct (`UserFields` fragment located in a separate file)",
322
+ code: (
323
+ /* GraphQL */
324
+ `
270
325
  # user.gql
271
326
  query {
272
327
  user {
@@ -279,224 +334,331 @@ exports.GRAPHQL_JS_VALIDATIONS = Object.assign({}, validationToRule({
279
334
  fragment UserFields on User {
280
335
  id
281
336
  }
282
- `,
283
- },
284
- ],
285
- }), validationToRule({
286
- ruleId: 'known-type-names',
287
- ruleName: 'KnownTypeNames',
288
- hasDidYouMeanSuggestions: true,
289
- }, {
290
- category: ['Schema', 'Operations'],
291
- description: 'A GraphQL document is only valid if referenced types (specifically variable definitions and fragment conditions) are defined by the type schema.',
292
- requiresSchema: true,
293
- }), validationToRule({
294
- ruleId: 'lone-anonymous-operation',
295
- ruleName: 'LoneAnonymousOperation',
296
- }, {
297
- category: 'Operations',
298
- description: 'A GraphQL document that contains an anonymous operation (the `query` short-hand) is only valid if it contains only that one operation definition.',
299
- requiresSchema: true,
300
- }), validationToRule({
301
- ruleId: 'lone-schema-definition',
302
- ruleName: 'LoneSchemaDefinition',
303
- }, {
304
- category: 'Schema',
305
- description: 'A GraphQL document is only valid if it contains only one schema definition.',
306
- }), validationToRule({
307
- ruleId: 'no-fragment-cycles',
308
- ruleName: 'NoFragmentCycles',
309
- }, {
310
- category: 'Operations',
311
- description: 'A GraphQL fragment is only valid when it does not have cycles in fragments usage.',
312
- requiresSchema: true,
313
- }), validationToRule({
314
- ruleId: 'no-undefined-variables',
315
- ruleName: 'NoUndefinedVariables',
316
- getDocumentNode: handleMissingFragments,
317
- }, {
318
- category: 'Operations',
319
- description: 'A GraphQL operation is only valid if all variables encountered, both directly and via fragment spreads, are defined by that operation.',
320
- requiresSchema: true,
321
- requiresSiblings: true,
322
- }), validationToRule({
323
- ruleId: 'no-unused-fragments',
324
- ruleName: 'NoUnusedFragments',
325
- getDocumentNode: ({ ruleId, context, node }) => {
326
- const siblings = (0, utils_js_1.requireSiblingsOperations)(ruleId, context);
337
+ `
338
+ )
339
+ }
340
+ ]
341
+ }
342
+ ),
343
+ validationToRule(
344
+ {
345
+ ruleId: "known-type-names",
346
+ ruleName: "KnownTypeNames",
347
+ hasDidYouMeanSuggestions: true
348
+ },
349
+ {
350
+ category: ["Schema", "Operations"],
351
+ description: "A GraphQL document is only valid if referenced types (specifically variable definitions and fragment conditions) are defined by the type schema.",
352
+ requiresSchema: true
353
+ }
354
+ ),
355
+ validationToRule(
356
+ {
357
+ ruleId: "lone-anonymous-operation",
358
+ ruleName: "LoneAnonymousOperation"
359
+ },
360
+ {
361
+ category: "Operations",
362
+ description: "A GraphQL document that contains an anonymous operation (the `query` short-hand) is only valid if it contains only that one operation definition.",
363
+ requiresSchema: true
364
+ }
365
+ ),
366
+ validationToRule(
367
+ {
368
+ ruleId: "lone-schema-definition",
369
+ ruleName: "LoneSchemaDefinition"
370
+ },
371
+ {
372
+ category: "Schema",
373
+ description: "A GraphQL document is only valid if it contains only one schema definition."
374
+ }
375
+ ),
376
+ validationToRule(
377
+ {
378
+ ruleId: "no-fragment-cycles",
379
+ ruleName: "NoFragmentCycles"
380
+ },
381
+ {
382
+ category: "Operations",
383
+ description: "A GraphQL fragment is only valid when it does not have cycles in fragments usage.",
384
+ requiresSchema: true
385
+ }
386
+ ),
387
+ validationToRule(
388
+ {
389
+ ruleId: "no-undefined-variables",
390
+ ruleName: "NoUndefinedVariables",
391
+ getDocumentNode: handleMissingFragments
392
+ },
393
+ {
394
+ category: "Operations",
395
+ description: "A GraphQL operation is only valid if all variables encountered, both directly and via fragment spreads, are defined by that operation.",
396
+ requiresSchema: true,
397
+ requiresSiblings: true
398
+ }
399
+ ),
400
+ validationToRule(
401
+ {
402
+ ruleId: "no-unused-fragments",
403
+ ruleName: "NoUnusedFragments",
404
+ getDocumentNode: ({ ruleId, context, node }) => {
405
+ const siblings = (0, import_utils.requireSiblingsOperations)(ruleId, context);
327
406
  const FilePathToDocumentsMap = [
328
- ...siblings.getOperations(),
329
- ...siblings.getFragments(),
407
+ ...siblings.getOperations(),
408
+ ...siblings.getFragments()
330
409
  ].reduce((map, { filePath, document }) => {
331
- var _a;
332
- (_a = map[filePath]) !== null && _a !== void 0 ? _a : (map[filePath] = []);
333
- map[filePath].push(document);
334
- return map;
335
- }, Object.create(null));
336
- const getParentNode = (currentFilePath, node) => {
337
- const { fragmentDefs } = getFragmentDefsAndFragmentSpreads(node);
338
- if (fragmentDefs.size === 0) {
339
- return node;
340
- }
341
- // skip iteration over documents for current filepath
342
- delete FilePathToDocumentsMap[currentFilePath];
343
- for (const [filePath, documents] of Object.entries(FilePathToDocumentsMap)) {
344
- const missingFragments = getMissingFragments({
345
- kind: graphql_1.Kind.DOCUMENT,
346
- definitions: documents,
347
- });
348
- const isCurrentFileImportFragment = missingFragments.some(fragment => fragmentDefs.has(fragment));
349
- if (isCurrentFileImportFragment) {
350
- return getParentNode(filePath, {
351
- kind: graphql_1.Kind.DOCUMENT,
352
- definitions: [...node.definitions, ...documents],
353
- });
354
- }
410
+ map[filePath] ??= [];
411
+ map[filePath].push(document);
412
+ return map;
413
+ }, /* @__PURE__ */ Object.create(null));
414
+ const getParentNode = (currentFilePath, node2) => {
415
+ const { fragmentDefs } = getFragmentDefsAndFragmentSpreads(node2);
416
+ if (fragmentDefs.size === 0) {
417
+ return node2;
418
+ }
419
+ delete FilePathToDocumentsMap[currentFilePath];
420
+ for (const [filePath, documents] of Object.entries(FilePathToDocumentsMap)) {
421
+ const missingFragments = getMissingFragments({
422
+ kind: import_graphql.Kind.DOCUMENT,
423
+ definitions: documents
424
+ });
425
+ const isCurrentFileImportFragment = missingFragments.some(
426
+ (fragment) => fragmentDefs.has(fragment)
427
+ );
428
+ if (isCurrentFileImportFragment) {
429
+ return getParentNode(filePath, {
430
+ kind: import_graphql.Kind.DOCUMENT,
431
+ definitions: [...node2.definitions, ...documents]
432
+ });
355
433
  }
356
- return node;
434
+ }
435
+ return node2;
357
436
  };
358
437
  return getParentNode(context.getFilename(), node);
438
+ }
439
+ },
440
+ {
441
+ category: "Operations",
442
+ description: "A GraphQL document is only valid if all fragment definitions are spread within operations, or spread within other fragments spread within operations.",
443
+ requiresSchema: true,
444
+ requiresSiblings: true
445
+ }
446
+ ),
447
+ validationToRule(
448
+ {
449
+ ruleId: "no-unused-variables",
450
+ ruleName: "NoUnusedVariables",
451
+ getDocumentNode: handleMissingFragments
452
+ },
453
+ {
454
+ category: "Operations",
455
+ description: "A GraphQL operation is only valid if all variables defined by an operation are used, either directly or within a spread fragment.",
456
+ requiresSchema: true,
457
+ requiresSiblings: true
458
+ }
459
+ ),
460
+ validationToRule(
461
+ {
462
+ ruleId: "overlapping-fields-can-be-merged",
463
+ ruleName: "OverlappingFieldsCanBeMerged"
464
+ },
465
+ {
466
+ category: "Operations",
467
+ description: "A selection set is only valid if all fields (including spreading any fragments) either correspond to distinct response names or can be merged without ambiguity.",
468
+ requiresSchema: true
469
+ }
470
+ ),
471
+ validationToRule(
472
+ {
473
+ ruleId: "possible-fragment-spread",
474
+ ruleName: "PossibleFragmentSpreads"
475
+ },
476
+ {
477
+ category: "Operations",
478
+ description: "A fragment spread is only valid if the type condition could ever possibly be true: if there is a non-empty intersection of the possible parent types, and possible types which pass the type condition.",
479
+ requiresSchema: true
480
+ }
481
+ ),
482
+ validationToRule(
483
+ {
484
+ ruleId: "possible-type-extension",
485
+ ruleName: "PossibleTypeExtensions",
486
+ hasDidYouMeanSuggestions: true
487
+ },
488
+ {
489
+ category: "Schema",
490
+ description: "A type extension is only valid if the type is defined and has the same kind.",
491
+ // TODO: add in graphql-eslint v4
492
+ recommended: false,
493
+ requiresSchema: true,
494
+ isDisabledForAllConfig: true
495
+ }
496
+ ),
497
+ validationToRule(
498
+ {
499
+ ruleId: "provided-required-arguments",
500
+ ruleName: "ProvidedRequiredArguments"
501
+ },
502
+ {
503
+ category: ["Schema", "Operations"],
504
+ description: "A field or directive is only valid if all required (non-null without a default value) field arguments have been provided.",
505
+ requiresSchema: true
506
+ }
507
+ ),
508
+ validationToRule(
509
+ {
510
+ ruleId: "scalar-leafs",
511
+ ruleName: "ScalarLeafs",
512
+ hasDidYouMeanSuggestions: true
513
+ },
514
+ {
515
+ category: "Operations",
516
+ description: "A GraphQL document is valid only if all leaf fields (fields without sub selections) are of scalar or enum types.",
517
+ requiresSchema: true
518
+ }
519
+ ),
520
+ validationToRule(
521
+ {
522
+ ruleId: "one-field-subscriptions",
523
+ ruleName: "SingleFieldSubscriptions"
524
+ },
525
+ {
526
+ category: "Operations",
527
+ description: "A GraphQL subscription is valid only if it contains a single root field.",
528
+ requiresSchema: true
529
+ }
530
+ ),
531
+ validationToRule(
532
+ {
533
+ ruleId: "unique-argument-names",
534
+ ruleName: "UniqueArgumentNames"
359
535
  },
360
- }, {
361
- category: 'Operations',
362
- description: 'A GraphQL document is only valid if all fragment definitions are spread within operations, or spread within other fragments spread within operations.',
363
- requiresSchema: true,
364
- requiresSiblings: true,
365
- }), validationToRule({
366
- ruleId: 'no-unused-variables',
367
- ruleName: 'NoUnusedVariables',
368
- getDocumentNode: handleMissingFragments,
369
- }, {
370
- category: 'Operations',
371
- description: 'A GraphQL operation is only valid if all variables defined by an operation are used, either directly or within a spread fragment.',
372
- requiresSchema: true,
373
- requiresSiblings: true,
374
- }), validationToRule({
375
- ruleId: 'overlapping-fields-can-be-merged',
376
- ruleName: 'OverlappingFieldsCanBeMerged',
377
- }, {
378
- category: 'Operations',
379
- description: 'A selection set is only valid if all fields (including spreading any fragments) either correspond to distinct response names or can be merged without ambiguity.',
380
- requiresSchema: true,
381
- }), validationToRule({
382
- ruleId: 'possible-fragment-spread',
383
- ruleName: 'PossibleFragmentSpreads',
384
- }, {
385
- category: 'Operations',
386
- description: 'A fragment spread is only valid if the type condition could ever possibly be true: if there is a non-empty intersection of the possible parent types, and possible types which pass the type condition.',
387
- requiresSchema: true,
388
- }), validationToRule({
389
- ruleId: 'possible-type-extension',
390
- ruleName: 'PossibleTypeExtensions',
391
- hasDidYouMeanSuggestions: true,
392
- }, {
393
- category: 'Schema',
394
- description: 'A type extension is only valid if the type is defined and has the same kind.',
395
- // TODO: add in graphql-eslint v4
396
- recommended: false,
397
- requiresSchema: true,
398
- isDisabledForAllConfig: true,
399
- }), validationToRule({
400
- ruleId: 'provided-required-arguments',
401
- ruleName: 'ProvidedRequiredArguments',
402
- }, {
403
- category: ['Schema', 'Operations'],
404
- description: 'A field or directive is only valid if all required (non-null without a default value) field arguments have been provided.',
405
- requiresSchema: true,
406
- }), validationToRule({
407
- ruleId: 'scalar-leafs',
408
- ruleName: 'ScalarLeafs',
409
- hasDidYouMeanSuggestions: true,
410
- }, {
411
- category: 'Operations',
412
- description: 'A GraphQL document is valid only if all leaf fields (fields without sub selections) are of scalar or enum types.',
413
- requiresSchema: true,
414
- }), validationToRule({
415
- ruleId: 'one-field-subscriptions',
416
- ruleName: 'SingleFieldSubscriptions',
417
- }, {
418
- category: 'Operations',
419
- description: 'A GraphQL subscription is valid only if it contains a single root field.',
420
- requiresSchema: true,
421
- }), validationToRule({
422
- ruleId: 'unique-argument-names',
423
- ruleName: 'UniqueArgumentNames',
424
- }, {
425
- category: 'Operations',
426
- description: 'A GraphQL field or directive is only valid if all supplied arguments are uniquely named.',
427
- requiresSchema: true,
428
- }), validationToRule({
429
- ruleId: 'unique-directive-names',
430
- ruleName: 'UniqueDirectiveNames',
431
- }, {
432
- category: 'Schema',
433
- description: 'A GraphQL document is only valid if all defined directives have unique names.',
434
- }), validationToRule({
435
- ruleId: 'unique-directive-names-per-location',
436
- ruleName: 'UniqueDirectivesPerLocation',
437
- }, {
438
- category: ['Schema', 'Operations'],
439
- description: 'A GraphQL document is only valid if all non-repeatable directives at a given location are uniquely named.',
440
- requiresSchema: true,
441
- }), validationToRule({
442
- ruleId: 'unique-enum-value-names',
443
- ruleName: 'UniqueEnumValueNames',
444
- }, {
445
- category: 'Schema',
446
- description: 'A GraphQL enum type is only valid if all its values are uniquely named.',
447
- recommended: false,
448
- isDisabledForAllConfig: true,
449
- }), validationToRule({
450
- ruleId: 'unique-field-definition-names',
451
- ruleName: 'UniqueFieldDefinitionNames',
452
- }, {
453
- category: 'Schema',
454
- description: 'A GraphQL complex type is only valid if all its fields are uniquely named.',
455
- }), validationToRule({
456
- ruleId: 'unique-input-field-names',
457
- ruleName: 'UniqueInputFieldNames',
458
- }, {
459
- category: 'Operations',
460
- description: 'A GraphQL input object value is only valid if all supplied fields are uniquely named.',
461
- }), validationToRule({
462
- ruleId: 'unique-operation-types',
463
- ruleName: 'UniqueOperationTypes',
464
- }, {
465
- category: 'Schema',
466
- description: 'A GraphQL document is only valid if it has only one type per operation.',
467
- }), validationToRule({
468
- ruleId: 'unique-type-names',
469
- ruleName: 'UniqueTypeNames',
470
- }, {
471
- category: 'Schema',
472
- description: 'A GraphQL document is only valid if all defined types have unique names.',
473
- }), validationToRule({
474
- ruleId: 'unique-variable-names',
475
- ruleName: 'UniqueVariableNames',
476
- }, {
477
- category: 'Operations',
478
- description: 'A GraphQL operation is only valid if all its variables are uniquely named.',
479
- requiresSchema: true,
480
- }), validationToRule({
481
- ruleId: 'value-literals-of-correct-type',
482
- ruleName: 'ValuesOfCorrectType',
483
- hasDidYouMeanSuggestions: true,
484
- }, {
485
- category: 'Operations',
486
- description: 'A GraphQL document is only valid if all value literals are of the type expected at their position.',
487
- requiresSchema: true,
488
- }), validationToRule({
489
- ruleId: 'variables-are-input-types',
490
- ruleName: 'VariablesAreInputTypes',
491
- }, {
492
- category: 'Operations',
493
- description: 'A GraphQL operation is only valid if all the variables it defines are of input types (scalar, enum, or input object).',
494
- requiresSchema: true,
495
- }), validationToRule({
496
- ruleId: 'variables-in-allowed-position',
497
- ruleName: 'VariablesInAllowedPosition',
498
- }, {
499
- category: 'Operations',
500
- description: 'Variables passed to field arguments conform to type.',
501
- requiresSchema: true,
502
- }));
536
+ {
537
+ category: "Operations",
538
+ description: "A GraphQL field or directive is only valid if all supplied arguments are uniquely named.",
539
+ requiresSchema: true
540
+ }
541
+ ),
542
+ validationToRule(
543
+ {
544
+ ruleId: "unique-directive-names",
545
+ ruleName: "UniqueDirectiveNames"
546
+ },
547
+ {
548
+ category: "Schema",
549
+ description: "A GraphQL document is only valid if all defined directives have unique names."
550
+ }
551
+ ),
552
+ validationToRule(
553
+ {
554
+ ruleId: "unique-directive-names-per-location",
555
+ ruleName: "UniqueDirectivesPerLocation"
556
+ },
557
+ {
558
+ category: ["Schema", "Operations"],
559
+ description: "A GraphQL document is only valid if all non-repeatable directives at a given location are uniquely named.",
560
+ requiresSchema: true
561
+ }
562
+ ),
563
+ validationToRule(
564
+ {
565
+ ruleId: "unique-enum-value-names",
566
+ ruleName: "UniqueEnumValueNames"
567
+ },
568
+ {
569
+ category: "Schema",
570
+ description: "A GraphQL enum type is only valid if all its values are uniquely named.",
571
+ recommended: false,
572
+ isDisabledForAllConfig: true
573
+ }
574
+ ),
575
+ validationToRule(
576
+ {
577
+ ruleId: "unique-field-definition-names",
578
+ ruleName: "UniqueFieldDefinitionNames"
579
+ },
580
+ {
581
+ category: "Schema",
582
+ description: "A GraphQL complex type is only valid if all its fields are uniquely named."
583
+ }
584
+ ),
585
+ validationToRule(
586
+ {
587
+ ruleId: "unique-input-field-names",
588
+ ruleName: "UniqueInputFieldNames"
589
+ },
590
+ {
591
+ category: "Operations",
592
+ description: "A GraphQL input object value is only valid if all supplied fields are uniquely named."
593
+ }
594
+ ),
595
+ validationToRule(
596
+ {
597
+ ruleId: "unique-operation-types",
598
+ ruleName: "UniqueOperationTypes"
599
+ },
600
+ {
601
+ category: "Schema",
602
+ description: "A GraphQL document is only valid if it has only one type per operation."
603
+ }
604
+ ),
605
+ validationToRule(
606
+ {
607
+ ruleId: "unique-type-names",
608
+ ruleName: "UniqueTypeNames"
609
+ },
610
+ {
611
+ category: "Schema",
612
+ description: "A GraphQL document is only valid if all defined types have unique names."
613
+ }
614
+ ),
615
+ validationToRule(
616
+ {
617
+ ruleId: "unique-variable-names",
618
+ ruleName: "UniqueVariableNames"
619
+ },
620
+ {
621
+ category: "Operations",
622
+ description: "A GraphQL operation is only valid if all its variables are uniquely named.",
623
+ requiresSchema: true
624
+ }
625
+ ),
626
+ validationToRule(
627
+ {
628
+ ruleId: "value-literals-of-correct-type",
629
+ ruleName: "ValuesOfCorrectType",
630
+ hasDidYouMeanSuggestions: true
631
+ },
632
+ {
633
+ category: "Operations",
634
+ description: "A GraphQL document is only valid if all value literals are of the type expected at their position.",
635
+ requiresSchema: true
636
+ }
637
+ ),
638
+ validationToRule(
639
+ {
640
+ ruleId: "variables-are-input-types",
641
+ ruleName: "VariablesAreInputTypes"
642
+ },
643
+ {
644
+ category: "Operations",
645
+ description: "A GraphQL operation is only valid if all the variables it defines are of input types (scalar, enum, or input object).",
646
+ requiresSchema: true
647
+ }
648
+ ),
649
+ validationToRule(
650
+ {
651
+ ruleId: "variables-in-allowed-position",
652
+ ruleName: "VariablesInAllowedPosition"
653
+ },
654
+ {
655
+ category: "Operations",
656
+ description: "Variables passed to field arguments conform to type.",
657
+ requiresSchema: true
658
+ }
659
+ )
660
+ );
661
+ // Annotate the CommonJS export names for ESM import in node:
662
+ 0 && (module.exports = {
663
+ GRAPHQL_JS_VALIDATIONS
664
+ });