@graphql-eslint/eslint-plugin 3.14.0-alpha-20221221142641-4e1a924 → 3.14.0-alpha-20221222012949-5caade4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (231) hide show
  1. package/README.md +309 -0
  2. package/cjs/cache.js +30 -0
  3. package/cjs/configs/base.js +7 -0
  4. package/cjs/configs/index.js +16 -0
  5. package/cjs/configs/operations-all.js +31 -0
  6. package/cjs/configs/operations-recommended.js +56 -0
  7. package/cjs/configs/relay.js +12 -0
  8. package/cjs/configs/schema-all.js +23 -0
  9. package/cjs/configs/schema-recommended.js +52 -0
  10. package/cjs/documents.js +149 -0
  11. package/cjs/estree-converter/converter.js +62 -0
  12. package/cjs/estree-converter/index.js +6 -0
  13. package/cjs/estree-converter/types.js +2 -0
  14. package/cjs/estree-converter/utils.js +109 -0
  15. package/cjs/graphql-config.js +55 -0
  16. package/cjs/index.js +17 -0
  17. package/cjs/parser.js +61 -0
  18. package/cjs/processor.js +78 -0
  19. package/cjs/rules/alphabetize.js +348 -0
  20. package/cjs/rules/description-style.js +78 -0
  21. package/cjs/rules/graphql-js-validation.js +499 -0
  22. package/cjs/rules/index.js +68 -0
  23. package/cjs/rules/input-name.js +136 -0
  24. package/cjs/rules/lone-executable-definition.js +88 -0
  25. package/cjs/rules/match-document-filename.js +235 -0
  26. package/cjs/rules/naming-convention.js +310 -0
  27. package/cjs/rules/no-anonymous-operations.js +67 -0
  28. package/cjs/rules/no-case-insensitive-enum-values-duplicates.js +61 -0
  29. package/cjs/rules/no-deprecated.js +124 -0
  30. package/cjs/rules/no-duplicate-fields.js +112 -0
  31. package/cjs/rules/no-hashtag-description.js +89 -0
  32. package/cjs/rules/no-root-type.js +86 -0
  33. package/cjs/rules/no-scalar-result-type-on-mutation.js +66 -0
  34. package/cjs/rules/no-typename-prefix.js +65 -0
  35. package/cjs/rules/no-unreachable-types.js +158 -0
  36. package/cjs/rules/no-unused-fields.js +130 -0
  37. package/cjs/rules/relay-arguments.js +121 -0
  38. package/cjs/rules/relay-connection-types.js +107 -0
  39. package/cjs/rules/relay-edge-types.js +189 -0
  40. package/cjs/rules/relay-page-info.js +100 -0
  41. package/cjs/rules/require-deprecation-date.js +123 -0
  42. package/cjs/rules/require-deprecation-reason.js +56 -0
  43. package/cjs/rules/require-description.js +193 -0
  44. package/cjs/rules/require-field-of-type-query-in-mutation-result.js +72 -0
  45. package/cjs/rules/require-id-when-available.js +199 -0
  46. package/cjs/rules/selection-set-depth.js +135 -0
  47. package/cjs/rules/strict-id-in-types.js +162 -0
  48. package/cjs/rules/unique-fragment-name.js +90 -0
  49. package/cjs/rules/unique-operation-name.js +65 -0
  50. package/cjs/schema.js +42 -0
  51. package/cjs/testkit.js +183 -0
  52. package/cjs/types.js +2 -0
  53. package/cjs/utils.js +96 -0
  54. package/docs/README.md +82 -0
  55. package/docs/custom-rules.md +184 -0
  56. package/docs/deprecated-rules.md +24 -0
  57. package/docs/parser-options.md +95 -0
  58. package/docs/parser.md +67 -0
  59. package/docs/rules/alphabetize.md +194 -0
  60. package/docs/rules/description-style.md +57 -0
  61. package/docs/rules/executable-definitions.md +20 -0
  62. package/docs/rules/fields-on-correct-type.md +23 -0
  63. package/docs/rules/fragments-on-composite-type.md +20 -0
  64. package/docs/rules/input-name.md +80 -0
  65. package/docs/rules/known-argument-names.md +23 -0
  66. package/docs/rules/known-directives.md +48 -0
  67. package/docs/rules/known-fragment-names.md +72 -0
  68. package/docs/rules/known-type-names.md +24 -0
  69. package/docs/rules/lone-anonymous-operation.md +20 -0
  70. package/docs/rules/lone-executable-definition.md +59 -0
  71. package/docs/rules/lone-schema-definition.md +19 -0
  72. package/docs/rules/match-document-filename.md +181 -0
  73. package/docs/rules/naming-convention.md +320 -0
  74. package/docs/rules/no-anonymous-operations.md +43 -0
  75. package/docs/rules/no-case-insensitive-enum-values-duplicates.md +46 -0
  76. package/docs/rules/no-deprecated.md +88 -0
  77. package/docs/rules/no-duplicate-fields.md +69 -0
  78. package/docs/rules/no-fragment-cycles.md +19 -0
  79. package/docs/rules/no-hashtag-description.md +62 -0
  80. package/docs/rules/no-root-type.md +55 -0
  81. package/docs/rules/no-scalar-result-type-on-mutation.md +39 -0
  82. package/docs/rules/no-typename-prefix.md +42 -0
  83. package/docs/rules/no-undefined-variables.md +20 -0
  84. package/docs/rules/no-unreachable-types.md +52 -0
  85. package/docs/rules/no-unused-fields.md +64 -0
  86. package/docs/rules/no-unused-fragments.md +20 -0
  87. package/docs/rules/no-unused-variables.md +20 -0
  88. package/docs/rules/one-field-subscriptions.md +19 -0
  89. package/docs/rules/overlapping-fields-can-be-merged.md +20 -0
  90. package/docs/rules/possible-fragment-spread.md +21 -0
  91. package/docs/rules/possible-type-extension.md +19 -0
  92. package/docs/rules/provided-required-arguments.md +21 -0
  93. package/docs/rules/relay-arguments.md +59 -0
  94. package/docs/rules/relay-connection-types.md +43 -0
  95. package/docs/rules/relay-edge-types.md +60 -0
  96. package/docs/rules/relay-page-info.md +34 -0
  97. package/docs/rules/require-deprecation-date.md +59 -0
  98. package/docs/rules/require-deprecation-reason.md +49 -0
  99. package/docs/rules/require-description.md +147 -0
  100. package/docs/rules/require-field-of-type-query-in-mutation-result.md +50 -0
  101. package/docs/rules/require-id-when-available.md +91 -0
  102. package/docs/rules/scalar-leafs.md +23 -0
  103. package/docs/rules/selection-set-depth.md +86 -0
  104. package/docs/rules/strict-id-in-types.md +129 -0
  105. package/docs/rules/unique-argument-names.md +19 -0
  106. package/docs/rules/unique-directive-names-per-location.md +21 -0
  107. package/docs/rules/unique-directive-names.md +19 -0
  108. package/docs/rules/unique-enum-value-names.md +16 -0
  109. package/docs/rules/unique-field-definition-names.md +19 -0
  110. package/docs/rules/unique-fragment-name.md +52 -0
  111. package/docs/rules/unique-input-field-names.md +19 -0
  112. package/docs/rules/unique-operation-name.md +56 -0
  113. package/docs/rules/unique-operation-types.md +19 -0
  114. package/docs/rules/unique-type-names.md +19 -0
  115. package/docs/rules/unique-variable-names.md +19 -0
  116. package/docs/rules/value-literals-of-correct-type.md +22 -0
  117. package/docs/rules/variables-are-input-types.md +20 -0
  118. package/docs/rules/variables-in-allowed-position.md +19 -0
  119. package/package.json +8 -11
  120. package/{cache.d.ts → typings/cache.d.cts} +0 -0
  121. package/typings/cache.d.ts +10 -0
  122. package/typings/configs/base.d.cts +5 -0
  123. package/typings/configs/base.d.ts +5 -0
  124. package/typings/configs/index.d.cts +139 -0
  125. package/typings/configs/index.d.ts +139 -0
  126. package/typings/configs/operations-all.d.cts +20 -0
  127. package/typings/configs/operations-all.d.ts +20 -0
  128. package/typings/configs/operations-recommended.d.cts +50 -0
  129. package/typings/configs/operations-recommended.d.ts +50 -0
  130. package/typings/configs/relay.d.cts +10 -0
  131. package/typings/configs/relay.d.ts +10 -0
  132. package/typings/configs/schema-all.d.cts +15 -0
  133. package/typings/configs/schema-all.d.ts +15 -0
  134. package/typings/configs/schema-recommended.d.cts +47 -0
  135. package/typings/configs/schema-recommended.d.ts +47 -0
  136. package/{documents.d.ts → typings/documents.d.cts} +0 -0
  137. package/typings/documents.d.ts +21 -0
  138. package/{estree-converter/converter.d.ts → typings/estree-converter/converter.d.cts} +0 -0
  139. package/typings/estree-converter/converter.d.ts +3 -0
  140. package/{estree-converter/index.d.ts → typings/estree-converter/index.d.cts} +0 -0
  141. package/typings/estree-converter/index.d.ts +3 -0
  142. package/{estree-converter/types.d.ts → typings/estree-converter/types.d.cts} +0 -0
  143. package/typings/estree-converter/types.d.ts +40 -0
  144. package/{estree-converter/utils.d.ts → typings/estree-converter/utils.d.cts} +0 -0
  145. package/typings/estree-converter/utils.d.ts +13 -0
  146. package/{graphql-config.d.ts → typings/graphql-config.d.cts} +0 -0
  147. package/typings/graphql-config.d.ts +4 -0
  148. package/typings/index.d.cts +9 -0
  149. package/{index.d.ts → typings/index.d.ts} +1 -5
  150. package/{parser.d.ts → typings/parser.d.cts} +0 -0
  151. package/typings/parser.d.ts +2 -0
  152. package/{processor.d.ts → typings/processor.d.cts} +0 -0
  153. package/typings/processor.d.ts +6 -0
  154. package/{rules/alphabetize.d.ts → typings/rules/alphabetize.d.cts} +0 -0
  155. package/typings/rules/alphabetize.d.ts +76 -0
  156. package/{rules/description-style.d.ts → typings/rules/description-style.d.cts} +0 -0
  157. package/typings/rules/description-style.d.ts +20 -0
  158. package/{rules/graphql-js-validation.d.ts → typings/rules/graphql-js-validation.d.cts} +0 -0
  159. package/typings/rules/graphql-js-validation.d.ts +2 -0
  160. package/{rules/index.d.ts → typings/rules/index.d.cts} +0 -0
  161. package/typings/rules/index.d.ts +104 -0
  162. package/{rules/input-name.d.ts → typings/rules/input-name.d.cts} +0 -0
  163. package/typings/rules/input-name.d.ts +35 -0
  164. package/{rules/lone-executable-definition.d.ts → typings/rules/lone-executable-definition.d.cts} +0 -0
  165. package/typings/rules/lone-executable-definition.d.ts +26 -0
  166. package/{rules/match-document-filename.d.ts → typings/rules/match-document-filename.d.cts} +0 -0
  167. package/typings/rules/match-document-filename.d.ts +72 -0
  168. package/{rules/naming-convention.d.ts → typings/rules/naming-convention.d.cts} +0 -0
  169. package/typings/rules/naming-convention.d.ts +83 -0
  170. package/{rules/no-anonymous-operations.d.ts → typings/rules/no-anonymous-operations.d.cts} +0 -0
  171. package/{rules/no-case-insensitive-enum-values-duplicates.d.ts → typings/rules/no-anonymous-operations.d.ts} +0 -0
  172. package/{rules/no-hashtag-description.d.ts → typings/rules/no-case-insensitive-enum-values-duplicates.d.cts} +0 -0
  173. package/{rules/no-scalar-result-type-on-mutation.d.ts → typings/rules/no-case-insensitive-enum-values-duplicates.d.ts} +0 -0
  174. package/{rules/no-deprecated.d.ts → typings/rules/no-deprecated.d.cts} +0 -0
  175. package/typings/rules/no-deprecated.d.ts +2 -0
  176. package/{rules/no-duplicate-fields.d.ts → typings/rules/no-duplicate-fields.d.cts} +0 -0
  177. package/{rules/relay-page-info.d.ts → typings/rules/no-duplicate-fields.d.ts} +0 -0
  178. package/{rules/no-typename-prefix.d.ts → typings/rules/no-hashtag-description.d.cts} +0 -0
  179. package/{rules/no-unreachable-types.d.ts → typings/rules/no-hashtag-description.d.ts} +0 -0
  180. package/{rules/no-root-type.d.ts → typings/rules/no-root-type.d.cts} +0 -0
  181. package/typings/rules/no-root-type.d.ts +25 -0
  182. package/{rules/no-unused-fields.d.ts → typings/rules/no-scalar-result-type-on-mutation.d.cts} +0 -0
  183. package/{rules/unique-operation-name.d.ts → typings/rules/no-scalar-result-type-on-mutation.d.ts} +0 -0
  184. package/typings/rules/no-typename-prefix.d.cts +2 -0
  185. package/typings/rules/no-typename-prefix.d.ts +2 -0
  186. package/typings/rules/no-unreachable-types.d.cts +2 -0
  187. package/typings/rules/no-unreachable-types.d.ts +2 -0
  188. package/typings/rules/no-unused-fields.d.cts +2 -0
  189. package/typings/rules/no-unused-fields.d.ts +2 -0
  190. package/{rules/relay-arguments.d.ts → typings/rules/relay-arguments.d.cts} +0 -0
  191. package/typings/rules/relay-arguments.d.ts +21 -0
  192. package/{rules/relay-connection-types.d.ts → typings/rules/relay-connection-types.d.cts} +0 -0
  193. package/typings/rules/relay-connection-types.d.ts +4 -0
  194. package/{rules/relay-edge-types.d.ts → typings/rules/relay-edge-types.d.cts} +0 -0
  195. package/typings/rules/relay-edge-types.d.ts +31 -0
  196. package/{rules/require-deprecation-reason.d.ts → typings/rules/relay-page-info.d.cts} +0 -0
  197. package/{rules/require-field-of-type-query-in-mutation-result.d.ts → typings/rules/relay-page-info.d.ts} +0 -0
  198. package/{rules/require-deprecation-date.d.ts → typings/rules/require-deprecation-date.d.cts} +0 -0
  199. package/typings/rules/require-deprecation-date.d.ts +18 -0
  200. package/typings/rules/require-deprecation-reason.d.cts +2 -0
  201. package/typings/rules/require-deprecation-reason.d.ts +2 -0
  202. package/{rules/require-description.d.ts → typings/rules/require-description.d.cts} +0 -0
  203. package/typings/rules/require-description.d.ts +14 -0
  204. package/typings/rules/require-field-of-type-query-in-mutation-result.d.cts +2 -0
  205. package/typings/rules/require-field-of-type-query-in-mutation-result.d.ts +2 -0
  206. package/{rules/require-id-when-available.d.ts → typings/rules/require-id-when-available.d.cts} +0 -0
  207. package/typings/rules/require-id-when-available.d.ts +36 -0
  208. package/{rules/selection-set-depth.d.ts → typings/rules/selection-set-depth.d.cts} +0 -0
  209. package/typings/rules/selection-set-depth.d.ts +28 -0
  210. package/{rules/strict-id-in-types.d.ts → typings/rules/strict-id-in-types.d.cts} +0 -0
  211. package/typings/rules/strict-id-in-types.d.ts +57 -0
  212. package/{rules/unique-fragment-name.d.ts → typings/rules/unique-fragment-name.d.cts} +0 -0
  213. package/typings/rules/unique-fragment-name.d.ts +5 -0
  214. package/typings/rules/unique-operation-name.d.cts +2 -0
  215. package/typings/rules/unique-operation-name.d.ts +2 -0
  216. package/{schema.d.ts → typings/schema.d.cts} +0 -0
  217. package/typings/schema.d.ts +3 -0
  218. package/{testkit.d.ts → typings/testkit.d.cts} +0 -0
  219. package/typings/testkit.d.ts +27 -0
  220. package/{types.d.ts → typings/types.d.cts} +0 -0
  221. package/typings/types.d.ts +81 -0
  222. package/{utils.d.ts → typings/utils.d.cts} +0 -0
  223. package/typings/utils.d.ts +34 -0
  224. package/configs/base.json +0 -4
  225. package/configs/operations-all.json +0 -25
  226. package/configs/operations-recommended.json +0 -50
  227. package/configs/relay.json +0 -9
  228. package/configs/schema-all.json +0 -17
  229. package/configs/schema-recommended.json +0 -49
  230. package/index.js +0 -4995
  231. package/index.mjs +0 -4983
