@graphql-eslint/eslint-plugin 4.1.1 → 4.2.0-alpha-20241129163937-ff1cb29d1ca25d7abfb49258af431afa1709b739
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 +19 -10
- 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 +19 -10
- package/index.browser.js +20 -11
- 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-20241129163937-ff1cb29d1ca25d7abfb49258af431afa1709b739";
|
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,12 +150,18 @@ Include it in your selection set{{ addition }}.`
|
|
146
150
|
}
|
147
151
|
function checkFields(rawType2) {
|
148
152
|
const fields = rawType2.getFields();
|
149
|
-
if (
|
150
|
-
|
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 report(idNames2) {
|
151
161
|
function hasIdField({ selections }) {
|
152
162
|
return selections.some((selection) => {
|
153
163
|
if (selection.kind === _graphql.Kind.FIELD)
|
154
|
-
return selection.alias &&
|
164
|
+
return selection.alias && idNames2.includes(selection.alias.value) ? !0 : idNames2.includes(selection.name.value);
|
155
165
|
if (selection.kind === _graphql.Kind.INLINE_FRAGMENT)
|
156
166
|
return hasIdField(selection.selectionSet);
|
157
167
|
if (selection.kind === _graphql.Kind.FRAGMENT_SPREAD) {
|
@@ -164,12 +174,11 @@ Include it in your selection set{{ addition }}.`
|
|
164
174
|
return !1;
|
165
175
|
});
|
166
176
|
}
|
167
|
-
|
168
|
-
if (checkFragments(node), hasId)
|
177
|
+
if (hasIdField(node))
|
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,12 +150,18 @@ Include it in your selection set{{ addition }}.`
|
|
146
150
|
}
|
147
151
|
function checkFields(rawType2) {
|
148
152
|
const fields = rawType2.getFields();
|
149
|
-
if (
|
150
|
-
|
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 report(idNames2) {
|
151
161
|
function hasIdField({ selections }) {
|
152
162
|
return selections.some((selection) => {
|
153
163
|
if (selection.kind === Kind.FIELD)
|
154
|
-
return selection.alias &&
|
164
|
+
return selection.alias && idNames2.includes(selection.alias.value) ? !0 : idNames2.includes(selection.name.value);
|
155
165
|
if (selection.kind === Kind.INLINE_FRAGMENT)
|
156
166
|
return hasIdField(selection.selectionSet);
|
157
167
|
if (selection.kind === Kind.FRAGMENT_SPREAD) {
|
@@ -164,12 +174,11 @@ Include it in your selection set{{ addition }}.`
|
|
164
174
|
return !1;
|
165
175
|
});
|
166
176
|
}
|
167
|
-
|
168
|
-
if (checkFragments(node), hasId)
|
177
|
+
if (hasIdField(node))
|
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-20241129163937-ff1cb29d1ca25d7abfb49258af431afa1709b739";
|
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,12 +4688,18 @@ Include it in your selection set{{ addition }}.`
|
|
4684
4688
|
}
|
4685
4689
|
function checkFields(rawType2) {
|
4686
4690
|
let fields = rawType2.getFields();
|
4687
|
-
if (
|
4688
|
-
|
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 report(idNames2) {
|
4689
4699
|
function hasIdField({ selections }) {
|
4690
4700
|
return selections.some((selection) => {
|
4691
4701
|
if (selection.kind === Kind20.FIELD)
|
4692
|
-
return selection.alias &&
|
4702
|
+
return selection.alias && idNames2.includes(selection.alias.value) ? !0 : idNames2.includes(selection.name.value);
|
4693
4703
|
if (selection.kind === Kind20.INLINE_FRAGMENT)
|
4694
4704
|
return hasIdField(selection.selectionSet);
|
4695
4705
|
if (selection.kind === Kind20.FRAGMENT_SPREAD) {
|
@@ -4702,12 +4712,11 @@ Include it in your selection set{{ addition }}.`
|
|
4702
4712
|
return !1;
|
4703
4713
|
});
|
4704
4714
|
}
|
4705
|
-
|
4706
|
-
if (checkFragments(node), hasId)
|
4715
|
+
if (hasIdField(node))
|
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-20241129163937-ff1cb29d1ca25d7abfb49258af431afa1709b739",
|
4
4
|
"type": "module",
|
5
5
|
"description": "GraphQL plugin for ESLint",
|
6
6
|
"repository": "https://github.com/dimaMachina/graphql-eslint",
|