@graphql-eslint/eslint-plugin 4.0.0-alpha-20230801163310-8bc4340 → 4.0.0-alpha-20230810155929-e89edf7
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 { asArray } from "@graphql-tools/utils";
|
3
3
|
import {
|
4
4
|
GraphQLInterfaceType,
|
@@ -16,9 +16,7 @@ import {
|
|
16
16
|
requireGraphQLSchemaFromContext,
|
17
17
|
requireSiblingsOperations
|
18
18
|
} from "../utils.js";
|
19
|
-
const RULE_ID = "require-id
|
20
|
-
const DEFAULT_ID_FIELD_NAME = "id";
|
21
|
-
const schema = {
|
19
|
+
const RULE_ID = "require-selections", DEFAULT_ID_FIELD_NAME = "id", schema = {
|
22
20
|
definitions: {
|
23
21
|
asString: {
|
24
22
|
type: "string"
|
@@ -29,7 +27,7 @@ const schema = {
|
|
29
27
|
maxItems: 1,
|
30
28
|
items: {
|
31
29
|
type: "object",
|
32
|
-
additionalProperties:
|
30
|
+
additionalProperties: !1,
|
33
31
|
properties: {
|
34
32
|
fieldName: {
|
35
33
|
oneOf: [{ $ref: "#/definitions/asString" }, { $ref: "#/definitions/asArray" }],
|
@@ -37,17 +35,16 @@ const schema = {
|
|
37
35
|
}
|
38
36
|
}
|
39
37
|
}
|
40
|
-
}
|
41
|
-
const rule = {
|
38
|
+
}, rule = {
|
42
39
|
meta: {
|
43
40
|
type: "suggestion",
|
44
|
-
hasSuggestions:
|
41
|
+
hasSuggestions: !0,
|
45
42
|
docs: {
|
46
43
|
category: "Operations",
|
47
44
|
description: "Enforce selecting specific fields when they are available on the GraphQL type.",
|
48
45
|
url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
|
49
|
-
requiresSchema:
|
50
|
-
requiresSiblings:
|
46
|
+
requiresSchema: !0,
|
47
|
+
requiresSiblings: !0,
|
51
48
|
examples: [
|
52
49
|
{
|
53
50
|
title: "Incorrect",
|
@@ -98,44 +95,33 @@ const rule = {
|
|
98
95
|
)
|
99
96
|
}
|
100
97
|
],
|
101
|
-
recommended:
|
98
|
+
recommended: !0
|
102
99
|
},
|
103
100
|
messages: {
|
104
|
-
[RULE_ID]:
|
101
|
+
[RULE_ID]: `Field{{ pluralSuffix }} {{ fieldName }} must be selected when it's available on a type.
|
102
|
+
Include it in your selection set{{ addition }}.`
|
105
103
|
},
|
106
104
|
schema
|
107
105
|
},
|
108
106
|
create(context) {
|
109
|
-
const schema2 = requireGraphQLSchemaFromContext(RULE_ID, context);
|
110
|
-
const siblings = requireSiblingsOperations(RULE_ID, context);
|
111
|
-
const { fieldName = DEFAULT_ID_FIELD_NAME } = context.options[0] || {};
|
112
|
-
const idNames = asArray(fieldName);
|
113
|
-
const selector = "OperationDefinition SelectionSet[parent.kind!=/(^OperationDefinition|InlineFragment)$/]";
|
114
|
-
const typeInfo = new TypeInfo(schema2);
|
107
|
+
const schema2 = requireGraphQLSchemaFromContext(RULE_ID, context), siblings = requireSiblingsOperations(RULE_ID, context), { fieldName = DEFAULT_ID_FIELD_NAME } = context.options[0] || {}, idNames = asArray(fieldName), selector = "OperationDefinition SelectionSet[parent.kind!=/(^OperationDefinition|InlineFragment)$/]", typeInfo = new TypeInfo(schema2);
|
115
108
|
function checkFragments(node) {
|
116
109
|
for (const selection of node.selections) {
|
117
|
-
if (selection.kind !== Kind.FRAGMENT_SPREAD)
|
110
|
+
if (selection.kind !== Kind.FRAGMENT_SPREAD)
|
118
111
|
continue;
|
119
|
-
}
|
120
112
|
const [foundSpread] = siblings.getFragment(selection.name.value);
|
121
|
-
if (!foundSpread)
|
113
|
+
if (!foundSpread)
|
122
114
|
continue;
|
123
|
-
|
124
|
-
const checkedFragmentSpreads = /* @__PURE__ */ new Set();
|
125
|
-
const visitor = visitWithTypeInfo(typeInfo, {
|
115
|
+
const checkedFragmentSpreads = /* @__PURE__ */ new Set(), visitor = visitWithTypeInfo(typeInfo, {
|
126
116
|
SelectionSet(node2, key, _parent) {
|
127
117
|
const parent = _parent;
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
parent,
|
136
|
-
checkedFragmentSpreads
|
137
|
-
);
|
138
|
-
}
|
118
|
+
parent.kind === Kind.FRAGMENT_DEFINITION ? checkedFragmentSpreads.add(parent.name.value) : parent.kind !== Kind.INLINE_FRAGMENT && checkSelections(
|
119
|
+
node2,
|
120
|
+
typeInfo.getType(),
|
121
|
+
selection.loc.start,
|
122
|
+
parent,
|
123
|
+
checkedFragmentSpreads
|
124
|
+
);
|
139
125
|
}
|
140
126
|
});
|
141
127
|
visit(foundSpread.document, visitor);
|
@@ -143,58 +129,41 @@ const rule = {
|
|
143
129
|
}
|
144
130
|
function checkSelections(node, type, loc, parent, checkedFragmentSpreads = /* @__PURE__ */ new Set()) {
|
145
131
|
const rawType = getBaseType(type);
|
146
|
-
if (rawType instanceof GraphQLObjectType || rawType instanceof GraphQLInterfaceType)
|
132
|
+
if (rawType instanceof GraphQLObjectType || rawType instanceof GraphQLInterfaceType)
|
147
133
|
checkFields(rawType);
|
148
|
-
|
149
|
-
for (const selection of node.selections)
|
134
|
+
else if (rawType instanceof GraphQLUnionType) {
|
135
|
+
for (const selection of node.selections)
|
150
136
|
if (selection.kind === Kind.INLINE_FRAGMENT) {
|
151
|
-
const
|
152
|
-
|
153
|
-
if (t) {
|
154
|
-
checkFields(t);
|
155
|
-
}
|
137
|
+
const t = rawType.getTypes().find((t2) => t2.name === selection.typeCondition.name.value);
|
138
|
+
t && checkFields(t);
|
156
139
|
}
|
157
|
-
}
|
158
140
|
}
|
159
141
|
function checkFields(rawType2) {
|
160
142
|
const fields = rawType2.getFields();
|
161
|
-
|
162
|
-
if (!hasIdFieldInType) {
|
143
|
+
if (!idNames.some((name) => fields[name]))
|
163
144
|
return;
|
164
|
-
}
|
165
145
|
function hasIdField({ selections }) {
|
166
146
|
return selections.some((selection) => {
|
167
|
-
if (selection.kind === Kind.FIELD)
|
168
|
-
|
169
|
-
|
170
|
-
}
|
171
|
-
return idNames.includes(selection.name.value);
|
172
|
-
}
|
173
|
-
if (selection.kind === Kind.INLINE_FRAGMENT) {
|
147
|
+
if (selection.kind === Kind.FIELD)
|
148
|
+
return selection.alias && idNames.includes(selection.alias.value) ? !0 : idNames.includes(selection.name.value);
|
149
|
+
if (selection.kind === Kind.INLINE_FRAGMENT)
|
174
150
|
return hasIdField(selection.selectionSet);
|
175
|
-
}
|
176
151
|
if (selection.kind === Kind.FRAGMENT_SPREAD) {
|
177
152
|
const [foundSpread] = siblings.getFragment(selection.name.value);
|
178
153
|
if (foundSpread) {
|
179
154
|
const fragmentSpread = foundSpread.document;
|
180
|
-
checkedFragmentSpreads.add(fragmentSpread.name.value);
|
181
|
-
return hasIdField(fragmentSpread.selectionSet);
|
155
|
+
return checkedFragmentSpreads.add(fragmentSpread.name.value), hasIdField(fragmentSpread.selectionSet);
|
182
156
|
}
|
183
157
|
}
|
184
|
-
return
|
158
|
+
return !1;
|
185
159
|
});
|
186
160
|
}
|
187
161
|
const hasId = hasIdField(node);
|
188
|
-
checkFragments(node)
|
189
|
-
if (hasId) {
|
162
|
+
if (checkFragments(node), hasId)
|
190
163
|
return;
|
191
|
-
|
192
|
-
const pluralSuffix = idNames.length > 1 ? "s" : "";
|
193
|
-
const fieldName2 = englishJoinWords(
|
164
|
+
const pluralSuffix = idNames.length > 1 ? "s" : "", fieldName2 = englishJoinWords(
|
194
165
|
idNames.map((name) => `\`${(parent.alias || parent.name).value}.${name}\``)
|
195
|
-
)
|
196
|
-
const addition = checkedFragmentSpreads.size === 0 ? "" : ` or add to used fragment${checkedFragmentSpreads.size > 1 ? "s" : ""} ${englishJoinWords([...checkedFragmentSpreads].map((name) => `\`${name}\``))}`;
|
197
|
-
const problem = {
|
166
|
+
), addition = checkedFragmentSpreads.size === 0 ? "" : ` or add to used fragment${checkedFragmentSpreads.size > 1 ? "s" : ""} ${englishJoinWords([...checkedFragmentSpreads].map((name) => `\`${name}\``))}`, problem = {
|
198
167
|
loc,
|
199
168
|
messageId: RULE_ID,
|
200
169
|
data: {
|
@@ -203,25 +172,19 @@ const rule = {
|
|
203
172
|
addition
|
204
173
|
}
|
205
174
|
};
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
}
|
214
|
-
}));
|
215
|
-
}
|
216
|
-
context.report(problem);
|
175
|
+
"type" in node && (problem.suggest = idNames.map((idName) => ({
|
176
|
+
desc: `Add \`${idName}\` selection`,
|
177
|
+
fix: (fixer) => {
|
178
|
+
let insertNode = node.selections[0];
|
179
|
+
return insertNode = insertNode.kind === Kind.INLINE_FRAGMENT ? insertNode.selectionSet.selections[0] : insertNode, fixer.insertTextBefore(insertNode, `${idName} `);
|
180
|
+
}
|
181
|
+
}))), context.report(problem);
|
217
182
|
}
|
218
183
|
}
|
219
184
|
return {
|
220
185
|
[selector](node) {
|
221
186
|
const typeInfo2 = node.typeInfo();
|
222
|
-
|
223
|
-
checkSelections(node, typeInfo2.gqlType, node.loc.start, node.parent);
|
224
|
-
}
|
187
|
+
typeInfo2.gqlType && checkSelections(node, typeInfo2.gqlType, node.loc.start, node.parent);
|
225
188
|
}
|
226
189
|
};
|
227
190
|
}
|
@@ -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,7 +1,6 @@
|
|
1
|
-
import "../chunk-
|
1
|
+
import "../chunk-U3TKCM4X.js";
|
2
2
|
import { displayNodeName } from "../utils.js";
|
3
|
-
const RULE_ID = "require-type-pattern-with-oneof"
|
4
|
-
const rule = {
|
3
|
+
const RULE_ID = "require-type-pattern-with-oneof", rule = {
|
5
4
|
meta: {
|
6
5
|
type: "suggestion",
|
7
6
|
docs: {
|
@@ -45,20 +44,16 @@ const rule = {
|
|
45
44
|
"Directive[name.value=oneOf][parent.kind=ObjectTypeDefinition]"({
|
46
45
|
parent
|
47
46
|
}) {
|
48
|
-
var _a;
|
49
47
|
const requiredFields = ["error", "ok"];
|
50
|
-
for (const fieldName of requiredFields)
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
});
|
60
|
-
}
|
61
|
-
}
|
48
|
+
for (const fieldName of requiredFields)
|
49
|
+
parent.fields?.some((field) => field.name.value === fieldName) || context.report({
|
50
|
+
node: parent.name,
|
51
|
+
messageId: RULE_ID,
|
52
|
+
data: {
|
53
|
+
nodeName: displayNodeName(parent),
|
54
|
+
fieldName
|
55
|
+
}
|
56
|
+
});
|
62
57
|
}
|
63
58
|
};
|
64
59
|
}
|
@@ -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 type: "array";
|
@@ -1,15 +1,14 @@
|
|
1
|
-
import "../chunk-
|
1
|
+
import "../chunk-U3TKCM4X.js";
|
2
2
|
import { Kind } from "graphql";
|
3
3
|
import depthLimit from "graphql-depth-limit";
|
4
4
|
import { ARRAY_DEFAULT_OPTIONS, logger, requireSiblingsOperations } from "../utils.js";
|
5
|
-
const RULE_ID = "selection-set-depth"
|
6
|
-
const schema = {
|
5
|
+
const RULE_ID = "selection-set-depth", schema = {
|
7
6
|
type: "array",
|
8
7
|
minItems: 1,
|
9
8
|
maxItems: 1,
|
10
9
|
items: {
|
11
10
|
type: "object",
|
12
|
-
additionalProperties:
|
11
|
+
additionalProperties: !1,
|
13
12
|
required: ["maxDepth"],
|
14
13
|
properties: {
|
15
14
|
maxDepth: {
|
@@ -18,16 +17,15 @@ const schema = {
|
|
18
17
|
ignore: ARRAY_DEFAULT_OPTIONS
|
19
18
|
}
|
20
19
|
}
|
21
|
-
}
|
22
|
-
const rule = {
|
20
|
+
}, rule = {
|
23
21
|
meta: {
|
24
22
|
type: "suggestion",
|
25
|
-
hasSuggestions:
|
23
|
+
hasSuggestions: !0,
|
26
24
|
docs: {
|
27
25
|
category: "Operations",
|
28
26
|
description: "Limit the complexity of the GraphQL operations solely by their depth. Based on [graphql-depth-limit](https://npmjs.com/package/graphql-depth-limit).",
|
29
27
|
url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
|
30
|
-
requiresSiblings:
|
28
|
+
requiresSiblings: !0,
|
31
29
|
examples: [
|
32
30
|
{
|
33
31
|
title: "Incorrect",
|
@@ -69,7 +67,7 @@ const rule = {
|
|
69
67
|
`
|
70
68
|
}
|
71
69
|
],
|
72
|
-
recommended:
|
70
|
+
recommended: !0,
|
73
71
|
configOptions: [{ maxDepth: 7 }]
|
74
72
|
},
|
75
73
|
schema
|
@@ -83,23 +81,18 @@ const rule = {
|
|
83
81
|
`Rule "${RULE_ID}" works best with siblings operations loaded. For more info: https://bit.ly/graphql-eslint-operations`
|
84
82
|
);
|
85
83
|
}
|
86
|
-
const { maxDepth, ignore = [] } = context.options[0];
|
87
|
-
const checkFn = depthLimit(maxDepth, { ignore });
|
84
|
+
const { maxDepth, ignore = [] } = context.options[0], checkFn = depthLimit(maxDepth, { ignore });
|
88
85
|
return {
|
89
86
|
"OperationDefinition, FragmentDefinition"(node) {
|
90
87
|
try {
|
91
|
-
const rawNode = node.rawNode()
|
92
|
-
const fragmentsInUse = siblings ? siblings.getFragmentsInUse(rawNode) : [];
|
93
|
-
const document = {
|
88
|
+
const rawNode = node.rawNode(), fragmentsInUse = siblings ? siblings.getFragmentsInUse(rawNode) : [], document = {
|
94
89
|
kind: Kind.DOCUMENT,
|
95
90
|
definitions: [rawNode, ...fragmentsInUse]
|
96
91
|
};
|
97
92
|
checkFn({
|
98
93
|
getDocument: () => document,
|
99
94
|
reportError(error) {
|
100
|
-
const { line, column } = error.locations[0]
|
101
|
-
const ancestors = context.getAncestors();
|
102
|
-
const token = ancestors[0].tokens.find(
|
95
|
+
const { line, column } = error.locations[0], token = context.getAncestors()[0].tokens.find(
|
103
96
|
(token2) => token2.loc.start.line === line && token2.loc.start.column === column - 1
|
104
97
|
);
|
105
98
|
context.report({
|
@@ -114,9 +107,7 @@ const rule = {
|
|
114
107
|
{
|
115
108
|
desc: "Remove selections",
|
116
109
|
fix(fixer) {
|
117
|
-
const
|
118
|
-
const foundNode = sourceCode.getNodeByRangeIndex(token.range[0]);
|
119
|
-
const parentNode = foundNode.parent.parent;
|
110
|
+
const foundNode = context.getSourceCode().getNodeByRangeIndex(token.range[0]), parentNode = foundNode.parent.parent;
|
120
111
|
return fixer.remove(
|
121
112
|
foundNode.kind === "Name" ? parentNode.parent : parentNode
|
122
113
|
);
|
@@ -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 type: "array";
|
@@ -1,4 +1,4 @@
|
|
1
|
-
import "../chunk-
|
1
|
+
import "../chunk-U3TKCM4X.js";
|
2
2
|
import { Kind } from "graphql";
|
3
3
|
import {
|
4
4
|
ARRAY_DEFAULT_OPTIONS,
|
@@ -7,13 +7,12 @@ import {
|
|
7
7
|
requireGraphQLSchemaFromContext,
|
8
8
|
truthy
|
9
9
|
} from "../utils.js";
|
10
|
-
const RULE_ID = "strict-id-in-types"
|
11
|
-
const schema = {
|
10
|
+
const RULE_ID = "strict-id-in-types", schema = {
|
12
11
|
type: "array",
|
13
12
|
maxItems: 1,
|
14
13
|
items: {
|
15
14
|
type: "object",
|
16
|
-
additionalProperties:
|
15
|
+
additionalProperties: !1,
|
17
16
|
properties: {
|
18
17
|
acceptedIdNames: {
|
19
18
|
...ARRAY_DEFAULT_OPTIONS,
|
@@ -25,7 +24,7 @@ const schema = {
|
|
25
24
|
},
|
26
25
|
exceptions: {
|
27
26
|
type: "object",
|
28
|
-
additionalProperties:
|
27
|
+
additionalProperties: !1,
|
29
28
|
properties: {
|
30
29
|
types: {
|
31
30
|
...ARRAY_DEFAULT_OPTIONS,
|
@@ -39,16 +38,15 @@ const schema = {
|
|
39
38
|
}
|
40
39
|
}
|
41
40
|
}
|
42
|
-
}
|
43
|
-
const rule = {
|
41
|
+
}, rule = {
|
44
42
|
meta: {
|
45
43
|
type: "suggestion",
|
46
44
|
docs: {
|
47
45
|
description: "Requires output types to have one unique identifier unless they do not have a logical one. Exceptions can be used to ignore output types that do not have unique identifiers.",
|
48
46
|
category: "Schema",
|
49
|
-
recommended:
|
47
|
+
recommended: !0,
|
50
48
|
url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
|
51
|
-
requiresSchema:
|
49
|
+
requiresSchema: !0,
|
52
50
|
examples: [
|
53
51
|
{
|
54
52
|
title: "Incorrect",
|
@@ -125,34 +123,22 @@ const rule = {
|
|
125
123
|
acceptedIdTypes: ["ID"],
|
126
124
|
exceptions: {},
|
127
125
|
...context.options[0]
|
128
|
-
};
|
129
|
-
const schema2 = requireGraphQLSchemaFromContext(RULE_ID, context);
|
130
|
-
const rootTypeNames = [
|
131
|
-
schema2.getQueryType(),
|
132
|
-
schema2.getMutationType(),
|
133
|
-
schema2.getSubscriptionType()
|
134
|
-
].filter(truthy).map((type) => type.name);
|
135
|
-
const selector = `ObjectTypeDefinition[name.value!=/^(${rootTypeNames.join("|")})$/]`;
|
126
|
+
}, schema2 = requireGraphQLSchemaFromContext(RULE_ID, context);
|
136
127
|
return {
|
137
|
-
[
|
138
|
-
|
128
|
+
[`ObjectTypeDefinition[name.value!=/^(${[
|
129
|
+
schema2.getQueryType(),
|
130
|
+
schema2.getMutationType(),
|
131
|
+
schema2.getSubscriptionType()
|
132
|
+
].filter(truthy).map((type) => type.name).join("|")})$/]`](node) {
|
139
133
|
const typeName = node.name.value;
|
140
|
-
|
141
|
-
if (shouldIgnoreNode) {
|
134
|
+
if (options.exceptions.types?.includes(typeName) || options.exceptions.suffixes?.some((suffix) => typeName.endsWith(suffix)))
|
142
135
|
return;
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
isValidIdType = options.acceptedIdTypes.includes(fieldNode.type.type.name.value);
|
150
|
-
}
|
151
|
-
return isValidIdName && isValidIdType;
|
152
|
-
});
|
153
|
-
if ((validIds == null ? void 0 : validIds.length) !== 1) {
|
154
|
-
const pluralNamesSuffix = options.acceptedIdNames.length > 1 ? "s" : "";
|
155
|
-
const pluralTypesSuffix = options.acceptedIdTypes.length > 1 ? "s" : "";
|
136
|
+
if (node.fields?.filter((field) => {
|
137
|
+
const fieldNode = field.rawNode(), isValidIdName = options.acceptedIdNames.includes(fieldNode.name.value);
|
138
|
+
let isValidIdType = !1;
|
139
|
+
return fieldNode.type.kind === Kind.NON_NULL_TYPE && fieldNode.type.type.kind === Kind.NAMED_TYPE && (isValidIdType = options.acceptedIdTypes.includes(fieldNode.type.type.name.value)), isValidIdName && isValidIdType;
|
140
|
+
})?.length !== 1) {
|
141
|
+
const pluralNamesSuffix = options.acceptedIdNames.length > 1 ? "s" : "", pluralTypesSuffix = options.acceptedIdTypes.length > 1 ? "s" : "";
|
156
142
|
context.report({
|
157
143
|
node: node.name,
|
158
144
|
message: `${displayNodeName(node)} must have exactly one non-nullable unique identifier.
|
package/esm/rules/{no-case-insensitive-enum-values-duplicates.d.mts → unique-enum-value-names.d.mts}
RENAMED
@@ -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
|
|
package/esm/rules/{no-case-insensitive-enum-values-duplicates.js → unique-enum-value-names.js}
RENAMED
@@ -1,15 +1,16 @@
|
|
1
|
-
import "../chunk-
|
1
|
+
import "../chunk-U3TKCM4X.js";
|
2
2
|
import { Kind } from "graphql";
|
3
3
|
import { getNodeName } from "../utils.js";
|
4
4
|
const rule = {
|
5
5
|
meta: {
|
6
6
|
type: "suggestion",
|
7
|
-
hasSuggestions:
|
7
|
+
hasSuggestions: !0,
|
8
8
|
docs: {
|
9
|
-
url: "https://the-guild.dev/graphql/eslint/rules/
|
9
|
+
url: "https://the-guild.dev/graphql/eslint/rules/unique-enum-value-names",
|
10
10
|
category: "Schema",
|
11
|
-
recommended:
|
12
|
-
description:
|
11
|
+
recommended: !0,
|
12
|
+
description: `A GraphQL enum type is only valid if all its values are uniquely named.
|
13
|
+
> This rule disallows case-insensitive enum values duplicates too.`,
|
13
14
|
examples: [
|
14
15
|
{
|
15
16
|
title: "Incorrect",
|
@@ -42,11 +43,9 @@ const rule = {
|
|
42
43
|
schema: []
|
43
44
|
},
|
44
45
|
create(context) {
|
45
|
-
const selector = [Kind.ENUM_TYPE_DEFINITION, Kind.ENUM_TYPE_EXTENSION].join(",");
|
46
46
|
return {
|
47
|
-
[
|
48
|
-
|
49
|
-
const duplicates = (_a = node.values) == null ? void 0 : _a.filter(
|
47
|
+
[[Kind.ENUM_TYPE_DEFINITION, Kind.ENUM_TYPE_EXTENSION].join(",")](node) {
|
48
|
+
const duplicates = node.values?.filter(
|
50
49
|
(item, index, array) => array.findIndex((v) => v.name.value.toLowerCase() === item.name.value.toLowerCase()) !== index
|
51
50
|
);
|
52
51
|
for (const duplicate of duplicates || []) {
|
@@ -1,11 +1,12 @@
|
|
1
1
|
import { ExecutableDefinitionNode } from 'graphql';
|
2
2
|
import { GraphQLESTreeNode } from '../estree-converter/types.mjs';
|
3
|
-
import {
|
3
|
+
import { GraphQLESLintRuleContext, GraphQLESLintRule } from '../types.mjs';
|
4
4
|
import 'eslint';
|
5
5
|
import 'estree';
|
6
|
+
import 'json-schema-to-ts';
|
7
|
+
import '../siblings.mjs';
|
6
8
|
import '@graphql-tools/utils';
|
7
9
|
import 'graphql-config';
|
8
|
-
import 'json-schema-to-ts';
|
9
10
|
|
10
11
|
declare const checkNode: (context: GraphQLESLintRuleContext, node: GraphQLESTreeNode<ExecutableDefinitionNode>, ruleId: string) => void;
|
11
12
|
declare const rule: GraphQLESLintRule;
|
@@ -1,39 +1,31 @@
|
|
1
|
-
import "../chunk-
|
2
|
-
import { relative } from "path";
|
1
|
+
import "../chunk-U3TKCM4X.js";
|
2
|
+
import { relative } from "node:path";
|
3
3
|
import { Kind } from "graphql";
|
4
4
|
import { CWD, normalizePath, requireSiblingsOperations, VIRTUAL_DOCUMENT_REGEX } from "../utils.js";
|
5
|
-
const RULE_ID = "unique-fragment-name"
|
6
|
-
const
|
7
|
-
|
8
|
-
const siblings = requireSiblingsOperations(ruleId, context);
|
9
|
-
const siblingDocuments = node.kind === Kind.FRAGMENT_DEFINITION ? siblings.getFragment(documentName) : siblings.getOperation(documentName);
|
10
|
-
const filepath = context.getFilename();
|
11
|
-
const conflictingDocuments = siblingDocuments.filter((f) => {
|
12
|
-
var _a;
|
13
|
-
const isSameName = ((_a = f.document.name) == null ? void 0 : _a.value) === documentName;
|
14
|
-
const isSamePath = normalizePath(f.filePath) === normalizePath(filepath);
|
5
|
+
const RULE_ID = "unique-fragment-name", checkNode = (context, node, ruleId) => {
|
6
|
+
const documentName = node.name.value, siblings = requireSiblingsOperations(ruleId, context), siblingDocuments = node.kind === Kind.FRAGMENT_DEFINITION ? siblings.getFragment(documentName) : siblings.getOperation(documentName), filepath = context.filename, conflictingDocuments = siblingDocuments.filter((f) => {
|
7
|
+
const isSameName = f.document.name?.value === documentName, isSamePath = normalizePath(f.filePath) === normalizePath(filepath);
|
15
8
|
return isSameName && !isSamePath;
|
16
9
|
});
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
};
|
29
|
-
const rule = {
|
10
|
+
conflictingDocuments.length > 0 && context.report({
|
11
|
+
messageId: ruleId,
|
12
|
+
data: {
|
13
|
+
documentName,
|
14
|
+
summary: conflictingDocuments.map((f) => ` ${relative(CWD, f.filePath.replace(VIRTUAL_DOCUMENT_REGEX, ""))}`).join(`
|
15
|
+
`)
|
16
|
+
},
|
17
|
+
// @ts-expect-error name will exist
|
18
|
+
node: node.name
|
19
|
+
});
|
20
|
+
}, rule = {
|
30
21
|
meta: {
|
31
22
|
type: "suggestion",
|
32
23
|
docs: {
|
33
24
|
category: "Operations",
|
34
25
|
description: "Enforce unique fragment names across your project.",
|
35
26
|
url: `https://the-guild.dev/graphql/eslint/rules/${RULE_ID}`,
|
36
|
-
requiresSiblings:
|
27
|
+
requiresSiblings: !0,
|
28
|
+
recommended: !0,
|
37
29
|
examples: [
|
38
30
|
{
|
39
31
|
title: "Incorrect",
|
@@ -76,7 +68,8 @@ const rule = {
|
|
76
68
|
]
|
77
69
|
},
|
78
70
|
messages: {
|
79
|
-
[RULE_ID]:
|
71
|
+
[RULE_ID]: `Fragment named "{{ documentName }}" already defined in:
|
72
|
+
{{ summary }}`
|
80
73
|
},
|
81
74
|
schema: []
|
82
75
|
},
|
@@ -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
|
|