@@ -0,0 +1,499 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GRAPHQL_JS_VALIDATIONS = void 0;
4
+ const graphql_1 = require("graphql");
5
+ const validate_1 = require("graphql/validation/validate");
6
+ const utils_1 = require("../utils");
7
+ function validateDocument({ context, schema = null, documentNode, rule, hasDidYouMeanSuggestions, }) {
8
+ var _a;
9
+ if (documentNode.definitions.length === 0) {
10
+ return;
11
+ }
12
+ try {
13
+ const validationErrors = schema
14
+ ? (0, graphql_1.validate)(schema, documentNode, [rule])
15
+ : (0, validate_1.validateSDL)(documentNode, null, [rule]);
16
+ for (const error of validationErrors) {
17
+ const { line, column } = error.locations[0];
18
+ const sourceCode = context.getSourceCode();
19
+ const { tokens } = sourceCode.ast;
20
+ const token = tokens.find(token => token.loc.start.line === line && token.loc.start.column === column - 1);
21
+ let loc = {
22
+ line,
23
+ column: column - 1,
24
+ };
25
+ if (token) {
26
+ loc =
27
+ // if cursor on `@` symbol than use next node
28
+ token.type === '@'
29
+ ? sourceCode.getNodeByRangeIndex(token.range[1] + 1).loc
30
+ : token.loc;
31
+ }
32
+ const didYouMeanContent = (_a = error.message.match(/Did you mean (?<content>.*)\?$/)) === null || _a === void 0 ? void 0 : _a.groups.content;
33
+ const matches = didYouMeanContent ? [...didYouMeanContent.matchAll(/"(?<name>[^"]*)"/g)] : [];
34
+ context.report({
35
+ loc,
36
+ message: error.message,
37
+ suggest: hasDidYouMeanSuggestions
38
+ ? matches.map(match => {
39
+ const { name } = match.groups;
40
+ return {
41
+ desc: `Rename to \`${name}\``,
42
+ fix: fixer => fixer.replaceText(token, name),
43
+ };
44
+ })
45
+ : [],
46
+ });
47
+ }
48
+ }
49
+ catch (e) {
50
+ context.report({
51
+ loc: utils_1.REPORT_ON_FIRST_CHARACTER,
52
+ message: e.message,
53
+ });
54
+ }
55
+ }
56
+ const getFragmentDefsAndFragmentSpreads = (node) => {
57
+ const fragmentDefs = new Set();
58
+ const fragmentSpreads = new Set();
59
+ const visitor = {
60
+ FragmentDefinition(node) {
61
+ fragmentDefs.add(node.name.value);
62
+ },
63
+ FragmentSpread(node) {
64
+ fragmentSpreads.add(node.name.value);
65
+ },
66
+ };
67
+ (0, graphql_1.visit)(node, visitor);
68
+ return { fragmentDefs, fragmentSpreads };
69
+ };
70
+ const getMissingFragments = (node) => {
71
+ const { fragmentDefs, fragmentSpreads } = getFragmentDefsAndFragmentSpreads(node);
72
+ return [...fragmentSpreads].filter(name => !fragmentDefs.has(name));
73
+ };
74
+ const handleMissingFragments = ({ ruleId, context, node }) => {
75
+ const missingFragments = getMissingFragments(node);
76
+ if (missingFragments.length > 0) {
77
+ const siblings = (0, utils_1.requireSiblingsOperations)(ruleId, context);
78
+ const fragmentsToAdd = [];
79
+ for (const fragmentName of missingFragments) {
80
+ const [foundFragment] = siblings.getFragment(fragmentName).map(source => source.document);
81
+ if (foundFragment) {
82
+ fragmentsToAdd.push(foundFragment);
83
+ }
84
+ }
85
+ if (fragmentsToAdd.length > 0) {
86
+ // recall fn to make sure to add fragments inside fragments
87
+ return handleMissingFragments({
88
+ ruleId,
89
+ context,
90
+ node: {
91
+ kind: graphql_1.Kind.DOCUMENT,
92
+ definitions: [...node.definitions, ...fragmentsToAdd],
93
+ },
94
+ });
95
+ }
96
+ }
97
+ return node;
98
+ };
99
+ const validationToRule = ({ ruleId, ruleName, getDocumentNode, schema = [], hasDidYouMeanSuggestions, }, docs) => {
100
+ let ruleFn = null;
101
+ try {
102
+ ruleFn = require(`graphql/validation/rules/${ruleName}Rule`)[`${ruleName}Rule`];
103
+ }
104
+ catch (_a) {
105
+ try {
106
+ ruleFn = require(`graphql/validation/rules/${ruleName}`)[`${ruleName}Rule`];
107
+ }
108
+ catch (_b) {
109
+ ruleFn = require('graphql/validation')[`${ruleName}Rule`];
110
+ }
111
+ }
112
+ return {
113
+ [ruleId]: {
114
+ meta: {
115
+ docs: {
116
+ recommended: true,
117
+ ...docs,
118
+ graphQLJSRuleName: ruleName,
119
+ url: `https://github.com/B2o5T/graphql-eslint/blob/master/docs/rules/${ruleId}.md`,
120
+ description: `${docs.description}\n> This rule is a wrapper around a \`graphql-js\` validation function.`,
121
+ },
122
+ schema,
123
+ hasSuggestions: hasDidYouMeanSuggestions,
124
+ },
125
+ create(context) {
126
+ if (!ruleFn) {
127
+ utils_1.logger.warn(`Rule "${ruleId}" depends on a GraphQL validation rule "${ruleName}" but it's not available in the "graphql" version you are using. Skipping…`);
128
+ return {};
129
+ }
130
+ return {
131
+ Document(node) {
132
+ const schema = docs.requiresSchema
133
+ ? (0, utils_1.requireGraphQLSchemaFromContext)(ruleId, context)
134
+ : null;
135
+ const documentNode = getDocumentNode
136
+ ? getDocumentNode({ ruleId, context, node: node.rawNode() })
137
+ : node.rawNode();
138
+ validateDocument({
139
+ context,
140
+ schema,
141
+ documentNode,
142
+ rule: ruleFn,
143
+ hasDidYouMeanSuggestions,
144
+ });
145
+ },
146
+ };
147
+ },
148
+ },
149
+ };
150
+ };
151
+ exports.GRAPHQL_JS_VALIDATIONS = Object.assign({}, validationToRule({
152
+ ruleId: 'executable-definitions',
153
+ ruleName: 'ExecutableDefinitions',
154
+ }, {
155
+ category: 'Operations',
156
+ description: 'A GraphQL document is only valid for execution if all definitions are either operation or fragment definitions.',
157
+ requiresSchema: true,
158
+ }), validationToRule({
159
+ ruleId: 'fields-on-correct-type',
160
+ ruleName: 'FieldsOnCorrectType',
161
+ hasDidYouMeanSuggestions: true,
162
+ }, {
163
+ category: 'Operations',
164
+ description: 'A GraphQL document is only valid if all fields selected are defined by the parent type, or are an allowed meta field such as `__typename`.',
165
+ requiresSchema: true,
166
+ }), validationToRule({
167
+ ruleId: 'fragments-on-composite-type',
168
+ ruleName: 'FragmentsOnCompositeTypes',
169
+ }, {
170
+ category: 'Operations',
171
+ description: 'Fragments use a type condition to determine if they apply, since fragments can only be spread into a composite type (object, interface, or union), the type condition must also be a composite type.',
172
+ requiresSchema: true,
173
+ }), validationToRule({
174
+ ruleId: 'known-argument-names',
175
+ ruleName: 'KnownArgumentNames',
176
+ hasDidYouMeanSuggestions: true,
177
+ }, {
178
+ category: ['Schema', 'Operations'],
179
+ description: 'A GraphQL field is only valid if all supplied arguments are defined by that field.',
180
+ requiresSchema: true,
181
+ }), validationToRule({
182
+ ruleId: 'known-directives',
183
+ ruleName: 'KnownDirectives',
184
+ getDocumentNode({ context, node: documentNode }) {
185
+ const { ignoreClientDirectives = [] } = context.options[0] || {};
186
+ if (ignoreClientDirectives.length === 0) {
187
+ return documentNode;
188
+ }
189
+ const filterDirectives = (node) => ({
190
+ ...node,
191
+ directives: node.directives.filter(directive => !ignoreClientDirectives.includes(directive.name.value)),
192
+ });
193
+ return (0, graphql_1.visit)(documentNode, {
194
+ Field: filterDirectives,
195
+ OperationDefinition: filterDirectives,
196
+ });
197
+ },
198
+ schema: {
199
+ type: 'array',
200
+ maxItems: 1,
201
+ items: {
202
+ type: 'object',
203
+ additionalProperties: false,
204
+ required: ['ignoreClientDirectives'],
205
+ properties: {
206
+ ignoreClientDirectives: utils_1.ARRAY_DEFAULT_OPTIONS,
207
+ },
208
+ },
209
+ },
210
+ }, {
211
+ category: ['Schema', 'Operations'],
212
+ description: 'A GraphQL document is only valid if all `@directive`s are known by the schema and legally positioned.',
213
+ requiresSchema: true,
214
+ examples: [
215
+ {
216
+ title: 'Valid',
217
+ usage: [{ ignoreClientDirectives: ['client'] }],
218
+ code: /* GraphQL */ `
219
+ {
220
+ product {
221
+ someClientField @client
222
+ }
223
+ }
224
+ `,
225
+ },
226
+ ],
227
+ }), validationToRule({
228
+ ruleId: 'known-fragment-names',
229
+ ruleName: 'KnownFragmentNames',
230
+ getDocumentNode: handleMissingFragments,
231
+ }, {
232
+ category: 'Operations',
233
+ description: 'A GraphQL document is only valid if all `...Fragment` fragment spreads refer to fragments defined in the same document.',
234
+ requiresSchema: true,
235
+ requiresSiblings: true,
236
+ examples: [
237
+ {
238
+ title: 'Incorrect',
239
+ code: /* GraphQL */ `
240
+ query {
241
+ user {
242
+ id
243
+ ...UserFields # fragment not defined in the document
244
+ }
245
+ }
246
+ `,
247
+ },
248
+ {
249
+ title: 'Correct',
250
+ code: /* GraphQL */ `
251
+ fragment UserFields on User {
252
+ firstName
253
+ lastName
254
+ }
255
+
256
+ query {
257
+ user {
258
+ id
259
+ ...UserFields
260
+ }
261
+ }
262
+ `,
263
+ },
264
+ {
265
+ title: 'Correct (`UserFields` fragment located in a separate file)',
266
+ code: /* GraphQL */ `
267
+ # user.gql
268
+ query {
269
+ user {
270
+ id
271
+ ...UserFields
272
+ }
273
+ }
274
+
275
+ # user-fields.gql
276
+ fragment UserFields on User {
277
+ id
278
+ }
279
+ `,
280
+ },
281
+ ],
282
+ }), validationToRule({
283
+ ruleId: 'known-type-names',
284
+ ruleName: 'KnownTypeNames',
285
+ hasDidYouMeanSuggestions: true,
286
+ }, {
287
+ category: ['Schema', 'Operations'],
288
+ description: 'A GraphQL document is only valid if referenced types (specifically variable definitions and fragment conditions) are defined by the type schema.',
289
+ requiresSchema: true,
290
+ }), validationToRule({
291
+ ruleId: 'lone-anonymous-operation',
292
+ ruleName: 'LoneAnonymousOperation',
293
+ }, {
294
+ category: 'Operations',
295
+ description: 'A GraphQL document that contains an anonymous operation (the `query` short-hand) is only valid if it contains only that one operation definition.',
296
+ requiresSchema: true,
297
+ }), validationToRule({
298
+ ruleId: 'lone-schema-definition',
299
+ ruleName: 'LoneSchemaDefinition',
300
+ }, {
301
+ category: 'Schema',
302
+ description: 'A GraphQL document is only valid if it contains only one schema definition.',
303
+ }), validationToRule({
304
+ ruleId: 'no-fragment-cycles',
305
+ ruleName: 'NoFragmentCycles',
306
+ }, {
307
+ category: 'Operations',
308
+ description: 'A GraphQL fragment is only valid when it does not have cycles in fragments usage.',
309
+ requiresSchema: true,
310
+ }), validationToRule({
311
+ ruleId: 'no-undefined-variables',
312
+ ruleName: 'NoUndefinedVariables',
313
+ getDocumentNode: handleMissingFragments,
314
+ }, {
315
+ category: 'Operations',
316
+ description: 'A GraphQL operation is only valid if all variables encountered, both directly and via fragment spreads, are defined by that operation.',
317
+ requiresSchema: true,
318
+ requiresSiblings: true,
319
+ }), validationToRule({
320
+ ruleId: 'no-unused-fragments',
321
+ ruleName: 'NoUnusedFragments',
322
+ getDocumentNode: ({ ruleId, context, node }) => {
323
+ const siblings = (0, utils_1.requireSiblingsOperations)(ruleId, context);
324
+ const FilePathToDocumentsMap = [
325
+ ...siblings.getOperations(),
326
+ ...siblings.getFragments(),
327
+ ].reduce((map, { filePath, document }) => {
328
+ var _a;
329
+ (_a = map[filePath]) !== null && _a !== void 0 ? _a : (map[filePath] = []);
330
+ map[filePath].push(document);
331
+ return map;
332
+ }, Object.create(null));
333
+ const getParentNode = (currentFilePath, node) => {
334
+ const { fragmentDefs } = getFragmentDefsAndFragmentSpreads(node);
335
+ if (fragmentDefs.size === 0) {
336
+ return node;
337
+ }
338
+ // skip iteration over documents for current filepath
339
+ delete FilePathToDocumentsMap[currentFilePath];
340
+ for (const [filePath, documents] of Object.entries(FilePathToDocumentsMap)) {
341
+ const missingFragments = getMissingFragments({
342
+ kind: graphql_1.Kind.DOCUMENT,
343
+ definitions: documents,
344
+ });
345
+ const isCurrentFileImportFragment = missingFragments.some(fragment => fragmentDefs.has(fragment));
346
+ if (isCurrentFileImportFragment) {
347
+ return getParentNode(filePath, {
348
+ kind: graphql_1.Kind.DOCUMENT,
349
+ definitions: [...node.definitions, ...documents],
350
+ });
351
+ }
352
+ }
353
+ return node;
354
+ };
355
+ return getParentNode(context.getFilename(), node);
356
+ },
357
+ }, {
358
+ category: 'Operations',
359
+ description: 'A GraphQL document is only valid if all fragment definitions are spread within operations, or spread within other fragments spread within operations.',
360
+ requiresSchema: true,
361
+ requiresSiblings: true,
362
+ }), validationToRule({
363
+ ruleId: 'no-unused-variables',
364
+ ruleName: 'NoUnusedVariables',
365
+ getDocumentNode: handleMissingFragments,
366
+ }, {
367
+ category: 'Operations',
368
+ description: 'A GraphQL operation is only valid if all variables defined by an operation are used, either directly or within a spread fragment.',
369
+ requiresSchema: true,
370
+ requiresSiblings: true,
371
+ }), validationToRule({
372
+ ruleId: 'overlapping-fields-can-be-merged',
373
+ ruleName: 'OverlappingFieldsCanBeMerged',
374
+ }, {
375
+ category: 'Operations',
376
+ 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.',
377
+ requiresSchema: true,
378
+ }), validationToRule({
379
+ ruleId: 'possible-fragment-spread',
380
+ ruleName: 'PossibleFragmentSpreads',
381
+ }, {
382
+ category: 'Operations',
383
+ 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.',
384
+ requiresSchema: true,
385
+ }), validationToRule({
386
+ ruleId: 'possible-type-extension',
387
+ ruleName: 'PossibleTypeExtensions',
388
+ hasDidYouMeanSuggestions: true,
389
+ }, {
390
+ category: 'Schema',
391
+ description: 'A type extension is only valid if the type is defined and has the same kind.',
392
+ // TODO: add in graphql-eslint v4
393
+ recommended: false,
394
+ requiresSchema: true,
395
+ isDisabledForAllConfig: true,
396
+ }), validationToRule({
397
+ ruleId: 'provided-required-arguments',
398
+ ruleName: 'ProvidedRequiredArguments',
399
+ }, {
400
+ category: ['Schema', 'Operations'],
401
+ description: 'A field or directive is only valid if all required (non-null without a default value) field arguments have been provided.',
402
+ requiresSchema: true,
403
+ }), validationToRule({
404
+ ruleId: 'scalar-leafs',
405
+ ruleName: 'ScalarLeafs',
406
+ hasDidYouMeanSuggestions: true,
407
+ }, {
408
+ category: 'Operations',
409
+ description: 'A GraphQL document is valid only if all leaf fields (fields without sub selections) are of scalar or enum types.',
410
+ requiresSchema: true,
411
+ }), validationToRule({
412
+ ruleId: 'one-field-subscriptions',
413
+ ruleName: 'SingleFieldSubscriptions',
414
+ }, {
415
+ category: 'Operations',
416
+ description: 'A GraphQL subscription is valid only if it contains a single root field.',
417
+ requiresSchema: true,
418
+ }), validationToRule({
419
+ ruleId: 'unique-argument-names',
420
+ ruleName: 'UniqueArgumentNames',
421
+ }, {
422
+ category: 'Operations',
423
+ description: 'A GraphQL field or directive is only valid if all supplied arguments are uniquely named.',
424
+ requiresSchema: true,
425
+ }), validationToRule({
426
+ ruleId: 'unique-directive-names',
427
+ ruleName: 'UniqueDirectiveNames',
428
+ }, {
429
+ category: 'Schema',
430
+ description: 'A GraphQL document is only valid if all defined directives have unique names.',
431
+ }), validationToRule({
432
+ ruleId: 'unique-directive-names-per-location',
433
+ ruleName: 'UniqueDirectivesPerLocation',
434
+ }, {
435
+ category: ['Schema', 'Operations'],
436
+ description: 'A GraphQL document is only valid if all non-repeatable directives at a given location are uniquely named.',
437
+ requiresSchema: true,
438
+ }), validationToRule({
439
+ ruleId: 'unique-enum-value-names',
440
+ ruleName: 'UniqueEnumValueNames',
441
+ }, {
442
+ category: 'Schema',
443
+ description: 'A GraphQL enum type is only valid if all its values are uniquely named.',
444
+ recommended: false,
445
+ isDisabledForAllConfig: true,
446
+ }), validationToRule({
447
+ ruleId: 'unique-field-definition-names',
448
+ ruleName: 'UniqueFieldDefinitionNames',
449
+ }, {
450
+ category: 'Schema',
451
+ description: 'A GraphQL complex type is only valid if all its fields are uniquely named.',
452
+ }), validationToRule({
453
+ ruleId: 'unique-input-field-names',
454
+ ruleName: 'UniqueInputFieldNames',
455
+ }, {
456
+ category: 'Operations',
457
+ description: 'A GraphQL input object value is only valid if all supplied fields are uniquely named.',
458
+ }), validationToRule({
459
+ ruleId: 'unique-operation-types',
460
+ ruleName: 'UniqueOperationTypes',
461
+ }, {
462
+ category: 'Schema',
463
+ description: 'A GraphQL document is only valid if it has only one type per operation.',
464
+ }), validationToRule({
465
+ ruleId: 'unique-type-names',
466
+ ruleName: 'UniqueTypeNames',
467
+ }, {
468
+ category: 'Schema',
469
+ description: 'A GraphQL document is only valid if all defined types have unique names.',
470
+ }), validationToRule({
471
+ ruleId: 'unique-variable-names',
472
+ ruleName: 'UniqueVariableNames',
473
+ }, {
474
+ category: 'Operations',
475
+ description: 'A GraphQL operation is only valid if all its variables are uniquely named.',
476
+ requiresSchema: true,
477
+ }), validationToRule({
478
+ ruleId: 'value-literals-of-correct-type',
479
+ ruleName: 'ValuesOfCorrectType',
480
+ hasDidYouMeanSuggestions: true,
481
+ }, {
482
+ category: 'Operations',
483
+ description: 'A GraphQL document is only valid if all value literals are of the type expected at their position.',
484
+ requiresSchema: true,
485
+ }), validationToRule({
486
+ ruleId: 'variables-are-input-types',
487
+ ruleName: 'VariablesAreInputTypes',
488
+ }, {
489
+ category: 'Operations',
490
+ description: 'A GraphQL operation is only valid if all the variables it defines are of input types (scalar, enum, or input object).',
491
+ requiresSchema: true,
492
+ }), validationToRule({
493
+ ruleId: 'variables-in-allowed-position',
494
+ ruleName: 'VariablesInAllowedPosition',
495
+ }, {
496
+ category: 'Operations',
497
+ description: 'Variables passed to field arguments conform to type.',
498
+ requiresSchema: true,
499
+ }));
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ /*
3
+ * 🚨 IMPORTANT! Do not manually modify this file. Run: `yarn generate-configs`
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.rules = void 0;
7
+ const graphql_js_validation_1 = require("./graphql-js-validation");
8
+ const alphabetize_1 = require("./alphabetize");
9
+ const description_style_1 = require("./description-style");
10
+ const input_name_1 = require("./input-name");
11
+ const lone_executable_definition_1 = require("./lone-executable-definition");
12
+ const match_document_filename_1 = require("./match-document-filename");
13
+ const naming_convention_1 = require("./naming-convention");
14
+ const no_anonymous_operations_1 = require("./no-anonymous-operations");
15
+ const no_case_insensitive_enum_values_duplicates_1 = require("./no-case-insensitive-enum-values-duplicates");
16
+ const no_deprecated_1 = require("./no-deprecated");
17
+ const no_duplicate_fields_1 = require("./no-duplicate-fields");
18
+ const no_hashtag_description_1 = require("./no-hashtag-description");
19
+ const no_root_type_1 = require("./no-root-type");
20
+ const no_scalar_result_type_on_mutation_1 = require("./no-scalar-result-type-on-mutation");
21
+ const no_typename_prefix_1 = require("./no-typename-prefix");
22
+ const no_unreachable_types_1 = require("./no-unreachable-types");
23
+ const no_unused_fields_1 = require("./no-unused-fields");
24
+ const relay_arguments_1 = require("./relay-arguments");
25
+ const relay_connection_types_1 = require("./relay-connection-types");
26
+ const relay_edge_types_1 = require("./relay-edge-types");
27
+ const relay_page_info_1 = require("./relay-page-info");
28
+ const require_deprecation_date_1 = require("./require-deprecation-date");
29
+ const require_deprecation_reason_1 = require("./require-deprecation-reason");
30
+ const require_description_1 = require("./require-description");
31
+ const require_field_of_type_query_in_mutation_result_1 = require("./require-field-of-type-query-in-mutation-result");
32
+ const require_id_when_available_1 = require("./require-id-when-available");
33
+ const selection_set_depth_1 = require("./selection-set-depth");
34
+ const strict_id_in_types_1 = require("./strict-id-in-types");
35
+ const unique_fragment_name_1 = require("./unique-fragment-name");
36
+ const unique_operation_name_1 = require("./unique-operation-name");
37
+ exports.rules = {
38
+ ...graphql_js_validation_1.GRAPHQL_JS_VALIDATIONS,
39
+ alphabetize: alphabetize_1.rule,
40
+ 'description-style': description_style_1.rule,
41
+ 'input-name': input_name_1.rule,
42
+ 'lone-executable-definition': lone_executable_definition_1.rule,
43
+ 'match-document-filename': match_document_filename_1.rule,
44
+ 'naming-convention': naming_convention_1.rule,
45
+ 'no-anonymous-operations': no_anonymous_operations_1.rule,
46
+ 'no-case-insensitive-enum-values-duplicates': no_case_insensitive_enum_values_duplicates_1.rule,
47
+ 'no-deprecated': no_deprecated_1.rule,
48
+ 'no-duplicate-fields': no_duplicate_fields_1.rule,
49
+ 'no-hashtag-description': no_hashtag_description_1.rule,
50
+ 'no-root-type': no_root_type_1.rule,
51
+ 'no-scalar-result-type-on-mutation': no_scalar_result_type_on_mutation_1.rule,
52
+ 'no-typename-prefix': no_typename_prefix_1.rule,
53
+ 'no-unreachable-types': no_unreachable_types_1.rule,
54
+ 'no-unused-fields': no_unused_fields_1.rule,
55
+ 'relay-arguments': relay_arguments_1.rule,
56
+ 'relay-connection-types': relay_connection_types_1.rule,
57
+ 'relay-edge-types': relay_edge_types_1.rule,
58
+ 'relay-page-info': relay_page_info_1.rule,
59
+ 'require-deprecation-date': require_deprecation_date_1.rule,
60
+ 'require-deprecation-reason': require_deprecation_reason_1.rule,
61
+ 'require-description': require_description_1.rule,
62
+ 'require-field-of-type-query-in-mutation-result': require_field_of_type_query_in_mutation_result_1.rule,
63
+ 'require-id-when-available': require_id_when_available_1.rule,
64
+ 'selection-set-depth': selection_set_depth_1.rule,
65
+ 'strict-id-in-types': strict_id_in_types_1.rule,
66
+ 'unique-fragment-name': unique_fragment_name_1.rule,
67
+ 'unique-operation-name': unique_operation_name_1.rule,
68
+ };