@graphql-eslint/eslint-plugin 4.0.0-alpha-20230801163310-8bc4340 → 4.0.0-alpha-20230810160036-304c2c0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +2 -0
- package/cjs/cache.js +10 -19
- package/cjs/configs/index.d.ts +42 -16
- package/cjs/configs/index.js +10 -19
- package/cjs/configs/operations-all.d.ts +4 -3
- package/cjs/configs/operations-all.js +5 -4
- package/cjs/configs/operations-recommended.d.ts +3 -1
- package/cjs/configs/operations-recommended.js +3 -1
- package/cjs/configs/schema-all.d.ts +6 -1
- package/cjs/configs/schema-all.js +5 -2
- package/cjs/configs/schema-recommended.d.ts +19 -1
- package/cjs/configs/schema-recommended.js +22 -2
- package/cjs/documents.js +17 -32
- package/cjs/estree-converter/converter.js +14 -27
- package/cjs/estree-converter/index.js +4 -7
- package/cjs/estree-converter/types.js +3 -5
- package/cjs/estree-converter/utils.d.ts +2 -3
- package/cjs/estree-converter/utils.js +15 -45
- package/cjs/flat-configs.d.ts +59 -12
- package/cjs/flat-configs.js +9 -14
- package/cjs/graphql-config.d.ts +4 -3
- package/cjs/graphql-config.js +23 -44
- package/cjs/index.d.ts +10 -4
- package/cjs/index.js +8 -16
- package/cjs/parser.d.ts +4 -3
- package/cjs/parser.js +38 -45
- package/cjs/processor.d.ts +5 -1
- package/cjs/processor.js +25 -57
- package/cjs/rules/alphabetize.d.ts +6 -16
- package/cjs/rules/alphabetize.js +60 -132
- package/cjs/rules/description-style.d.ts +4 -3
- package/cjs/rules/description-style.js +11 -18
- package/cjs/rules/graphql-js-validation.d.ts +4 -3
- package/cjs/rules/graphql-js-validation.js +151 -225
- package/cjs/rules/index.d.ts +15 -13
- package/cjs/rules/index.js +8 -45
- package/cjs/rules/input-name.d.ts +4 -3
- package/cjs/rules/input-name.js +43 -59
- package/cjs/rules/lone-executable-definition.d.ts +6 -5
- package/cjs/rules/lone-executable-definition.js +14 -28
- package/cjs/rules/match-document-filename.d.ts +4 -3
- package/cjs/rules/match-document-filename.js +39 -70
- package/cjs/rules/naming-convention.d.ts +4 -3
- package/cjs/rules/naming-convention.js +56 -74
- package/cjs/rules/no-anonymous-operations.d.ts +4 -3
- package/cjs/rules/no-anonymous-operations.js +11 -18
- package/cjs/rules/no-deprecated.d.ts +4 -3
- package/cjs/rules/no-deprecated.js +15 -29
- package/cjs/rules/no-duplicate-fields.d.ts +4 -3
- package/cjs/rules/no-duplicate-fields.js +13 -23
- package/cjs/rules/no-hashtag-description.d.ts +4 -3
- package/cjs/rules/no-hashtag-description.js +16 -29
- package/cjs/rules/no-one-place-fragments.d.ts +4 -3
- package/cjs/rules/no-one-place-fragments.js +17 -29
- package/cjs/rules/no-root-type.d.ts +4 -3
- package/cjs/rules/no-root-type.js +15 -25
- package/cjs/rules/no-scalar-result-type-on-mutation.d.ts +4 -3
- package/cjs/rules/no-scalar-result-type-on-mutation.js +18 -30
- package/cjs/rules/no-typename-prefix.d.ts +4 -3
- package/cjs/rules/no-typename-prefix.js +26 -33
- package/cjs/rules/no-unreachable-types.d.ts +4 -3
- package/cjs/rules/no-unreachable-types.js +25 -47
- package/cjs/rules/no-unused-fields.d.ts +4 -3
- package/cjs/rules/no-unused-fields.js +24 -49
- package/cjs/rules/relay-arguments.d.ts +4 -3
- package/cjs/rules/relay-arguments.js +20 -43
- package/cjs/rules/relay-connection-types.d.ts +4 -3
- package/cjs/rules/relay-connection-types.js +14 -45
- package/cjs/rules/relay-edge-types.d.ts +4 -3
- package/cjs/rules/relay-edge-types.js +48 -99
- package/cjs/rules/relay-page-info.d.ts +4 -3
- package/cjs/rules/relay-page-info.js +21 -44
- package/cjs/rules/require-deprecation-date.d.ts +4 -3
- package/cjs/rules/require-deprecation-date.js +15 -31
- package/cjs/rules/require-deprecation-reason.d.ts +4 -3
- package/cjs/rules/require-deprecation-reason.js +12 -20
- package/cjs/rules/require-description.d.ts +4 -3
- package/cjs/rules/require-description.js +39 -65
- package/cjs/rules/require-field-of-type-query-in-mutation-result.d.ts +4 -3
- package/cjs/rules/require-field-of-type-query-in-mutation-result.js +16 -31
- package/cjs/rules/require-import-fragment.d.ts +4 -3
- package/cjs/rules/require-import-fragment.js +22 -40
- package/cjs/rules/require-nullable-fields-with-oneof.d.ts +4 -3
- package/cjs/rules/require-nullable-fields-with-oneof.js +11 -22
- package/cjs/rules/require-nullable-result-in-root.d.ts +4 -3
- package/cjs/rules/require-nullable-result-in-root.js +34 -44
- package/cjs/rules/{require-id-when-available.d.ts → require-selections.d.ts} +4 -3
- package/cjs/rules/require-selections.js +198 -0
- package/cjs/rules/require-type-pattern-with-oneof.d.ts +4 -3
- package/cjs/rules/require-type-pattern-with-oneof.js +15 -23
- package/cjs/rules/selection-set-depth.d.ts +4 -3
- package/cjs/rules/selection-set-depth.js +18 -34
- package/cjs/rules/strict-id-in-types.d.ts +4 -3
- package/cjs/rules/strict-id-in-types.js +25 -43
- package/cjs/rules/{no-case-insensitive-enum-values-duplicates.d.ts → unique-enum-value-names.d.ts} +4 -3
- package/cjs/rules/{no-case-insensitive-enum-values-duplicates.js → unique-enum-value-names.js} +16 -21
- package/cjs/rules/unique-fragment-name.d.ts +3 -2
- package/cjs/rules/unique-fragment-name.js +24 -36
- package/cjs/rules/unique-operation-name.d.ts +4 -3
- package/cjs/rules/unique-operation-name.js +10 -12
- package/cjs/schema.d.ts +4 -3
- package/cjs/schema.js +14 -27
- package/cjs/siblings.d.ts +24 -8
- package/cjs/siblings.js +42 -82
- package/cjs/types.d.ts +74 -7
- package/cjs/types.js +3 -5
- package/cjs/utils.d.ts +3 -2
- package/cjs/utils.js +27 -44
- package/esm/cache.js +4 -8
- package/esm/{chunk-BMTV3EA2.js → chunk-U3TKCM4X.js} +1 -1
- package/esm/configs/index.d.mts +42 -16
- package/esm/configs/index.js +4 -4
- package/esm/configs/operations-all.d.mts +4 -3
- package/esm/configs/operations-all.js +6 -5
- package/esm/configs/operations-recommended.d.mts +3 -1
- package/esm/configs/operations-recommended.js +4 -2
- package/esm/configs/schema-all.d.mts +6 -1
- package/esm/configs/schema-all.js +6 -3
- package/esm/configs/schema-recommended.d.mts +19 -1
- package/esm/configs/schema-recommended.js +23 -3
- package/esm/configs/{relay.js → schema-relay.js} +4 -4
- package/esm/documents.js +10 -17
- package/esm/estree-converter/converter.js +9 -18
- package/esm/estree-converter/utils.d.mts +2 -3
- package/esm/estree-converter/utils.js +11 -38
- package/esm/flat-configs.d.mts +59 -12
- package/esm/flat-configs.js +4 -5
- package/esm/graphql-config.d.mts +4 -3
- package/esm/graphql-config.js +18 -34
- package/esm/index.d.mts +10 -4
- package/esm/index.js +1 -1
- package/esm/parser.d.mts +4 -3
- package/esm/parser.js +33 -27
- package/esm/processor.d.mts +5 -1
- package/esm/processor.js +21 -46
- package/esm/rules/alphabetize.d.mts +6 -16
- package/esm/rules/alphabetize.js +53 -118
- package/esm/rules/description-style.d.mts +4 -3
- package/esm/rules/description-style.js +7 -11
- package/esm/rules/graphql-js-validation.d.mts +4 -3
- package/esm/rules/graphql-js-validation.js +178 -218
- package/esm/rules/index.d.mts +15 -13
- package/esm/rules/index.js +5 -5
- package/esm/rules/input-name.d.mts +4 -3
- package/esm/rules/input-name.js +39 -52
- package/esm/rules/lone-executable-definition.d.mts +6 -5
- package/esm/rules/lone-executable-definition.js +10 -20
- package/esm/rules/match-document-filename.d.mts +4 -3
- package/esm/rules/match-document-filename.js +35 -61
- package/esm/rules/naming-convention.d.mts +4 -3
- package/esm/rules/naming-convention.js +51 -65
- package/esm/rules/no-anonymous-operations.d.mts +4 -3
- package/esm/rules/no-anonymous-operations.js +6 -9
- package/esm/rules/no-deprecated.d.mts +4 -3
- package/esm/rules/no-deprecated.js +10 -20
- package/esm/rules/no-duplicate-fields.d.mts +4 -3
- package/esm/rules/no-duplicate-fields.js +9 -16
- package/esm/rules/no-hashtag-description.d.mts +4 -3
- package/esm/rules/no-hashtag-description.js +11 -20
- package/esm/rules/no-one-place-fragments.d.mts +4 -3
- package/esm/rules/no-one-place-fragments.js +12 -19
- package/esm/rules/no-root-type.d.mts +4 -3
- package/esm/rules/no-root-type.js +11 -18
- package/esm/rules/no-scalar-result-type-on-mutation.d.mts +4 -3
- package/esm/rules/no-scalar-result-type-on-mutation.js +13 -21
- package/esm/rules/no-typename-prefix.d.mts +4 -3
- package/esm/rules/no-typename-prefix.js +22 -26
- package/esm/rules/no-unreachable-types.d.mts +4 -3
- package/esm/rules/no-unreachable-types.js +18 -33
- package/esm/rules/no-unused-fields.d.mts +4 -3
- package/esm/rules/no-unused-fields.js +19 -40
- package/esm/rules/relay-arguments.d.mts +4 -3
- package/esm/rules/relay-arguments.js +15 -34
- package/esm/rules/relay-connection-types.d.mts +4 -3
- package/esm/rules/relay-connection-types.js +10 -38
- package/esm/rules/relay-edge-types.d.mts +4 -3
- package/esm/rules/relay-edge-types.js +43 -89
- package/esm/rules/relay-page-info.d.mts +4 -3
- package/esm/rules/relay-page-info.js +16 -34
- package/esm/rules/require-deprecation-date.d.mts +4 -3
- package/esm/rules/require-deprecation-date.js +10 -22
- package/esm/rules/require-deprecation-reason.d.mts +4 -3
- package/esm/rules/require-deprecation-reason.js +7 -11
- package/esm/rules/require-description.d.mts +4 -3
- package/esm/rules/require-description.js +34 -55
- package/esm/rules/require-field-of-type-query-in-mutation-result.d.mts +4 -3
- package/esm/rules/require-field-of-type-query-in-mutation-result.js +11 -22
- package/esm/rules/require-import-fragment.d.mts +4 -3
- package/esm/rules/require-import-fragment.js +14 -26
- package/esm/rules/require-nullable-fields-with-oneof.d.mts +4 -3
- package/esm/rules/require-nullable-fields-with-oneof.js +6 -13
- package/esm/rules/require-nullable-result-in-root.d.mts +4 -3
- package/esm/rules/require-nullable-result-in-root.js +29 -35
- package/esm/rules/{require-id-when-available.d.mts → require-selections.d.mts} +4 -3
- package/esm/rules/{require-id-when-available.js → require-selections.js} +43 -80
- package/esm/rules/require-type-pattern-with-oneof.d.mts +4 -3
- package/esm/rules/require-type-pattern-with-oneof.js +11 -16
- package/esm/rules/selection-set-depth.d.mts +4 -3
- package/esm/rules/selection-set-depth.js +11 -20
- package/esm/rules/strict-id-in-types.d.mts +4 -3
- package/esm/rules/strict-id-in-types.js +20 -34
- package/esm/rules/{no-case-insensitive-enum-values-duplicates.d.mts → unique-enum-value-names.d.mts} +4 -3
- package/esm/rules/{no-case-insensitive-enum-values-duplicates.js → unique-enum-value-names.js} +8 -9
- package/esm/rules/unique-fragment-name.d.mts +3 -2
- package/esm/rules/unique-fragment-name.js +20 -27
- package/esm/rules/unique-operation-name.d.mts +4 -3
- package/esm/rules/unique-operation-name.js +6 -5
- package/esm/schema.d.mts +4 -3
- package/esm/schema.js +7 -12
- package/esm/siblings.d.mts +24 -8
- package/esm/siblings.js +37 -73
- package/esm/types.d.mts +74 -7
- package/esm/utils.d.mts +3 -2
- package/esm/utils.js +20 -31
- package/index.browser.mjs +5323 -0
- package/package.json +8 -13
- package/cjs/rules/require-id-when-available.js +0 -241
- package/cjs/types-8d5f4ae0.d.ts +0 -107
- package/esm/types-ace77d86.d.ts +0 -107
- /package/cjs/configs/{relay.d.ts → schema-relay.d.ts} +0 -0
- /package/cjs/configs/{relay.js → schema-relay.js} +0 -0
- /package/esm/configs/{relay.d.mts → schema-relay.d.mts} +0 -0
@@ -1,15 +1,44 @@
|
|
1
|
-
import
|
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
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
120
|
+
rule,
|
111
121
|
getDocumentNode,
|
112
122
|
schema = [],
|
113
123
|
hasDidYouMeanSuggestions
|
114
|
-
}, docs) => {
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
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
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
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
|
-
|
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
|
-
|
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:
|
163
|
+
requiresSchema: !0
|
174
164
|
}
|
175
165
|
),
|
176
166
|
validationToRule(
|
177
167
|
{
|
178
168
|
ruleId: "fields-on-correct-type",
|
179
|
-
|
180
|
-
hasDidYouMeanSuggestions:
|
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:
|
175
|
+
requiresSchema: !0
|
186
176
|
}
|
187
177
|
),
|
188
178
|
validationToRule(
|
189
179
|
{
|
190
180
|
ruleId: "fragments-on-composite-type",
|
191
|
-
|
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:
|
186
|
+
requiresSchema: !0
|
197
187
|
}
|
198
188
|
),
|
199
189
|
validationToRule(
|
200
190
|
{
|
201
191
|
ruleId: "known-argument-names",
|
202
|
-
|
203
|
-
hasDidYouMeanSuggestions:
|
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:
|
198
|
+
requiresSchema: !0
|
209
199
|
}
|
210
200
|
),
|
211
201
|
validationToRule(
|
212
202
|
{
|
213
203
|
ruleId: "known-directives",
|
214
|
-
|
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
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
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:
|
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:
|
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
|
-
|
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:
|
279
|
-
requiresSiblings:
|
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
|
-
|
341
|
-
hasDidYouMeanSuggestions:
|
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:
|
332
|
+
requiresSchema: !0
|
347
333
|
}
|
348
334
|
),
|
349
335
|
validationToRule(
|
350
336
|
{
|
351
337
|
ruleId: "lone-anonymous-operation",
|
352
|
-
|
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:
|
343
|
+
requiresSchema: !0
|
358
344
|
}
|
359
345
|
),
|
360
346
|
validationToRule(
|
361
347
|
{
|
362
348
|
ruleId: "lone-schema-definition",
|
363
|
-
|
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
|
-
|
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:
|
364
|
+
requiresSchema: !0
|
379
365
|
}
|
380
366
|
),
|
381
367
|
validationToRule(
|
382
368
|
{
|
383
369
|
ruleId: "no-undefined-variables",
|
384
|
-
|
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:
|
391
|
-
requiresSiblings:
|
376
|
+
requiresSchema: !0,
|
377
|
+
requiresSiblings: !0
|
392
378
|
}
|
393
379
|
),
|
394
380
|
validationToRule(
|
395
381
|
{
|
396
382
|
ruleId: "no-unused-fragments",
|
397
|
-
|
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
|
-
|
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.
|
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:
|
439
|
-
requiresSiblings:
|
412
|
+
requiresSchema: !0,
|
413
|
+
requiresSiblings: !0
|
440
414
|
}
|
441
415
|
),
|
442
416
|
validationToRule(
|
443
417
|
{
|
444
418
|
ruleId: "no-unused-variables",
|
445
|
-
|
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:
|
452
|
-
requiresSiblings:
|
425
|
+
requiresSchema: !0,
|
426
|
+
requiresSiblings: !0
|
453
427
|
}
|
454
428
|
),
|
455
429
|
validationToRule(
|
456
430
|
{
|
457
431
|
ruleId: "overlapping-fields-can-be-merged",
|
458
|
-
|
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:
|
437
|
+
requiresSchema: !0
|
464
438
|
}
|
465
439
|
),
|
466
440
|
validationToRule(
|
467
441
|
{
|
468
442
|
ruleId: "possible-fragment-spread",
|
469
|
-
|
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:
|
448
|
+
requiresSchema: !0
|
475
449
|
}
|
476
450
|
),
|
477
451
|
validationToRule(
|
478
452
|
{
|
479
453
|
ruleId: "possible-type-extension",
|
480
|
-
|
481
|
-
hasDidYouMeanSuggestions:
|
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
|
-
|
487
|
-
|
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
|
-
|
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:
|
472
|
+
requiresSchema: !0
|
501
473
|
}
|
502
474
|
),
|
503
475
|
validationToRule(
|
504
476
|
{
|
505
477
|
ruleId: "scalar-leafs",
|
506
|
-
|
507
|
-
hasDidYouMeanSuggestions:
|
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:
|
484
|
+
requiresSchema: !0
|
513
485
|
}
|
514
486
|
),
|
515
487
|
validationToRule(
|
516
488
|
{
|
517
489
|
ruleId: "one-field-subscriptions",
|
518
|
-
|
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:
|
495
|
+
requiresSchema: !0
|
524
496
|
}
|
525
497
|
),
|
526
498
|
validationToRule(
|
527
499
|
{
|
528
500
|
ruleId: "unique-argument-names",
|
529
|
-
|
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:
|
506
|
+
requiresSchema: !0
|
535
507
|
}
|
536
508
|
),
|
537
509
|
validationToRule(
|
538
510
|
{
|
539
511
|
ruleId: "unique-directive-names",
|
540
|
-
|
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
|
-
|
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:
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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:
|
578
|
+
requiresSchema: !0
|
619
579
|
}
|
620
580
|
),
|
621
581
|
validationToRule(
|
622
582
|
{
|
623
583
|
ruleId: "value-literals-of-correct-type",
|
624
|
-
|
625
|
-
hasDidYouMeanSuggestions:
|
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:
|
590
|
+
requiresSchema: !0
|
631
591
|
}
|
632
592
|
),
|
633
593
|
validationToRule(
|
634
594
|
{
|
635
595
|
ruleId: "variables-are-input-types",
|
636
|
-
|
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:
|
601
|
+
requiresSchema: !0
|
642
602
|
}
|
643
603
|
),
|
644
604
|
validationToRule(
|
645
605
|
{
|
646
606
|
ruleId: "variables-in-allowed-position",
|
647
|
-
|
607
|
+
rule: VariablesInAllowedPositionRule
|
648
608
|
},
|
649
609
|
{
|
650
610
|
category: "Operations",
|
651
611
|
description: "Variables passed to field arguments conform to type.",
|
652
|
-
requiresSchema:
|
612
|
+
requiresSchema: !0
|
653
613
|
}
|
654
614
|
)
|
655
615
|
);
|