@graphql-eslint/eslint-plugin 3.19.3 → 3.20.0-alpha-20230703154330-0d51273
Sign up to get free protection for your applications and to get access to all the features.
- package/{typings → cjs}/cache.d.ts +3 -1
- package/cjs/cache.js +57 -26
- package/{typings → cjs}/configs/index.d.ts +3 -1
- package/cjs/configs/index.js +47 -14
- package/{typings → cjs}/configs/operations-all.d.ts +2 -1
- package/cjs/configs/operations-all.js +47 -30
- package/{typings → cjs}/configs/operations-recommended.d.ts +2 -1
- package/cjs/configs/operations-recommended.js +72 -55
- package/{typings → cjs}/configs/relay.d.ts +2 -1
- package/cjs/configs/relay.js +31 -11
- package/{typings → cjs}/configs/schema-all.d.ts +2 -1
- package/cjs/configs/schema-all.js +41 -24
- package/{typings → cjs}/configs/schema-recommended.d.ts +2 -1
- package/cjs/configs/schema-recommended.js +68 -51
- package/{typings → cjs}/documents.d.ts +4 -1
- package/cjs/documents.js +74 -43
- package/cjs/estree-converter/converter.d.ts +8 -0
- package/cjs/estree-converter/converter.js +80 -59
- package/cjs/estree-converter/index.d.ts +8 -0
- package/cjs/estree-converter/index.js +25 -5
- package/{typings → cjs}/estree-converter/types.d.ts +7 -5
- package/cjs/estree-converter/types.js +16 -0
- package/cjs/estree-converter/utils.d.ts +18 -0
- package/cjs/estree-converter/utils.js +119 -95
- package/{typings → cjs}/flat-configs.d.ts +12 -1
- package/cjs/flat-configs.js +56 -32
- package/cjs/graphql-config.d.ts +13 -0
- package/cjs/graphql-config.js +78 -47
- package/cjs/index.d.ts +22 -0
- package/cjs/index.js +50 -18
- package/cjs/parser.d.ts +12 -0
- package/cjs/parser.js +96 -76
- package/cjs/processor.d.ts +9 -0
- package/cjs/processor.js +119 -88
- package/{typings → cjs}/rules/alphabetize.d.ts +12 -4
- package/cjs/rules/alphabetize.js +337 -295
- package/{typings → cjs}/rules/description-style.d.ts +12 -4
- package/cjs/rules/description-style.js +96 -66
- package/cjs/rules/graphql-js-validation.d.ts +12 -0
- package/cjs/rules/graphql-js-validation.js +595 -433
- package/cjs/rules/index.d.ts +125 -0
- package/cjs/rules/index.js +97 -76
- package/{typings → cjs}/rules/input-name.d.ts +12 -4
- package/cjs/rules/input-name.js +153 -123
- package/{typings → cjs}/rules/lone-executable-definition.d.ts +12 -4
- package/cjs/rules/lone-executable-definition.js +101 -72
- package/{typings → cjs}/rules/match-document-filename.d.ts +14 -6
- package/cjs/rules/match-document-filename.js +229 -182
- package/{typings → cjs}/rules/naming-convention.d.ts +12 -4
- package/cjs/rules/naming-convention.js +380 -316
- package/cjs/rules/no-anonymous-operations.d.ts +12 -0
- package/cjs/rules/no-anonymous-operations.js +88 -57
- package/cjs/rules/no-case-insensitive-enum-values-duplicates.d.ts +12 -0
- package/cjs/rules/no-case-insensitive-enum-values-duplicates.js +82 -50
- package/cjs/rules/no-deprecated.d.ts +12 -0
- package/cjs/rules/no-deprecated.js +106 -75
- package/cjs/rules/no-duplicate-fields.d.ts +12 -0
- package/cjs/rules/no-duplicate-fields.js +116 -82
- package/cjs/rules/no-hashtag-description.d.ts +13 -0
- package/cjs/rules/no-hashtag-description.js +119 -82
- package/cjs/rules/no-one-place-fragments.d.ts +12 -0
- package/cjs/rules/no-one-place-fragments.js +88 -58
- package/{typings → cjs}/rules/no-root-type.d.ts +12 -4
- package/cjs/rules/no-root-type.js +101 -74
- package/cjs/rules/no-scalar-result-type-on-mutation.d.ts +12 -0
- package/cjs/rules/no-scalar-result-type-on-mutation.js +90 -60
- package/cjs/rules/no-typename-prefix.d.ts +12 -0
- package/cjs/rules/no-typename-prefix.js +88 -55
- package/cjs/rules/no-unreachable-types.d.ts +12 -0
- package/cjs/rules/no-unreachable-types.js +169 -134
- package/cjs/rules/no-unused-fields.d.ts +12 -0
- package/cjs/rules/no-unused-fields.js +117 -92
- package/{typings → cjs}/rules/relay-arguments.d.ts +12 -4
- package/cjs/rules/relay-arguments.js +136 -110
- package/cjs/rules/relay-connection-types.d.ts +13 -0
- package/cjs/rules/relay-connection-types.js +123 -94
- package/{typings → cjs}/rules/relay-edge-types.d.ts +12 -4
- package/cjs/rules/relay-edge-types.js +196 -179
- package/cjs/rules/relay-page-info.d.ts +12 -0
- package/cjs/rules/relay-page-info.js +108 -89
- package/{typings → cjs}/rules/require-deprecation-date.d.ts +12 -4
- package/cjs/rules/require-deprecation-date.js +143 -112
- package/cjs/rules/require-deprecation-reason.d.ts +12 -0
- package/cjs/rules/require-deprecation-reason.js +80 -46
- package/{typings → cjs}/rules/require-description.d.ts +13 -5
- package/cjs/rules/require-description.js +170 -132
- package/cjs/rules/require-field-of-type-query-in-mutation-result.d.ts +12 -0
- package/cjs/rules/require-field-of-type-query-in-mutation-result.js +81 -51
- package/{typings → cjs}/rules/require-id-when-available.d.ts +12 -4
- package/cjs/rules/require-id-when-available.js +196 -173
- package/cjs/rules/require-import-fragment.d.ts +12 -0
- package/cjs/rules/require-import-fragment.js +138 -88
- package/cjs/rules/require-nullable-fields-with-oneof.d.ts +12 -0
- package/cjs/rules/require-nullable-fields-with-oneof.js +80 -50
- package/cjs/rules/require-nullable-result-in-root.d.ts +12 -0
- package/cjs/rules/require-nullable-result-in-root.js +97 -68
- package/cjs/rules/require-type-pattern-with-oneof.d.ts +12 -0
- package/cjs/rules/require-type-pattern-with-oneof.js +70 -42
- package/{typings → cjs}/rules/selection-set-depth.d.ts +12 -4
- package/cjs/rules/selection-set-depth.js +147 -107
- package/{typings → cjs}/rules/strict-id-in-types.d.ts +12 -4
- package/cjs/rules/strict-id-in-types.js +143 -122
- package/cjs/rules/unique-fragment-name.d.ts +13 -0
- package/cjs/rules/unique-fragment-name.js +88 -62
- package/cjs/rules/unique-operation-name.d.ts +12 -0
- package/cjs/rules/unique-operation-name.js +65 -35
- package/cjs/schema.d.ts +12 -0
- package/cjs/schema.js +62 -30
- package/cjs/siblings.d.ts +8 -0
- package/cjs/siblings.js +124 -106
- package/cjs/testkit.d.ts +8 -0
- package/cjs/testkit.js +165 -144
- package/cjs/types-e3367e3c.d.ts +129 -0
- package/cjs/types.d.ts +8 -0
- package/cjs/types.js +16 -0
- package/cjs/utils.d.ts +44 -0
- package/cjs/utils.js +181 -124
- package/{typings/cache.d.cts → esm/cache.d.mts} +3 -1
- package/esm/cache.js +25 -23
- package/{typings/configs/index.d.cts → esm/configs/index.d.mts} +3 -1
- package/esm/configs/index.js +14 -11
- package/{typings/configs/operations-all.d.cts → esm/configs/operations-all.d.mts} +2 -1
- package/esm/configs/operations-all.js +28 -28
- package/{typings/configs/operations-recommended.d.cts → esm/configs/operations-recommended.d.mts} +2 -1
- package/esm/configs/operations-recommended.js +53 -53
- package/{typings/configs/relay.d.cts → esm/configs/relay.d.mts} +2 -1
- package/esm/configs/relay.js +12 -9
- package/{typings/configs/schema-all.d.cts → esm/configs/schema-all.d.mts} +2 -1
- package/esm/configs/schema-all.js +22 -22
- package/{typings/configs/schema-recommended.d.cts → esm/configs/schema-recommended.d.mts} +2 -1
- package/esm/configs/schema-recommended.js +49 -49
- package/{typings/documents.d.cts → esm/documents.d.mts} +4 -1
- package/esm/documents.js +41 -39
- package/esm/estree-converter/converter.d.mts +8 -0
- package/esm/estree-converter/converter.js +63 -57
- package/esm/estree-converter/index.d.mts +8 -0
- package/esm/estree-converter/index.js +3 -3
- package/{typings/estree-converter/types.d.cts → esm/estree-converter/types.d.mts} +7 -5
- package/esm/estree-converter/utils.d.mts +18 -0
- package/esm/estree-converter/utils.js +102 -93
- package/{typings/flat-configs.d.cts → esm/flat-configs.d.mts} +13 -2
- package/esm/flat-configs.js +33 -30
- package/esm/graphql-config.d.mts +13 -0
- package/esm/graphql-config.js +49 -44
- package/esm/index.d.mts +22 -0
- package/esm/index.js +18 -9
- package/esm/package.json +1 -1
- package/esm/parser.d.mts +12 -0
- package/esm/parser.js +64 -73
- package/esm/processor.d.mts +9 -0
- package/esm/processor.js +98 -86
- package/{typings/rules/alphabetize.d.cts → esm/rules/alphabetize.d.mts} +12 -4
- package/esm/rules/alphabetize.js +304 -290
- package/{typings/rules/description-style.d.cts → esm/rules/description-style.d.mts} +12 -4
- package/esm/rules/description-style.js +73 -64
- package/esm/rules/graphql-js-validation.d.mts +12 -0
- package/esm/rules/graphql-js-validation.js +580 -429
- package/esm/rules/index.d.mts +125 -0
- package/esm/rules/index.js +74 -74
- package/{typings/rules/input-name.d.cts → esm/rules/input-name.d.mts} +12 -4
- package/esm/rules/input-name.js +132 -121
- package/{typings/rules/lone-executable-definition.d.cts → esm/rules/lone-executable-definition.d.mts} +12 -4
- package/esm/rules/lone-executable-definition.js +78 -70
- package/{typings/rules/match-document-filename.d.cts → esm/rules/match-document-filename.d.mts} +14 -6
- package/esm/rules/match-document-filename.js +210 -180
- package/{typings/rules/naming-convention.d.cts → esm/rules/naming-convention.d.mts} +12 -4
- package/esm/rules/naming-convention.js +363 -314
- package/esm/rules/no-anonymous-operations.d.mts +12 -0
- package/esm/rules/no-anonymous-operations.js +65 -55
- package/esm/rules/no-case-insensitive-enum-values-duplicates.d.mts +12 -0
- package/esm/rules/no-case-insensitive-enum-values-duplicates.js +59 -48
- package/esm/rules/no-deprecated.d.mts +12 -0
- package/esm/rules/no-deprecated.js +83 -73
- package/esm/rules/no-duplicate-fields.d.mts +12 -0
- package/esm/rules/no-duplicate-fields.js +93 -80
- package/esm/rules/no-hashtag-description.d.mts +13 -0
- package/esm/rules/no-hashtag-description.js +95 -80
- package/esm/rules/no-one-place-fragments.d.mts +12 -0
- package/esm/rules/no-one-place-fragments.js +65 -56
- package/{typings/rules/no-root-type.d.cts → esm/rules/no-root-type.d.mts} +12 -4
- package/esm/rules/no-root-type.js +78 -72
- package/esm/rules/no-scalar-result-type-on-mutation.d.mts +12 -0
- package/esm/rules/no-scalar-result-type-on-mutation.js +67 -58
- package/esm/rules/no-typename-prefix.d.mts +12 -0
- package/esm/rules/no-typename-prefix.js +65 -53
- package/esm/rules/no-unreachable-types.d.mts +12 -0
- package/esm/rules/no-unreachable-types.js +141 -131
- package/esm/rules/no-unused-fields.d.mts +12 -0
- package/esm/rules/no-unused-fields.js +94 -90
- package/{typings/rules/relay-arguments.d.cts → esm/rules/relay-arguments.d.mts} +12 -4
- package/esm/rules/relay-arguments.js +113 -108
- package/esm/rules/relay-connection-types.d.mts +13 -0
- package/esm/rules/relay-connection-types.js +98 -91
- package/{typings/rules/relay-edge-types.d.cts → esm/rules/relay-edge-types.d.mts} +12 -4
- package/esm/rules/relay-edge-types.js +178 -177
- package/esm/rules/relay-page-info.d.mts +12 -0
- package/esm/rules/relay-page-info.js +84 -86
- package/{typings/rules/require-deprecation-date.d.cts → esm/rules/require-deprecation-date.d.mts} +12 -4
- package/esm/rules/require-deprecation-date.js +120 -110
- package/esm/rules/require-deprecation-reason.d.mts +12 -0
- package/esm/rules/require-deprecation-reason.js +57 -44
- package/{typings/rules/require-description.d.cts → esm/rules/require-description.d.mts} +13 -5
- package/esm/rules/require-description.js +151 -130
- package/esm/rules/require-field-of-type-query-in-mutation-result.d.mts +12 -0
- package/esm/rules/require-field-of-type-query-in-mutation-result.js +58 -49
- package/{typings/rules/require-id-when-available.d.cts → esm/rules/require-id-when-available.d.mts} +12 -4
- package/esm/rules/require-id-when-available.js +186 -171
- package/esm/rules/require-import-fragment.d.mts +12 -0
- package/esm/rules/require-import-fragment.js +105 -85
- package/esm/rules/require-nullable-fields-with-oneof.d.mts +12 -0
- package/esm/rules/require-nullable-fields-with-oneof.js +57 -48
- package/esm/rules/require-nullable-result-in-root.d.mts +12 -0
- package/esm/rules/require-nullable-result-in-root.js +74 -66
- package/esm/rules/require-type-pattern-with-oneof.d.mts +12 -0
- package/esm/rules/require-type-pattern-with-oneof.js +47 -40
- package/{typings/rules/selection-set-depth.d.cts → esm/rules/selection-set-depth.d.mts} +12 -4
- package/esm/rules/selection-set-depth.js +114 -104
- package/{typings/rules/strict-id-in-types.d.cts → esm/rules/strict-id-in-types.d.mts} +12 -4
- package/esm/rules/strict-id-in-types.js +125 -119
- package/esm/rules/unique-fragment-name.d.mts +13 -0
- package/esm/rules/unique-fragment-name.js +65 -60
- package/esm/rules/unique-operation-name.d.mts +12 -0
- package/esm/rules/unique-operation-name.js +42 -33
- package/esm/schema.d.mts +12 -0
- package/esm/schema.js +29 -26
- package/esm/siblings.d.mts +8 -0
- package/esm/siblings.js +105 -104
- package/esm/testkit.d.mts +8 -0
- package/esm/testkit.js +132 -141
- package/esm/types-2e1afd7c.d.ts +129 -0
- package/esm/types.d.mts +8 -0
- package/esm/utils.d.mts +44 -0
- package/esm/utils.js +138 -116
- package/package.json +40 -30
- package/typings/estree-converter/converter.d.cts +0 -3
- package/typings/estree-converter/converter.d.ts +0 -3
- package/typings/estree-converter/index.d.cts +0 -3
- package/typings/estree-converter/index.d.ts +0 -3
- package/typings/estree-converter/utils.d.cts +0 -13
- package/typings/estree-converter/utils.d.ts +0 -13
- package/typings/graphql-config.d.cts +0 -4
- package/typings/graphql-config.d.ts +0 -4
- package/typings/index.d.cts +0 -10
- package/typings/index.d.ts +0 -10
- package/typings/parser.d.cts +0 -2
- package/typings/parser.d.ts +0 -2
- package/typings/processor.d.cts +0 -6
- package/typings/processor.d.ts +0 -6
- package/typings/rules/graphql-js-validation.d.cts +0 -2
- package/typings/rules/graphql-js-validation.d.ts +0 -2
- package/typings/rules/index.d.cts +0 -111
- package/typings/rules/index.d.ts +0 -111
- package/typings/rules/no-anonymous-operations.d.cts +0 -2
- package/typings/rules/no-anonymous-operations.d.ts +0 -2
- package/typings/rules/no-case-insensitive-enum-values-duplicates.d.cts +0 -2
- package/typings/rules/no-case-insensitive-enum-values-duplicates.d.ts +0 -2
- package/typings/rules/no-deprecated.d.cts +0 -2
- package/typings/rules/no-deprecated.d.ts +0 -2
- package/typings/rules/no-duplicate-fields.d.cts +0 -2
- package/typings/rules/no-duplicate-fields.d.ts +0 -2
- package/typings/rules/no-hashtag-description.d.cts +0 -3
- package/typings/rules/no-hashtag-description.d.ts +0 -3
- package/typings/rules/no-one-place-fragments.d.cts +0 -2
- package/typings/rules/no-one-place-fragments.d.ts +0 -2
- package/typings/rules/no-scalar-result-type-on-mutation.d.cts +0 -2
- package/typings/rules/no-scalar-result-type-on-mutation.d.ts +0 -2
- package/typings/rules/no-typename-prefix.d.cts +0 -2
- package/typings/rules/no-typename-prefix.d.ts +0 -2
- package/typings/rules/no-unreachable-types.d.cts +0 -2
- package/typings/rules/no-unreachable-types.d.ts +0 -2
- package/typings/rules/no-unused-fields.d.cts +0 -2
- package/typings/rules/no-unused-fields.d.ts +0 -2
- package/typings/rules/relay-connection-types.d.cts +0 -4
- package/typings/rules/relay-connection-types.d.ts +0 -4
- package/typings/rules/relay-page-info.d.cts +0 -2
- package/typings/rules/relay-page-info.d.ts +0 -2
- package/typings/rules/require-deprecation-reason.d.cts +0 -2
- package/typings/rules/require-deprecation-reason.d.ts +0 -2
- package/typings/rules/require-field-of-type-query-in-mutation-result.d.cts +0 -2
- package/typings/rules/require-field-of-type-query-in-mutation-result.d.ts +0 -2
- package/typings/rules/require-import-fragment.d.cts +0 -2
- package/typings/rules/require-import-fragment.d.ts +0 -2
- package/typings/rules/require-nullable-fields-with-oneof.d.cts +0 -2
- package/typings/rules/require-nullable-fields-with-oneof.d.ts +0 -2
- package/typings/rules/require-nullable-result-in-root.d.cts +0 -2
- package/typings/rules/require-nullable-result-in-root.d.ts +0 -2
- package/typings/rules/require-type-pattern-with-oneof.d.cts +0 -2
- package/typings/rules/require-type-pattern-with-oneof.d.ts +0 -2
- package/typings/rules/unique-fragment-name.d.cts +0 -5
- package/typings/rules/unique-fragment-name.d.ts +0 -5
- package/typings/rules/unique-operation-name.d.cts +0 -2
- package/typings/rules/unique-operation-name.d.ts +0 -2
- package/typings/schema.d.cts +0 -3
- package/typings/schema.d.ts +0 -3
- package/typings/siblings.d.cts +0 -22
- package/typings/siblings.d.ts +0 -22
- package/typings/testkit.d.cts +0 -29
- package/typings/testkit.d.ts +0 -29
- package/typings/types.d.cts +0 -83
- package/typings/types.d.ts +0 -83
- package/typings/utils.d.cts +0 -40
- 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 {
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
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
|
-
|
71
|
-
|
79
|
+
const { fragmentDefs, fragmentSpreads } = getFragmentDefsAndFragmentSpreads(node);
|
80
|
+
return [...fragmentSpreads].filter((name) => !fragmentDefs.has(name));
|
72
81
|
};
|
73
82
|
const handleMissingFragments = ({ ruleId, context, node }) => {
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
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
|
-
|
103
|
+
}
|
104
|
+
return node;
|
97
105
|
};
|
98
|
-
const validationToRule = ({
|
99
|
-
|
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
|
-
|
118
|
+
ruleFn = require(`graphql/validation/rules/${ruleName}`)[`${ruleName}Rule`];
|
119
|
+
} catch {
|
120
|
+
ruleFn = require("graphql/validation")[`${ruleName}Rule`];
|
102
121
|
}
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
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
|
-
|
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
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
}
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
},
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
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
|
-
|
216
|
+
return documentNode;
|
187
217
|
}
|
188
|
-
const filterDirectives = (node) => {
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
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
|
-
|
197
|
-
|
225
|
+
Field: filterDirectives,
|
226
|
+
OperationDefinition: filterDirectives
|
198
227
|
});
|
199
|
-
|
200
|
-
|
201
|
-
type:
|
228
|
+
},
|
229
|
+
schema: {
|
230
|
+
type: "array",
|
202
231
|
maxItems: 1,
|
203
232
|
items: {
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
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
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
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
|
-
|
219
|
-
|
220
|
-
|
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
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
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
|
-
|
241
|
-
|
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
|
-
|
252
|
-
|
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
|
-
|
268
|
-
|
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
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
}
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
}
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
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
|
-
|
328
|
-
|
396
|
+
...siblings.getOperations(),
|
397
|
+
...siblings.getFragments()
|
329
398
|
].reduce((map, { filePath, document }) => {
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
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
|
-
|
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
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
}
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
},
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
}
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
},
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
}
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
}
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
},
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
}
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
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
|
+
};
|