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

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