@graphql-eslint/eslint-plugin 3.14.4-alpha-20230112222814-ed38c21 → 3.14.4-alpha-20230112232227-647789a
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/rules/graphql-js-validation.js +19 -10
- package/cjs/rules/no-deprecated.js +3 -1
- package/cjs/rules/no-one-place-fragments.js +4 -2
- package/cjs/rules/no-root-type.js +3 -1
- package/cjs/rules/no-scalar-result-type-on-mutation.js +3 -1
- package/cjs/rules/no-unreachable-types.js +3 -1
- package/cjs/rules/no-unused-fields.js +5 -3
- package/cjs/rules/relay-arguments.js +3 -1
- package/cjs/rules/relay-edge-types.js +3 -1
- package/cjs/rules/relay-page-info.js +3 -1
- package/cjs/rules/require-description.js +7 -5
- package/cjs/rules/require-field-of-type-query-in-mutation-result.js +3 -1
- package/cjs/rules/require-id-when-available.js +4 -2
- package/cjs/rules/selection-set-depth.js +2 -5
- package/cjs/rules/strict-id-in-types.js +3 -1
- package/cjs/rules/unique-fragment-name.js +5 -3
- package/cjs/rules/unique-operation-name.js +5 -1
- package/cjs/schema.js +1 -2
- package/cjs/utils.js +20 -6
- package/esm/rules/graphql-js-validation.js +19 -10
- package/esm/rules/no-deprecated.js +3 -1
- package/esm/rules/no-one-place-fragments.js +4 -2
- package/esm/rules/no-root-type.js +3 -1
- package/esm/rules/no-scalar-result-type-on-mutation.js +3 -1
- package/esm/rules/no-unreachable-types.js +3 -1
- package/esm/rules/no-unused-fields.js +5 -3
- package/esm/rules/relay-arguments.js +3 -1
- package/esm/rules/relay-edge-types.js +3 -1
- package/esm/rules/relay-page-info.js +3 -1
- package/esm/rules/require-description.js +7 -5
- package/esm/rules/require-field-of-type-query-in-mutation-result.js +3 -1
- package/esm/rules/require-id-when-available.js +4 -2
- package/esm/rules/selection-set-depth.js +2 -5
- package/esm/rules/strict-id-in-types.js +3 -1
- package/esm/rules/unique-fragment-name.js +5 -3
- package/esm/rules/unique-operation-name.js +5 -1
- package/esm/schema.js +1 -2
- package/esm/utils.js +20 -6
- package/package.json +1 -1
- package/typings/rules/unique-fragment-name.d.cts +2 -1
- package/typings/rules/unique-fragment-name.d.ts +2 -1
- package/typings/utils.d.cts +2 -2
- package/typings/utils.d.ts +2 -2
@@ -71,10 +71,12 @@ const getMissingFragments = (node) => {
|
|
71
71
|
const { fragmentDefs, fragmentSpreads } = getFragmentDefsAndFragmentSpreads(node);
|
72
72
|
return [...fragmentSpreads].filter(name => !fragmentDefs.has(name));
|
73
73
|
};
|
74
|
-
const handleMissingFragments = ({
|
74
|
+
const handleMissingFragments = ({ context, node }) => {
|
75
75
|
const missingFragments = getMissingFragments(node);
|
76
76
|
if (missingFragments.length > 0) {
|
77
|
-
const siblings = (0, utils_js_1.requireSiblingsOperations)(
|
77
|
+
const siblings = (0, utils_js_1.requireSiblingsOperations)(context);
|
78
|
+
if (!siblings)
|
79
|
+
return null;
|
78
80
|
const fragmentsToAdd = [];
|
79
81
|
for (const fragmentName of missingFragments) {
|
80
82
|
const [foundFragment] = siblings.getFragment(fragmentName).map(source => source.document);
|
@@ -85,7 +87,6 @@ const handleMissingFragments = ({ ruleId, context, node }) => {
|
|
85
87
|
if (fragmentsToAdd.length > 0) {
|
86
88
|
// recall fn to make sure to add fragments inside fragments
|
87
89
|
return handleMissingFragments({
|
88
|
-
ruleId,
|
89
90
|
context,
|
90
91
|
node: {
|
91
92
|
kind: graphql_1.Kind.DOCUMENT,
|
@@ -129,12 +130,18 @@ const validationToRule = ({ ruleId, ruleName, getDocumentNode, schema = [], hasD
|
|
129
130
|
}
|
130
131
|
return {
|
131
132
|
Document(node) {
|
132
|
-
|
133
|
-
|
134
|
-
|
133
|
+
let schema = null;
|
134
|
+
if (docs.requiresSchema) {
|
135
|
+
schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(context);
|
136
|
+
if (!schema)
|
137
|
+
return;
|
138
|
+
}
|
139
|
+
const rawNode = node.rawNode();
|
135
140
|
const documentNode = getDocumentNode
|
136
|
-
? getDocumentNode({
|
137
|
-
:
|
141
|
+
? getDocumentNode({ context, node: rawNode })
|
142
|
+
: rawNode;
|
143
|
+
if (!documentNode)
|
144
|
+
return;
|
138
145
|
validateDocument({
|
139
146
|
context,
|
140
147
|
schema,
|
@@ -322,8 +329,10 @@ exports.GRAPHQL_JS_VALIDATIONS = Object.assign({}, validationToRule({
|
|
322
329
|
}), validationToRule({
|
323
330
|
ruleId: 'no-unused-fragments',
|
324
331
|
ruleName: 'NoUnusedFragments',
|
325
|
-
getDocumentNode: ({
|
326
|
-
const siblings = (0, utils_js_1.requireSiblingsOperations)(
|
332
|
+
getDocumentNode: ({ context, node }) => {
|
333
|
+
const siblings = (0, utils_js_1.requireSiblingsOperations)(context);
|
334
|
+
if (!siblings)
|
335
|
+
return null;
|
327
336
|
const FilePathToDocumentsMap = [
|
328
337
|
...siblings.getOperations(),
|
329
338
|
...siblings.getFragments(),
|
@@ -83,7 +83,9 @@ exports.rule = {
|
|
83
83
|
schema: [],
|
84
84
|
},
|
85
85
|
create(context) {
|
86
|
-
(0, utils_js_1.requireGraphQLSchemaFromContext)(
|
86
|
+
const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(context);
|
87
|
+
if (!schema)
|
88
|
+
return {};
|
87
89
|
function report(node, reason) {
|
88
90
|
const nodeName = node.kind === graphql_1.Kind.ENUM ? node.value : node.name.value;
|
89
91
|
const nodeType = node.kind === graphql_1.Kind.ENUM ? 'enum value' : 'field';
|
@@ -53,8 +53,10 @@ exports.rule = {
|
|
53
53
|
schema: [],
|
54
54
|
},
|
55
55
|
create(context) {
|
56
|
-
const
|
57
|
-
|
56
|
+
const siblings = (0, utils_js_1.requireSiblingsOperations)(context);
|
57
|
+
if (!siblings)
|
58
|
+
return {};
|
59
|
+
const allDocuments = [...siblings.getOperations(), ...siblings.getFragments()];
|
58
60
|
const usedFragmentsMap = Object.create(null);
|
59
61
|
for (const { document, filePath } of allDocuments) {
|
60
62
|
const relativeFilePath = (0, path_1.relative)(utils_js_1.CWD, filePath);
|
@@ -54,7 +54,9 @@ exports.rule = {
|
|
54
54
|
schema,
|
55
55
|
},
|
56
56
|
create(context) {
|
57
|
-
const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(
|
57
|
+
const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(context);
|
58
|
+
if (!schema)
|
59
|
+
return {};
|
58
60
|
const disallow = new Set(context.options[0].disallow);
|
59
61
|
const rootTypeNames = [
|
60
62
|
disallow.has('mutation') && schema.getMutationType(),
|
@@ -35,7 +35,9 @@ exports.rule = {
|
|
35
35
|
schema: [],
|
36
36
|
},
|
37
37
|
create(context) {
|
38
|
-
const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(
|
38
|
+
const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(context);
|
39
|
+
if (!schema)
|
40
|
+
return {};
|
39
41
|
const mutationType = schema.getMutationType();
|
40
42
|
if (!mutationType) {
|
41
43
|
return {};
|
@@ -130,7 +130,9 @@ exports.rule = {
|
|
130
130
|
hasSuggestions: true,
|
131
131
|
},
|
132
132
|
create(context) {
|
133
|
-
const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(
|
133
|
+
const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(context);
|
134
|
+
if (!schema)
|
135
|
+
return {};
|
134
136
|
const reachableTypes = getReachableTypes(schema);
|
135
137
|
return {
|
136
138
|
[`:matches(${KINDS}) > .name`](node) {
|
@@ -95,9 +95,11 @@ exports.rule = {
|
|
95
95
|
hasSuggestions: true,
|
96
96
|
},
|
97
97
|
create(context) {
|
98
|
-
const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(
|
99
|
-
const
|
100
|
-
|
98
|
+
const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(context);
|
99
|
+
const siblings = (0, utils_js_1.requireSiblingsOperations)(context);
|
100
|
+
if (!schema || !siblings)
|
101
|
+
return {};
|
102
|
+
const usedFields = getUsedFields(schema, siblings);
|
101
103
|
return {
|
102
104
|
FieldDefinition(node) {
|
103
105
|
var _a;
|
@@ -68,7 +68,9 @@ exports.rule = {
|
|
68
68
|
schema,
|
69
69
|
},
|
70
70
|
create(context) {
|
71
|
-
const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(
|
71
|
+
const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(context);
|
72
|
+
if (!schema)
|
73
|
+
return {};
|
72
74
|
const { includeBoth = true } = context.options[0] || {};
|
73
75
|
return {
|
74
76
|
'FieldDefinition > .gqlType Name[value=/Connection$/]'(node) {
|
@@ -106,7 +106,9 @@ exports.rule = {
|
|
106
106
|
schema,
|
107
107
|
},
|
108
108
|
create(context) {
|
109
|
-
const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(
|
109
|
+
const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(context);
|
110
|
+
if (!schema)
|
111
|
+
return {};
|
110
112
|
const edgeTypes = getEdgeTypes(schema);
|
111
113
|
const options = {
|
112
114
|
withEdgeSuffix: true,
|
@@ -45,7 +45,9 @@ exports.rule = {
|
|
45
45
|
schema: [],
|
46
46
|
},
|
47
47
|
create(context) {
|
48
|
-
const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(
|
48
|
+
const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(context);
|
49
|
+
if (!schema)
|
50
|
+
return {};
|
49
51
|
if (process.env.NODE_ENV === 'test' || !hasPageInfoChecked) {
|
50
52
|
const pageInfoType = schema.getType('PageInfo');
|
51
53
|
if (!pageInfoType) {
|
@@ -152,11 +152,13 @@ exports.rule = {
|
|
152
152
|
}
|
153
153
|
}
|
154
154
|
if (rootField) {
|
155
|
-
const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
155
|
+
const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(context);
|
156
|
+
if (schema) {
|
157
|
+
const rootTypeNames = (0, utils_1.getRootTypeNames)(schema);
|
158
|
+
kinds.add(`:matches(ObjectTypeDefinition, ObjectTypeExtension)[name.value=/^(${[
|
159
|
+
...rootTypeNames,
|
160
|
+
].join(',')})$/] > FieldDefinition`);
|
161
|
+
}
|
160
162
|
}
|
161
163
|
const selector = [...kinds].join(',');
|
162
164
|
return {
|
@@ -45,7 +45,9 @@ exports.rule = {
|
|
45
45
|
schema: [],
|
46
46
|
},
|
47
47
|
create(context) {
|
48
|
-
const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(
|
48
|
+
const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(context);
|
49
|
+
if (!schema)
|
50
|
+
return {};
|
49
51
|
const mutationType = schema.getMutationType();
|
50
52
|
const queryType = schema.getQueryType();
|
51
53
|
if (!mutationType || !queryType) {
|
@@ -89,8 +89,10 @@ exports.rule = {
|
|
89
89
|
schema,
|
90
90
|
},
|
91
91
|
create(context) {
|
92
|
-
const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(
|
93
|
-
const siblings = (0, utils_js_1.requireSiblingsOperations)(
|
92
|
+
const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(context);
|
93
|
+
const siblings = (0, utils_js_1.requireSiblingsOperations)(context);
|
94
|
+
if (!schema || !siblings)
|
95
|
+
return {};
|
94
96
|
const { fieldName = DEFAULT_ID_FIELD_NAME } = context.options[0] || {};
|
95
97
|
const idNames = (0, utils_1.asArray)(fieldName);
|
96
98
|
// Check selections only in OperationDefinition,
|
@@ -78,11 +78,8 @@ exports.rule = {
|
|
78
78
|
schema,
|
79
79
|
},
|
80
80
|
create(context) {
|
81
|
-
|
82
|
-
|
83
|
-
siblings = (0, utils_js_1.requireSiblingsOperations)(RULE_ID, context);
|
84
|
-
}
|
85
|
-
catch (_a) {
|
81
|
+
const siblings = (0, utils_js_1.requireSiblingsOperations)(context, false);
|
82
|
+
if (!siblings) {
|
86
83
|
utils_js_1.logger.warn(`Rule "${RULE_ID}" works best with siblings operations loaded. For more info: https://bit.ly/graphql-eslint-operations`);
|
87
84
|
}
|
88
85
|
const { maxDepth, ignore = [] } = context.options[0];
|
@@ -116,7 +116,9 @@ exports.rule = {
|
|
116
116
|
exceptions: {},
|
117
117
|
...context.options[0],
|
118
118
|
};
|
119
|
-
const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(
|
119
|
+
const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(context);
|
120
|
+
if (!schema)
|
121
|
+
return {};
|
120
122
|
const rootTypeNames = [
|
121
123
|
schema.getQueryType(),
|
122
124
|
schema.getMutationType(),
|
@@ -5,9 +5,8 @@ const path_1 = require("path");
|
|
5
5
|
const graphql_1 = require("graphql");
|
6
6
|
const utils_js_1 = require("../utils.js");
|
7
7
|
const RULE_ID = 'unique-fragment-name';
|
8
|
-
const checkNode = (context, node, ruleId) => {
|
8
|
+
const checkNode = (context, node, ruleId, siblings) => {
|
9
9
|
const documentName = node.name.value;
|
10
|
-
const siblings = (0, utils_js_1.requireSiblingsOperations)(ruleId, context);
|
11
10
|
const siblingDocuments = node.kind === graphql_1.Kind.FRAGMENT_DEFINITION
|
12
11
|
? siblings.getFragment(documentName)
|
13
12
|
: siblings.getOperation(documentName);
|
@@ -82,9 +81,12 @@ exports.rule = {
|
|
82
81
|
schema: [],
|
83
82
|
},
|
84
83
|
create(context) {
|
84
|
+
const siblings = (0, utils_js_1.requireSiblingsOperations)(context);
|
85
|
+
if (!siblings)
|
86
|
+
return {};
|
85
87
|
return {
|
86
88
|
FragmentDefinition(node) {
|
87
|
-
(0, exports.checkNode)(context, node, RULE_ID);
|
89
|
+
(0, exports.checkNode)(context, node, RULE_ID, siblings);
|
88
90
|
},
|
89
91
|
};
|
90
92
|
},
|
@@ -1,6 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.rule = void 0;
|
4
|
+
const utils_js_1 = require("../utils.js");
|
4
5
|
const unique_fragment_name_js_1 = require("./unique-fragment-name.js");
|
5
6
|
const RULE_ID = 'unique-operation-name';
|
6
7
|
exports.rule = {
|
@@ -56,9 +57,12 @@ exports.rule = {
|
|
56
57
|
schema: [],
|
57
58
|
},
|
58
59
|
create(context) {
|
60
|
+
const siblings = (0, utils_js_1.requireSiblingsOperations)(context);
|
61
|
+
if (!siblings)
|
62
|
+
return {};
|
59
63
|
return {
|
60
64
|
'OperationDefinition[name!=undefined]'(node) {
|
61
|
-
(0, unique_fragment_name_js_1.checkNode)(context, node, RULE_ID);
|
65
|
+
(0, unique_fragment_name_js_1.checkNode)(context, node, RULE_ID, siblings);
|
62
66
|
},
|
63
67
|
};
|
64
68
|
},
|
package/cjs/schema.js
CHANGED
@@ -2,7 +2,6 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.getSchema = void 0;
|
4
4
|
const tslib_1 = require("tslib");
|
5
|
-
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
6
5
|
const debug_1 = tslib_1.__importDefault(require("debug"));
|
7
6
|
const fast_glob_1 = tslib_1.__importDefault(require("fast-glob"));
|
8
7
|
const graphql_1 = require("graphql");
|
@@ -35,7 +34,7 @@ function getSchema(project, schemaOptions) {
|
|
35
34
|
}
|
36
35
|
catch (error) {
|
37
36
|
if (error instanceof Error) {
|
38
|
-
error.message =
|
37
|
+
error.message = `Error while loading schema: ${error.message}`;
|
39
38
|
}
|
40
39
|
schema = error;
|
41
40
|
}
|
package/cjs/utils.js
CHANGED
@@ -5,21 +5,35 @@ const tslib_1 = require("tslib");
|
|
5
5
|
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
6
6
|
const graphql_1 = require("graphql");
|
7
7
|
const lodash_lowercase_1 = tslib_1.__importDefault(require("lodash.lowercase"));
|
8
|
-
function requireSiblingsOperations(
|
8
|
+
function requireSiblingsOperations(context, shouldReport = true) {
|
9
9
|
const { siblingOperations } = context.parserServices;
|
10
10
|
if (!siblingOperations.available) {
|
11
|
-
|
11
|
+
if (shouldReport) {
|
12
|
+
context.report({
|
13
|
+
loc: exports.REPORT_ON_FIRST_CHARACTER,
|
14
|
+
message: 'Rule requires `parserOptions.operations` to be set and loaded. See https://bit.ly/graphql-eslint-operations for more info',
|
15
|
+
});
|
16
|
+
}
|
17
|
+
return null;
|
12
18
|
}
|
13
19
|
return siblingOperations;
|
14
20
|
}
|
15
21
|
exports.requireSiblingsOperations = requireSiblingsOperations;
|
16
|
-
function requireGraphQLSchemaFromContext(
|
22
|
+
function requireGraphQLSchemaFromContext(context) {
|
17
23
|
const { schema } = context.parserServices;
|
18
24
|
if (!schema) {
|
19
|
-
|
25
|
+
context.report({
|
26
|
+
loc: exports.REPORT_ON_FIRST_CHARACTER,
|
27
|
+
message: 'Rule requires `parserOptions.schema` to be set and loaded. See https://bit.ly/graphql-eslint-schema for more info',
|
28
|
+
});
|
29
|
+
return null;
|
20
30
|
}
|
21
|
-
|
22
|
-
|
31
|
+
if (schema instanceof Error) {
|
32
|
+
context.report({
|
33
|
+
loc: exports.REPORT_ON_FIRST_CHARACTER,
|
34
|
+
message: schema.message,
|
35
|
+
});
|
36
|
+
return null;
|
23
37
|
}
|
24
38
|
return schema;
|
25
39
|
}
|
@@ -70,10 +70,12 @@ const getMissingFragments = (node) => {
|
|
70
70
|
const { fragmentDefs, fragmentSpreads } = getFragmentDefsAndFragmentSpreads(node);
|
71
71
|
return [...fragmentSpreads].filter(name => !fragmentDefs.has(name));
|
72
72
|
};
|
73
|
-
const handleMissingFragments = ({
|
73
|
+
const handleMissingFragments = ({ context, node }) => {
|
74
74
|
const missingFragments = getMissingFragments(node);
|
75
75
|
if (missingFragments.length > 0) {
|
76
|
-
const siblings = requireSiblingsOperations(
|
76
|
+
const siblings = requireSiblingsOperations(context);
|
77
|
+
if (!siblings)
|
78
|
+
return null;
|
77
79
|
const fragmentsToAdd = [];
|
78
80
|
for (const fragmentName of missingFragments) {
|
79
81
|
const [foundFragment] = siblings.getFragment(fragmentName).map(source => source.document);
|
@@ -84,7 +86,6 @@ const handleMissingFragments = ({ ruleId, context, node }) => {
|
|
84
86
|
if (fragmentsToAdd.length > 0) {
|
85
87
|
// recall fn to make sure to add fragments inside fragments
|
86
88
|
return handleMissingFragments({
|
87
|
-
ruleId,
|
88
89
|
context,
|
89
90
|
node: {
|
90
91
|
kind: Kind.DOCUMENT,
|
@@ -128,12 +129,18 @@ const validationToRule = ({ ruleId, ruleName, getDocumentNode, schema = [], hasD
|
|
128
129
|
}
|
129
130
|
return {
|
130
131
|
Document(node) {
|
131
|
-
|
132
|
-
|
133
|
-
|
132
|
+
let schema = null;
|
133
|
+
if (docs.requiresSchema) {
|
134
|
+
schema = requireGraphQLSchemaFromContext(context);
|
135
|
+
if (!schema)
|
136
|
+
return;
|
137
|
+
}
|
138
|
+
const rawNode = node.rawNode();
|
134
139
|
const documentNode = getDocumentNode
|
135
|
-
? getDocumentNode({
|
136
|
-
:
|
140
|
+
? getDocumentNode({ context, node: rawNode })
|
141
|
+
: rawNode;
|
142
|
+
if (!documentNode)
|
143
|
+
return;
|
137
144
|
validateDocument({
|
138
145
|
context,
|
139
146
|
schema,
|
@@ -321,8 +328,10 @@ export const GRAPHQL_JS_VALIDATIONS = Object.assign({}, validationToRule({
|
|
321
328
|
}), validationToRule({
|
322
329
|
ruleId: 'no-unused-fragments',
|
323
330
|
ruleName: 'NoUnusedFragments',
|
324
|
-
getDocumentNode: ({
|
325
|
-
const siblings = requireSiblingsOperations(
|
331
|
+
getDocumentNode: ({ context, node }) => {
|
332
|
+
const siblings = requireSiblingsOperations(context);
|
333
|
+
if (!siblings)
|
334
|
+
return null;
|
326
335
|
const FilePathToDocumentsMap = [
|
327
336
|
...siblings.getOperations(),
|
328
337
|
...siblings.getFragments(),
|
@@ -80,7 +80,9 @@ export const rule = {
|
|
80
80
|
schema: [],
|
81
81
|
},
|
82
82
|
create(context) {
|
83
|
-
requireGraphQLSchemaFromContext(
|
83
|
+
const schema = requireGraphQLSchemaFromContext(context);
|
84
|
+
if (!schema)
|
85
|
+
return {};
|
84
86
|
function report(node, reason) {
|
85
87
|
const nodeName = node.kind === Kind.ENUM ? node.value : node.name.value;
|
86
88
|
const nodeType = node.kind === Kind.ENUM ? 'enum value' : 'field';
|
@@ -50,8 +50,10 @@ export const rule = {
|
|
50
50
|
schema: [],
|
51
51
|
},
|
52
52
|
create(context) {
|
53
|
-
const
|
54
|
-
|
53
|
+
const siblings = requireSiblingsOperations(context);
|
54
|
+
if (!siblings)
|
55
|
+
return {};
|
56
|
+
const allDocuments = [...siblings.getOperations(), ...siblings.getFragments()];
|
55
57
|
const usedFragmentsMap = Object.create(null);
|
56
58
|
for (const { document, filePath } of allDocuments) {
|
57
59
|
const relativeFilePath = relative(CWD, filePath);
|
@@ -51,7 +51,9 @@ export const rule = {
|
|
51
51
|
schema,
|
52
52
|
},
|
53
53
|
create(context) {
|
54
|
-
const schema = requireGraphQLSchemaFromContext(
|
54
|
+
const schema = requireGraphQLSchemaFromContext(context);
|
55
|
+
if (!schema)
|
56
|
+
return {};
|
55
57
|
const disallow = new Set(context.options[0].disallow);
|
56
58
|
const rootTypeNames = [
|
57
59
|
disallow.has('mutation') && schema.getMutationType(),
|
@@ -32,7 +32,9 @@ export const rule = {
|
|
32
32
|
schema: [],
|
33
33
|
},
|
34
34
|
create(context) {
|
35
|
-
const schema = requireGraphQLSchemaFromContext(
|
35
|
+
const schema = requireGraphQLSchemaFromContext(context);
|
36
|
+
if (!schema)
|
37
|
+
return {};
|
36
38
|
const mutationType = schema.getMutationType();
|
37
39
|
if (!mutationType) {
|
38
40
|
return {};
|
@@ -126,7 +126,9 @@ export const rule = {
|
|
126
126
|
hasSuggestions: true,
|
127
127
|
},
|
128
128
|
create(context) {
|
129
|
-
const schema = requireGraphQLSchemaFromContext(
|
129
|
+
const schema = requireGraphQLSchemaFromContext(context);
|
130
|
+
if (!schema)
|
131
|
+
return {};
|
130
132
|
const reachableTypes = getReachableTypes(schema);
|
131
133
|
return {
|
132
134
|
[`:matches(${KINDS}) > .name`](node) {
|
@@ -92,9 +92,11 @@ export const rule = {
|
|
92
92
|
hasSuggestions: true,
|
93
93
|
},
|
94
94
|
create(context) {
|
95
|
-
const schema = requireGraphQLSchemaFromContext(
|
96
|
-
const
|
97
|
-
|
95
|
+
const schema = requireGraphQLSchemaFromContext(context);
|
96
|
+
const siblings = requireSiblingsOperations(context);
|
97
|
+
if (!schema || !siblings)
|
98
|
+
return {};
|
99
|
+
const usedFields = getUsedFields(schema, siblings);
|
98
100
|
return {
|
99
101
|
FieldDefinition(node) {
|
100
102
|
var _a;
|
@@ -65,7 +65,9 @@ export const rule = {
|
|
65
65
|
schema,
|
66
66
|
},
|
67
67
|
create(context) {
|
68
|
-
const schema = requireGraphQLSchemaFromContext(
|
68
|
+
const schema = requireGraphQLSchemaFromContext(context);
|
69
|
+
if (!schema)
|
70
|
+
return {};
|
69
71
|
const { includeBoth = true } = context.options[0] || {};
|
70
72
|
return {
|
71
73
|
'FieldDefinition > .gqlType Name[value=/Connection$/]'(node) {
|
@@ -103,7 +103,9 @@ export const rule = {
|
|
103
103
|
schema,
|
104
104
|
},
|
105
105
|
create(context) {
|
106
|
-
const schema = requireGraphQLSchemaFromContext(
|
106
|
+
const schema = requireGraphQLSchemaFromContext(context);
|
107
|
+
if (!schema)
|
108
|
+
return {};
|
107
109
|
const edgeTypes = getEdgeTypes(schema);
|
108
110
|
const options = {
|
109
111
|
withEdgeSuffix: true,
|
@@ -42,7 +42,9 @@ export const rule = {
|
|
42
42
|
schema: [],
|
43
43
|
},
|
44
44
|
create(context) {
|
45
|
-
const schema = requireGraphQLSchemaFromContext(
|
45
|
+
const schema = requireGraphQLSchemaFromContext(context);
|
46
|
+
if (!schema)
|
47
|
+
return {};
|
46
48
|
if (process.env.NODE_ENV === 'test' || !hasPageInfoChecked) {
|
47
49
|
const pageInfoType = schema.getType('PageInfo');
|
48
50
|
if (!pageInfoType) {
|
@@ -149,11 +149,13 @@ export const rule = {
|
|
149
149
|
}
|
150
150
|
}
|
151
151
|
if (rootField) {
|
152
|
-
const schema = requireGraphQLSchemaFromContext(
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
152
|
+
const schema = requireGraphQLSchemaFromContext(context);
|
153
|
+
if (schema) {
|
154
|
+
const rootTypeNames = getRootTypeNames(schema);
|
155
|
+
kinds.add(`:matches(ObjectTypeDefinition, ObjectTypeExtension)[name.value=/^(${[
|
156
|
+
...rootTypeNames,
|
157
|
+
].join(',')})$/] > FieldDefinition`);
|
158
|
+
}
|
157
159
|
}
|
158
160
|
const selector = [...kinds].join(',');
|
159
161
|
return {
|
@@ -42,7 +42,9 @@ export const rule = {
|
|
42
42
|
schema: [],
|
43
43
|
},
|
44
44
|
create(context) {
|
45
|
-
const schema = requireGraphQLSchemaFromContext(
|
45
|
+
const schema = requireGraphQLSchemaFromContext(context);
|
46
|
+
if (!schema)
|
47
|
+
return {};
|
46
48
|
const mutationType = schema.getMutationType();
|
47
49
|
const queryType = schema.getQueryType();
|
48
50
|
if (!mutationType || !queryType) {
|
@@ -86,8 +86,10 @@ export const rule = {
|
|
86
86
|
schema,
|
87
87
|
},
|
88
88
|
create(context) {
|
89
|
-
const schema = requireGraphQLSchemaFromContext(
|
90
|
-
const siblings = requireSiblingsOperations(
|
89
|
+
const schema = requireGraphQLSchemaFromContext(context);
|
90
|
+
const siblings = requireSiblingsOperations(context);
|
91
|
+
if (!schema || !siblings)
|
92
|
+
return {};
|
91
93
|
const { fieldName = DEFAULT_ID_FIELD_NAME } = context.options[0] || {};
|
92
94
|
const idNames = asArray(fieldName);
|
93
95
|
// Check selections only in OperationDefinition,
|
@@ -74,11 +74,8 @@ export const rule = {
|
|
74
74
|
schema,
|
75
75
|
},
|
76
76
|
create(context) {
|
77
|
-
|
78
|
-
|
79
|
-
siblings = requireSiblingsOperations(RULE_ID, context);
|
80
|
-
}
|
81
|
-
catch (_a) {
|
77
|
+
const siblings = requireSiblingsOperations(context, false);
|
78
|
+
if (!siblings) {
|
82
79
|
logger.warn(`Rule "${RULE_ID}" works best with siblings operations loaded. For more info: https://bit.ly/graphql-eslint-operations`);
|
83
80
|
}
|
84
81
|
const { maxDepth, ignore = [] } = context.options[0];
|
@@ -113,7 +113,9 @@ export const rule = {
|
|
113
113
|
exceptions: {},
|
114
114
|
...context.options[0],
|
115
115
|
};
|
116
|
-
const schema = requireGraphQLSchemaFromContext(
|
116
|
+
const schema = requireGraphQLSchemaFromContext(context);
|
117
|
+
if (!schema)
|
118
|
+
return {};
|
117
119
|
const rootTypeNames = [
|
118
120
|
schema.getQueryType(),
|
119
121
|
schema.getMutationType(),
|
@@ -2,9 +2,8 @@ import { relative } from 'path';
|
|
2
2
|
import { Kind } from 'graphql';
|
3
3
|
import { CWD, normalizePath, requireSiblingsOperations, VIRTUAL_DOCUMENT_REGEX } from '../utils.js';
|
4
4
|
const RULE_ID = 'unique-fragment-name';
|
5
|
-
export const checkNode = (context, node, ruleId) => {
|
5
|
+
export const checkNode = (context, node, ruleId, siblings) => {
|
6
6
|
const documentName = node.name.value;
|
7
|
-
const siblings = requireSiblingsOperations(ruleId, context);
|
8
7
|
const siblingDocuments = node.kind === Kind.FRAGMENT_DEFINITION
|
9
8
|
? siblings.getFragment(documentName)
|
10
9
|
: siblings.getOperation(documentName);
|
@@ -78,9 +77,12 @@ export const rule = {
|
|
78
77
|
schema: [],
|
79
78
|
},
|
80
79
|
create(context) {
|
80
|
+
const siblings = requireSiblingsOperations(context);
|
81
|
+
if (!siblings)
|
82
|
+
return {};
|
81
83
|
return {
|
82
84
|
FragmentDefinition(node) {
|
83
|
-
checkNode(context, node, RULE_ID);
|
85
|
+
checkNode(context, node, RULE_ID, siblings);
|
84
86
|
},
|
85
87
|
};
|
86
88
|
},
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import { requireSiblingsOperations } from '../utils.js';
|
1
2
|
import { checkNode } from './unique-fragment-name.js';
|
2
3
|
const RULE_ID = 'unique-operation-name';
|
3
4
|
export const rule = {
|
@@ -53,9 +54,12 @@ export const rule = {
|
|
53
54
|
schema: [],
|
54
55
|
},
|
55
56
|
create(context) {
|
57
|
+
const siblings = requireSiblingsOperations(context);
|
58
|
+
if (!siblings)
|
59
|
+
return {};
|
56
60
|
return {
|
57
61
|
'OperationDefinition[name!=undefined]'(node) {
|
58
|
-
checkNode(context, node, RULE_ID);
|
62
|
+
checkNode(context, node, RULE_ID, siblings);
|
59
63
|
},
|
60
64
|
};
|
61
65
|
},
|
package/esm/schema.js
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
import chalk from 'chalk';
|
2
1
|
import debugFactory from 'debug';
|
3
2
|
import fg from 'fast-glob';
|
4
3
|
import { GraphQLSchema } from 'graphql';
|
@@ -31,7 +30,7 @@ export function getSchema(project, schemaOptions) {
|
|
31
30
|
}
|
32
31
|
catch (error) {
|
33
32
|
if (error instanceof Error) {
|
34
|
-
error.message =
|
33
|
+
error.message = `Error while loading schema: ${error.message}`;
|
35
34
|
}
|
36
35
|
schema = error;
|
37
36
|
}
|
package/esm/utils.js
CHANGED
@@ -1,20 +1,34 @@
|
|
1
1
|
import chalk from 'chalk';
|
2
2
|
import { Kind } from 'graphql';
|
3
3
|
import lowerCase from 'lodash.lowercase';
|
4
|
-
export function requireSiblingsOperations(
|
4
|
+
export function requireSiblingsOperations(context, shouldReport = true) {
|
5
5
|
const { siblingOperations } = context.parserServices;
|
6
6
|
if (!siblingOperations.available) {
|
7
|
-
|
7
|
+
if (shouldReport) {
|
8
|
+
context.report({
|
9
|
+
loc: REPORT_ON_FIRST_CHARACTER,
|
10
|
+
message: 'Rule requires `parserOptions.operations` to be set and loaded. See https://bit.ly/graphql-eslint-operations for more info',
|
11
|
+
});
|
12
|
+
}
|
13
|
+
return null;
|
8
14
|
}
|
9
15
|
return siblingOperations;
|
10
16
|
}
|
11
|
-
export function requireGraphQLSchemaFromContext(
|
17
|
+
export function requireGraphQLSchemaFromContext(context) {
|
12
18
|
const { schema } = context.parserServices;
|
13
19
|
if (!schema) {
|
14
|
-
|
20
|
+
context.report({
|
21
|
+
loc: REPORT_ON_FIRST_CHARACTER,
|
22
|
+
message: 'Rule requires `parserOptions.schema` to be set and loaded. See https://bit.ly/graphql-eslint-schema for more info',
|
23
|
+
});
|
24
|
+
return null;
|
15
25
|
}
|
16
|
-
|
17
|
-
|
26
|
+
if (schema instanceof Error) {
|
27
|
+
context.report({
|
28
|
+
loc: REPORT_ON_FIRST_CHARACTER,
|
29
|
+
message: schema.message,
|
30
|
+
});
|
31
|
+
return null;
|
18
32
|
}
|
19
33
|
return schema;
|
20
34
|
}
|
package/package.json
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import { ExecutableDefinitionNode } from 'graphql';
|
2
2
|
import { GraphQLESTreeNode } from '../estree-converter/index.cjs';
|
3
|
+
import { SiblingOperations } from '../siblings.cjs';
|
3
4
|
import { GraphQLESLintRule, GraphQLESLintRuleContext } from '../types.cjs';
|
4
|
-
export declare const checkNode: (context: GraphQLESLintRuleContext, node: GraphQLESTreeNode<ExecutableDefinitionNode>, ruleId: string) => void;
|
5
|
+
export declare const checkNode: (context: GraphQLESLintRuleContext, node: GraphQLESTreeNode<ExecutableDefinitionNode>, ruleId: string, siblings: SiblingOperations) => void;
|
5
6
|
export declare const rule: GraphQLESLintRule;
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import { ExecutableDefinitionNode } from 'graphql';
|
2
2
|
import { GraphQLESTreeNode } from '../estree-converter/index.js';
|
3
|
+
import { SiblingOperations } from '../siblings.js';
|
3
4
|
import { GraphQLESLintRule, GraphQLESLintRuleContext } from '../types.js';
|
4
|
-
export declare const checkNode: (context: GraphQLESLintRuleContext, node: GraphQLESTreeNode<ExecutableDefinitionNode>, ruleId: string) => void;
|
5
|
+
export declare const checkNode: (context: GraphQLESLintRuleContext, node: GraphQLESTreeNode<ExecutableDefinitionNode>, ruleId: string, siblings: SiblingOperations) => void;
|
5
6
|
export declare const rule: GraphQLESLintRule;
|
package/typings/utils.d.cts
CHANGED
@@ -3,8 +3,8 @@ import { Position } from 'estree';
|
|
3
3
|
import { ASTNode, GraphQLSchema, Kind } from 'graphql';
|
4
4
|
import { SiblingOperations } from './siblings.cjs';
|
5
5
|
import { GraphQLESLintRuleContext } from './types.cjs';
|
6
|
-
export declare function requireSiblingsOperations(
|
7
|
-
export declare function requireGraphQLSchemaFromContext(
|
6
|
+
export declare function requireSiblingsOperations(context: GraphQLESLintRuleContext, shouldReport?: boolean): SiblingOperations | null;
|
7
|
+
export declare function requireGraphQLSchemaFromContext(context: GraphQLESLintRuleContext): GraphQLSchema | null;
|
8
8
|
export declare const logger: {
|
9
9
|
error: (...args: unknown[]) => void;
|
10
10
|
warn: (...args: unknown[]) => void;
|
package/typings/utils.d.ts
CHANGED
@@ -3,8 +3,8 @@ import { Position } from 'estree';
|
|
3
3
|
import { ASTNode, GraphQLSchema, Kind } from 'graphql';
|
4
4
|
import { SiblingOperations } from './siblings.js';
|
5
5
|
import { GraphQLESLintRuleContext } from './types.js';
|
6
|
-
export declare function requireSiblingsOperations(
|
7
|
-
export declare function requireGraphQLSchemaFromContext(
|
6
|
+
export declare function requireSiblingsOperations(context: GraphQLESLintRuleContext, shouldReport?: boolean): SiblingOperations | null;
|
7
|
+
export declare function requireGraphQLSchemaFromContext(context: GraphQLESLintRuleContext): GraphQLSchema | null;
|
8
8
|
export declare const logger: {
|
9
9
|
error: (...args: unknown[]) => void;
|
10
10
|
warn: (...args: unknown[]) => void;
|