@graphql-eslint/eslint-plugin 4.0.0-alpha-20230801163310-8bc4340 → 4.0.0-alpha-20230810160036-304c2c0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +2 -0
- package/cjs/cache.js +10 -19
- package/cjs/configs/index.d.ts +42 -16
- package/cjs/configs/index.js +10 -19
- package/cjs/configs/operations-all.d.ts +4 -3
- package/cjs/configs/operations-all.js +5 -4
- package/cjs/configs/operations-recommended.d.ts +3 -1
- package/cjs/configs/operations-recommended.js +3 -1
- package/cjs/configs/schema-all.d.ts +6 -1
- package/cjs/configs/schema-all.js +5 -2
- package/cjs/configs/schema-recommended.d.ts +19 -1
- package/cjs/configs/schema-recommended.js +22 -2
- package/cjs/documents.js +17 -32
- package/cjs/estree-converter/converter.js +14 -27
- package/cjs/estree-converter/index.js +4 -7
- package/cjs/estree-converter/types.js +3 -5
- package/cjs/estree-converter/utils.d.ts +2 -3
- package/cjs/estree-converter/utils.js +15 -45
- package/cjs/flat-configs.d.ts +59 -12
- package/cjs/flat-configs.js +9 -14
- package/cjs/graphql-config.d.ts +4 -3
- package/cjs/graphql-config.js +23 -44
- package/cjs/index.d.ts +10 -4
- package/cjs/index.js +8 -16
- package/cjs/parser.d.ts +4 -3
- package/cjs/parser.js +38 -45
- package/cjs/processor.d.ts +5 -1
- package/cjs/processor.js +25 -57
- package/cjs/rules/alphabetize.d.ts +6 -16
- package/cjs/rules/alphabetize.js +60 -132
- package/cjs/rules/description-style.d.ts +4 -3
- package/cjs/rules/description-style.js +11 -18
- package/cjs/rules/graphql-js-validation.d.ts +4 -3
- package/cjs/rules/graphql-js-validation.js +151 -225
- package/cjs/rules/index.d.ts +15 -13
- package/cjs/rules/index.js +8 -45
- package/cjs/rules/input-name.d.ts +4 -3
- package/cjs/rules/input-name.js +43 -59
- package/cjs/rules/lone-executable-definition.d.ts +6 -5
- package/cjs/rules/lone-executable-definition.js +14 -28
- package/cjs/rules/match-document-filename.d.ts +4 -3
- package/cjs/rules/match-document-filename.js +39 -70
- package/cjs/rules/naming-convention.d.ts +4 -3
- package/cjs/rules/naming-convention.js +56 -74
- package/cjs/rules/no-anonymous-operations.d.ts +4 -3
- package/cjs/rules/no-anonymous-operations.js +11 -18
- package/cjs/rules/no-deprecated.d.ts +4 -3
- package/cjs/rules/no-deprecated.js +15 -29
- package/cjs/rules/no-duplicate-fields.d.ts +4 -3
- package/cjs/rules/no-duplicate-fields.js +13 -23
- package/cjs/rules/no-hashtag-description.d.ts +4 -3
- package/cjs/rules/no-hashtag-description.js +16 -29
- package/cjs/rules/no-one-place-fragments.d.ts +4 -3
- package/cjs/rules/no-one-place-fragments.js +17 -29
- package/cjs/rules/no-root-type.d.ts +4 -3
- package/cjs/rules/no-root-type.js +15 -25
- package/cjs/rules/no-scalar-result-type-on-mutation.d.ts +4 -3
- package/cjs/rules/no-scalar-result-type-on-mutation.js +18 -30
- package/cjs/rules/no-typename-prefix.d.ts +4 -3
- package/cjs/rules/no-typename-prefix.js +26 -33
- package/cjs/rules/no-unreachable-types.d.ts +4 -3
- package/cjs/rules/no-unreachable-types.js +25 -47
- package/cjs/rules/no-unused-fields.d.ts +4 -3
- package/cjs/rules/no-unused-fields.js +24 -49
- package/cjs/rules/relay-arguments.d.ts +4 -3
- package/cjs/rules/relay-arguments.js +20 -43
- package/cjs/rules/relay-connection-types.d.ts +4 -3
- package/cjs/rules/relay-connection-types.js +14 -45
- package/cjs/rules/relay-edge-types.d.ts +4 -3
- package/cjs/rules/relay-edge-types.js +48 -99
- package/cjs/rules/relay-page-info.d.ts +4 -3
- package/cjs/rules/relay-page-info.js +21 -44
- package/cjs/rules/require-deprecation-date.d.ts +4 -3
- package/cjs/rules/require-deprecation-date.js +15 -31
- package/cjs/rules/require-deprecation-reason.d.ts +4 -3
- package/cjs/rules/require-deprecation-reason.js +12 -20
- package/cjs/rules/require-description.d.ts +4 -3
- package/cjs/rules/require-description.js +39 -65
- package/cjs/rules/require-field-of-type-query-in-mutation-result.d.ts +4 -3
- package/cjs/rules/require-field-of-type-query-in-mutation-result.js +16 -31
- package/cjs/rules/require-import-fragment.d.ts +4 -3
- package/cjs/rules/require-import-fragment.js +22 -40
- package/cjs/rules/require-nullable-fields-with-oneof.d.ts +4 -3
- package/cjs/rules/require-nullable-fields-with-oneof.js +11 -22
- package/cjs/rules/require-nullable-result-in-root.d.ts +4 -3
- package/cjs/rules/require-nullable-result-in-root.js +34 -44
- package/cjs/rules/{require-id-when-available.d.ts → require-selections.d.ts} +4 -3
- package/cjs/rules/require-selections.js +198 -0
- package/cjs/rules/require-type-pattern-with-oneof.d.ts +4 -3
- package/cjs/rules/require-type-pattern-with-oneof.js +15 -23
- package/cjs/rules/selection-set-depth.d.ts +4 -3
- package/cjs/rules/selection-set-depth.js +18 -34
- package/cjs/rules/strict-id-in-types.d.ts +4 -3
- package/cjs/rules/strict-id-in-types.js +25 -43
- package/cjs/rules/{no-case-insensitive-enum-values-duplicates.d.ts → unique-enum-value-names.d.ts} +4 -3
- package/cjs/rules/{no-case-insensitive-enum-values-duplicates.js → unique-enum-value-names.js} +16 -21
- package/cjs/rules/unique-fragment-name.d.ts +3 -2
- package/cjs/rules/unique-fragment-name.js +24 -36
- package/cjs/rules/unique-operation-name.d.ts +4 -3
- package/cjs/rules/unique-operation-name.js +10 -12
- package/cjs/schema.d.ts +4 -3
- package/cjs/schema.js +14 -27
- package/cjs/siblings.d.ts +24 -8
- package/cjs/siblings.js +42 -82
- package/cjs/types.d.ts +74 -7
- package/cjs/types.js +3 -5
- package/cjs/utils.d.ts +3 -2
- package/cjs/utils.js +27 -44
- package/esm/cache.js +4 -8
- package/esm/{chunk-BMTV3EA2.js → chunk-U3TKCM4X.js} +1 -1
- package/esm/configs/index.d.mts +42 -16
- package/esm/configs/index.js +4 -4
- package/esm/configs/operations-all.d.mts +4 -3
- package/esm/configs/operations-all.js +6 -5
- package/esm/configs/operations-recommended.d.mts +3 -1
- package/esm/configs/operations-recommended.js +4 -2
- package/esm/configs/schema-all.d.mts +6 -1
- package/esm/configs/schema-all.js +6 -3
- package/esm/configs/schema-recommended.d.mts +19 -1
- package/esm/configs/schema-recommended.js +23 -3
- package/esm/configs/{relay.js → schema-relay.js} +4 -4
- package/esm/documents.js +10 -17
- package/esm/estree-converter/converter.js +9 -18
- package/esm/estree-converter/utils.d.mts +2 -3
- package/esm/estree-converter/utils.js +11 -38
- package/esm/flat-configs.d.mts +59 -12
- package/esm/flat-configs.js +4 -5
- package/esm/graphql-config.d.mts +4 -3
- package/esm/graphql-config.js +18 -34
- package/esm/index.d.mts +10 -4
- package/esm/index.js +1 -1
- package/esm/parser.d.mts +4 -3
- package/esm/parser.js +33 -27
- package/esm/processor.d.mts +5 -1
- package/esm/processor.js +21 -46
- package/esm/rules/alphabetize.d.mts +6 -16
- package/esm/rules/alphabetize.js +53 -118
- package/esm/rules/description-style.d.mts +4 -3
- package/esm/rules/description-style.js +7 -11
- package/esm/rules/graphql-js-validation.d.mts +4 -3
- package/esm/rules/graphql-js-validation.js +178 -218
- package/esm/rules/index.d.mts +15 -13
- package/esm/rules/index.js +5 -5
- package/esm/rules/input-name.d.mts +4 -3
- package/esm/rules/input-name.js +39 -52
- package/esm/rules/lone-executable-definition.d.mts +6 -5
- package/esm/rules/lone-executable-definition.js +10 -20
- package/esm/rules/match-document-filename.d.mts +4 -3
- package/esm/rules/match-document-filename.js +35 -61
- package/esm/rules/naming-convention.d.mts +4 -3
- package/esm/rules/naming-convention.js +51 -65
- package/esm/rules/no-anonymous-operations.d.mts +4 -3
- package/esm/rules/no-anonymous-operations.js +6 -9
- package/esm/rules/no-deprecated.d.mts +4 -3
- package/esm/rules/no-deprecated.js +10 -20
- package/esm/rules/no-duplicate-fields.d.mts +4 -3
- package/esm/rules/no-duplicate-fields.js +9 -16
- package/esm/rules/no-hashtag-description.d.mts +4 -3
- package/esm/rules/no-hashtag-description.js +11 -20
- package/esm/rules/no-one-place-fragments.d.mts +4 -3
- package/esm/rules/no-one-place-fragments.js +12 -19
- package/esm/rules/no-root-type.d.mts +4 -3
- package/esm/rules/no-root-type.js +11 -18
- package/esm/rules/no-scalar-result-type-on-mutation.d.mts +4 -3
- package/esm/rules/no-scalar-result-type-on-mutation.js +13 -21
- package/esm/rules/no-typename-prefix.d.mts +4 -3
- package/esm/rules/no-typename-prefix.js +22 -26
- package/esm/rules/no-unreachable-types.d.mts +4 -3
- package/esm/rules/no-unreachable-types.js +18 -33
- package/esm/rules/no-unused-fields.d.mts +4 -3
- package/esm/rules/no-unused-fields.js +19 -40
- package/esm/rules/relay-arguments.d.mts +4 -3
- package/esm/rules/relay-arguments.js +15 -34
- package/esm/rules/relay-connection-types.d.mts +4 -3
- package/esm/rules/relay-connection-types.js +10 -38
- package/esm/rules/relay-edge-types.d.mts +4 -3
- package/esm/rules/relay-edge-types.js +43 -89
- package/esm/rules/relay-page-info.d.mts +4 -3
- package/esm/rules/relay-page-info.js +16 -34
- package/esm/rules/require-deprecation-date.d.mts +4 -3
- package/esm/rules/require-deprecation-date.js +10 -22
- package/esm/rules/require-deprecation-reason.d.mts +4 -3
- package/esm/rules/require-deprecation-reason.js +7 -11
- package/esm/rules/require-description.d.mts +4 -3
- package/esm/rules/require-description.js +34 -55
- package/esm/rules/require-field-of-type-query-in-mutation-result.d.mts +4 -3
- package/esm/rules/require-field-of-type-query-in-mutation-result.js +11 -22
- package/esm/rules/require-import-fragment.d.mts +4 -3
- package/esm/rules/require-import-fragment.js +14 -26
- package/esm/rules/require-nullable-fields-with-oneof.d.mts +4 -3
- package/esm/rules/require-nullable-fields-with-oneof.js +6 -13
- package/esm/rules/require-nullable-result-in-root.d.mts +4 -3
- package/esm/rules/require-nullable-result-in-root.js +29 -35
- package/esm/rules/{require-id-when-available.d.mts → require-selections.d.mts} +4 -3
- package/esm/rules/{require-id-when-available.js → require-selections.js} +43 -80
- package/esm/rules/require-type-pattern-with-oneof.d.mts +4 -3
- package/esm/rules/require-type-pattern-with-oneof.js +11 -16
- package/esm/rules/selection-set-depth.d.mts +4 -3
- package/esm/rules/selection-set-depth.js +11 -20
- package/esm/rules/strict-id-in-types.d.mts +4 -3
- package/esm/rules/strict-id-in-types.js +20 -34
- package/esm/rules/{no-case-insensitive-enum-values-duplicates.d.mts → unique-enum-value-names.d.mts} +4 -3
- package/esm/rules/{no-case-insensitive-enum-values-duplicates.js → unique-enum-value-names.js} +8 -9
- package/esm/rules/unique-fragment-name.d.mts +3 -2
- package/esm/rules/unique-fragment-name.js +20 -27
- package/esm/rules/unique-operation-name.d.mts +4 -3
- package/esm/rules/unique-operation-name.js +6 -5
- package/esm/schema.d.mts +4 -3
- package/esm/schema.js +7 -12
- package/esm/siblings.d.mts +24 -8
- package/esm/siblings.js +37 -73
- package/esm/types.d.mts +74 -7
- package/esm/utils.d.mts +3 -2
- package/esm/utils.js +20 -31
- package/index.browser.mjs +5323 -0
- package/package.json +8 -13
- package/cjs/rules/require-id-when-available.js +0 -241
- package/cjs/types-8d5f4ae0.d.ts +0 -107
- package/esm/types-ace77d86.d.ts +0 -107
- /package/cjs/configs/{relay.d.ts → schema-relay.d.ts} +0 -0
- /package/cjs/configs/{relay.js → schema-relay.js} +0 -0
- /package/esm/configs/{relay.d.mts → schema-relay.d.mts} +0 -0
@@ -1,4 +1,4 @@
|
|
1
|
-
import "../chunk-
|
1
|
+
import "../chunk-U3TKCM4X.js";
|
2
2
|
import { getRootTypeNames } from "@graphql-tools/utils";
|
3
3
|
import { Kind, TokenKind } from "graphql";
|
4
4
|
import {
|
@@ -7,28 +7,27 @@ import {
|
|
7
7
|
requireGraphQLSchemaFromContext,
|
8
8
|
TYPES_KINDS
|
9
9
|
} from "../utils.js";
|
10
|
-
const RULE_ID = "require-description"
|
11
|
-
const ALLOWED_KINDS = [
|
10
|
+
const RULE_ID = "require-description", ALLOWED_KINDS = [
|
12
11
|
...TYPES_KINDS,
|
13
12
|
Kind.DIRECTIVE_DEFINITION,
|
14
13
|
Kind.FIELD_DEFINITION,
|
15
14
|
Kind.INPUT_VALUE_DEFINITION,
|
16
15
|
Kind.ENUM_VALUE_DEFINITION,
|
17
16
|
Kind.OPERATION_DEFINITION
|
18
|
-
]
|
19
|
-
const schema = {
|
17
|
+
], schema = {
|
20
18
|
type: "array",
|
21
19
|
minItems: 1,
|
22
20
|
maxItems: 1,
|
23
21
|
items: {
|
24
22
|
type: "object",
|
25
|
-
additionalProperties:
|
23
|
+
additionalProperties: !1,
|
26
24
|
minProperties: 1,
|
27
25
|
properties: {
|
28
26
|
types: {
|
29
27
|
type: "boolean",
|
30
28
|
description: `Includes:
|
31
|
-
${TYPES_KINDS.map((kind) => `- \`${kind}\``).join(
|
29
|
+
${TYPES_KINDS.map((kind) => `- \`${kind}\``).join(`
|
30
|
+
`)}`
|
32
31
|
},
|
33
32
|
rootField: {
|
34
33
|
type: "boolean",
|
@@ -37,16 +36,12 @@ ${TYPES_KINDS.map((kind) => `- \`${kind}\``).join("\n")}`
|
|
37
36
|
...Object.fromEntries(
|
38
37
|
[...ALLOWED_KINDS].sort().map((kind) => {
|
39
38
|
let description = `Read more about this kind on [spec.graphql.org](https://spec.graphql.org/October2021/#${kind}).`;
|
40
|
-
|
41
|
-
description += '\n> You must use only comment syntax `#` and not description syntax `"""` or `"`.';
|
42
|
-
}
|
43
|
-
return [kind, { type: "boolean", description }];
|
39
|
+
return kind === Kind.OPERATION_DEFINITION && (description += '\n> You must use only comment syntax `#` and not description syntax `"""` or `"`.'), [kind, { type: "boolean", description }];
|
44
40
|
})
|
45
41
|
)
|
46
42
|
}
|
47
43
|
}
|
48
|
-
}
|
49
|
-
const rule = {
|
44
|
+
}, rule = {
|
50
45
|
meta: {
|
51
46
|
docs: {
|
52
47
|
category: "Schema",
|
@@ -55,7 +50,7 @@ const rule = {
|
|
55
50
|
examples: [
|
56
51
|
{
|
57
52
|
title: "Incorrect",
|
58
|
-
usage: [{ types:
|
53
|
+
usage: [{ types: !0, FieldDefinition: !0 }],
|
59
54
|
code: (
|
60
55
|
/* GraphQL */
|
61
56
|
`
|
@@ -67,7 +62,7 @@ const rule = {
|
|
67
62
|
},
|
68
63
|
{
|
69
64
|
title: "Correct",
|
70
|
-
usage: [{ types:
|
65
|
+
usage: [{ types: !0, FieldDefinition: !0 }],
|
71
66
|
code: (
|
72
67
|
/* GraphQL */
|
73
68
|
`
|
@@ -85,7 +80,7 @@ const rule = {
|
|
85
80
|
},
|
86
81
|
{
|
87
82
|
title: "Correct",
|
88
|
-
usage: [{ OperationDefinition:
|
83
|
+
usage: [{ OperationDefinition: !0 }],
|
89
84
|
code: (
|
90
85
|
/* GraphQL */
|
91
86
|
`
|
@@ -98,7 +93,7 @@ const rule = {
|
|
98
93
|
},
|
99
94
|
{
|
100
95
|
title: "Correct",
|
101
|
-
usage: [{ rootField:
|
96
|
+
usage: [{ rootField: !0 }],
|
102
97
|
code: (
|
103
98
|
/* GraphQL */
|
104
99
|
`
|
@@ -116,12 +111,12 @@ const rule = {
|
|
116
111
|
],
|
117
112
|
configOptions: [
|
118
113
|
{
|
119
|
-
types:
|
120
|
-
[Kind.DIRECTIVE_DEFINITION]:
|
121
|
-
|
114
|
+
types: !0,
|
115
|
+
[Kind.DIRECTIVE_DEFINITION]: !0,
|
116
|
+
rootField: !0
|
122
117
|
}
|
123
118
|
],
|
124
|
-
recommended:
|
119
|
+
recommended: !0
|
125
120
|
},
|
126
121
|
type: "suggestion",
|
127
122
|
messages: {
|
@@ -130,52 +125,36 @@ const rule = {
|
|
130
125
|
schema
|
131
126
|
},
|
132
127
|
create(context) {
|
133
|
-
const { types, rootField, ...restOptions } = context.options[0] || {};
|
134
|
-
const
|
135
|
-
|
136
|
-
if (isEnabled) {
|
137
|
-
kinds.add(kind);
|
138
|
-
} else {
|
139
|
-
kinds.delete(kind);
|
140
|
-
}
|
141
|
-
}
|
128
|
+
const { types, rootField, ...restOptions } = context.options[0] || {}, kinds = new Set(types ? TYPES_KINDS : []);
|
129
|
+
for (const [kind, isEnabled] of Object.entries(restOptions))
|
130
|
+
isEnabled ? kinds.add(kind) : kinds.delete(kind);
|
142
131
|
if (rootField) {
|
143
|
-
const schema2 = requireGraphQLSchemaFromContext(RULE_ID, context);
|
144
|
-
const rootTypeNames = getRootTypeNames(schema2);
|
132
|
+
const schema2 = requireGraphQLSchemaFromContext(RULE_ID, context), rootTypeNames = getRootTypeNames(schema2);
|
145
133
|
kinds.add(
|
146
134
|
`:matches(ObjectTypeDefinition, ObjectTypeExtension)[name.value=/^(${[
|
147
135
|
...rootTypeNames
|
148
136
|
].join(",")})$/] > FieldDefinition`
|
149
137
|
);
|
150
138
|
}
|
151
|
-
const selector = [...kinds].join(",");
|
152
139
|
return {
|
153
|
-
[
|
154
|
-
var _a;
|
140
|
+
[[...kinds].join(",")](node) {
|
155
141
|
let description = "";
|
156
142
|
const isOperation = node.kind === Kind.OPERATION_DEFINITION;
|
157
143
|
if (isOperation) {
|
158
|
-
const rawNode = node.rawNode();
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
const linesBefore = line - prev.line;
|
163
|
-
if (!value.startsWith("eslint") && linesBefore === 1) {
|
164
|
-
description = value;
|
165
|
-
}
|
144
|
+
const rawNode = node.rawNode(), { prev, line } = rawNode.loc.startToken;
|
145
|
+
if (prev?.kind === TokenKind.COMMENT) {
|
146
|
+
const value = prev.value.trim(), linesBefore = line - prev.line;
|
147
|
+
!value.startsWith("eslint") && linesBefore === 1 && (description = value);
|
166
148
|
}
|
167
|
-
} else
|
168
|
-
description =
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
}
|
177
|
-
});
|
178
|
-
}
|
149
|
+
} else
|
150
|
+
description = node.description?.value.trim() || "";
|
151
|
+
description.length === 0 && context.report({
|
152
|
+
loc: isOperation ? getLocation(node.loc.start, node.operation) : node.name.loc,
|
153
|
+
messageId: RULE_ID,
|
154
|
+
data: {
|
155
|
+
nodeName: getNodeName(node)
|
156
|
+
}
|
157
|
+
});
|
179
158
|
}
|
180
159
|
};
|
181
160
|
}
|
@@ -1,11 +1,12 @@
|
|
1
|
-
import {
|
2
|
-
import '@graphql-tools/utils';
|
1
|
+
import { GraphQLESLintRule } from '../types.mjs';
|
3
2
|
import 'eslint';
|
4
3
|
import 'estree';
|
5
4
|
import 'graphql';
|
6
|
-
import 'graphql-config';
|
7
5
|
import 'json-schema-to-ts';
|
6
|
+
import '../siblings.mjs';
|
7
|
+
import '@graphql-tools/utils';
|
8
8
|
import '../estree-converter/types.mjs';
|
9
|
+
import 'graphql-config';
|
9
10
|
|
10
11
|
declare const rule: GraphQLESLintRule;
|
11
12
|
|
@@ -1,15 +1,14 @@
|
|
1
|
-
import "../chunk-
|
1
|
+
import "../chunk-U3TKCM4X.js";
|
2
2
|
import { isObjectType } from "graphql";
|
3
3
|
import { getTypeName, requireGraphQLSchemaFromContext } from "../utils.js";
|
4
|
-
const RULE_ID = "require-field-of-type-query-in-mutation-result"
|
5
|
-
const rule = {
|
4
|
+
const RULE_ID = "require-field-of-type-query-in-mutation-result", rule = {
|
6
5
|
meta: {
|
7
6
|
type: "suggestion",
|
8
7
|
docs: {
|
9
8
|
category: "Schema",
|
10
9
|
description: "Allow the client in one round-trip not only to call mutation but also to get a wagon of data to update their application.\n> Currently, no errors are reported for result type `union`, `interface` and `scalar`.",
|
11
10
|
url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
|
12
|
-
requiresSchema:
|
11
|
+
requiresSchema: !0,
|
13
12
|
examples: [
|
14
13
|
{
|
15
14
|
title: "Incorrect",
|
@@ -49,26 +48,16 @@ const rule = {
|
|
49
48
|
schema: []
|
50
49
|
},
|
51
50
|
create(context) {
|
52
|
-
const schema = requireGraphQLSchemaFromContext(RULE_ID, context);
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
return {};
|
57
|
-
}
|
58
|
-
const selector = `:matches(ObjectTypeDefinition, ObjectTypeExtension)[name.value=${mutationType.name}] > FieldDefinition > .gqlType Name`;
|
59
|
-
return {
|
60
|
-
[selector](node) {
|
61
|
-
const typeName = node.value;
|
62
|
-
const graphQLType = schema.getType(typeName);
|
51
|
+
const schema = requireGraphQLSchemaFromContext(RULE_ID, context), mutationType = schema.getMutationType(), queryType = schema.getQueryType();
|
52
|
+
return !mutationType || !queryType ? {} : {
|
53
|
+
[`:matches(ObjectTypeDefinition, ObjectTypeExtension)[name.value=${mutationType.name}] > FieldDefinition > .gqlType Name`](node) {
|
54
|
+
const typeName = node.value, graphQLType = schema.getType(typeName);
|
63
55
|
if (isObjectType(graphQLType)) {
|
64
56
|
const { fields } = graphQLType.astNode;
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
message: `Mutation result type "${graphQLType.name}" must contain field of type "${queryType.name}"`
|
70
|
-
});
|
71
|
-
}
|
57
|
+
fields?.some((field) => getTypeName(field) === queryType.name) || context.report({
|
58
|
+
node,
|
59
|
+
message: `Mutation result type "${graphQLType.name}" must contain field of type "${queryType.name}"`
|
60
|
+
});
|
72
61
|
}
|
73
62
|
}
|
74
63
|
};
|
@@ -1,11 +1,12 @@
|
|
1
|
-
import {
|
2
|
-
import '@graphql-tools/utils';
|
1
|
+
import { GraphQLESLintRule } from '../types.mjs';
|
3
2
|
import 'eslint';
|
4
3
|
import 'estree';
|
5
4
|
import 'graphql';
|
6
|
-
import 'graphql-config';
|
7
5
|
import 'json-schema-to-ts';
|
6
|
+
import '../siblings.mjs';
|
7
|
+
import '@graphql-tools/utils';
|
8
8
|
import '../estree-converter/types.mjs';
|
9
|
+
import 'graphql-config';
|
9
10
|
|
10
11
|
declare const rule: GraphQLESLintRule;
|
11
12
|
|
@@ -1,9 +1,7 @@
|
|
1
|
-
import "../chunk-
|
2
|
-
import path from "path";
|
1
|
+
import "../chunk-U3TKCM4X.js";
|
2
|
+
import path from "node:path";
|
3
3
|
import { requireSiblingsOperations } from "../utils.js";
|
4
|
-
const RULE_ID = "require-import-fragment"
|
5
|
-
const SUGGESTION_ID = "add-import-expression";
|
6
|
-
const rule = {
|
4
|
+
const RULE_ID = "require-import-fragment", SUGGESTION_ID = "add-import-expression", rule = {
|
7
5
|
meta: {
|
8
6
|
type: "suggestion",
|
9
7
|
docs: {
|
@@ -67,10 +65,9 @@ const rule = {
|
|
67
65
|
)
|
68
66
|
}
|
69
67
|
],
|
70
|
-
requiresSiblings:
|
71
|
-
isDisabledForAllConfig: true
|
68
|
+
requiresSiblings: !0
|
72
69
|
},
|
73
|
-
hasSuggestions:
|
70
|
+
hasSuggestions: !0,
|
74
71
|
messages: {
|
75
72
|
[RULE_ID]: 'Expected "{{fragmentName}}" fragment to be imported.',
|
76
73
|
[SUGGESTION_ID]: 'Add import expression for "{{fragmentName}}".'
|
@@ -78,36 +75,27 @@ const rule = {
|
|
78
75
|
schema: []
|
79
76
|
},
|
80
77
|
create(context) {
|
81
|
-
const comments = context.getSourceCode().getAllComments();
|
82
|
-
const siblings = requireSiblingsOperations(RULE_ID, context);
|
83
|
-
const filePath = context.getFilename();
|
78
|
+
const comments = context.getSourceCode().getAllComments(), siblings = requireSiblingsOperations(RULE_ID, context), filePath = context.filename;
|
84
79
|
return {
|
85
80
|
"FragmentSpread > .name"(node) {
|
86
|
-
|
87
|
-
const fragmentName = node.value;
|
88
|
-
const fragmentsFromSiblings = siblings.getFragment(fragmentName);
|
81
|
+
const fragmentName = node.value, fragmentsFromSiblings = siblings.getFragment(fragmentName);
|
89
82
|
for (const comment of comments) {
|
90
|
-
if (comment.type !== "Line"
|
91
|
-
continue;
|
92
|
-
const isPossibleImported = new RegExp(
|
83
|
+
if (comment.type !== "Line" || !new RegExp(
|
93
84
|
`^\\s*import\\s+(${fragmentName}\\s+from\\s+)?['"]`
|
94
|
-
).test(comment.value)
|
95
|
-
if (!isPossibleImported)
|
85
|
+
).test(comment.value))
|
96
86
|
continue;
|
97
|
-
const extractedImportPath =
|
87
|
+
const extractedImportPath = comment.value.match(/(["'])((?:\1|.)*?)\1/)?.[2];
|
98
88
|
if (!extractedImportPath)
|
99
89
|
continue;
|
100
90
|
const importPath = path.join(path.dirname(filePath), extractedImportPath);
|
101
|
-
|
91
|
+
if (fragmentsFromSiblings.some(
|
102
92
|
(source) => source.filePath === importPath
|
103
|
-
)
|
104
|
-
if (hasInSiblings)
|
93
|
+
))
|
105
94
|
return;
|
106
95
|
}
|
107
|
-
|
96
|
+
if (fragmentsFromSiblings.some(
|
108
97
|
(source) => source.filePath === filePath
|
109
|
-
)
|
110
|
-
if (fragmentInSameFile)
|
98
|
+
))
|
111
99
|
return;
|
112
100
|
const suggestedFilePaths = fragmentsFromSiblings.length ? fragmentsFromSiblings.map((o) => path.relative(path.dirname(filePath), o.filePath)) : ["CHANGE_ME.graphql"];
|
113
101
|
context.report({
|
@@ -1,11 +1,12 @@
|
|
1
|
-
import {
|
2
|
-
import '@graphql-tools/utils';
|
1
|
+
import { GraphQLESLintRule } from '../types.mjs';
|
3
2
|
import 'eslint';
|
4
3
|
import 'estree';
|
5
4
|
import 'graphql';
|
6
|
-
import 'graphql-config';
|
7
5
|
import 'json-schema-to-ts';
|
6
|
+
import '../siblings.mjs';
|
7
|
+
import '@graphql-tools/utils';
|
8
8
|
import '../estree-converter/types.mjs';
|
9
|
+
import 'graphql-config';
|
9
10
|
|
10
11
|
declare const rule: GraphQLESLintRule;
|
11
12
|
|
@@ -1,8 +1,7 @@
|
|
1
|
-
import "../chunk-
|
1
|
+
import "../chunk-U3TKCM4X.js";
|
2
2
|
import { Kind } from "graphql";
|
3
3
|
import { getNodeName } from "../utils.js";
|
4
|
-
const RULE_ID = "require-nullable-fields-with-oneof"
|
5
|
-
const rule = {
|
4
|
+
const RULE_ID = "require-nullable-fields-with-oneof", rule = {
|
6
5
|
meta: {
|
7
6
|
type: "suggestion",
|
8
7
|
docs: {
|
@@ -44,22 +43,16 @@ const rule = {
|
|
44
43
|
create(context) {
|
45
44
|
return {
|
46
45
|
"Directive[name.value=oneOf]"({ parent }) {
|
47
|
-
|
46
|
+
if ([
|
48
47
|
Kind.OBJECT_TYPE_DEFINITION,
|
49
48
|
Kind.INPUT_OBJECT_TYPE_DEFINITION
|
50
|
-
].includes(parent.kind)
|
51
|
-
|
52
|
-
|
53
|
-
}
|
54
|
-
for (const field of parent.fields || []) {
|
55
|
-
if (field.gqlType.kind === Kind.NON_NULL_TYPE) {
|
56
|
-
context.report({
|
49
|
+
].includes(parent.kind))
|
50
|
+
for (const field of parent.fields || [])
|
51
|
+
field.gqlType.kind === Kind.NON_NULL_TYPE && context.report({
|
57
52
|
node: field.name,
|
58
53
|
messageId: RULE_ID,
|
59
54
|
data: { nodeName: getNodeName(field) }
|
60
55
|
});
|
61
|
-
}
|
62
|
-
}
|
63
56
|
}
|
64
57
|
};
|
65
58
|
}
|
@@ -1,11 +1,12 @@
|
|
1
|
-
import {
|
2
|
-
import '@graphql-tools/utils';
|
1
|
+
import { GraphQLESLintRule } from '../types.mjs';
|
3
2
|
import 'eslint';
|
4
3
|
import 'estree';
|
5
4
|
import 'graphql';
|
6
|
-
import 'graphql-config';
|
7
5
|
import 'json-schema-to-ts';
|
6
|
+
import '../siblings.mjs';
|
7
|
+
import '@graphql-tools/utils';
|
8
8
|
import '../estree-converter/types.mjs';
|
9
|
+
import 'graphql-config';
|
9
10
|
|
10
11
|
declare const rule: GraphQLESLintRule;
|
11
12
|
|
@@ -1,16 +1,15 @@
|
|
1
|
-
import "../chunk-
|
1
|
+
import "../chunk-U3TKCM4X.js";
|
2
2
|
import { Kind } from "graphql";
|
3
3
|
import { getNodeName, requireGraphQLSchemaFromContext, truthy } from "../utils.js";
|
4
|
-
const RULE_ID = "require-nullable-result-in-root"
|
5
|
-
const rule = {
|
4
|
+
const RULE_ID = "require-nullable-result-in-root", rule = {
|
6
5
|
meta: {
|
7
6
|
type: "suggestion",
|
8
|
-
hasSuggestions:
|
7
|
+
hasSuggestions: !0,
|
9
8
|
docs: {
|
10
9
|
category: "Schema",
|
11
10
|
description: "Require nullable fields in root types.",
|
12
11
|
url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
|
13
|
-
requiresSchema:
|
12
|
+
requiresSchema: !0,
|
14
13
|
examples: [
|
15
14
|
{
|
16
15
|
title: "Incorrect",
|
@@ -44,39 +43,34 @@ const rule = {
|
|
44
43
|
schema: []
|
45
44
|
},
|
46
45
|
create(context) {
|
47
|
-
const schema = requireGraphQLSchemaFromContext(RULE_ID, context)
|
48
|
-
|
49
|
-
|
50
|
-
);
|
51
|
-
const sourceCode = context.getSourceCode();
|
46
|
+
const schema = requireGraphQLSchemaFromContext(RULE_ID, context), rootTypeNames = new Set(
|
47
|
+
[schema.getQueryType(), schema.getMutationType()].filter(truthy).map((type) => type.name)
|
48
|
+
), sourceCode = context.getSourceCode();
|
52
49
|
return {
|
53
50
|
"ObjectTypeDefinition,ObjectTypeExtension"(node) {
|
54
|
-
if (
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
const text = sourceCode.getText(field.gqlType);
|
74
|
-
return fixer.replaceText(field.gqlType, text.replace("!", ""));
|
51
|
+
if (rootTypeNames.has(node.name.value))
|
52
|
+
for (const field of node.fields || []) {
|
53
|
+
if (field.gqlType.type !== Kind.NON_NULL_TYPE || field.gqlType.gqlType.type !== Kind.NAMED_TYPE)
|
54
|
+
continue;
|
55
|
+
const name = field.gqlType.gqlType.name.value, type = schema.getType(name), resultType = type?.astNode ? getNodeName(type.astNode) : type?.name;
|
56
|
+
context.report({
|
57
|
+
node: field.gqlType,
|
58
|
+
messageId: RULE_ID,
|
59
|
+
data: {
|
60
|
+
resultType: resultType || "",
|
61
|
+
rootType: getNodeName(node)
|
62
|
+
},
|
63
|
+
suggest: [
|
64
|
+
{
|
65
|
+
desc: `Make ${resultType} nullable`,
|
66
|
+
fix(fixer) {
|
67
|
+
const text = sourceCode.getText(field.gqlType);
|
68
|
+
return fixer.replaceText(field.gqlType, text.replace("!", ""));
|
69
|
+
}
|
75
70
|
}
|
76
|
-
|
77
|
-
|
78
|
-
}
|
79
|
-
}
|
71
|
+
]
|
72
|
+
});
|
73
|
+
}
|
80
74
|
}
|
81
75
|
};
|
82
76
|
}
|
@@ -1,11 +1,12 @@
|
|
1
1
|
import { FromSchema } from 'json-schema-to-ts';
|
2
|
-
import {
|
3
|
-
import '@graphql-tools/utils';
|
2
|
+
import { GraphQLESLintRule } from '../types.mjs';
|
4
3
|
import 'eslint';
|
5
4
|
import 'estree';
|
6
5
|
import 'graphql';
|
7
|
-
import '
|
6
|
+
import '../siblings.mjs';
|
7
|
+
import '@graphql-tools/utils';
|
8
8
|
import '../estree-converter/types.mjs';
|
9
|
+
import 'graphql-config';
|
9
10
|
|
10
11
|
declare const schema: {
|
11
12
|
readonly definitions: {
|