@graphql-eslint/eslint-plugin 4.3.0-alpha-20241205065956-601947f40654914ef0effc1cdf4fe269245fc7bc → 4.3.1-alpha-20241207204625-6a4230707a78900a6339b03afe904b9dd6c31561
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/cache.js +6 -2
- package/cjs/configs/operations-all.js +2 -2
- package/cjs/configs/schema-all.js +2 -2
- package/cjs/configs/schema-recommended.js +1 -1
- package/cjs/documents.js +13 -7
- package/cjs/estree-converter/converter.js +17 -8
- package/cjs/estree-converter/utils.js +22 -9
- package/cjs/graphql-config.js +13 -6
- package/cjs/index.d.cts +18 -4
- package/cjs/meta.js +1 -1
- package/cjs/parser.js +36 -9
- package/cjs/processor.js +48 -20
- package/cjs/rules/alphabetize/index.js +99 -47
- package/cjs/rules/description-style/index.js +10 -6
- package/cjs/rules/graphql-js-validation.js +142 -108
- package/cjs/rules/index.d.cts +18 -4
- package/cjs/rules/input-name/index.js +51 -38
- package/cjs/rules/lone-executable-definition/index.js +15 -6
- package/cjs/rules/match-document-filename/index.d.cts +4 -3
- package/cjs/rules/match-document-filename/index.js +63 -37
- package/cjs/rules/naming-convention/index.d.cts +6 -10
- package/cjs/rules/naming-convention/index.js +146 -57
- package/cjs/rules/no-anonymous-operations/index.js +8 -5
- package/cjs/rules/no-deprecated/index.js +27 -13
- package/cjs/rules/no-duplicate-fields/index.js +15 -8
- package/cjs/rules/no-hashtag-description/index.js +18 -10
- package/cjs/rules/no-one-place-fragments/index.js +17 -10
- package/cjs/rules/no-root-type/index.js +15 -8
- package/cjs/rules/no-scalar-result-type-on-mutation/index.js +20 -12
- package/cjs/rules/no-typename-prefix/index.js +25 -21
- package/cjs/rules/no-unreachable-types/index.js +34 -17
- package/cjs/rules/no-unused-fields/index.js +56 -30
- package/cjs/rules/relay-arguments/index.js +31 -13
- package/cjs/rules/relay-connection-types/index.js +31 -9
- package/cjs/rules/relay-edge-types/index.js +84 -41
- package/cjs/rules/relay-page-info/index.js +31 -14
- package/cjs/rules/require-deprecation-date/index.js +20 -9
- package/cjs/rules/require-deprecation-reason/index.js +8 -5
- package/cjs/rules/require-description/index.d.cts +79 -13
- package/cjs/rules/require-description/index.js +67 -49
- package/cjs/rules/require-field-of-type-query-in-mutation-result/index.js +21 -10
- package/cjs/rules/require-import-fragment/index.js +20 -11
- package/cjs/rules/require-nullable-fields-with-oneof/index.js +12 -5
- package/cjs/rules/require-nullable-result-in-root/index.js +32 -27
- package/cjs/rules/require-selections/index.js +88 -46
- package/cjs/rules/require-type-pattern-with-oneof/index.js +14 -10
- package/cjs/rules/selection-set-depth/index.js +19 -10
- package/cjs/rules/strict-id-in-types/index.js +32 -19
- package/cjs/rules/unique-enum-value-names/index.js +4 -3
- package/cjs/rules/unique-fragment-name/index.js +25 -18
- package/cjs/rules/unique-operation-name/index.js +5 -5
- package/cjs/schema.js +14 -8
- package/cjs/siblings.js +60 -32
- package/cjs/utils.js +23 -9
- package/esm/cache.js +6 -2
- package/esm/configs/operations-all.js +2 -2
- package/esm/configs/schema-all.js +2 -2
- package/esm/configs/schema-recommended.js +1 -1
- package/esm/documents.js +13 -7
- package/esm/estree-converter/converter.js +17 -8
- package/esm/estree-converter/utils.js +22 -9
- package/esm/graphql-config.js +13 -6
- package/esm/index.d.ts +19 -5
- package/esm/meta.js +1 -1
- package/esm/parser.js +36 -9
- package/esm/processor.js +48 -20
- package/esm/rules/alphabetize/index.js +99 -47
- package/esm/rules/description-style/index.js +10 -6
- package/esm/rules/graphql-js-validation.js +142 -108
- package/esm/rules/index.d.ts +19 -5
- package/esm/rules/input-name/index.js +51 -38
- package/esm/rules/lone-executable-definition/index.js +15 -6
- package/esm/rules/match-document-filename/index.d.ts +4 -3
- package/esm/rules/match-document-filename/index.js +63 -37
- package/esm/rules/naming-convention/index.d.ts +6 -10
- package/esm/rules/naming-convention/index.js +146 -57
- package/esm/rules/no-anonymous-operations/index.js +8 -5
- package/esm/rules/no-deprecated/index.js +27 -13
- package/esm/rules/no-duplicate-fields/index.js +15 -8
- package/esm/rules/no-hashtag-description/index.js +18 -10
- package/esm/rules/no-one-place-fragments/index.js +17 -10
- package/esm/rules/no-root-type/index.js +15 -8
- package/esm/rules/no-scalar-result-type-on-mutation/index.js +20 -12
- package/esm/rules/no-typename-prefix/index.js +25 -21
- package/esm/rules/no-unreachable-types/index.js +34 -17
- package/esm/rules/no-unused-fields/index.js +56 -30
- package/esm/rules/relay-arguments/index.js +31 -13
- package/esm/rules/relay-connection-types/index.js +31 -9
- package/esm/rules/relay-edge-types/index.js +84 -41
- package/esm/rules/relay-page-info/index.js +31 -14
- package/esm/rules/require-deprecation-date/index.js +20 -9
- package/esm/rules/require-deprecation-reason/index.js +8 -5
- package/esm/rules/require-description/index.d.ts +79 -13
- package/esm/rules/require-description/index.js +67 -49
- package/esm/rules/require-field-of-type-query-in-mutation-result/index.js +21 -10
- package/esm/rules/require-import-fragment/index.js +20 -11
- package/esm/rules/require-nullable-fields-with-oneof/index.js +12 -5
- package/esm/rules/require-nullable-result-in-root/index.js +32 -27
- package/esm/rules/require-selections/index.js +88 -46
- package/esm/rules/require-type-pattern-with-oneof/index.js +14 -10
- package/esm/rules/selection-set-depth/index.js +19 -10
- package/esm/rules/strict-id-in-types/index.js +32 -19
- package/esm/rules/unique-enum-value-names/index.js +4 -3
- package/esm/rules/unique-fragment-name/index.js +25 -18
- package/esm/rules/unique-operation-name/index.js +5 -5
- package/esm/schema.js +15 -8
- package/esm/siblings.js +60 -32
- package/esm/utils.js +23 -9
- package/index.browser.js +1838 -1135
- package/package.json +1 -1
package/esm/siblings.js
CHANGED
@@ -6,12 +6,18 @@ import { logger } from "./utils.js";
|
|
6
6
|
const siblingOperationsCache = /* @__PURE__ */ new Map();
|
7
7
|
function getSiblings(documents) {
|
8
8
|
if (documents.length === 0) {
|
9
|
-
let printed =
|
10
|
-
const noopWarn = () =>
|
11
|
-
|
12
|
-
|
9
|
+
let printed = false;
|
10
|
+
const noopWarn = () => {
|
11
|
+
if (!printed) {
|
12
|
+
logger.warn(
|
13
|
+
"getSiblingOperations was called without any operations. Make sure to set graphql-config `documents` field to make this feature available! See https://the-guild.dev/graphql/config/docs/user/documents for more info"
|
14
|
+
);
|
15
|
+
printed = true;
|
16
|
+
}
|
17
|
+
return [];
|
18
|
+
};
|
13
19
|
return {
|
14
|
-
available:
|
20
|
+
available: false,
|
15
21
|
getFragment: noopWarn,
|
16
22
|
getFragments: noopWarn,
|
17
23
|
getFragmentByType: noopWarn,
|
@@ -22,18 +28,23 @@ function getSiblings(documents) {
|
|
22
28
|
};
|
23
29
|
}
|
24
30
|
const value = siblingOperationsCache.get(documents);
|
25
|
-
if (value)
|
31
|
+
if (value) {
|
26
32
|
return value;
|
33
|
+
}
|
27
34
|
let fragmentsCache = null;
|
28
35
|
const getFragments = () => {
|
29
36
|
if (fragmentsCache === null) {
|
30
37
|
const result = [];
|
31
|
-
for (const source of documents)
|
32
|
-
for (const definition of source.document?.definitions || [])
|
33
|
-
definition.kind === Kind.FRAGMENT_DEFINITION
|
34
|
-
|
35
|
-
|
36
|
-
|
38
|
+
for (const source of documents) {
|
39
|
+
for (const definition of source.document?.definitions || []) {
|
40
|
+
if (definition.kind === Kind.FRAGMENT_DEFINITION) {
|
41
|
+
result.push({
|
42
|
+
filePath: source.location,
|
43
|
+
document: definition
|
44
|
+
});
|
45
|
+
}
|
46
|
+
}
|
47
|
+
}
|
37
48
|
fragmentsCache = result;
|
38
49
|
}
|
39
50
|
return fragmentsCache;
|
@@ -42,37 +53,54 @@ function getSiblings(documents) {
|
|
42
53
|
const getOperations = () => {
|
43
54
|
if (cachedOperations === null) {
|
44
55
|
const result = [];
|
45
|
-
for (const source of documents)
|
46
|
-
for (const definition of source.document?.definitions || [])
|
47
|
-
definition.kind === Kind.OPERATION_DEFINITION
|
48
|
-
|
49
|
-
|
50
|
-
|
56
|
+
for (const source of documents) {
|
57
|
+
for (const definition of source.document?.definitions || []) {
|
58
|
+
if (definition.kind === Kind.OPERATION_DEFINITION) {
|
59
|
+
result.push({
|
60
|
+
filePath: source.location,
|
61
|
+
document: definition
|
62
|
+
});
|
63
|
+
}
|
64
|
+
}
|
65
|
+
}
|
51
66
|
cachedOperations = result;
|
52
67
|
}
|
53
68
|
return cachedOperations;
|
54
|
-
}
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
);
|
61
|
-
|
69
|
+
};
|
70
|
+
const getFragment = (name) => getFragments().filter((f) => f.document.name.value === name);
|
71
|
+
const collectFragments = (selectable, recursive, collected = /* @__PURE__ */ new Map()) => {
|
72
|
+
visit(selectable, {
|
73
|
+
FragmentSpread(spread) {
|
74
|
+
const fragmentName = spread.name.value;
|
75
|
+
const [fragment] = getFragment(fragmentName);
|
76
|
+
if (!fragment) {
|
77
|
+
logger.warn(
|
78
|
+
`Unable to locate fragment named "${fragmentName}", please make sure it's loaded using "parserOptions.operations"`
|
79
|
+
);
|
80
|
+
return;
|
81
|
+
}
|
82
|
+
if (!collected.has(fragmentName)) {
|
83
|
+
collected.set(fragmentName, fragment.document);
|
84
|
+
if (recursive) {
|
85
|
+
collectFragments(fragment.document, recursive, collected);
|
86
|
+
}
|
87
|
+
}
|
62
88
|
}
|
63
|
-
|
64
|
-
|
65
|
-
}
|
66
|
-
|
89
|
+
});
|
90
|
+
return collected;
|
91
|
+
};
|
92
|
+
const siblingOperations = {
|
93
|
+
available: true,
|
67
94
|
getFragment,
|
68
95
|
getFragments,
|
69
96
|
getFragmentByType: (typeName) => getFragments().filter((f) => f.document.typeCondition.name.value === typeName),
|
70
|
-
getFragmentsInUse: (selectable, recursive =
|
97
|
+
getFragmentsInUse: (selectable, recursive = true) => Array.from(collectFragments(selectable, recursive).values()),
|
71
98
|
getOperation: (name) => getOperations().filter((o) => o.document.name?.value === name),
|
72
99
|
getOperations,
|
73
100
|
getOperationByType: (type) => getOperations().filter((o) => o.document.operation === type)
|
74
101
|
};
|
75
|
-
|
102
|
+
siblingOperationsCache.set(documents, siblingOperations);
|
103
|
+
return siblingOperations;
|
76
104
|
}
|
77
105
|
export {
|
78
106
|
getSiblings
|
package/esm/utils.js
CHANGED
@@ -2,24 +2,27 @@ import { Kind } from "graphql";
|
|
2
2
|
import lowerCase from "lodash.lowercase";
|
3
3
|
function requireGraphQLOperations(ruleId, context) {
|
4
4
|
const { siblingOperations } = context.sourceCode.parserServices;
|
5
|
-
if (!siblingOperations.available)
|
5
|
+
if (!siblingOperations.available) {
|
6
6
|
throw new Error(
|
7
7
|
`Rule \`${ruleId}\` requires graphql-config \`documents\` field to be set and loaded. See https://the-guild.dev/graphql/eslint/docs/usage#providing-operations for more info`
|
8
8
|
);
|
9
|
+
}
|
9
10
|
return siblingOperations;
|
10
11
|
}
|
11
12
|
function requireGraphQLSchema(ruleId, context) {
|
12
13
|
const { schema } = context.sourceCode.parserServices;
|
13
|
-
if (!schema)
|
14
|
+
if (!schema) {
|
14
15
|
throw new Error(
|
15
16
|
`Rule \`${ruleId}\` requires graphql-config \`schema\` field to be set and loaded. See https://the-guild.dev/graphql/eslint/docs/usage#providing-schema for more info`
|
16
17
|
);
|
18
|
+
}
|
17
19
|
return schema;
|
18
20
|
}
|
19
21
|
const chalk = {
|
20
22
|
red: (str) => `\x1B[31m${str}\x1B[39m`,
|
21
23
|
yellow: (str) => `\x1B[33m${str}\x1B[39m`
|
22
|
-
}
|
24
|
+
};
|
25
|
+
const logger = {
|
23
26
|
error: (...args) => (
|
24
27
|
// eslint-disable-next-line no-console
|
25
28
|
console.error(chalk.red("error"), "[graphql-eslint]", ...args)
|
@@ -28,17 +31,25 @@ const chalk = {
|
|
28
31
|
// eslint-disable-next-line no-console
|
29
32
|
console.warn(chalk.yellow("warning"), "[graphql-eslint]", ...args)
|
30
33
|
)
|
31
|
-
}
|
34
|
+
};
|
35
|
+
const slash = (path) => path.replaceAll("\\", "/");
|
36
|
+
const VIRTUAL_DOCUMENT_REGEX = /[/\\]\d+_document.graphql$/;
|
37
|
+
const CWD = process.cwd();
|
38
|
+
const getTypeName = (node) => "type" in node ? getTypeName(node.type) : "name" in node && node.name ? node.name.value : "";
|
39
|
+
const TYPES_KINDS = [
|
32
40
|
Kind.OBJECT_TYPE_DEFINITION,
|
33
41
|
Kind.INTERFACE_TYPE_DEFINITION,
|
34
42
|
Kind.ENUM_TYPE_DEFINITION,
|
35
43
|
Kind.SCALAR_TYPE_DEFINITION,
|
36
44
|
Kind.INPUT_OBJECT_TYPE_DEFINITION,
|
37
45
|
Kind.UNION_TYPE_DEFINITION
|
38
|
-
]
|
46
|
+
];
|
47
|
+
const pascalCase = (str) => lowerCase(str).split(" ").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join("");
|
48
|
+
const camelCase = (str) => {
|
39
49
|
const result = pascalCase(str);
|
40
50
|
return result.charAt(0).toLowerCase() + result.slice(1);
|
41
|
-
}
|
51
|
+
};
|
52
|
+
const convertCase = (style, str) => {
|
42
53
|
switch (style) {
|
43
54
|
case "camelCase":
|
44
55
|
return camelCase(str);
|
@@ -65,14 +76,17 @@ function getLocation(start, fieldName = "") {
|
|
65
76
|
}
|
66
77
|
};
|
67
78
|
}
|
68
|
-
const REPORT_ON_FIRST_CHARACTER = { column: 0, line: 1 }
|
79
|
+
const REPORT_ON_FIRST_CHARACTER = { column: 0, line: 1 };
|
80
|
+
const ARRAY_DEFAULT_OPTIONS = {
|
69
81
|
type: "array",
|
70
|
-
uniqueItems:
|
82
|
+
uniqueItems: true,
|
71
83
|
minItems: 1,
|
72
84
|
items: {
|
73
85
|
type: "string"
|
74
86
|
}
|
75
|
-
}
|
87
|
+
};
|
88
|
+
const englishJoinWords = (words) => new Intl.ListFormat("en-US", { type: "disjunction" }).format(words);
|
89
|
+
const DisplayNodeNameMap = {
|
76
90
|
[Kind.ARGUMENT]: "argument",
|
77
91
|
[Kind.BOOLEAN]: "boolean",
|
78
92
|
[Kind.DIRECTIVE_DEFINITION]: "directive",
|