@graphql-eslint/eslint-plugin 3.14.0-alpha-20221222211539-5e993f5 → 3.14.0-alpha-20221223011223-bd3e820
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/index.js +10 -10
- package/cjs/documents.js +5 -5
- package/cjs/estree-converter/converter.js +2 -2
- package/cjs/estree-converter/index.js +3 -3
- package/cjs/estree-converter/utils.js +2 -2
- package/cjs/flat-configs.js +36 -0
- package/cjs/index.js +16 -14
- package/cjs/parser.js +13 -13
- package/cjs/processor.js +2 -2
- package/cjs/rules/alphabetize.js +7 -7
- package/cjs/rules/graphql-js-validation.js +9 -9
- package/cjs/rules/index.js +66 -66
- package/cjs/rules/lone-executable-definition.js +4 -4
- package/cjs/rules/match-document-filename.js +4 -4
- package/cjs/rules/naming-convention.js +6 -6
- package/cjs/rules/no-anonymous-operations.js +2 -2
- package/cjs/rules/no-deprecated.js +2 -2
- package/cjs/rules/no-one-place-fragments.js +3 -4
- package/cjs/rules/no-root-type.js +3 -3
- package/cjs/rules/no-scalar-result-type-on-mutation.js +2 -2
- package/cjs/rules/no-unreachable-types.js +3 -3
- package/cjs/rules/no-unused-fields.js +3 -3
- package/cjs/rules/relay-arguments.js +2 -2
- package/cjs/rules/relay-edge-types.js +6 -6
- package/cjs/rules/relay-page-info.js +5 -5
- package/cjs/rules/require-deprecation-date.js +2 -2
- package/cjs/rules/require-deprecation-reason.js +2 -2
- package/cjs/rules/require-description.js +8 -8
- package/cjs/rules/require-field-of-type-query-in-mutation-result.js +3 -3
- package/cjs/rules/require-id-when-available.js +8 -8
- package/cjs/rules/selection-set-depth.js +5 -5
- package/cjs/rules/strict-id-in-types.js +7 -7
- package/cjs/rules/unique-fragment-name.js +4 -4
- package/cjs/rules/unique-operation-name.js +2 -2
- package/cjs/schema.js +2 -2
- package/esm/cache.js +25 -0
- package/esm/configs/base.js +4 -0
- package/esm/configs/index.js +12 -0
- package/esm/configs/operations-all.js +29 -0
- package/esm/configs/operations-recommended.js +53 -0
- package/esm/configs/relay.js +9 -0
- package/esm/configs/schema-all.js +22 -0
- package/esm/configs/schema-recommended.js +49 -0
- package/esm/documents.js +144 -0
- package/esm/estree-converter/converter.js +58 -0
- package/esm/estree-converter/index.js +3 -0
- package/esm/estree-converter/types.js +1 -0
- package/esm/estree-converter/utils.js +102 -0
- package/esm/flat-configs.js +33 -0
- package/esm/graphql-config.js +49 -0
- package/esm/index.js +9 -0
- package/esm/package.json +1 -0
- package/esm/parser.js +56 -0
- package/esm/processor.js +75 -0
- package/esm/rules/alphabetize.js +344 -0
- package/esm/rules/description-style.js +75 -0
- package/esm/rules/graphql-js-validation.js +498 -0
- package/esm/rules/index.js +71 -0
- package/esm/rules/input-name.js +133 -0
- package/esm/rules/lone-executable-definition.js +85 -0
- package/esm/rules/match-document-filename.js +232 -0
- package/esm/rules/naming-convention.js +307 -0
- package/esm/rules/no-anonymous-operations.js +64 -0
- package/esm/rules/no-case-insensitive-enum-values-duplicates.js +58 -0
- package/esm/rules/no-deprecated.js +121 -0
- package/esm/rules/no-duplicate-fields.js +109 -0
- package/esm/rules/no-hashtag-description.js +86 -0
- package/esm/rules/no-one-place-fragments.js +80 -0
- package/esm/rules/no-root-type.js +83 -0
- package/esm/rules/no-scalar-result-type-on-mutation.js +63 -0
- package/esm/rules/no-typename-prefix.js +62 -0
- package/esm/rules/no-unreachable-types.js +154 -0
- package/esm/rules/no-unused-fields.js +127 -0
- package/esm/rules/relay-arguments.js +118 -0
- package/esm/rules/relay-connection-types.js +104 -0
- package/esm/rules/relay-edge-types.js +186 -0
- package/esm/rules/relay-page-info.js +97 -0
- package/esm/rules/require-deprecation-date.js +120 -0
- package/esm/rules/require-deprecation-reason.js +53 -0
- package/esm/rules/require-description.js +190 -0
- package/esm/rules/require-field-of-type-query-in-mutation-result.js +69 -0
- package/esm/rules/require-id-when-available.js +196 -0
- package/esm/rules/require-nullable-fields-with-oneof.js +58 -0
- package/esm/rules/require-type-pattern-with-oneof.js +57 -0
- package/esm/rules/selection-set-depth.js +131 -0
- package/esm/rules/strict-id-in-types.js +159 -0
- package/esm/rules/unique-fragment-name.js +86 -0
- package/esm/rules/unique-operation-name.js +62 -0
- package/esm/schema.js +37 -0
- package/esm/testkit.js +181 -0
- package/esm/types.js +1 -0
- package/esm/utils.js +83 -0
- package/package.json +10 -1
- package/typings/estree-converter/converter.d.cts +1 -1
- package/typings/estree-converter/converter.d.ts +1 -1
- package/typings/estree-converter/index.d.cts +3 -3
- package/typings/estree-converter/index.d.ts +3 -3
- package/typings/estree-converter/types.d.cts +3 -3
- package/typings/estree-converter/types.d.ts +3 -3
- package/typings/estree-converter/utils.d.cts +2 -2
- package/typings/estree-converter/utils.d.ts +2 -2
- package/typings/flat-configs.d.cts +248 -0
- package/typings/flat-configs.d.ts +248 -0
- package/typings/graphql-config.d.cts +1 -1
- package/typings/graphql-config.d.ts +1 -1
- package/typings/index.d.cts +8 -7
- package/typings/index.d.ts +8 -7
- package/typings/parser.d.cts +1 -1
- package/typings/parser.d.ts +1 -1
- package/typings/rules/alphabetize.d.cts +1 -1
- package/typings/rules/alphabetize.d.ts +1 -1
- package/typings/rules/description-style.d.cts +1 -1
- package/typings/rules/description-style.d.ts +1 -1
- package/typings/rules/graphql-js-validation.d.cts +1 -1
- package/typings/rules/graphql-js-validation.d.ts +1 -1
- package/typings/rules/index.d.cts +45 -45
- package/typings/rules/index.d.ts +45 -45
- package/typings/rules/input-name.d.cts +1 -1
- package/typings/rules/input-name.d.ts +1 -1
- package/typings/rules/lone-executable-definition.d.cts +1 -1
- package/typings/rules/lone-executable-definition.d.ts +1 -1
- package/typings/rules/match-document-filename.d.cts +2 -2
- package/typings/rules/match-document-filename.d.ts +2 -2
- package/typings/rules/naming-convention.d.cts +1 -1
- package/typings/rules/naming-convention.d.ts +1 -1
- package/typings/rules/no-anonymous-operations.d.cts +1 -1
- package/typings/rules/no-anonymous-operations.d.ts +1 -1
- package/typings/rules/no-case-insensitive-enum-values-duplicates.d.cts +1 -1
- package/typings/rules/no-case-insensitive-enum-values-duplicates.d.ts +1 -1
- package/typings/rules/no-deprecated.d.cts +1 -1
- package/typings/rules/no-deprecated.d.ts +1 -1
- package/typings/rules/no-duplicate-fields.d.cts +1 -1
- package/typings/rules/no-duplicate-fields.d.ts +1 -1
- package/typings/rules/no-hashtag-description.d.cts +1 -1
- package/typings/rules/no-hashtag-description.d.ts +1 -1
- package/typings/rules/no-one-place-fragments.d.cts +1 -1
- package/typings/rules/no-one-place-fragments.d.ts +1 -1
- package/typings/rules/no-root-type.d.cts +1 -1
- package/typings/rules/no-root-type.d.ts +1 -1
- package/typings/rules/no-scalar-result-type-on-mutation.d.cts +1 -1
- package/typings/rules/no-scalar-result-type-on-mutation.d.ts +1 -1
- package/typings/rules/no-typename-prefix.d.cts +1 -1
- package/typings/rules/no-typename-prefix.d.ts +1 -1
- package/typings/rules/no-unreachable-types.d.cts +1 -1
- package/typings/rules/no-unreachable-types.d.ts +1 -1
- package/typings/rules/no-unused-fields.d.cts +1 -1
- package/typings/rules/no-unused-fields.d.ts +1 -1
- package/typings/rules/relay-arguments.d.cts +1 -1
- package/typings/rules/relay-arguments.d.ts +1 -1
- package/typings/rules/relay-connection-types.d.cts +1 -1
- package/typings/rules/relay-connection-types.d.ts +1 -1
- package/typings/rules/relay-edge-types.d.cts +1 -1
- package/typings/rules/relay-edge-types.d.ts +1 -1
- package/typings/rules/relay-page-info.d.cts +1 -1
- package/typings/rules/relay-page-info.d.ts +1 -1
- package/typings/rules/require-deprecation-date.d.cts +1 -1
- package/typings/rules/require-deprecation-date.d.ts +1 -1
- package/typings/rules/require-deprecation-reason.d.cts +1 -1
- package/typings/rules/require-deprecation-reason.d.ts +1 -1
- package/typings/rules/require-description.d.cts +1 -1
- package/typings/rules/require-description.d.ts +1 -1
- package/typings/rules/require-field-of-type-query-in-mutation-result.d.cts +1 -1
- package/typings/rules/require-field-of-type-query-in-mutation-result.d.ts +1 -1
- package/typings/rules/require-id-when-available.d.cts +1 -1
- package/typings/rules/require-id-when-available.d.ts +1 -1
- package/typings/rules/require-nullable-fields-with-oneof.d.cts +1 -1
- package/typings/rules/require-nullable-fields-with-oneof.d.ts +1 -1
- package/typings/rules/require-type-pattern-with-oneof.d.cts +1 -1
- package/typings/rules/require-type-pattern-with-oneof.d.ts +1 -1
- package/typings/rules/selection-set-depth.d.cts +1 -1
- package/typings/rules/selection-set-depth.d.ts +1 -1
- package/typings/rules/strict-id-in-types.d.cts +1 -1
- package/typings/rules/strict-id-in-types.d.ts +1 -1
- package/typings/rules/unique-fragment-name.d.cts +2 -2
- package/typings/rules/unique-fragment-name.d.ts +2 -2
- package/typings/rules/unique-operation-name.d.cts +1 -1
- package/typings/rules/unique-operation-name.d.ts +1 -1
- package/typings/schema.d.cts +1 -1
- package/typings/schema.d.ts +1 -1
- package/typings/testkit.d.cts +3 -3
- package/typings/testkit.d.ts +3 -3
- package/typings/types.d.cts +2 -2
- package/typings/types.d.ts +2 -2
- package/typings/utils.d.cts +2 -2
- package/typings/utils.d.ts +2 -2
@@ -2,7 +2,7 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.rule = void 0;
|
4
4
|
const graphql_1 = require("graphql");
|
5
|
-
const
|
5
|
+
const utils_js_1 = require("../utils.js");
|
6
6
|
const RULE_ID = 'no-anonymous-operations';
|
7
7
|
exports.rule = {
|
8
8
|
meta: {
|
@@ -45,7 +45,7 @@ exports.rule = {
|
|
45
45
|
? (firstSelection.alias || firstSelection.name).value
|
46
46
|
: node.operation;
|
47
47
|
context.report({
|
48
|
-
loc: (0,
|
48
|
+
loc: (0, utils_js_1.getLocation)(node.loc.start, node.operation),
|
49
49
|
messageId: RULE_ID,
|
50
50
|
data: {
|
51
51
|
operation: node.operation,
|
@@ -2,7 +2,7 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.rule = void 0;
|
4
4
|
const graphql_1 = require("graphql");
|
5
|
-
const
|
5
|
+
const utils_js_1 = require("../utils.js");
|
6
6
|
const RULE_ID = 'no-deprecated';
|
7
7
|
exports.rule = {
|
8
8
|
meta: {
|
@@ -83,7 +83,7 @@ exports.rule = {
|
|
83
83
|
schema: [],
|
84
84
|
},
|
85
85
|
create(context) {
|
86
|
-
(0,
|
86
|
+
(0, utils_js_1.requireGraphQLSchemaFromContext)(RULE_ID, context);
|
87
87
|
function report(node, reason) {
|
88
88
|
const nodeName = node.kind === graphql_1.Kind.ENUM ? node.value : node.name.value;
|
89
89
|
const nodeType = node.kind === graphql_1.Kind.ENUM ? 'enum value' : 'field';
|
@@ -1,8 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.rule = void 0;
|
4
|
-
const
|
5
|
-
const utils_1 = require("../utils");
|
4
|
+
const utils_js_1 = require("../utils.js");
|
6
5
|
const path_1 = require("path");
|
7
6
|
const graphql_1 = require("graphql");
|
8
7
|
const RULE_ID = 'no-one-place-fragments';
|
@@ -54,11 +53,11 @@ exports.rule = {
|
|
54
53
|
schema: [],
|
55
54
|
},
|
56
55
|
create(context) {
|
57
|
-
const operations = (0,
|
56
|
+
const operations = (0, utils_js_1.requireSiblingsOperations)(RULE_ID, context);
|
58
57
|
const allDocuments = [...operations.getOperations(), ...operations.getFragments()];
|
59
58
|
const usedFragmentsMap = Object.create(null);
|
60
59
|
for (const { document, filePath } of allDocuments) {
|
61
|
-
const relativeFilePath = (0, path_1.relative)(
|
60
|
+
const relativeFilePath = (0, path_1.relative)(utils_js_1.CWD, filePath);
|
62
61
|
(0, graphql_1.visit)(document, {
|
63
62
|
FragmentSpread({ name }) {
|
64
63
|
const spreadName = name.value;
|
@@ -1,7 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.rule = void 0;
|
4
|
-
const
|
4
|
+
const utils_js_1 = require("../utils.js");
|
5
5
|
const schema = {
|
6
6
|
type: 'array',
|
7
7
|
minItems: 1,
|
@@ -12,7 +12,7 @@ const schema = {
|
|
12
12
|
required: ['disallow'],
|
13
13
|
properties: {
|
14
14
|
disallow: {
|
15
|
-
...
|
15
|
+
...utils_js_1.ARRAY_DEFAULT_OPTIONS,
|
16
16
|
items: {
|
17
17
|
enum: ['mutation', 'subscription'],
|
18
18
|
},
|
@@ -54,7 +54,7 @@ exports.rule = {
|
|
54
54
|
schema,
|
55
55
|
},
|
56
56
|
create(context) {
|
57
|
-
const schema = (0,
|
57
|
+
const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)('no-root-type', context);
|
58
58
|
const disallow = new Set(context.options[0].disallow);
|
59
59
|
const rootTypeNames = [
|
60
60
|
disallow.has('mutation') && schema.getMutationType(),
|
@@ -2,7 +2,7 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.rule = void 0;
|
4
4
|
const graphql_1 = require("graphql");
|
5
|
-
const
|
5
|
+
const utils_js_1 = require("../utils.js");
|
6
6
|
const RULE_ID = 'no-scalar-result-type-on-mutation';
|
7
7
|
exports.rule = {
|
8
8
|
meta: {
|
@@ -35,7 +35,7 @@ exports.rule = {
|
|
35
35
|
schema: [],
|
36
36
|
},
|
37
37
|
create(context) {
|
38
|
-
const schema = (0,
|
38
|
+
const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(RULE_ID, context);
|
39
39
|
const mutationType = schema.getMutationType();
|
40
40
|
if (!mutationType) {
|
41
41
|
return {};
|
@@ -4,7 +4,7 @@ exports.rule = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
5
5
|
const graphql_1 = require("graphql");
|
6
6
|
const lodash_lowercase_1 = tslib_1.__importDefault(require("lodash.lowercase"));
|
7
|
-
const
|
7
|
+
const utils_js_1 = require("../utils.js");
|
8
8
|
const RULE_ID = 'no-unreachable-types';
|
9
9
|
const KINDS = [
|
10
10
|
graphql_1.Kind.DIRECTIVE_DEFINITION,
|
@@ -40,7 +40,7 @@ function getReachableTypes(schema) {
|
|
40
40
|
}
|
41
41
|
const reachableTypes = new Set();
|
42
42
|
const collect = (node) => {
|
43
|
-
const typeName = (0,
|
43
|
+
const typeName = (0, utils_js_1.getTypeName)(node);
|
44
44
|
if (reachableTypes.has(typeName)) {
|
45
45
|
return;
|
46
46
|
}
|
@@ -130,7 +130,7 @@ exports.rule = {
|
|
130
130
|
hasSuggestions: true,
|
131
131
|
},
|
132
132
|
create(context) {
|
133
|
-
const schema = (0,
|
133
|
+
const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(RULE_ID, context);
|
134
134
|
const reachableTypes = getReachableTypes(schema);
|
135
135
|
return {
|
136
136
|
[`:matches(${KINDS}) > .name`](node) {
|
@@ -2,7 +2,7 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.rule = void 0;
|
4
4
|
const graphql_1 = require("graphql");
|
5
|
-
const
|
5
|
+
const utils_js_1 = require("../utils.js");
|
6
6
|
const RULE_ID = 'no-unused-fields';
|
7
7
|
let usedFieldsCache;
|
8
8
|
function getUsedFields(schema, operations) {
|
@@ -95,8 +95,8 @@ exports.rule = {
|
|
95
95
|
hasSuggestions: true,
|
96
96
|
},
|
97
97
|
create(context) {
|
98
|
-
const schema = (0,
|
99
|
-
const siblingsOperations = (0,
|
98
|
+
const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(RULE_ID, context);
|
99
|
+
const siblingsOperations = (0, utils_js_1.requireSiblingsOperations)(RULE_ID, context);
|
100
100
|
const usedFields = getUsedFields(schema, siblingsOperations);
|
101
101
|
return {
|
102
102
|
FieldDefinition(node) {
|
@@ -2,7 +2,7 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.rule = void 0;
|
4
4
|
const graphql_1 = require("graphql");
|
5
|
-
const
|
5
|
+
const utils_js_1 = require("../utils.js");
|
6
6
|
const RULE_ID = 'relay-arguments';
|
7
7
|
const MISSING_ARGUMENTS = 'MISSING_ARGUMENTS';
|
8
8
|
const schema = {
|
@@ -68,7 +68,7 @@ exports.rule = {
|
|
68
68
|
schema,
|
69
69
|
},
|
70
70
|
create(context) {
|
71
|
-
const schema = (0,
|
71
|
+
const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(RULE_ID, context);
|
72
72
|
const { includeBoth = true } = context.options[0] || {};
|
73
73
|
return {
|
74
74
|
'FieldDefinition > .gqlType Name[value=/Connection$/]'(node) {
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.rule = void 0;
|
4
4
|
const graphql_1 = require("graphql");
|
5
5
|
const utils_1 = require("@graphql-tools/utils");
|
6
|
-
const
|
6
|
+
const utils_js_1 = require("../utils.js");
|
7
7
|
const RULE_ID = 'relay-edge-types';
|
8
8
|
const MESSAGE_MUST_BE_OBJECT_TYPE = 'MESSAGE_MUST_BE_OBJECT_TYPE';
|
9
9
|
const MESSAGE_MISSING_EDGE_SUFFIX = 'MESSAGE_MISSING_EDGE_SUFFIX';
|
@@ -26,7 +26,7 @@ function getEdgeTypes(schema) {
|
|
26
26
|
}
|
27
27
|
const edges = node.fields.find(field => field.name.value === 'edges');
|
28
28
|
if (edges) {
|
29
|
-
const edgesTypeName = (0,
|
29
|
+
const edgesTypeName = (0, utils_js_1.getTypeName)(edges);
|
30
30
|
const edgesType = schema.getType(edgesTypeName);
|
31
31
|
if ((0, graphql_1.isObjectType)(edgesType)) {
|
32
32
|
edgeTypes.add(edgesTypeName);
|
@@ -105,7 +105,7 @@ exports.rule = {
|
|
105
105
|
schema,
|
106
106
|
},
|
107
107
|
create(context) {
|
108
|
-
const schema = (0,
|
108
|
+
const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(RULE_ID, context);
|
109
109
|
const edgeTypes = getEdgeTypes(schema);
|
110
110
|
const options = {
|
111
111
|
withEdgeSuffix: true,
|
@@ -128,7 +128,7 @@ exports.rule = {
|
|
128
128
|
context.report({ node: nodeField.name, message: `Field \`node\` must ${message}` });
|
129
129
|
}
|
130
130
|
else if (options.shouldImplementNode) {
|
131
|
-
const nodeReturnTypeName = (0,
|
131
|
+
const nodeReturnTypeName = (0, utils_js_1.getTypeName)(nodeField.gqlType.rawNode());
|
132
132
|
const type = schema.getType(nodeReturnTypeName);
|
133
133
|
if (!(0, graphql_1.isObjectType)(type)) {
|
134
134
|
return;
|
@@ -149,7 +149,7 @@ exports.rule = {
|
|
149
149
|
});
|
150
150
|
return;
|
151
151
|
}
|
152
|
-
const typeName = (0,
|
152
|
+
const typeName = (0, utils_js_1.getTypeName)(cursorField.rawNode());
|
153
153
|
if (!isNamedOrNonNullNamed(cursorField.gqlType) ||
|
154
154
|
(typeName !== 'String' && !(0, graphql_1.isScalarType)(schema.getType(typeName)))) {
|
155
155
|
context.report({ node: cursorField.name, message: `Field \`cursor\` must ${message}` });
|
@@ -177,7 +177,7 @@ exports.rule = {
|
|
177
177
|
listeners['FieldDefinition > .gqlType'] = (node) => {
|
178
178
|
if (node.kind === graphql_1.Kind.LIST_TYPE ||
|
179
179
|
(node.kind === graphql_1.Kind.NON_NULL_TYPE && node.gqlType.kind === graphql_1.Kind.LIST_TYPE)) {
|
180
|
-
const typeName = (0,
|
180
|
+
const typeName = (0, utils_js_1.getTypeName)(node.rawNode());
|
181
181
|
if (!edgeTypes.has(typeName)) {
|
182
182
|
context.report({ node, messageId: MESSAGE_LIST_TYPE_ONLY_EDGE_TYPE });
|
183
183
|
}
|
@@ -2,12 +2,12 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.rule = void 0;
|
4
4
|
const graphql_1 = require("graphql");
|
5
|
-
const
|
6
|
-
const
|
5
|
+
const relay_connection_types_js_1 = require("./relay-connection-types.js");
|
6
|
+
const utils_js_1 = require("../utils.js");
|
7
7
|
const RULE_ID = 'relay-page-info';
|
8
8
|
const MESSAGE_MUST_EXIST = 'MESSAGE_MUST_EXIST';
|
9
9
|
const MESSAGE_MUST_BE_OBJECT_TYPE = 'MESSAGE_MUST_BE_OBJECT_TYPE';
|
10
|
-
const notPageInfoTypesSelector = `:matches(${
|
10
|
+
const notPageInfoTypesSelector = `:matches(${relay_connection_types_js_1.NON_OBJECT_TYPES})[name.value=PageInfo] > .name`;
|
11
11
|
let hasPageInfoChecked = false;
|
12
12
|
exports.rule = {
|
13
13
|
meta: {
|
@@ -45,12 +45,12 @@ exports.rule = {
|
|
45
45
|
schema: [],
|
46
46
|
},
|
47
47
|
create(context) {
|
48
|
-
const schema = (0,
|
48
|
+
const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(RULE_ID, context);
|
49
49
|
if (process.env.NODE_ENV === 'test' || !hasPageInfoChecked) {
|
50
50
|
const pageInfoType = schema.getType('PageInfo');
|
51
51
|
if (!pageInfoType) {
|
52
52
|
context.report({
|
53
|
-
loc:
|
53
|
+
loc: utils_js_1.REPORT_ON_FIRST_CHARACTER,
|
54
54
|
messageId: MESSAGE_MUST_EXIST,
|
55
55
|
});
|
56
56
|
}
|
@@ -1,7 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.rule = void 0;
|
4
|
-
const
|
4
|
+
const index_js_1 = require("../estree-converter/index.js");
|
5
5
|
// eslint-disable-next-line unicorn/better-regex
|
6
6
|
const DATE_REGEX = /^\d{2}\/\d{2}\/\d{4}$/;
|
7
7
|
const MESSAGE_REQUIRE_DATE = 'MESSAGE_REQUIRE_DATE';
|
@@ -81,7 +81,7 @@ exports.rule = {
|
|
81
81
|
});
|
82
82
|
return;
|
83
83
|
}
|
84
|
-
const deletionDate = (0,
|
84
|
+
const deletionDate = (0, index_js_1.valueFromNode)(deletionDateNode.value);
|
85
85
|
const isValidDate = DATE_REGEX.test(deletionDate);
|
86
86
|
if (!isValidDate) {
|
87
87
|
context.report({ node: deletionDateNode.value, messageId: MESSAGE_INVALID_FORMAT });
|
@@ -1,7 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.rule = void 0;
|
4
|
-
const
|
4
|
+
const index_js_1 = require("../estree-converter/index.js");
|
5
5
|
exports.rule = {
|
6
6
|
meta: {
|
7
7
|
docs: {
|
@@ -43,7 +43,7 @@ exports.rule = {
|
|
43
43
|
return {
|
44
44
|
'Directive[name.value=deprecated]'(node) {
|
45
45
|
const reasonArgument = node.arguments.find(arg => arg.name.value === 'reason');
|
46
|
-
const value = reasonArgument && String((0,
|
46
|
+
const value = reasonArgument && String((0, index_js_1.valueFromNode)(reasonArgument.value)).trim();
|
47
47
|
if (!value) {
|
48
48
|
context.report({
|
49
49
|
node: node.name,
|
@@ -2,11 +2,11 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.rule = void 0;
|
4
4
|
const graphql_1 = require("graphql");
|
5
|
-
const
|
6
|
-
const
|
5
|
+
const utils_js_1 = require("../utils.js");
|
6
|
+
const utils_1 = require("@graphql-tools/utils");
|
7
7
|
const RULE_ID = 'require-description';
|
8
8
|
const ALLOWED_KINDS = [
|
9
|
-
...
|
9
|
+
...utils_js_1.TYPES_KINDS,
|
10
10
|
graphql_1.Kind.DIRECTIVE_DEFINITION,
|
11
11
|
graphql_1.Kind.FIELD_DEFINITION,
|
12
12
|
graphql_1.Kind.INPUT_VALUE_DEFINITION,
|
@@ -52,7 +52,7 @@ const schema = {
|
|
52
52
|
properties: {
|
53
53
|
types: {
|
54
54
|
type: 'boolean',
|
55
|
-
description: `Includes:\n${
|
55
|
+
description: `Includes:\n${utils_js_1.TYPES_KINDS.map(kind => `- \`${kind}\``).join('\n')}`,
|
56
56
|
},
|
57
57
|
rootField: {
|
58
58
|
type: 'boolean',
|
@@ -142,7 +142,7 @@ exports.rule = {
|
|
142
142
|
},
|
143
143
|
create(context) {
|
144
144
|
const { types, rootField, ...restOptions } = context.options[0] || {};
|
145
|
-
const kinds = new Set(types ?
|
145
|
+
const kinds = new Set(types ? utils_js_1.TYPES_KINDS : []);
|
146
146
|
for (const [kind, isEnabled] of Object.entries(restOptions)) {
|
147
147
|
if (isEnabled) {
|
148
148
|
kinds.add(kind);
|
@@ -152,8 +152,8 @@ exports.rule = {
|
|
152
152
|
}
|
153
153
|
}
|
154
154
|
if (rootField) {
|
155
|
-
const schema = (0,
|
156
|
-
const rootTypeNames = (0,
|
155
|
+
const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(RULE_ID, context);
|
156
|
+
const rootTypeNames = (0, utils_1.getRootTypeNames)(schema);
|
157
157
|
kinds.add(`:matches(ObjectTypeDefinition, ObjectTypeExtension)[name.value=/^(${[
|
158
158
|
...rootTypeNames,
|
159
159
|
].join(',')})$/] > FieldDefinition`);
|
@@ -180,7 +180,7 @@ exports.rule = {
|
|
180
180
|
}
|
181
181
|
if (description.length === 0) {
|
182
182
|
context.report({
|
183
|
-
loc: isOperation ? (0,
|
183
|
+
loc: isOperation ? (0, utils_js_1.getLocation)(node.loc.start, node.operation) : node.name.loc,
|
184
184
|
messageId: RULE_ID,
|
185
185
|
data: {
|
186
186
|
nodeName: getNodeName(node),
|
@@ -2,7 +2,7 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.rule = void 0;
|
4
4
|
const graphql_1 = require("graphql");
|
5
|
-
const
|
5
|
+
const utils_js_1 = require("../utils.js");
|
6
6
|
const RULE_ID = 'require-field-of-type-query-in-mutation-result';
|
7
7
|
exports.rule = {
|
8
8
|
meta: {
|
@@ -45,7 +45,7 @@ exports.rule = {
|
|
45
45
|
schema: [],
|
46
46
|
},
|
47
47
|
create(context) {
|
48
|
-
const schema = (0,
|
48
|
+
const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(RULE_ID, context);
|
49
49
|
const mutationType = schema.getMutationType();
|
50
50
|
const queryType = schema.getQueryType();
|
51
51
|
if (!mutationType || !queryType) {
|
@@ -58,7 +58,7 @@ exports.rule = {
|
|
58
58
|
const graphQLType = schema.getType(typeName);
|
59
59
|
if ((0, graphql_1.isObjectType)(graphQLType)) {
|
60
60
|
const { fields } = graphQLType.astNode;
|
61
|
-
const hasQueryType = fields.some(field => (0,
|
61
|
+
const hasQueryType = fields.some(field => (0, utils_js_1.getTypeName)(field) === queryType.name);
|
62
62
|
if (!hasQueryType) {
|
63
63
|
context.report({
|
64
64
|
node,
|
@@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.rule = void 0;
|
4
4
|
const graphql_1 = require("graphql");
|
5
5
|
const utils_1 = require("@graphql-tools/utils");
|
6
|
-
const
|
7
|
-
const
|
6
|
+
const utils_js_1 = require("../utils.js");
|
7
|
+
const index_js_1 = require("../estree-converter/index.js");
|
8
8
|
const RULE_ID = 'require-id-when-available';
|
9
9
|
const DEFAULT_ID_FIELD_NAME = 'id';
|
10
10
|
const schema = {
|
@@ -12,7 +12,7 @@ const schema = {
|
|
12
12
|
asString: {
|
13
13
|
type: 'string',
|
14
14
|
},
|
15
|
-
asArray:
|
15
|
+
asArray: utils_js_1.ARRAY_DEFAULT_OPTIONS,
|
16
16
|
},
|
17
17
|
type: 'array',
|
18
18
|
maxItems: 1,
|
@@ -89,8 +89,8 @@ exports.rule = {
|
|
89
89
|
schema,
|
90
90
|
},
|
91
91
|
create(context) {
|
92
|
-
const schema = (0,
|
93
|
-
const siblings = (0,
|
92
|
+
const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(RULE_ID, context);
|
93
|
+
const siblings = (0, utils_js_1.requireSiblingsOperations)(RULE_ID, context);
|
94
94
|
const { fieldName = DEFAULT_ID_FIELD_NAME } = context.options[0] || {};
|
95
95
|
const idNames = (0, utils_1.asArray)(fieldName);
|
96
96
|
// Check selections only in OperationDefinition,
|
@@ -126,7 +126,7 @@ exports.rule = {
|
|
126
126
|
loc,
|
127
127
|
// Can't access to node.parent in GraphQL AST.Node, so pass as argument
|
128
128
|
parent, checkedFragmentSpreads = new Set()) {
|
129
|
-
const rawType = (0,
|
129
|
+
const rawType = (0, index_js_1.getBaseType)(type);
|
130
130
|
const isObjectType = rawType instanceof graphql_1.GraphQLObjectType;
|
131
131
|
const isInterfaceType = rawType instanceof graphql_1.GraphQLInterfaceType;
|
132
132
|
if (!isObjectType && !isInterfaceType) {
|
@@ -165,10 +165,10 @@ exports.rule = {
|
|
165
165
|
return;
|
166
166
|
}
|
167
167
|
const pluralSuffix = idNames.length > 1 ? 's' : '';
|
168
|
-
const fieldName = (0,
|
168
|
+
const fieldName = (0, utils_js_1.englishJoinWords)(idNames.map(name => `\`${(parent.alias || parent.name).value}.${name}\``));
|
169
169
|
const addition = checkedFragmentSpreads.size === 0
|
170
170
|
? ''
|
171
|
-
: ` or add to used fragment${checkedFragmentSpreads.size > 1 ? 's' : ''} ${(0,
|
171
|
+
: ` or add to used fragment${checkedFragmentSpreads.size > 1 ? 's' : ''} ${(0, utils_js_1.englishJoinWords)([...checkedFragmentSpreads].map(name => `\`${name}\``))}`;
|
172
172
|
const problem = {
|
173
173
|
loc,
|
174
174
|
messageId: RULE_ID,
|
@@ -4,7 +4,7 @@ exports.rule = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
5
5
|
const graphql_depth_limit_1 = tslib_1.__importDefault(require("graphql-depth-limit"));
|
6
6
|
const graphql_1 = require("graphql");
|
7
|
-
const
|
7
|
+
const utils_js_1 = require("../utils.js");
|
8
8
|
const RULE_ID = 'selection-set-depth';
|
9
9
|
const schema = {
|
10
10
|
type: 'array',
|
@@ -18,7 +18,7 @@ const schema = {
|
|
18
18
|
maxDepth: {
|
19
19
|
type: 'number',
|
20
20
|
},
|
21
|
-
ignore:
|
21
|
+
ignore: utils_js_1.ARRAY_DEFAULT_OPTIONS,
|
22
22
|
},
|
23
23
|
},
|
24
24
|
};
|
@@ -80,10 +80,10 @@ exports.rule = {
|
|
80
80
|
create(context) {
|
81
81
|
let siblings = null;
|
82
82
|
try {
|
83
|
-
siblings = (0,
|
83
|
+
siblings = (0, utils_js_1.requireSiblingsOperations)(RULE_ID, context);
|
84
84
|
}
|
85
85
|
catch (_a) {
|
86
|
-
|
86
|
+
utils_js_1.logger.warn(`Rule "${RULE_ID}" works best with siblings operations loaded. For more info: https://bit.ly/graphql-eslint-operations`);
|
87
87
|
}
|
88
88
|
const { maxDepth, ignore = [] } = context.options[0];
|
89
89
|
const checkFn = (0, graphql_depth_limit_1.default)(maxDepth, { ignore });
|
@@ -127,7 +127,7 @@ exports.rule = {
|
|
127
127
|
});
|
128
128
|
}
|
129
129
|
catch (e) {
|
130
|
-
|
130
|
+
utils_js_1.logger.warn(`Rule "${RULE_ID}" check failed due to a missing siblings operations. For more info: https://bit.ly/graphql-eslint-operations`, e);
|
131
131
|
}
|
132
132
|
},
|
133
133
|
};
|
@@ -2,7 +2,7 @@
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.rule = void 0;
|
4
4
|
const graphql_1 = require("graphql");
|
5
|
-
const
|
5
|
+
const utils_js_1 = require("../utils.js");
|
6
6
|
const RULE_ID = 'strict-id-in-types';
|
7
7
|
const schema = {
|
8
8
|
type: 'array',
|
@@ -12,11 +12,11 @@ const schema = {
|
|
12
12
|
additionalProperties: false,
|
13
13
|
properties: {
|
14
14
|
acceptedIdNames: {
|
15
|
-
...
|
15
|
+
...utils_js_1.ARRAY_DEFAULT_OPTIONS,
|
16
16
|
default: ['id'],
|
17
17
|
},
|
18
18
|
acceptedIdTypes: {
|
19
|
-
...
|
19
|
+
...utils_js_1.ARRAY_DEFAULT_OPTIONS,
|
20
20
|
default: ['ID'],
|
21
21
|
},
|
22
22
|
exceptions: {
|
@@ -24,11 +24,11 @@ const schema = {
|
|
24
24
|
additionalProperties: false,
|
25
25
|
properties: {
|
26
26
|
types: {
|
27
|
-
...
|
27
|
+
...utils_js_1.ARRAY_DEFAULT_OPTIONS,
|
28
28
|
description: 'This is used to exclude types with names that match one of the specified values.',
|
29
29
|
},
|
30
30
|
suffixes: {
|
31
|
-
...
|
31
|
+
...utils_js_1.ARRAY_DEFAULT_OPTIONS,
|
32
32
|
description: 'This is used to exclude types with names with suffixes that match one of the specified values.',
|
33
33
|
},
|
34
34
|
},
|
@@ -116,7 +116,7 @@ exports.rule = {
|
|
116
116
|
exceptions: {},
|
117
117
|
...context.options[0],
|
118
118
|
};
|
119
|
-
const schema = (0,
|
119
|
+
const schema = (0, utils_js_1.requireGraphQLSchemaFromContext)(RULE_ID, context);
|
120
120
|
const rootTypeNames = [
|
121
121
|
schema.getQueryType(),
|
122
122
|
schema.getMutationType(),
|
@@ -153,7 +153,7 @@ exports.rule = {
|
|
153
153
|
const pluralTypesSuffix = options.acceptedIdTypes.length > 1 ? 's' : '';
|
154
154
|
context.report({
|
155
155
|
node: node.name,
|
156
|
-
message: `${typeName} must have exactly one non-nullable unique identifier. Accepted name${pluralNamesSuffix}: ${(0,
|
156
|
+
message: `${typeName} must have exactly one non-nullable unique identifier. Accepted name${pluralNamesSuffix}: ${(0, utils_js_1.englishJoinWords)(options.acceptedIdNames)}. Accepted type${pluralTypesSuffix}: ${(0, utils_js_1.englishJoinWords)(options.acceptedIdTypes)}.`,
|
157
157
|
});
|
158
158
|
}
|
159
159
|
},
|
@@ -3,11 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.rule = exports.checkNode = void 0;
|
4
4
|
const path_1 = require("path");
|
5
5
|
const graphql_1 = require("graphql");
|
6
|
-
const
|
6
|
+
const utils_js_1 = require("../utils.js");
|
7
7
|
const RULE_ID = 'unique-fragment-name';
|
8
8
|
const checkNode = (context, node, ruleId) => {
|
9
9
|
const documentName = node.name.value;
|
10
|
-
const siblings = (0,
|
10
|
+
const siblings = (0, utils_js_1.requireSiblingsOperations)(ruleId, context);
|
11
11
|
const siblingDocuments = node.kind === graphql_1.Kind.FRAGMENT_DEFINITION
|
12
12
|
? siblings.getFragment(documentName)
|
13
13
|
: siblings.getOperation(documentName);
|
@@ -15,7 +15,7 @@ const checkNode = (context, node, ruleId) => {
|
|
15
15
|
const conflictingDocuments = siblingDocuments.filter(f => {
|
16
16
|
var _a;
|
17
17
|
const isSameName = ((_a = f.document.name) === null || _a === void 0 ? void 0 : _a.value) === documentName;
|
18
|
-
const isSamePath = (0,
|
18
|
+
const isSamePath = (0, utils_js_1.normalizePath)(f.filePath) === (0, utils_js_1.normalizePath)(filepath);
|
19
19
|
return isSameName && !isSamePath;
|
20
20
|
});
|
21
21
|
if (conflictingDocuments.length > 0) {
|
@@ -24,7 +24,7 @@ const checkNode = (context, node, ruleId) => {
|
|
24
24
|
data: {
|
25
25
|
documentName,
|
26
26
|
summary: conflictingDocuments
|
27
|
-
.map(f => `\t${(0, path_1.relative)(
|
27
|
+
.map(f => `\t${(0, path_1.relative)(utils_js_1.CWD, f.filePath.replace(utils_js_1.VIRTUAL_DOCUMENT_REGEX, ''))}`)
|
28
28
|
.join('\n'),
|
29
29
|
},
|
30
30
|
node: node.name,
|
@@ -1,7 +1,7 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
3
|
exports.rule = void 0;
|
4
|
-
const
|
4
|
+
const unique_fragment_name_js_1 = require("./unique-fragment-name.js");
|
5
5
|
const RULE_ID = 'unique-operation-name';
|
6
6
|
exports.rule = {
|
7
7
|
meta: {
|
@@ -58,7 +58,7 @@ exports.rule = {
|
|
58
58
|
create(context) {
|
59
59
|
return {
|
60
60
|
'OperationDefinition[name!=undefined]'(node) {
|
61
|
-
(0,
|
61
|
+
(0, unique_fragment_name_js_1.checkNode)(context, node, RULE_ID);
|
62
62
|
},
|
63
63
|
};
|
64
64
|
},
|
package/cjs/schema.js
CHANGED
@@ -6,8 +6,8 @@ const graphql_1 = require("graphql");
|
|
6
6
|
const debug_1 = tslib_1.__importDefault(require("debug"));
|
7
7
|
const fast_glob_1 = tslib_1.__importDefault(require("fast-glob"));
|
8
8
|
const chalk_1 = tslib_1.__importDefault(require("chalk"));
|
9
|
-
const
|
10
|
-
const schemaCache = new
|
9
|
+
const cache_js_1 = require("./cache.js");
|
10
|
+
const schemaCache = new cache_js_1.ModuleCache();
|
11
11
|
const debug = (0, debug_1.default)('graphql-eslint:schema');
|
12
12
|
function getSchema(project, schemaOptions) {
|
13
13
|
const schemaKey = project.schema;
|
package/esm/cache.js
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
// Based on the `eslint-plugin-import`'s cache
|
2
|
+
// https://github.com/import-js/eslint-plugin-import/blob/main/utils/ModuleCache.js
|
3
|
+
import debugFactory from 'debug';
|
4
|
+
const log = debugFactory('graphql-eslint:ModuleCache');
|
5
|
+
export class ModuleCache {
|
6
|
+
constructor() {
|
7
|
+
this.map = new Map();
|
8
|
+
}
|
9
|
+
set(cacheKey, result) {
|
10
|
+
this.map.set(cacheKey, { lastSeen: process.hrtime(), result });
|
11
|
+
log('setting entry for', cacheKey);
|
12
|
+
}
|
13
|
+
get(cacheKey, settings = { lifetime: 10 /* seconds */ }) {
|
14
|
+
if (!this.map.has(cacheKey)) {
|
15
|
+
log('cache miss for', cacheKey);
|
16
|
+
return;
|
17
|
+
}
|
18
|
+
const { lastSeen, result } = this.map.get(cacheKey);
|
19
|
+
// check freshness
|
20
|
+
if (process.env.NODE /* don't check for ESLint CLI */ ||
|
21
|
+
process.hrtime(lastSeen)[0] < settings.lifetime) {
|
22
|
+
return result;
|
23
|
+
}
|
24
|
+
}
|
25
|
+
}
|
@@ -0,0 +1,12 @@
|
|
1
|
+
import schemaRecommendedConfig from './schema-recommended.js';
|
2
|
+
import schemaAllConfig from './schema-all.js';
|
3
|
+
import operationsRecommendedConfig from './operations-recommended.js';
|
4
|
+
import operationsAllConfig from './operations-all.js';
|
5
|
+
import relayConfig from './relay.js';
|
6
|
+
export const configs = {
|
7
|
+
'schema-recommended': schemaRecommendedConfig,
|
8
|
+
'schema-all': schemaAllConfig,
|
9
|
+
'operations-recommended': operationsRecommendedConfig,
|
10
|
+
'operations-all': operationsAllConfig,
|
11
|
+
relay: relayConfig,
|
12
|
+
};
|