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