@graphql-eslint/eslint-plugin 4.1.1-alpha-20241129112753-0d7b851c3b8febe16330bfe78c1ac3ffd9dacd86 → 4.2.0-alpha-20241129163655-f92a3665247a2f1c386ecaae7f3dcb301398ef03
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/index.d.cts +1 -0
- package/cjs/meta.js +1 -1
- package/cjs/rules/index.d.cts +1 -0
- package/cjs/rules/require-selections/index.d.cts +4 -0
- package/cjs/rules/require-selections/index.js +33 -24
- package/esm/index.d.ts +1 -0
- package/esm/meta.js +1 -1
- package/esm/rules/index.d.ts +1 -0
- package/esm/rules/require-selections/index.d.ts +4 -0
- package/esm/rules/require-selections/index.js +33 -24
- package/index.browser.js +34 -25
- package/package.json +1 -1
package/cjs/index.d.cts
CHANGED
@@ -147,6 +147,7 @@ declare const _default: {
|
|
147
147
|
'require-nullable-fields-with-oneof': GraphQLESLintRule;
|
148
148
|
'require-nullable-result-in-root': GraphQLESLintRule;
|
149
149
|
'require-selections': GraphQLESLintRule<{
|
150
|
+
requireAllFields?: boolean | undefined;
|
150
151
|
fieldName: string | string[];
|
151
152
|
}[], true>;
|
152
153
|
'require-type-pattern-with-oneof': GraphQLESLintRule;
|
package/cjs/meta.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});const version = "4.
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});const version = "4.2.0-alpha-20241129163655-f92a3665247a2f1c386ecaae7f3dcb301398ef03";
|
2
2
|
|
3
3
|
|
4
4
|
exports.version = version;
|
package/cjs/rules/index.d.cts
CHANGED
@@ -110,6 +110,7 @@ declare const rules: {
|
|
110
110
|
'require-nullable-fields-with-oneof': GraphQLESLintRule;
|
111
111
|
'require-nullable-result-in-root': GraphQLESLintRule;
|
112
112
|
'require-selections': GraphQLESLintRule<{
|
113
|
+
requireAllFields?: boolean | undefined;
|
113
114
|
fieldName: string | string[];
|
114
115
|
}[], true>;
|
115
116
|
'require-type-pattern-with-oneof': GraphQLESLintRule;
|
@@ -31,6 +31,10 @@ const RULE_ID = "require-selections", DEFAULT_ID_FIELD_NAME = "id", schema = {
|
|
31
31
|
fieldName: {
|
32
32
|
oneOf: [{ $ref: "#/definitions/asString" }, { $ref: "#/definitions/asArray" }],
|
33
33
|
default: DEFAULT_ID_FIELD_NAME
|
34
|
+
},
|
35
|
+
requireAllFields: {
|
36
|
+
type: "boolean",
|
37
|
+
description: "Whether all fields of `fieldName` option must be included."
|
34
38
|
}
|
35
39
|
}
|
36
40
|
}
|
@@ -104,7 +108,7 @@ Include it in your selection set{{ addition }}.`
|
|
104
108
|
schema
|
105
109
|
},
|
106
110
|
create(context) {
|
107
|
-
const schema2 = _utilsjs.requireGraphQLSchema.call(void 0, RULE_ID, context), siblings = _utilsjs.requireGraphQLOperations.call(void 0, RULE_ID, context), { fieldName = DEFAULT_ID_FIELD_NAME } = context.options[0] || {}, idNames = _utils.asArray.call(void 0, fieldName), selector = "SelectionSet[parent.kind!=/(^OperationDefinition|InlineFragment)$/]", typeInfo = new (0, _graphql.TypeInfo)(schema2);
|
111
|
+
const schema2 = _utilsjs.requireGraphQLSchema.call(void 0, RULE_ID, context), siblings = _utilsjs.requireGraphQLOperations.call(void 0, RULE_ID, context), { fieldName = DEFAULT_ID_FIELD_NAME, requireAllFields } = context.options[0] || {}, idNames = _utils.asArray.call(void 0, fieldName), selector = "SelectionSet[parent.kind!=/(^OperationDefinition|InlineFragment)$/]", typeInfo = new (0, _graphql.TypeInfo)(schema2);
|
108
112
|
function checkFragments(node) {
|
109
113
|
for (const selection of node.selections) {
|
110
114
|
if (selection.kind !== _graphql.Kind.FRAGMENT_SPREAD)
|
@@ -146,30 +150,35 @@ Include it in your selection set{{ addition }}.`
|
|
146
150
|
}
|
147
151
|
function checkFields(rawType2) {
|
148
152
|
const fields = rawType2.getFields();
|
149
|
-
if (
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
153
|
+
if (idNames.some((name) => fields[name]))
|
154
|
+
if (checkFragments(node), requireAllFields)
|
155
|
+
for (const idName of idNames)
|
156
|
+
report([idName]);
|
157
|
+
else
|
158
|
+
report(idNames);
|
159
|
+
}
|
160
|
+
function hasIdField({ selections }, idNames2) {
|
161
|
+
return selections.some((selection) => {
|
162
|
+
if (selection.kind === _graphql.Kind.FIELD)
|
163
|
+
return selection.alias && idNames2.includes(selection.alias.value) ? !0 : idNames2.includes(selection.name.value);
|
164
|
+
if (selection.kind === _graphql.Kind.INLINE_FRAGMENT)
|
165
|
+
return hasIdField(selection.selectionSet, idNames2);
|
166
|
+
if (selection.kind === _graphql.Kind.FRAGMENT_SPREAD) {
|
167
|
+
const [foundSpread] = siblings.getFragment(selection.name.value);
|
168
|
+
if (foundSpread) {
|
169
|
+
const fragmentSpread = foundSpread.document;
|
170
|
+
return checkedFragmentSpreads.add(fragmentSpread.name.value), hasIdField(fragmentSpread.selectionSet, idNames2);
|
163
171
|
}
|
164
|
-
|
165
|
-
|
166
|
-
}
|
167
|
-
|
168
|
-
|
172
|
+
}
|
173
|
+
return !1;
|
174
|
+
});
|
175
|
+
}
|
176
|
+
function report(idNames2) {
|
177
|
+
if (hasIdField(node, idNames2))
|
169
178
|
return;
|
170
|
-
const
|
171
|
-
|
172
|
-
), addition = checkedFragmentSpreads.size === 0 ? "" : ` or add to used fragment${checkedFragmentSpreads.size > 1 ? "s" : ""} ${_utilsjs.englishJoinWords.call(void 0, [...checkedFragmentSpreads].map((name) => `\`${name}\``))}`, problem = {
|
179
|
+
const fieldName2 = _utilsjs.englishJoinWords.call(void 0,
|
180
|
+
idNames2.map((name) => `\`${(parent.alias || parent.name).value}.${name}\``)
|
181
|
+
), pluralSuffix = idNames2.length > 1 ? "s" : "", addition = checkedFragmentSpreads.size === 0 ? "" : ` or add to used fragment${checkedFragmentSpreads.size > 1 ? "s" : ""} ${_utilsjs.englishJoinWords.call(void 0, [...checkedFragmentSpreads].map((name) => `\`${name}\``))}`, problem = {
|
173
182
|
loc,
|
174
183
|
messageId: RULE_ID,
|
175
184
|
data: {
|
@@ -178,7 +187,7 @@ Include it in your selection set{{ addition }}.`
|
|
178
187
|
addition
|
179
188
|
}
|
180
189
|
};
|
181
|
-
"type" in node && (problem.suggest =
|
190
|
+
"type" in node && (problem.suggest = idNames2.map((idName) => ({
|
182
191
|
desc: `Add \`${idName}\` selection`,
|
183
192
|
fix: (fixer) => {
|
184
193
|
let insertNode = node.selections[0];
|
package/esm/index.d.ts
CHANGED
@@ -147,6 +147,7 @@ declare const _default: {
|
|
147
147
|
'require-nullable-fields-with-oneof': GraphQLESLintRule;
|
148
148
|
'require-nullable-result-in-root': GraphQLESLintRule;
|
149
149
|
'require-selections': GraphQLESLintRule<{
|
150
|
+
requireAllFields?: boolean | undefined;
|
150
151
|
fieldName: string | string[];
|
151
152
|
}[], true>;
|
152
153
|
'require-type-pattern-with-oneof': GraphQLESLintRule;
|
package/esm/meta.js
CHANGED
package/esm/rules/index.d.ts
CHANGED
@@ -110,6 +110,7 @@ declare const rules: {
|
|
110
110
|
'require-nullable-fields-with-oneof': GraphQLESLintRule;
|
111
111
|
'require-nullable-result-in-root': GraphQLESLintRule;
|
112
112
|
'require-selections': GraphQLESLintRule<{
|
113
|
+
requireAllFields?: boolean | undefined;
|
113
114
|
fieldName: string | string[];
|
114
115
|
}[], true>;
|
115
116
|
'require-type-pattern-with-oneof': GraphQLESLintRule;
|
@@ -31,6 +31,10 @@ const RULE_ID = "require-selections", DEFAULT_ID_FIELD_NAME = "id", schema = {
|
|
31
31
|
fieldName: {
|
32
32
|
oneOf: [{ $ref: "#/definitions/asString" }, { $ref: "#/definitions/asArray" }],
|
33
33
|
default: DEFAULT_ID_FIELD_NAME
|
34
|
+
},
|
35
|
+
requireAllFields: {
|
36
|
+
type: "boolean",
|
37
|
+
description: "Whether all fields of `fieldName` option must be included."
|
34
38
|
}
|
35
39
|
}
|
36
40
|
}
|
@@ -104,7 +108,7 @@ Include it in your selection set{{ addition }}.`
|
|
104
108
|
schema
|
105
109
|
},
|
106
110
|
create(context) {
|
107
|
-
const schema2 = requireGraphQLSchema(RULE_ID, context), siblings = requireGraphQLOperations(RULE_ID, context), { fieldName = DEFAULT_ID_FIELD_NAME } = context.options[0] || {}, idNames = asArray(fieldName), selector = "SelectionSet[parent.kind!=/(^OperationDefinition|InlineFragment)$/]", typeInfo = new TypeInfo(schema2);
|
111
|
+
const schema2 = requireGraphQLSchema(RULE_ID, context), siblings = requireGraphQLOperations(RULE_ID, context), { fieldName = DEFAULT_ID_FIELD_NAME, requireAllFields } = context.options[0] || {}, idNames = asArray(fieldName), selector = "SelectionSet[parent.kind!=/(^OperationDefinition|InlineFragment)$/]", typeInfo = new TypeInfo(schema2);
|
108
112
|
function checkFragments(node) {
|
109
113
|
for (const selection of node.selections) {
|
110
114
|
if (selection.kind !== Kind.FRAGMENT_SPREAD)
|
@@ -146,30 +150,35 @@ Include it in your selection set{{ addition }}.`
|
|
146
150
|
}
|
147
151
|
function checkFields(rawType2) {
|
148
152
|
const fields = rawType2.getFields();
|
149
|
-
if (
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
153
|
+
if (idNames.some((name) => fields[name]))
|
154
|
+
if (checkFragments(node), requireAllFields)
|
155
|
+
for (const idName of idNames)
|
156
|
+
report([idName]);
|
157
|
+
else
|
158
|
+
report(idNames);
|
159
|
+
}
|
160
|
+
function hasIdField({ selections }, idNames2) {
|
161
|
+
return selections.some((selection) => {
|
162
|
+
if (selection.kind === Kind.FIELD)
|
163
|
+
return selection.alias && idNames2.includes(selection.alias.value) ? !0 : idNames2.includes(selection.name.value);
|
164
|
+
if (selection.kind === Kind.INLINE_FRAGMENT)
|
165
|
+
return hasIdField(selection.selectionSet, idNames2);
|
166
|
+
if (selection.kind === Kind.FRAGMENT_SPREAD) {
|
167
|
+
const [foundSpread] = siblings.getFragment(selection.name.value);
|
168
|
+
if (foundSpread) {
|
169
|
+
const fragmentSpread = foundSpread.document;
|
170
|
+
return checkedFragmentSpreads.add(fragmentSpread.name.value), hasIdField(fragmentSpread.selectionSet, idNames2);
|
163
171
|
}
|
164
|
-
|
165
|
-
|
166
|
-
}
|
167
|
-
|
168
|
-
|
172
|
+
}
|
173
|
+
return !1;
|
174
|
+
});
|
175
|
+
}
|
176
|
+
function report(idNames2) {
|
177
|
+
if (hasIdField(node, idNames2))
|
169
178
|
return;
|
170
|
-
const
|
171
|
-
|
172
|
-
), addition = checkedFragmentSpreads.size === 0 ? "" : ` or add to used fragment${checkedFragmentSpreads.size > 1 ? "s" : ""} ${englishJoinWords([...checkedFragmentSpreads].map((name) => `\`${name}\``))}`, problem = {
|
179
|
+
const fieldName2 = englishJoinWords(
|
180
|
+
idNames2.map((name) => `\`${(parent.alias || parent.name).value}.${name}\``)
|
181
|
+
), pluralSuffix = idNames2.length > 1 ? "s" : "", addition = checkedFragmentSpreads.size === 0 ? "" : ` or add to used fragment${checkedFragmentSpreads.size > 1 ? "s" : ""} ${englishJoinWords([...checkedFragmentSpreads].map((name) => `\`${name}\``))}`, problem = {
|
173
182
|
loc,
|
174
183
|
messageId: RULE_ID,
|
175
184
|
data: {
|
@@ -178,7 +187,7 @@ Include it in your selection set{{ addition }}.`
|
|
178
187
|
addition
|
179
188
|
}
|
180
189
|
};
|
181
|
-
"type" in node && (problem.suggest =
|
190
|
+
"type" in node && (problem.suggest = idNames2.map((idName) => ({
|
182
191
|
desc: `Add \`${idName}\` selection`,
|
183
192
|
fix: (fixer) => {
|
184
193
|
let insertNode = node.selections[0];
|
package/index.browser.js
CHANGED
@@ -150,7 +150,7 @@ function convertToESTree(node, schema16) {
|
|
150
150
|
}
|
151
151
|
|
152
152
|
// src/meta.ts
|
153
|
-
var version = "4.
|
153
|
+
var version = "4.2.0-alpha-20241129163655-f92a3665247a2f1c386ecaae7f3dcb301398ef03";
|
154
154
|
|
155
155
|
// src/siblings.ts
|
156
156
|
import {
|
@@ -4569,6 +4569,10 @@ var RULE_ID19 = "require-selections", DEFAULT_ID_FIELD_NAME = "id", schema13 = {
|
|
4569
4569
|
fieldName: {
|
4570
4570
|
oneOf: [{ $ref: "#/definitions/asString" }, { $ref: "#/definitions/asArray" }],
|
4571
4571
|
default: DEFAULT_ID_FIELD_NAME
|
4572
|
+
},
|
4573
|
+
requireAllFields: {
|
4574
|
+
type: "boolean",
|
4575
|
+
description: "Whether all fields of `fieldName` option must be included."
|
4572
4576
|
}
|
4573
4577
|
}
|
4574
4578
|
}
|
@@ -4642,7 +4646,7 @@ Include it in your selection set{{ addition }}.`
|
|
4642
4646
|
schema: schema13
|
4643
4647
|
},
|
4644
4648
|
create(context) {
|
4645
|
-
let schema16 = requireGraphQLSchema(RULE_ID19, context), siblings = requireGraphQLOperations(RULE_ID19, context), { fieldName = DEFAULT_ID_FIELD_NAME } = context.options[0] || {}, idNames = asArray(fieldName), selector = "SelectionSet[parent.kind!=/(^OperationDefinition|InlineFragment)$/]", typeInfo = new TypeInfo3(schema16);
|
4649
|
+
let schema16 = requireGraphQLSchema(RULE_ID19, context), siblings = requireGraphQLOperations(RULE_ID19, context), { fieldName = DEFAULT_ID_FIELD_NAME, requireAllFields } = context.options[0] || {}, idNames = asArray(fieldName), selector = "SelectionSet[parent.kind!=/(^OperationDefinition|InlineFragment)$/]", typeInfo = new TypeInfo3(schema16);
|
4646
4650
|
function checkFragments(node) {
|
4647
4651
|
for (let selection of node.selections) {
|
4648
4652
|
if (selection.kind !== Kind20.FRAGMENT_SPREAD)
|
@@ -4684,30 +4688,35 @@ Include it in your selection set{{ addition }}.`
|
|
4684
4688
|
}
|
4685
4689
|
function checkFields(rawType2) {
|
4686
4690
|
let fields = rawType2.getFields();
|
4687
|
-
if (
|
4688
|
-
|
4689
|
-
|
4690
|
-
|
4691
|
-
|
4692
|
-
|
4693
|
-
|
4694
|
-
|
4695
|
-
|
4696
|
-
|
4697
|
-
|
4698
|
-
|
4699
|
-
|
4700
|
-
|
4691
|
+
if (idNames.some((name) => fields[name]))
|
4692
|
+
if (checkFragments(node), requireAllFields)
|
4693
|
+
for (let idName of idNames)
|
4694
|
+
report([idName]);
|
4695
|
+
else
|
4696
|
+
report(idNames);
|
4697
|
+
}
|
4698
|
+
function hasIdField({ selections }, idNames2) {
|
4699
|
+
return selections.some((selection) => {
|
4700
|
+
if (selection.kind === Kind20.FIELD)
|
4701
|
+
return selection.alias && idNames2.includes(selection.alias.value) ? !0 : idNames2.includes(selection.name.value);
|
4702
|
+
if (selection.kind === Kind20.INLINE_FRAGMENT)
|
4703
|
+
return hasIdField(selection.selectionSet, idNames2);
|
4704
|
+
if (selection.kind === Kind20.FRAGMENT_SPREAD) {
|
4705
|
+
let [foundSpread] = siblings.getFragment(selection.name.value);
|
4706
|
+
if (foundSpread) {
|
4707
|
+
let fragmentSpread = foundSpread.document;
|
4708
|
+
return checkedFragmentSpreads.add(fragmentSpread.name.value), hasIdField(fragmentSpread.selectionSet, idNames2);
|
4701
4709
|
}
|
4702
|
-
|
4703
|
-
|
4704
|
-
}
|
4705
|
-
|
4706
|
-
|
4710
|
+
}
|
4711
|
+
return !1;
|
4712
|
+
});
|
4713
|
+
}
|
4714
|
+
function report(idNames2) {
|
4715
|
+
if (hasIdField(node, idNames2))
|
4707
4716
|
return;
|
4708
|
-
let
|
4709
|
-
|
4710
|
-
), addition = checkedFragmentSpreads.size === 0 ? "" : ` or add to used fragment${checkedFragmentSpreads.size > 1 ? "s" : ""} ${englishJoinWords([...checkedFragmentSpreads].map((name) => `\`${name}\``))}`, problem = {
|
4717
|
+
let fieldName2 = englishJoinWords(
|
4718
|
+
idNames2.map((name) => `\`${(parent.alias || parent.name).value}.${name}\``)
|
4719
|
+
), pluralSuffix = idNames2.length > 1 ? "s" : "", addition = checkedFragmentSpreads.size === 0 ? "" : ` or add to used fragment${checkedFragmentSpreads.size > 1 ? "s" : ""} ${englishJoinWords([...checkedFragmentSpreads].map((name) => `\`${name}\``))}`, problem = {
|
4711
4720
|
loc,
|
4712
4721
|
messageId: RULE_ID19,
|
4713
4722
|
data: {
|
@@ -4716,7 +4725,7 @@ Include it in your selection set{{ addition }}.`
|
|
4716
4725
|
addition
|
4717
4726
|
}
|
4718
4727
|
};
|
4719
|
-
"type" in node && (problem.suggest =
|
4728
|
+
"type" in node && (problem.suggest = idNames2.map((idName) => ({
|
4720
4729
|
desc: `Add \`${idName}\` selection`,
|
4721
4730
|
fix: (fixer) => {
|
4722
4731
|
let insertNode = node.selections[0];
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@graphql-eslint/eslint-plugin",
|
3
|
-
"version": "4.
|
3
|
+
"version": "4.2.0-alpha-20241129163655-f92a3665247a2f1c386ecaae7f3dcb301398ef03",
|
4
4
|
"type": "module",
|
5
5
|
"description": "GraphQL plugin for ESLint",
|
6
6
|
"repository": "https://github.com/dimaMachina/graphql-eslint",
|