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