@graphql-eslint/eslint-plugin 4.0.0-alpha.7 → 4.0.0-alpha.8
Sign up to get free protection for your applications and to get access to all the features.
- package/cjs/configs/operations-all.js +1 -1
- package/cjs/meta.js +1 -1
- package/cjs/rules/alphabetize/index.d.cts +1 -1
- package/cjs/rules/alphabetize/index.js +27 -11
- package/cjs/utils.js +37 -14
- package/esm/configs/operations-all.js +1 -1
- package/esm/meta.js +1 -1
- package/esm/rules/alphabetize/index.d.ts +1 -1
- package/esm/rules/alphabetize/index.js +24 -8
- package/esm/utils.js +37 -14
- package/index.browser.js +62 -23
- package/package.json +1 -1
@@ -13,7 +13,7 @@ var require_operations_all = _chunkUIAXBAMDjs.__commonJS.call(void 0, {
|
|
13
13
|
selections: ["OperationDefinition", "FragmentDefinition"],
|
14
14
|
variables: !0,
|
15
15
|
arguments: ["Field", "Directive"],
|
16
|
-
groups: ["
|
16
|
+
groups: ["...", "id", "*", "{"]
|
17
17
|
}
|
18
18
|
],
|
19
19
|
"@graphql-eslint/lone-executable-definition": "error",
|
package/cjs/meta.js
CHANGED
@@ -58,7 +58,7 @@ declare const schema: {
|
|
58
58
|
};
|
59
59
|
readonly groups: {
|
60
60
|
readonly minItems: 2;
|
61
|
-
readonly description:
|
61
|
+
readonly description: string;
|
62
62
|
readonly type: "array";
|
63
63
|
readonly uniqueItems: true;
|
64
64
|
readonly items: {
|
@@ -61,7 +61,14 @@ const RULE_ID = "alphabetize", fieldsEnum = [
|
|
61
61
|
groups: {
|
62
62
|
..._utilsjs.ARRAY_DEFAULT_OPTIONS,
|
63
63
|
minItems: 2,
|
64
|
-
description:
|
64
|
+
description: [
|
65
|
+
"Order group. Example: `['...', 'id', '*', '{']` where:",
|
66
|
+
"- `...` stands for fragment spreads",
|
67
|
+
"- `id` stands for field with name `id`",
|
68
|
+
"- `*` stands for everything else",
|
69
|
+
"- `{` stands for fields `selection set`"
|
70
|
+
].join(`
|
71
|
+
`)
|
65
72
|
}
|
66
73
|
}
|
67
74
|
}
|
@@ -183,7 +190,7 @@ const RULE_ID = "alphabetize", fieldsEnum = [
|
|
183
190
|
selections: selectionsEnum,
|
184
191
|
variables: !0,
|
185
192
|
arguments: [_graphql.Kind.FIELD, _graphql.Kind.DIRECTIVE],
|
186
|
-
groups: ["
|
193
|
+
groups: ["...", "id", "*", "{"]
|
187
194
|
}
|
188
195
|
]
|
189
196
|
}
|
@@ -221,20 +228,18 @@ const RULE_ID = "alphabetize", fieldsEnum = [
|
|
221
228
|
}
|
222
229
|
function checkNodes(nodes = []) {
|
223
230
|
for (let i = 1; i < nodes.length; i += 1) {
|
224
|
-
const currNode = nodes[i], currName =
|
231
|
+
const currNode = nodes[i], currName = getName(currNode);
|
225
232
|
if (!currName)
|
226
233
|
continue;
|
227
|
-
const prevNode = nodes[i - 1], prevName =
|
234
|
+
const prevNode = nodes[i - 1], prevName = getName(prevNode);
|
228
235
|
if (prevName) {
|
229
236
|
const compareResult = prevName.localeCompare(currName), { groups } = opts;
|
230
237
|
let shouldSortByGroup = !1;
|
231
|
-
if (_optionalChain([groups, 'optionalAccess',
|
238
|
+
if (_optionalChain([groups, 'optionalAccess', _ => _.length])) {
|
232
239
|
if (!groups.includes("*"))
|
233
240
|
throw new Error("`groups` option should contain `*` string.");
|
234
|
-
|
235
|
-
indexForPrev
|
236
|
-
let indexForCurr = groups.indexOf(currName);
|
237
|
-
if (indexForCurr === -1 && (indexForCurr = groups.indexOf("*")), shouldSortByGroup = indexForPrev - indexForCurr > 0, indexForPrev < indexForCurr)
|
241
|
+
const indexForPrev = getIndex({ node: prevNode, groups }), indexForCurr = getIndex({ node: currNode, groups });
|
242
|
+
if (shouldSortByGroup = indexForPrev - indexForCurr > 0, indexForPrev < indexForCurr)
|
238
243
|
continue;
|
239
244
|
}
|
240
245
|
if (!shouldSortByGroup && !(compareResult === 1) && (!(compareResult === 0) || !prevNode.kind.endsWith("Extension") || currNode.kind.endsWith("Extension")))
|
@@ -274,7 +279,7 @@ const RULE_ID = "alphabetize", fieldsEnum = [
|
|
274
279
|
_graphql.Kind.INPUT_OBJECT_TYPE_DEFINITION,
|
275
280
|
_graphql.Kind.INPUT_OBJECT_TYPE_EXTENSION
|
276
281
|
]
|
277
|
-
].filter(_utilsjs.truthy).flat().join(","), selectionsSelector = _optionalChain([opts, 'access',
|
282
|
+
].filter(_utilsjs.truthy).flat().join(","), selectionsSelector = _optionalChain([opts, 'access', _2 => _2.selections, 'optionalAccess', _3 => _3.join, 'call', _4 => _4(",")]), argumentsSelector = _optionalChain([opts, 'access', _5 => _5.arguments, 'optionalAccess', _6 => _6.join, 'call', _7 => _7(",")]);
|
278
283
|
if (fieldsSelector && (listeners[fieldsSelector] = (node) => {
|
279
284
|
checkNodes(node.fields);
|
280
285
|
}), opts.values) {
|
@@ -286,7 +291,7 @@ const RULE_ID = "alphabetize", fieldsEnum = [
|
|
286
291
|
return selectionsSelector && (listeners[`:matches(${selectionsSelector}) SelectionSet`] = (node) => {
|
287
292
|
checkNodes(node.selections);
|
288
293
|
}), opts.variables && (listeners.OperationDefinition = (node) => {
|
289
|
-
checkNodes(_optionalChain([node, 'access',
|
294
|
+
checkNodes(_optionalChain([node, 'access', _8 => _8.variableDefinitions, 'optionalAccess', _9 => _9.map, 'call', _10 => _10((varDef) => varDef.variable)]));
|
290
295
|
}), argumentsSelector && (listeners[argumentsSelector] = (node) => {
|
291
296
|
checkNodes(node.arguments);
|
292
297
|
}), opts.definitions && (listeners.Document = (node) => {
|
@@ -294,6 +299,17 @@ const RULE_ID = "alphabetize", fieldsEnum = [
|
|
294
299
|
}), listeners;
|
295
300
|
}
|
296
301
|
};
|
302
|
+
function getIndex({
|
303
|
+
node,
|
304
|
+
groups
|
305
|
+
}) {
|
306
|
+
let index = groups.indexOf(getName(node));
|
307
|
+
return index === -1 && "selectionSet" in node && node.selectionSet && (index = groups.indexOf("{")), index === -1 && node.kind === _graphql.Kind.FRAGMENT_SPREAD && (index = groups.indexOf("...")), index === -1 && (index = groups.indexOf("*")), index;
|
308
|
+
}
|
309
|
+
function getName(node) {
|
310
|
+
return "alias" in node && _optionalChain([node, 'access', _11 => _11.alias, 'optionalAccess', _12 => _12.value]) || //
|
311
|
+
"name" in node && _optionalChain([node, 'access', _13 => _13.name, 'optionalAccess', _14 => _14.value]) || "";
|
312
|
+
}
|
297
313
|
|
298
314
|
|
299
315
|
exports.rule = rule;
|
package/cjs/utils.js
CHANGED
@@ -78,26 +78,49 @@ function truthy(value) {
|
|
78
78
|
return !!value;
|
79
79
|
}
|
80
80
|
const DisplayNodeNameMap = {
|
81
|
-
[_graphql.Kind.
|
82
|
-
[_graphql.Kind.
|
83
|
-
[_graphql.Kind.
|
84
|
-
[_graphql.Kind.
|
81
|
+
[_graphql.Kind.ARGUMENT]: "argument",
|
82
|
+
[_graphql.Kind.BOOLEAN]: "boolean",
|
83
|
+
[_graphql.Kind.DIRECTIVE_DEFINITION]: "directive",
|
84
|
+
[_graphql.Kind.DIRECTIVE]: "directive",
|
85
|
+
[_graphql.Kind.DOCUMENT]: "document",
|
85
86
|
[_graphql.Kind.ENUM_TYPE_DEFINITION]: "enum",
|
86
87
|
[_graphql.Kind.ENUM_TYPE_EXTENSION]: "enum",
|
87
|
-
[_graphql.Kind.
|
88
|
+
[_graphql.Kind.ENUM_VALUE_DEFINITION]: "enum value",
|
89
|
+
[_graphql.Kind.ENUM]: "enum",
|
90
|
+
[_graphql.Kind.FIELD_DEFINITION]: "field",
|
91
|
+
[_graphql.Kind.FIELD]: "field",
|
92
|
+
[_graphql.Kind.FLOAT]: "float",
|
93
|
+
[_graphql.Kind.FRAGMENT_DEFINITION]: "fragment",
|
94
|
+
[_graphql.Kind.FRAGMENT_SPREAD]: "fragment spread",
|
95
|
+
[_graphql.Kind.INLINE_FRAGMENT]: "inline fragment",
|
88
96
|
[_graphql.Kind.INPUT_OBJECT_TYPE_DEFINITION]: "input",
|
89
97
|
[_graphql.Kind.INPUT_OBJECT_TYPE_EXTENSION]: "input",
|
90
|
-
[_graphql.Kind.UNION_TYPE_DEFINITION]: "union",
|
91
|
-
[_graphql.Kind.UNION_TYPE_EXTENSION]: "union",
|
92
|
-
[_graphql.Kind.DIRECTIVE_DEFINITION]: "directive",
|
93
|
-
[_graphql.Kind.FIELD_DEFINITION]: "field",
|
94
|
-
[_graphql.Kind.ENUM_VALUE_DEFINITION]: "enum value",
|
95
98
|
[_graphql.Kind.INPUT_VALUE_DEFINITION]: "input value",
|
96
|
-
[_graphql.Kind.
|
97
|
-
[_graphql.Kind.
|
98
|
-
[_graphql.Kind.
|
99
|
+
[_graphql.Kind.INT]: "int",
|
100
|
+
[_graphql.Kind.INTERFACE_TYPE_DEFINITION]: "interface",
|
101
|
+
[_graphql.Kind.INTERFACE_TYPE_EXTENSION]: "interface",
|
102
|
+
[_graphql.Kind.LIST_TYPE]: "list type",
|
103
|
+
[_graphql.Kind.LIST]: "list",
|
104
|
+
[_graphql.Kind.NAME]: "name",
|
105
|
+
[_graphql.Kind.NAMED_TYPE]: "named type",
|
106
|
+
[_graphql.Kind.NON_NULL_TYPE]: "non-null type",
|
107
|
+
[_graphql.Kind.NULL]: "null",
|
108
|
+
[_graphql.Kind.OBJECT_FIELD]: "object field",
|
109
|
+
[_graphql.Kind.OBJECT_TYPE_DEFINITION]: "type",
|
110
|
+
[_graphql.Kind.OBJECT_TYPE_EXTENSION]: "type",
|
111
|
+
[_graphql.Kind.OBJECT]: "object",
|
99
112
|
[_graphql.Kind.OPERATION_DEFINITION]: "operation",
|
100
|
-
[_graphql.Kind.
|
113
|
+
[_graphql.Kind.OPERATION_TYPE_DEFINITION]: "operation type",
|
114
|
+
[_graphql.Kind.SCALAR_TYPE_DEFINITION]: "scalar",
|
115
|
+
[_graphql.Kind.SCALAR_TYPE_EXTENSION]: "scalar",
|
116
|
+
[_graphql.Kind.SCHEMA_DEFINITION]: "schema",
|
117
|
+
[_graphql.Kind.SCHEMA_EXTENSION]: "schema",
|
118
|
+
[_graphql.Kind.SELECTION_SET]: "selection set",
|
119
|
+
[_graphql.Kind.STRING]: "string",
|
120
|
+
[_graphql.Kind.UNION_TYPE_DEFINITION]: "union",
|
121
|
+
[_graphql.Kind.UNION_TYPE_EXTENSION]: "union",
|
122
|
+
[_graphql.Kind.VARIABLE_DEFINITION]: "variable",
|
123
|
+
[_graphql.Kind.VARIABLE]: "variable"
|
101
124
|
};
|
102
125
|
function displayNodeName(node) {
|
103
126
|
return `${node.kind === _graphql.Kind.OPERATION_DEFINITION ? node.operation : DisplayNodeNameMap[node.kind]} "${"alias" in node && _optionalChain([node, 'access', _ => _.alias, 'optionalAccess', _2 => _2.value]) || "name" in node && _optionalChain([node, 'access', _3 => _3.name, 'optionalAccess', _4 => _4.value])}"`;
|
@@ -13,7 +13,7 @@ var require_operations_all = __commonJS({
|
|
13
13
|
selections: ["OperationDefinition", "FragmentDefinition"],
|
14
14
|
variables: !0,
|
15
15
|
arguments: ["Field", "Directive"],
|
16
|
-
groups: ["
|
16
|
+
groups: ["...", "id", "*", "{"]
|
17
17
|
}
|
18
18
|
],
|
19
19
|
"@graphql-eslint/lone-executable-definition": "error",
|
package/esm/meta.js
CHANGED
@@ -58,7 +58,7 @@ declare const schema: {
|
|
58
58
|
};
|
59
59
|
readonly groups: {
|
60
60
|
readonly minItems: 2;
|
61
|
-
readonly description:
|
61
|
+
readonly description: string;
|
62
62
|
readonly type: "array";
|
63
63
|
readonly uniqueItems: true;
|
64
64
|
readonly items: {
|
@@ -61,7 +61,14 @@ const RULE_ID = "alphabetize", fieldsEnum = [
|
|
61
61
|
groups: {
|
62
62
|
...ARRAY_DEFAULT_OPTIONS,
|
63
63
|
minItems: 2,
|
64
|
-
description:
|
64
|
+
description: [
|
65
|
+
"Order group. Example: `['...', 'id', '*', '{']` where:",
|
66
|
+
"- `...` stands for fragment spreads",
|
67
|
+
"- `id` stands for field with name `id`",
|
68
|
+
"- `*` stands for everything else",
|
69
|
+
"- `{` stands for fields `selection set`"
|
70
|
+
].join(`
|
71
|
+
`)
|
65
72
|
}
|
66
73
|
}
|
67
74
|
}
|
@@ -183,7 +190,7 @@ const RULE_ID = "alphabetize", fieldsEnum = [
|
|
183
190
|
selections: selectionsEnum,
|
184
191
|
variables: !0,
|
185
192
|
arguments: [Kind.FIELD, Kind.DIRECTIVE],
|
186
|
-
groups: ["
|
193
|
+
groups: ["...", "id", "*", "{"]
|
187
194
|
}
|
188
195
|
]
|
189
196
|
}
|
@@ -221,20 +228,18 @@ const RULE_ID = "alphabetize", fieldsEnum = [
|
|
221
228
|
}
|
222
229
|
function checkNodes(nodes = []) {
|
223
230
|
for (let i = 1; i < nodes.length; i += 1) {
|
224
|
-
const currNode = nodes[i], currName =
|
231
|
+
const currNode = nodes[i], currName = getName(currNode);
|
225
232
|
if (!currName)
|
226
233
|
continue;
|
227
|
-
const prevNode = nodes[i - 1], prevName =
|
234
|
+
const prevNode = nodes[i - 1], prevName = getName(prevNode);
|
228
235
|
if (prevName) {
|
229
236
|
const compareResult = prevName.localeCompare(currName), { groups } = opts;
|
230
237
|
let shouldSortByGroup = !1;
|
231
238
|
if (groups?.length) {
|
232
239
|
if (!groups.includes("*"))
|
233
240
|
throw new Error("`groups` option should contain `*` string.");
|
234
|
-
|
235
|
-
indexForPrev
|
236
|
-
let indexForCurr = groups.indexOf(currName);
|
237
|
-
if (indexForCurr === -1 && (indexForCurr = groups.indexOf("*")), shouldSortByGroup = indexForPrev - indexForCurr > 0, indexForPrev < indexForCurr)
|
241
|
+
const indexForPrev = getIndex({ node: prevNode, groups }), indexForCurr = getIndex({ node: currNode, groups });
|
242
|
+
if (shouldSortByGroup = indexForPrev - indexForCurr > 0, indexForPrev < indexForCurr)
|
238
243
|
continue;
|
239
244
|
}
|
240
245
|
if (!shouldSortByGroup && !(compareResult === 1) && (!(compareResult === 0) || !prevNode.kind.endsWith("Extension") || currNode.kind.endsWith("Extension")))
|
@@ -294,6 +299,17 @@ const RULE_ID = "alphabetize", fieldsEnum = [
|
|
294
299
|
}), listeners;
|
295
300
|
}
|
296
301
|
};
|
302
|
+
function getIndex({
|
303
|
+
node,
|
304
|
+
groups
|
305
|
+
}) {
|
306
|
+
let index = groups.indexOf(getName(node));
|
307
|
+
return index === -1 && "selectionSet" in node && node.selectionSet && (index = groups.indexOf("{")), index === -1 && node.kind === Kind.FRAGMENT_SPREAD && (index = groups.indexOf("...")), index === -1 && (index = groups.indexOf("*")), index;
|
308
|
+
}
|
309
|
+
function getName(node) {
|
310
|
+
return "alias" in node && node.alias?.value || //
|
311
|
+
"name" in node && node.name?.value || "";
|
312
|
+
}
|
297
313
|
export {
|
298
314
|
rule
|
299
315
|
};
|
package/esm/utils.js
CHANGED
@@ -78,26 +78,49 @@ function truthy(value) {
|
|
78
78
|
return !!value;
|
79
79
|
}
|
80
80
|
const DisplayNodeNameMap = {
|
81
|
-
[Kind.
|
82
|
-
[Kind.
|
83
|
-
[Kind.
|
84
|
-
[Kind.
|
81
|
+
[Kind.ARGUMENT]: "argument",
|
82
|
+
[Kind.BOOLEAN]: "boolean",
|
83
|
+
[Kind.DIRECTIVE_DEFINITION]: "directive",
|
84
|
+
[Kind.DIRECTIVE]: "directive",
|
85
|
+
[Kind.DOCUMENT]: "document",
|
85
86
|
[Kind.ENUM_TYPE_DEFINITION]: "enum",
|
86
87
|
[Kind.ENUM_TYPE_EXTENSION]: "enum",
|
87
|
-
[Kind.
|
88
|
+
[Kind.ENUM_VALUE_DEFINITION]: "enum value",
|
89
|
+
[Kind.ENUM]: "enum",
|
90
|
+
[Kind.FIELD_DEFINITION]: "field",
|
91
|
+
[Kind.FIELD]: "field",
|
92
|
+
[Kind.FLOAT]: "float",
|
93
|
+
[Kind.FRAGMENT_DEFINITION]: "fragment",
|
94
|
+
[Kind.FRAGMENT_SPREAD]: "fragment spread",
|
95
|
+
[Kind.INLINE_FRAGMENT]: "inline fragment",
|
88
96
|
[Kind.INPUT_OBJECT_TYPE_DEFINITION]: "input",
|
89
97
|
[Kind.INPUT_OBJECT_TYPE_EXTENSION]: "input",
|
90
|
-
[Kind.UNION_TYPE_DEFINITION]: "union",
|
91
|
-
[Kind.UNION_TYPE_EXTENSION]: "union",
|
92
|
-
[Kind.DIRECTIVE_DEFINITION]: "directive",
|
93
|
-
[Kind.FIELD_DEFINITION]: "field",
|
94
|
-
[Kind.ENUM_VALUE_DEFINITION]: "enum value",
|
95
98
|
[Kind.INPUT_VALUE_DEFINITION]: "input value",
|
96
|
-
[Kind.
|
97
|
-
[Kind.
|
98
|
-
[Kind.
|
99
|
+
[Kind.INT]: "int",
|
100
|
+
[Kind.INTERFACE_TYPE_DEFINITION]: "interface",
|
101
|
+
[Kind.INTERFACE_TYPE_EXTENSION]: "interface",
|
102
|
+
[Kind.LIST_TYPE]: "list type",
|
103
|
+
[Kind.LIST]: "list",
|
104
|
+
[Kind.NAME]: "name",
|
105
|
+
[Kind.NAMED_TYPE]: "named type",
|
106
|
+
[Kind.NON_NULL_TYPE]: "non-null type",
|
107
|
+
[Kind.NULL]: "null",
|
108
|
+
[Kind.OBJECT_FIELD]: "object field",
|
109
|
+
[Kind.OBJECT_TYPE_DEFINITION]: "type",
|
110
|
+
[Kind.OBJECT_TYPE_EXTENSION]: "type",
|
111
|
+
[Kind.OBJECT]: "object",
|
99
112
|
[Kind.OPERATION_DEFINITION]: "operation",
|
100
|
-
[Kind.
|
113
|
+
[Kind.OPERATION_TYPE_DEFINITION]: "operation type",
|
114
|
+
[Kind.SCALAR_TYPE_DEFINITION]: "scalar",
|
115
|
+
[Kind.SCALAR_TYPE_EXTENSION]: "scalar",
|
116
|
+
[Kind.SCHEMA_DEFINITION]: "schema",
|
117
|
+
[Kind.SCHEMA_EXTENSION]: "schema",
|
118
|
+
[Kind.SELECTION_SET]: "selection set",
|
119
|
+
[Kind.STRING]: "string",
|
120
|
+
[Kind.UNION_TYPE_DEFINITION]: "union",
|
121
|
+
[Kind.UNION_TYPE_EXTENSION]: "union",
|
122
|
+
[Kind.VARIABLE_DEFINITION]: "variable",
|
123
|
+
[Kind.VARIABLE]: "variable"
|
101
124
|
};
|
102
125
|
function displayNodeName(node) {
|
103
126
|
return `${node.kind === Kind.OPERATION_DEFINITION ? node.operation : DisplayNodeNameMap[node.kind]} "${"alias" in node && node.alias?.value || "name" in node && node.name?.value}"`;
|
package/index.browser.js
CHANGED
@@ -35,7 +35,7 @@ var require_operations_all = __commonJS({
|
|
35
35
|
selections: ["OperationDefinition", "FragmentDefinition"],
|
36
36
|
variables: !0,
|
37
37
|
arguments: ["Field", "Directive"],
|
38
|
-
groups: ["
|
38
|
+
groups: ["...", "id", "*", "{"]
|
39
39
|
}
|
40
40
|
],
|
41
41
|
"@graphql-eslint/lone-executable-definition": "error",
|
@@ -476,26 +476,49 @@ function truthy(value) {
|
|
476
476
|
return !!value;
|
477
477
|
}
|
478
478
|
var DisplayNodeNameMap = {
|
479
|
-
[Kind2.
|
480
|
-
[Kind2.
|
481
|
-
[Kind2.
|
482
|
-
[Kind2.
|
479
|
+
[Kind2.ARGUMENT]: "argument",
|
480
|
+
[Kind2.BOOLEAN]: "boolean",
|
481
|
+
[Kind2.DIRECTIVE_DEFINITION]: "directive",
|
482
|
+
[Kind2.DIRECTIVE]: "directive",
|
483
|
+
[Kind2.DOCUMENT]: "document",
|
483
484
|
[Kind2.ENUM_TYPE_DEFINITION]: "enum",
|
484
485
|
[Kind2.ENUM_TYPE_EXTENSION]: "enum",
|
485
|
-
[Kind2.
|
486
|
+
[Kind2.ENUM_VALUE_DEFINITION]: "enum value",
|
487
|
+
[Kind2.ENUM]: "enum",
|
488
|
+
[Kind2.FIELD_DEFINITION]: "field",
|
489
|
+
[Kind2.FIELD]: "field",
|
490
|
+
[Kind2.FLOAT]: "float",
|
491
|
+
[Kind2.FRAGMENT_DEFINITION]: "fragment",
|
492
|
+
[Kind2.FRAGMENT_SPREAD]: "fragment spread",
|
493
|
+
[Kind2.INLINE_FRAGMENT]: "inline fragment",
|
486
494
|
[Kind2.INPUT_OBJECT_TYPE_DEFINITION]: "input",
|
487
495
|
[Kind2.INPUT_OBJECT_TYPE_EXTENSION]: "input",
|
488
|
-
[Kind2.UNION_TYPE_DEFINITION]: "union",
|
489
|
-
[Kind2.UNION_TYPE_EXTENSION]: "union",
|
490
|
-
[Kind2.DIRECTIVE_DEFINITION]: "directive",
|
491
|
-
[Kind2.FIELD_DEFINITION]: "field",
|
492
|
-
[Kind2.ENUM_VALUE_DEFINITION]: "enum value",
|
493
496
|
[Kind2.INPUT_VALUE_DEFINITION]: "input value",
|
494
|
-
[Kind2.
|
495
|
-
[Kind2.
|
496
|
-
[Kind2.
|
497
|
+
[Kind2.INT]: "int",
|
498
|
+
[Kind2.INTERFACE_TYPE_DEFINITION]: "interface",
|
499
|
+
[Kind2.INTERFACE_TYPE_EXTENSION]: "interface",
|
500
|
+
[Kind2.LIST_TYPE]: "list type",
|
501
|
+
[Kind2.LIST]: "list",
|
502
|
+
[Kind2.NAME]: "name",
|
503
|
+
[Kind2.NAMED_TYPE]: "named type",
|
504
|
+
[Kind2.NON_NULL_TYPE]: "non-null type",
|
505
|
+
[Kind2.NULL]: "null",
|
506
|
+
[Kind2.OBJECT_FIELD]: "object field",
|
507
|
+
[Kind2.OBJECT_TYPE_DEFINITION]: "type",
|
508
|
+
[Kind2.OBJECT_TYPE_EXTENSION]: "type",
|
509
|
+
[Kind2.OBJECT]: "object",
|
497
510
|
[Kind2.OPERATION_DEFINITION]: "operation",
|
498
|
-
[Kind2.
|
511
|
+
[Kind2.OPERATION_TYPE_DEFINITION]: "operation type",
|
512
|
+
[Kind2.SCALAR_TYPE_DEFINITION]: "scalar",
|
513
|
+
[Kind2.SCALAR_TYPE_EXTENSION]: "scalar",
|
514
|
+
[Kind2.SCHEMA_DEFINITION]: "schema",
|
515
|
+
[Kind2.SCHEMA_EXTENSION]: "schema",
|
516
|
+
[Kind2.SELECTION_SET]: "selection set",
|
517
|
+
[Kind2.STRING]: "string",
|
518
|
+
[Kind2.UNION_TYPE_DEFINITION]: "union",
|
519
|
+
[Kind2.UNION_TYPE_EXTENSION]: "union",
|
520
|
+
[Kind2.VARIABLE_DEFINITION]: "variable",
|
521
|
+
[Kind2.VARIABLE]: "variable"
|
499
522
|
};
|
500
523
|
function displayNodeName(node) {
|
501
524
|
return `${node.kind === Kind2.OPERATION_DEFINITION ? node.operation : DisplayNodeNameMap[node.kind]} "${"alias" in node && node.alias?.value || "name" in node && node.name?.value}"`;
|
@@ -726,7 +749,14 @@ var RULE_ID = "alphabetize", fieldsEnum = [
|
|
726
749
|
groups: {
|
727
750
|
...ARRAY_DEFAULT_OPTIONS,
|
728
751
|
minItems: 2,
|
729
|
-
description:
|
752
|
+
description: [
|
753
|
+
"Order group. Example: `['...', 'id', '*', '{']` where:",
|
754
|
+
"- `...` stands for fragment spreads",
|
755
|
+
"- `id` stands for field with name `id`",
|
756
|
+
"- `*` stands for everything else",
|
757
|
+
"- `{` stands for fields `selection set`"
|
758
|
+
].join(`
|
759
|
+
`)
|
730
760
|
}
|
731
761
|
}
|
732
762
|
}
|
@@ -848,7 +878,7 @@ var RULE_ID = "alphabetize", fieldsEnum = [
|
|
848
878
|
selections: selectionsEnum,
|
849
879
|
variables: !0,
|
850
880
|
arguments: [Kind4.FIELD, Kind4.DIRECTIVE],
|
851
|
-
groups: ["
|
881
|
+
groups: ["...", "id", "*", "{"]
|
852
882
|
}
|
853
883
|
]
|
854
884
|
}
|
@@ -886,19 +916,17 @@ var RULE_ID = "alphabetize", fieldsEnum = [
|
|
886
916
|
}
|
887
917
|
function checkNodes(nodes = []) {
|
888
918
|
for (let i = 1; i < nodes.length; i += 1) {
|
889
|
-
let currNode = nodes[i], currName =
|
919
|
+
let currNode = nodes[i], currName = getName(currNode);
|
890
920
|
if (!currName)
|
891
921
|
continue;
|
892
|
-
let prevNode = nodes[i - 1], prevName =
|
922
|
+
let prevNode = nodes[i - 1], prevName = getName(prevNode);
|
893
923
|
if (prevName) {
|
894
924
|
let compareResult = prevName.localeCompare(currName), { groups } = opts, shouldSortByGroup = !1;
|
895
925
|
if (groups?.length) {
|
896
926
|
if (!groups.includes("*"))
|
897
927
|
throw new Error("`groups` option should contain `*` string.");
|
898
|
-
let indexForPrev = groups
|
899
|
-
indexForPrev
|
900
|
-
let indexForCurr = groups.indexOf(currName);
|
901
|
-
if (indexForCurr === -1 && (indexForCurr = groups.indexOf("*")), shouldSortByGroup = indexForPrev - indexForCurr > 0, indexForPrev < indexForCurr)
|
928
|
+
let indexForPrev = getIndex({ node: prevNode, groups }), indexForCurr = getIndex({ node: currNode, groups });
|
929
|
+
if (shouldSortByGroup = indexForPrev - indexForCurr > 0, indexForPrev < indexForCurr)
|
902
930
|
continue;
|
903
931
|
}
|
904
932
|
if (!shouldSortByGroup && !(compareResult === 1) && (!(compareResult === 0) || !prevNode.kind.endsWith("Extension") || currNode.kind.endsWith("Extension")))
|
@@ -958,6 +986,17 @@ var RULE_ID = "alphabetize", fieldsEnum = [
|
|
958
986
|
}), listeners;
|
959
987
|
}
|
960
988
|
};
|
989
|
+
function getIndex({
|
990
|
+
node,
|
991
|
+
groups
|
992
|
+
}) {
|
993
|
+
let index = groups.indexOf(getName(node));
|
994
|
+
return index === -1 && "selectionSet" in node && node.selectionSet && (index = groups.indexOf("{")), index === -1 && node.kind === Kind4.FRAGMENT_SPREAD && (index = groups.indexOf("...")), index === -1 && (index = groups.indexOf("*")), index;
|
995
|
+
}
|
996
|
+
function getName(node) {
|
997
|
+
return "alias" in node && node.alias?.value || //
|
998
|
+
"name" in node && node.name?.value || "";
|
999
|
+
}
|
961
1000
|
|
962
1001
|
// src/rules/description-style/index.ts
|
963
1002
|
var schema2 = {
|