@graphql-eslint/eslint-plugin 3.20.0-alpha-20230704095135-8d287d5 → 3.20.1-alpha-20230713065115-b9bc635
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/configs/operations-all.js +1 -23
- package/cjs/configs/operations-recommended.js +1 -23
- package/cjs/configs/relay.js +1 -23
- package/cjs/configs/schema-all.js +1 -23
- package/cjs/configs/schema-recommended.js +1 -23
- package/cjs/documents.js +2 -1
- package/cjs/estree-converter/utils.js +1 -1
- package/cjs/parser.js +4 -3
- package/cjs/processor.js +1 -1
- package/cjs/rules/alphabetize.js +12 -9
- package/cjs/rules/graphql-js-validation.js +13 -8
- package/cjs/rules/lone-executable-definition.js +5 -3
- package/cjs/rules/match-document-filename.js +2 -1
- package/cjs/rules/naming-convention.js +2 -2
- package/cjs/rules/no-case-insensitive-enum-values-duplicates.js +2 -1
- package/cjs/rules/no-deprecated.js +4 -2
- package/cjs/rules/no-one-place-fragments.js +1 -1
- package/cjs/rules/no-unreachable-types.js +2 -2
- package/cjs/rules/no-unused-fields.js +4 -2
- package/cjs/rules/relay-arguments.js +2 -1
- package/cjs/rules/relay-connection-types.js +8 -2
- package/cjs/rules/relay-edge-types.js +7 -4
- package/cjs/rules/relay-page-info.js +2 -1
- package/cjs/rules/require-deprecation-date.js +3 -2
- package/cjs/rules/require-deprecation-reason.js +2 -1
- package/cjs/rules/require-description.js +3 -2
- package/cjs/rules/require-field-of-type-query-in-mutation-result.js +1 -1
- package/cjs/rules/require-import-fragment.js +2 -1
- package/cjs/rules/require-nullable-result-in-root.js +1 -1
- package/cjs/rules/require-type-pattern-with-oneof.js +2 -1
- package/cjs/rules/strict-id-in-types.js +4 -3
- package/cjs/rules/unique-fragment-name.js +2 -1
- package/cjs/siblings.js +8 -3
- package/cjs/utils.js +2 -1
- package/esm/cache.js +1 -0
- package/esm/chunk-BMTV3EA2.js +8 -0
- package/esm/configs/index.js +1 -0
- package/esm/configs/operations-all.js +32 -27
- package/esm/configs/operations-recommended.js +57 -52
- package/esm/configs/relay.js +17 -12
- package/esm/configs/schema-all.js +26 -21
- package/esm/configs/schema-recommended.js +53 -48
- package/esm/documents.js +3 -1
- package/esm/estree-converter/converter.js +1 -0
- package/esm/estree-converter/utils.js +2 -1
- package/esm/flat-configs.js +1 -0
- package/esm/graphql-config.js +1 -0
- package/esm/index.js +1 -0
- package/esm/parser.js +5 -3
- package/esm/processor.js +2 -1
- package/esm/rules/alphabetize.js +13 -9
- package/esm/rules/description-style.js +1 -0
- package/esm/rules/graphql-js-validation.js +14 -8
- package/esm/rules/index.js +1 -0
- package/esm/rules/input-name.js +1 -0
- package/esm/rules/lone-executable-definition.js +6 -3
- package/esm/rules/match-document-filename.js +3 -1
- package/esm/rules/naming-convention.js +3 -2
- package/esm/rules/no-anonymous-operations.js +1 -0
- package/esm/rules/no-case-insensitive-enum-values-duplicates.js +3 -1
- package/esm/rules/no-deprecated.js +5 -2
- package/esm/rules/no-duplicate-fields.js +1 -0
- package/esm/rules/no-hashtag-description.js +1 -0
- package/esm/rules/no-one-place-fragments.js +2 -1
- package/esm/rules/no-root-type.js +1 -0
- package/esm/rules/no-scalar-result-type-on-mutation.js +1 -0
- package/esm/rules/no-typename-prefix.js +1 -0
- package/esm/rules/no-unreachable-types.js +3 -2
- package/esm/rules/no-unused-fields.js +5 -2
- package/esm/rules/relay-arguments.js +3 -1
- package/esm/rules/relay-connection-types.js +9 -2
- package/esm/rules/relay-edge-types.js +8 -4
- package/esm/rules/relay-page-info.js +3 -1
- package/esm/rules/require-deprecation-date.js +4 -2
- package/esm/rules/require-deprecation-reason.js +3 -1
- package/esm/rules/require-description.js +4 -2
- package/esm/rules/require-field-of-type-query-in-mutation-result.js +2 -1
- package/esm/rules/require-id-when-available.js +1 -0
- package/esm/rules/require-import-fragment.js +3 -1
- package/esm/rules/require-nullable-fields-with-oneof.js +1 -0
- package/esm/rules/require-nullable-result-in-root.js +2 -1
- package/esm/rules/require-type-pattern-with-oneof.js +3 -1
- package/esm/rules/selection-set-depth.js +1 -0
- package/esm/rules/strict-id-in-types.js +5 -3
- package/esm/rules/unique-fragment-name.js +3 -1
- package/esm/rules/unique-operation-name.js +1 -0
- package/esm/schema.js +1 -0
- package/esm/siblings.js +9 -3
- package/esm/testkit.js +1 -0
- package/esm/utils.js +3 -1
- package/package.json +1 -4
@@ -1,27 +1,5 @@
|
|
1
1
|
"use strict";
|
2
|
-
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
-
var __export = (target, all) => {
|
7
|
-
for (var name in all)
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
-
};
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
-
for (let key of __getOwnPropNames(from))
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
-
}
|
16
|
-
return to;
|
17
|
-
};
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
-
var operations_all_exports = {};
|
20
|
-
__export(operations_all_exports, {
|
21
|
-
default: () => operations_all_default
|
22
|
-
});
|
23
|
-
module.exports = __toCommonJS(operations_all_exports);
|
24
|
-
var operations_all_default = {
|
2
|
+
module.exports = {
|
25
3
|
extends: "./configs/operations-recommended",
|
26
4
|
rules: {
|
27
5
|
"@graphql-eslint/alphabetize": [
|
@@ -1,27 +1,5 @@
|
|
1
1
|
"use strict";
|
2
|
-
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
-
var __export = (target, all) => {
|
7
|
-
for (var name in all)
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
-
};
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
-
for (let key of __getOwnPropNames(from))
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
-
}
|
16
|
-
return to;
|
17
|
-
};
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
-
var operations_recommended_exports = {};
|
20
|
-
__export(operations_recommended_exports, {
|
21
|
-
default: () => operations_recommended_default
|
22
|
-
});
|
23
|
-
module.exports = __toCommonJS(operations_recommended_exports);
|
24
|
-
var operations_recommended_default = {
|
2
|
+
module.exports = {
|
25
3
|
parser: "@graphql-eslint/eslint-plugin",
|
26
4
|
plugins: ["@graphql-eslint"],
|
27
5
|
rules: {
|
package/cjs/configs/relay.js
CHANGED
@@ -1,27 +1,5 @@
|
|
1
1
|
"use strict";
|
2
|
-
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
-
var __export = (target, all) => {
|
7
|
-
for (var name in all)
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
-
};
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
-
for (let key of __getOwnPropNames(from))
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
-
}
|
16
|
-
return to;
|
17
|
-
};
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
-
var relay_exports = {};
|
20
|
-
__export(relay_exports, {
|
21
|
-
default: () => relay_default
|
22
|
-
});
|
23
|
-
module.exports = __toCommonJS(relay_exports);
|
24
|
-
var relay_default = {
|
2
|
+
module.exports = {
|
25
3
|
parser: "@graphql-eslint/eslint-plugin",
|
26
4
|
plugins: ["@graphql-eslint"],
|
27
5
|
rules: {
|
@@ -1,27 +1,5 @@
|
|
1
1
|
"use strict";
|
2
|
-
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
-
var __export = (target, all) => {
|
7
|
-
for (var name in all)
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
-
};
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
-
for (let key of __getOwnPropNames(from))
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
-
}
|
16
|
-
return to;
|
17
|
-
};
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
-
var schema_all_exports = {};
|
20
|
-
__export(schema_all_exports, {
|
21
|
-
default: () => schema_all_default
|
22
|
-
});
|
23
|
-
module.exports = __toCommonJS(schema_all_exports);
|
24
|
-
var schema_all_default = {
|
2
|
+
module.exports = {
|
25
3
|
extends: "./configs/schema-recommended",
|
26
4
|
rules: {
|
27
5
|
"@graphql-eslint/alphabetize": [
|
@@ -1,27 +1,5 @@
|
|
1
1
|
"use strict";
|
2
|
-
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
6
|
-
var __export = (target, all) => {
|
7
|
-
for (var name in all)
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
9
|
-
};
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
12
|
-
for (let key of __getOwnPropNames(from))
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
15
|
-
}
|
16
|
-
return to;
|
17
|
-
};
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
19
|
-
var schema_recommended_exports = {};
|
20
|
-
__export(schema_recommended_exports, {
|
21
|
-
default: () => schema_recommended_default
|
22
|
-
});
|
23
|
-
module.exports = __toCommonJS(schema_recommended_exports);
|
24
|
-
var schema_recommended_default = {
|
2
|
+
module.exports = {
|
25
3
|
parser: "@graphql-eslint/eslint-plugin",
|
26
4
|
plugins: ["@graphql-eslint"],
|
27
5
|
rules: {
|
package/cjs/documents.js
CHANGED
@@ -40,11 +40,12 @@ const operationsCache = new import_cache.ModuleCache();
|
|
40
40
|
const handleVirtualPath = (documents) => {
|
41
41
|
const filepathMap = /* @__PURE__ */ Object.create(null);
|
42
42
|
return documents.map((source) => {
|
43
|
+
var _a;
|
43
44
|
const location = source.location;
|
44
45
|
if ([".gql", ".graphql"].some((extension) => location.endsWith(extension))) {
|
45
46
|
return source;
|
46
47
|
}
|
47
|
-
filepathMap[location]
|
48
|
+
(_a = filepathMap[location]) != null ? _a : filepathMap[location] = -1;
|
48
49
|
const index = filepathMap[location] += 1;
|
49
50
|
return {
|
50
51
|
...source,
|
@@ -62,7 +62,7 @@ function convertToken(token, type) {
|
|
62
62
|
}
|
63
63
|
function getLexer(source) {
|
64
64
|
const gqlLanguage = require("graphql/language");
|
65
|
-
if (gqlLanguage
|
65
|
+
if (gqlLanguage == null ? void 0 : gqlLanguage.createLexer) {
|
66
66
|
return gqlLanguage.createLexer(source, {});
|
67
67
|
}
|
68
68
|
const { Lexer: LexerCls } = require("graphql");
|
package/cjs/parser.js
CHANGED
@@ -42,9 +42,10 @@ var import_utils2 = require("./utils.js");
|
|
42
42
|
const debug = (0, import_debug.default)("graphql-eslint:parser");
|
43
43
|
debug("cwd %o", import_utils2.CWD);
|
44
44
|
function parseForESLint(code, options) {
|
45
|
+
var _a, _b;
|
45
46
|
try {
|
46
47
|
const { filePath } = options;
|
47
|
-
options.documents
|
48
|
+
options.documents || (options.documents = options.operations);
|
48
49
|
const { document } = (0, import_utils.parseGraphQLSDL)(filePath, code, {
|
49
50
|
...options.graphQLParserOptions,
|
50
51
|
noLocation: false
|
@@ -82,9 +83,9 @@ function parseForESLint(code, options) {
|
|
82
83
|
error.message = `[graphql-eslint] ${error.message}`;
|
83
84
|
}
|
84
85
|
if (error instanceof import_graphql.GraphQLError) {
|
85
|
-
const location = error.locations
|
86
|
+
const location = (_a = error.locations) == null ? void 0 : _a[0];
|
86
87
|
const eslintError = {
|
87
|
-
index: error.positions
|
88
|
+
index: (_b = error.positions) == null ? void 0 : _b[0],
|
88
89
|
...location && {
|
89
90
|
lineNumber: location.line,
|
90
91
|
column: location.column - 1
|
package/cjs/processor.js
CHANGED
@@ -38,7 +38,7 @@ const processor = {
|
|
38
38
|
onDiskConfigLoaded = true;
|
39
39
|
}
|
40
40
|
let keywords = RELEVANT_KEYWORDS;
|
41
|
-
const pluckConfig = onDiskConfig
|
41
|
+
const pluckConfig = onDiskConfig == null ? void 0 : onDiskConfig.getProjectForFile(filePath).extensions.pluckConfig;
|
42
42
|
if (pluckConfig) {
|
43
43
|
const {
|
44
44
|
modules = [],
|
package/cjs/rules/alphabetize.js
CHANGED
@@ -237,6 +237,7 @@ const rule = {
|
|
237
237
|
schema
|
238
238
|
},
|
239
239
|
create(context) {
|
240
|
+
var _a, _b, _c, _d, _e;
|
240
241
|
const sourceCode = context.getSourceCode();
|
241
242
|
function isNodeAndCommentOnSameLine(node, comment) {
|
242
243
|
return node.loc.end.line === comment.loc.start.line;
|
@@ -272,19 +273,20 @@ const rule = {
|
|
272
273
|
return [from.range[0], to.range[1]];
|
273
274
|
}
|
274
275
|
function checkNodes(nodes = []) {
|
276
|
+
var _a2, _b2, _c2, _d2;
|
275
277
|
for (let i = 1; i < nodes.length; i += 1) {
|
276
278
|
const currNode = nodes[i];
|
277
|
-
const currName = "alias" in currNode && currNode.alias
|
279
|
+
const currName = "alias" in currNode && ((_a2 = currNode.alias) == null ? void 0 : _a2.value) || "name" in currNode && ((_b2 = currNode.name) == null ? void 0 : _b2.value);
|
278
280
|
if (!currName) {
|
279
281
|
continue;
|
280
282
|
}
|
281
283
|
const prevNode = nodes[i - 1];
|
282
|
-
const prevName = "alias" in prevNode && prevNode.alias
|
284
|
+
const prevName = "alias" in prevNode && ((_c2 = prevNode.alias) == null ? void 0 : _c2.value) || "name" in prevNode && ((_d2 = prevNode.name) == null ? void 0 : _d2.value);
|
283
285
|
if (prevName) {
|
284
286
|
const compareResult = prevName.localeCompare(currName);
|
285
287
|
const { groups } = opts;
|
286
288
|
let shouldSortByGroup = false;
|
287
|
-
if (groups
|
289
|
+
if (groups == null ? void 0 : groups.length) {
|
288
290
|
if (!groups.includes("*")) {
|
289
291
|
throw new Error("`groups` option should contain `*` string.");
|
290
292
|
}
|
@@ -331,7 +333,7 @@ const rule = {
|
|
331
333
|
}
|
332
334
|
}
|
333
335
|
const opts = context.options[0];
|
334
|
-
const fields = new Set(opts.fields
|
336
|
+
const fields = new Set((_a = opts.fields) != null ? _a : []);
|
335
337
|
const listeners = {};
|
336
338
|
const kinds = [
|
337
339
|
fields.has(import_graphql.Kind.OBJECT_TYPE_DEFINITION) && [
|
@@ -348,10 +350,10 @@ const rule = {
|
|
348
350
|
]
|
349
351
|
].filter(import_utils.truthy).flat();
|
350
352
|
const fieldsSelector = kinds.join(",");
|
351
|
-
const hasEnumValues = opts.values
|
352
|
-
const selectionsSelector = opts.selections
|
353
|
-
const hasVariables = opts.variables
|
354
|
-
const argumentsSelector = opts.arguments
|
353
|
+
const hasEnumValues = ((_b = opts.values) == null ? void 0 : _b[0]) === import_graphql.Kind.ENUM_TYPE_DEFINITION;
|
354
|
+
const selectionsSelector = (_c = opts.selections) == null ? void 0 : _c.join(",");
|
355
|
+
const hasVariables = ((_d = opts.variables) == null ? void 0 : _d[0]) === import_graphql.Kind.OPERATION_DEFINITION;
|
356
|
+
const argumentsSelector = (_e = opts.arguments) == null ? void 0 : _e.join(",");
|
355
357
|
if (fieldsSelector) {
|
356
358
|
listeners[fieldsSelector] = (node) => {
|
357
359
|
checkNodes(node.fields);
|
@@ -370,7 +372,8 @@ const rule = {
|
|
370
372
|
}
|
371
373
|
if (hasVariables) {
|
372
374
|
listeners.OperationDefinition = (node) => {
|
373
|
-
|
375
|
+
var _a2;
|
376
|
+
checkNodes((_a2 = node.variableDefinitions) == null ? void 0 : _a2.map((varDef) => varDef.variable));
|
374
377
|
};
|
375
378
|
}
|
376
379
|
if (argumentsSelector) {
|
@@ -31,6 +31,7 @@ function validateDocument({
|
|
31
31
|
rule,
|
32
32
|
hasDidYouMeanSuggestions
|
33
33
|
}) {
|
34
|
+
var _a;
|
34
35
|
if (documentNode.definitions.length === 0) {
|
35
36
|
return;
|
36
37
|
}
|
@@ -51,7 +52,7 @@ function validateDocument({
|
|
51
52
|
loc = // if cursor on `@` symbol than use next node
|
52
53
|
token.type === "@" ? sourceCode.getNodeByRangeIndex(token.range[1] + 1).loc : token.loc;
|
53
54
|
}
|
54
|
-
const didYouMeanContent = error.message.match(/Did you mean (?<content>.*)\?$/)
|
55
|
+
const didYouMeanContent = (_a = error.message.match(/Did you mean (?<content>.*)\?$/)) == null ? void 0 : _a.groups.content;
|
55
56
|
const matches = didYouMeanContent ? [...didYouMeanContent.matchAll(/"(?<name>[^"]*)"/g)] : [];
|
56
57
|
context.report({
|
57
58
|
loc,
|
@@ -226,12 +227,15 @@ const GRAPHQL_JS_VALIDATIONS = Object.assign(
|
|
226
227
|
if (ignoreClientDirectives.length === 0) {
|
227
228
|
return documentNode;
|
228
229
|
}
|
229
|
-
const filterDirectives = (node) =>
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
230
|
+
const filterDirectives = (node) => {
|
231
|
+
var _a;
|
232
|
+
return {
|
233
|
+
...node,
|
234
|
+
directives: (_a = node.directives) == null ? void 0 : _a.filter(
|
235
|
+
(directive) => !ignoreClientDirectives.includes(directive.name.value)
|
236
|
+
)
|
237
|
+
};
|
238
|
+
};
|
235
239
|
return (0, import_graphql.visit)(documentNode, {
|
236
240
|
Field: filterDirectives,
|
237
241
|
OperationDefinition: filterDirectives
|
@@ -407,7 +411,8 @@ const GRAPHQL_JS_VALIDATIONS = Object.assign(
|
|
407
411
|
...siblings.getOperations(),
|
408
412
|
...siblings.getFragments()
|
409
413
|
].reduce((map, { filePath, document }) => {
|
410
|
-
|
414
|
+
var _a;
|
415
|
+
(_a = map[filePath]) != null ? _a : map[filePath] = [];
|
411
416
|
map[filePath].push(document);
|
412
417
|
return map;
|
413
418
|
}, /* @__PURE__ */ Object.create(null));
|
@@ -85,7 +85,8 @@ const rule = {
|
|
85
85
|
schema
|
86
86
|
},
|
87
87
|
create(context) {
|
88
|
-
|
88
|
+
var _a;
|
89
|
+
const ignore = new Set(((_a = context.options[0]) == null ? void 0 : _a.ignore) || []);
|
89
90
|
const definitions = [];
|
90
91
|
return {
|
91
92
|
":matches(OperationDefinition, FragmentDefinition)"(node) {
|
@@ -95,14 +96,15 @@ const rule = {
|
|
95
96
|
}
|
96
97
|
},
|
97
98
|
"Document:exit"() {
|
99
|
+
var _a2, _b;
|
98
100
|
for (const { node, type } of definitions.slice(1)) {
|
99
101
|
let name = (0, import_utils.pascalCase)(type);
|
100
|
-
const definitionName = node.name
|
102
|
+
const definitionName = (_a2 = node.name) == null ? void 0 : _a2.value;
|
101
103
|
if (definitionName) {
|
102
104
|
name += ` "${definitionName}"`;
|
103
105
|
}
|
104
106
|
context.report({
|
105
|
-
loc: node.name
|
107
|
+
loc: ((_b = node.name) == null ? void 0 : _b.loc) || (0, import_utils.getLocation)(node.loc.start, type),
|
106
108
|
messageId: RULE_ID,
|
107
109
|
data: { name }
|
108
110
|
});
|
@@ -220,6 +220,7 @@ const rule = {
|
|
220
220
|
const filename = (0, import_path.basename)(filePath, fileExtension);
|
221
221
|
return {
|
222
222
|
Document(documentNode) {
|
223
|
+
var _a;
|
223
224
|
if (options.fileExtension && options.fileExtension !== fileExtension) {
|
224
225
|
context.report({
|
225
226
|
loc: import_utils.REPORT_ON_FIRST_CHARACTER,
|
@@ -240,7 +241,7 @@ const rule = {
|
|
240
241
|
if (!node) {
|
241
242
|
return;
|
242
243
|
}
|
243
|
-
const docName = node.name
|
244
|
+
const docName = (_a = node.name) == null ? void 0 : _a.value;
|
244
245
|
if (!docName) {
|
245
246
|
return;
|
246
247
|
}
|
@@ -364,14 +364,14 @@ const rule = {
|
|
364
364
|
renameToNames: [name + suffix]
|
365
365
|
};
|
366
366
|
}
|
367
|
-
const forbiddenPrefix = forbiddenPrefixes
|
367
|
+
const forbiddenPrefix = forbiddenPrefixes == null ? void 0 : forbiddenPrefixes.find((prefix2) => name.startsWith(prefix2));
|
368
368
|
if (forbiddenPrefix) {
|
369
369
|
return {
|
370
370
|
errorMessage: `not have "${forbiddenPrefix}" prefix`,
|
371
371
|
renameToNames: [name.replace(new RegExp(`^${forbiddenPrefix}`), "")]
|
372
372
|
};
|
373
373
|
}
|
374
|
-
const forbiddenSuffix = forbiddenSuffixes
|
374
|
+
const forbiddenSuffix = forbiddenSuffixes == null ? void 0 : forbiddenSuffixes.find((suffix2) => name.endsWith(suffix2));
|
375
375
|
if (forbiddenSuffix) {
|
376
376
|
return {
|
377
377
|
errorMessage: `not have "${forbiddenSuffix}" suffix`,
|
@@ -67,7 +67,8 @@ const rule = {
|
|
67
67
|
const selector = [import_graphql.Kind.ENUM_TYPE_DEFINITION, import_graphql.Kind.ENUM_TYPE_EXTENSION].join(",");
|
68
68
|
return {
|
69
69
|
[selector](node) {
|
70
|
-
|
70
|
+
var _a;
|
71
|
+
const duplicates = (_a = node.values) == null ? void 0 : _a.filter(
|
71
72
|
(item, index, array) => array.findIndex((v) => v.name.value.toLowerCase() === item.name.value.toLowerCase()) !== index
|
72
73
|
);
|
73
74
|
for (const duplicate of duplicates || []) {
|
@@ -133,15 +133,17 @@ const rule = {
|
|
133
133
|
}
|
134
134
|
return {
|
135
135
|
EnumValue(node) {
|
136
|
+
var _a;
|
136
137
|
const typeInfo = node.typeInfo();
|
137
|
-
const reason = typeInfo.enumValue
|
138
|
+
const reason = (_a = typeInfo.enumValue) == null ? void 0 : _a.deprecationReason;
|
138
139
|
if (reason) {
|
139
140
|
report(node, reason);
|
140
141
|
}
|
141
142
|
},
|
142
143
|
Field(node) {
|
144
|
+
var _a;
|
143
145
|
const typeInfo = node.typeInfo();
|
144
|
-
const reason = typeInfo.fieldDef
|
146
|
+
const reason = (_a = typeInfo.fieldDef) == null ? void 0 : _a.deprecationReason;
|
145
147
|
if (reason) {
|
146
148
|
report(node, reason);
|
147
149
|
}
|
@@ -87,7 +87,7 @@ const rule = {
|
|
87
87
|
(0, import_graphql.visit)(document, {
|
88
88
|
FragmentSpread({ name }) {
|
89
89
|
const spreadName = name.value;
|
90
|
-
usedFragmentsMap[spreadName]
|
90
|
+
usedFragmentsMap[spreadName] || (usedFragmentsMap[spreadName] = []);
|
91
91
|
usedFragmentsMap[spreadName].push(relativeFilePath);
|
92
92
|
}
|
93
93
|
});
|
@@ -78,7 +78,7 @@ function getReachableTypes(schema) {
|
|
78
78
|
for (const { astNode } of [...objects, ...interfaces]) {
|
79
79
|
(0, import_graphql.visit)(astNode, visitor);
|
80
80
|
}
|
81
|
-
} else if (type
|
81
|
+
} else if (type == null ? void 0 : type.astNode) {
|
82
82
|
(0, import_graphql.visit)(type.astNode, visitor);
|
83
83
|
}
|
84
84
|
};
|
@@ -98,7 +98,7 @@ function getReachableTypes(schema) {
|
|
98
98
|
schema.getMutationType(),
|
99
99
|
schema.getSubscriptionType()
|
100
100
|
]) {
|
101
|
-
if (type
|
101
|
+
if (type == null ? void 0 : type.astNode) {
|
102
102
|
(0, import_graphql.visit)(type.astNode, visitor);
|
103
103
|
}
|
104
104
|
}
|
@@ -33,13 +33,14 @@ function getUsedFields(schema, operations) {
|
|
33
33
|
const typeInfo = new import_graphql.TypeInfo(schema);
|
34
34
|
const visitor = (0, import_graphql.visitWithTypeInfo)(typeInfo, {
|
35
35
|
Field(node) {
|
36
|
+
var _a;
|
36
37
|
const fieldDef = typeInfo.getFieldDef();
|
37
38
|
if (!fieldDef) {
|
38
39
|
return false;
|
39
40
|
}
|
40
41
|
const parentTypeName = typeInfo.getParentType().name;
|
41
42
|
const fieldName = node.name.value;
|
42
|
-
usedFields[parentTypeName]
|
43
|
+
(_a = usedFields[parentTypeName]) != null ? _a : usedFields[parentTypeName] = /* @__PURE__ */ new Set();
|
43
44
|
usedFields[parentTypeName].add(fieldName);
|
44
45
|
}
|
45
46
|
});
|
@@ -122,9 +123,10 @@ const rule = {
|
|
122
123
|
const usedFields = getUsedFields(schema, siblingsOperations);
|
123
124
|
return {
|
124
125
|
FieldDefinition(node) {
|
126
|
+
var _a;
|
125
127
|
const fieldName = node.name.value;
|
126
128
|
const parentTypeName = node.parent.name.value;
|
127
|
-
const isUsed = usedFields[parentTypeName]
|
129
|
+
const isUsed = (_a = usedFields[parentTypeName]) == null ? void 0 : _a.has(fieldName);
|
128
130
|
if (isUsed) {
|
129
131
|
return;
|
130
132
|
}
|
@@ -98,12 +98,13 @@ const rule = {
|
|
98
98
|
const { includeBoth = true } = context.options[0] || {};
|
99
99
|
return {
|
100
100
|
"FieldDefinition > .gqlType Name[value=/Connection$/]"(node) {
|
101
|
+
var _a;
|
101
102
|
let fieldNode = node.parent;
|
102
103
|
while (fieldNode.kind !== import_graphql.Kind.FIELD_DEFINITION) {
|
103
104
|
fieldNode = fieldNode.parent;
|
104
105
|
}
|
105
106
|
const args = Object.fromEntries(
|
106
|
-
fieldNode.arguments
|
107
|
+
((_a = fieldNode.arguments) == null ? void 0 : _a.map((argument) => [argument.name.value, argument])) || []
|
107
108
|
);
|
108
109
|
const hasForwardPagination = !!(args.first && args.after);
|
109
110
|
const hasBackwardPagination = !!(args.last && args.before);
|
@@ -41,8 +41,14 @@ const NON_OBJECT_TYPES = [
|
|
41
41
|
import_graphql.Kind.INTERFACE_TYPE_EXTENSION
|
42
42
|
];
|
43
43
|
const notConnectionTypesSelector = `:matches(${NON_OBJECT_TYPES})[name.value=/Connection$/] > .name`;
|
44
|
-
const hasEdgesField = (node) =>
|
45
|
-
|
44
|
+
const hasEdgesField = (node) => {
|
45
|
+
var _a;
|
46
|
+
return (_a = node.fields) == null ? void 0 : _a.some((field) => field.name.value === "edges");
|
47
|
+
};
|
48
|
+
const hasPageInfoField = (node) => {
|
49
|
+
var _a;
|
50
|
+
return (_a = node.fields) == null ? void 0 : _a.some((field) => field.name.value === "pageInfo");
|
51
|
+
};
|
46
52
|
const rule = {
|
47
53
|
meta: {
|
48
54
|
type: "problem",
|
@@ -37,12 +37,13 @@ function getEdgeTypes(schema2) {
|
|
37
37
|
const edgeTypes = /* @__PURE__ */ new Set();
|
38
38
|
const visitor = {
|
39
39
|
ObjectTypeDefinition(node) {
|
40
|
+
var _a;
|
40
41
|
const typeName = node.name.value;
|
41
42
|
const hasConnectionSuffix = typeName.endsWith("Connection");
|
42
43
|
if (!hasConnectionSuffix) {
|
43
44
|
return;
|
44
45
|
}
|
45
|
-
const edges = node.fields
|
46
|
+
const edges = (_a = node.fields) == null ? void 0 : _a.find((field) => field.name.value === "edges");
|
46
47
|
if (edges) {
|
47
48
|
const edgesTypeName = (0, import_utils2.getTypeName)(edges);
|
48
49
|
const edgesType = schema2.getType(edgesTypeName);
|
@@ -136,7 +137,8 @@ const rule = {
|
|
136
137
|
};
|
137
138
|
const isNamedOrNonNullNamed = (node) => node.kind === import_graphql.Kind.NAMED_TYPE || node.kind === import_graphql.Kind.NON_NULL_TYPE && node.gqlType.kind === import_graphql.Kind.NAMED_TYPE;
|
138
139
|
const checkNodeField = (node) => {
|
139
|
-
|
140
|
+
var _a, _b;
|
141
|
+
const nodeField = (_a = node.fields) == null ? void 0 : _a.find((field) => field.name.value === "node");
|
140
142
|
const message = "return either a Scalar, Enum, Object, Interface, Union, or a non-null wrapper around one of those types.";
|
141
143
|
if (!nodeField) {
|
142
144
|
context.report({
|
@@ -151,14 +153,15 @@ const rule = {
|
|
151
153
|
if (!(0, import_graphql.isObjectType)(type)) {
|
152
154
|
return;
|
153
155
|
}
|
154
|
-
const implementsNode = type.astNode.interfaces
|
156
|
+
const implementsNode = (_b = type.astNode.interfaces) == null ? void 0 : _b.some((n) => n.name.value === "Node");
|
155
157
|
if (!implementsNode) {
|
156
158
|
context.report({ node: node.name, messageId: MESSAGE_SHOULD_IMPLEMENTS_NODE });
|
157
159
|
}
|
158
160
|
}
|
159
161
|
};
|
160
162
|
const checkCursorField = (node) => {
|
161
|
-
|
163
|
+
var _a;
|
164
|
+
const cursorField = (_a = node.fields) == null ? void 0 : _a.find((field) => field.name.value === "cursor");
|
162
165
|
const message = "return either a String, Scalar, or a non-null wrapper wrapper around one of those types.";
|
163
166
|
if (!cursorField) {
|
164
167
|
context.report({
|
@@ -84,8 +84,9 @@ const rule = {
|
|
84
84
|
context.report({ node, messageId: MESSAGE_MUST_BE_OBJECT_TYPE });
|
85
85
|
},
|
86
86
|
"ObjectTypeDefinition[name.value=PageInfo]"(node) {
|
87
|
+
var _a;
|
87
88
|
const fieldMap = Object.fromEntries(
|
88
|
-
node.fields
|
89
|
+
((_a = node.fields) == null ? void 0 : _a.map((field) => [field.name.value, field])) || []
|
89
90
|
);
|
90
91
|
const checkField = (fieldName, typeName) => {
|
91
92
|
const field = fieldMap[fieldName];
|
@@ -100,8 +100,9 @@ const rule = {
|
|
100
100
|
create(context) {
|
101
101
|
return {
|
102
102
|
"Directive[name.value=deprecated]"(node) {
|
103
|
-
|
104
|
-
const
|
103
|
+
var _a, _b;
|
104
|
+
const argName = ((_a = context.options[0]) == null ? void 0 : _a.argumentName) || "deletionDate";
|
105
|
+
const deletionDateNode = (_b = node.arguments) == null ? void 0 : _b.find((arg) => arg.name.value === argName);
|
105
106
|
if (!deletionDateNode) {
|
106
107
|
context.report({
|
107
108
|
node: node.name,
|
@@ -72,7 +72,8 @@ const rule = {
|
|
72
72
|
create(context) {
|
73
73
|
return {
|
74
74
|
"Directive[name.value=deprecated]"(node) {
|
75
|
-
|
75
|
+
var _a;
|
76
|
+
const reasonArgument = (_a = node.arguments) == null ? void 0 : _a.find(
|
76
77
|
(arg) => arg.name.value === "reason"
|
77
78
|
);
|
78
79
|
const value = reasonArgument && String((0, import_estree_converter.valueFromNode)(reasonArgument.value)).trim();
|
@@ -169,12 +169,13 @@ const rule = {
|
|
169
169
|
const selector = [...kinds].join(",");
|
170
170
|
return {
|
171
171
|
[selector](node) {
|
172
|
+
var _a;
|
172
173
|
let description = "";
|
173
174
|
const isOperation = node.kind === import_graphql.Kind.OPERATION_DEFINITION;
|
174
175
|
if (isOperation) {
|
175
176
|
const rawNode = node.rawNode();
|
176
177
|
const { prev, line } = rawNode.loc.startToken;
|
177
|
-
if (prev
|
178
|
+
if ((prev == null ? void 0 : prev.kind) === import_graphql.TokenKind.COMMENT) {
|
178
179
|
const value = prev.value.trim();
|
179
180
|
const linesBefore = line - prev.line;
|
180
181
|
if (!value.startsWith("eslint") && linesBefore === 1) {
|
@@ -182,7 +183,7 @@ const rule = {
|
|
182
183
|
}
|
183
184
|
}
|
184
185
|
} else {
|
185
|
-
description = node.description
|
186
|
+
description = ((_a = node.description) == null ? void 0 : _a.value.trim()) || "";
|
186
187
|
}
|
187
188
|
if (description.length === 0) {
|
188
189
|
context.report({
|
@@ -84,7 +84,7 @@ const rule = {
|
|
84
84
|
const graphQLType = schema.getType(typeName);
|
85
85
|
if ((0, import_graphql.isObjectType)(graphQLType)) {
|
86
86
|
const { fields } = graphQLType.astNode;
|
87
|
-
const hasQueryType = fields
|
87
|
+
const hasQueryType = fields == null ? void 0 : fields.some((field) => (0, import_utils.getTypeName)(field) === queryType.name);
|
88
88
|
if (!hasQueryType) {
|
89
89
|
context.report({
|
90
90
|
node,
|
@@ -115,6 +115,7 @@ const rule = {
|
|
115
115
|
const filePath = context.getFilename();
|
116
116
|
return {
|
117
117
|
"FragmentSpread > .name"(node) {
|
118
|
+
var _a;
|
118
119
|
const fragmentName = node.value;
|
119
120
|
const fragmentsFromSiblings = siblings.getFragment(fragmentName);
|
120
121
|
for (const comment of comments) {
|
@@ -125,7 +126,7 @@ const rule = {
|
|
125
126
|
).test(comment.value);
|
126
127
|
if (!isPossibleImported)
|
127
128
|
continue;
|
128
|
-
const extractedImportPath = comment.value.match(/(["'])((?:\1|.)*?)\1/)
|
129
|
+
const extractedImportPath = (_a = comment.value.match(/(["'])((?:\1|.)*?)\1/)) == null ? void 0 : _a[2];
|
129
130
|
if (!extractedImportPath)
|
130
131
|
continue;
|
131
132
|
const importPath = import_path.default.join(import_path.default.dirname(filePath), extractedImportPath);
|