@graphql-eslint/eslint-plugin 4.0.0-alpha.7 → 4.0.0-alpha.9

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.
@@ -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: ["id", "*", "createdAt", "updatedAt"]
16
+ groups: ["...", "id", "*", "{"]
17
17
  }
18
18
  ],
19
19
  "@graphql-eslint/lone-executable-definition": "error",
package/cjs/documents.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }require('./chunk-UIAXBAMD.js');
2
- var _nodepath = require('node:path');
2
+ var _nodepath = require('node:path'); var _nodepath2 = _interopRequireDefault(_nodepath);
3
3
  var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
4
4
  var _fastglob = require('fast-glob'); var _fastglob2 = _interopRequireDefault(_fastglob);
5
5
  var _cachejs = require('./cache.js');
@@ -8,12 +8,17 @@ const debug = _debug2.default.call(void 0, "graphql-eslint:operations"), operati
8
8
  return documents.map((source) => {
9
9
  const location = source.location;
10
10
  if ([".gql", ".graphql"].some((extension) => location.endsWith(extension)))
11
- return source;
11
+ return {
12
+ ...source,
13
+ // When using glob pattern e.g. `**/*.gql` location contains always forward slashes even on
14
+ // Windows
15
+ location: _nodepath2.default.resolve(location)
16
+ };
12
17
  filepathMap[location] ??= -1;
13
18
  const index = filepathMap[location] += 1;
14
19
  return {
15
20
  ...source,
16
- location: _nodepath.resolve.call(void 0, location, `${index}_document.graphql`)
21
+ location: _nodepath2.default.resolve(location, `${index}_document.graphql`)
17
22
  };
18
23
  });
19
24
  }, getDocuments = exports.getDocuments = (project) => {
package/cjs/meta.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});require('./chunk-UIAXBAMD.js');
2
- const version = "4.0.0-alpha.7";
2
+ const version = "4.0.0-alpha.9";
3
3
 
4
4
 
5
5
  exports.version = version;
@@ -58,7 +58,7 @@ declare const schema: {
58
58
  };
59
59
  readonly groups: {
60
60
  readonly minItems: 2;
61
- readonly description: "Custom order group. Example: `['id', '*', 'createdAt', 'updatedAt']` where `*` says for everything else.";
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: "Custom order group. Example: `['id', '*', 'createdAt', 'updatedAt']` where `*` says for everything else."
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: ["id", "*", "createdAt", "updatedAt"]
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 = "alias" in currNode && _optionalChain([currNode, 'access', _ => _.alias, 'optionalAccess', _2 => _2.value]) || "name" in currNode && _optionalChain([currNode, 'access', _3 => _3.name, 'optionalAccess', _4 => _4.value]);
231
+ const currNode = nodes[i], currName = getName(currNode);
225
232
  if (!currName)
226
233
  continue;
227
- const prevNode = nodes[i - 1], prevName = "alias" in prevNode && _optionalChain([prevNode, 'access', _5 => _5.alias, 'optionalAccess', _6 => _6.value]) || "name" in prevNode && _optionalChain([prevNode, 'access', _7 => _7.name, 'optionalAccess', _8 => _8.value]);
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', _9 => _9.length])) {
238
+ if (_optionalChain([groups, 'optionalAccess', _ => _.length])) {
232
239
  if (!groups.includes("*"))
233
240
  throw new Error("`groups` option should contain `*` string.");
234
- let indexForPrev = groups.indexOf(prevName);
235
- indexForPrev === -1 && (indexForPrev = groups.indexOf("*"));
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', _10 => _10.selections, 'optionalAccess', _11 => _11.join, 'call', _12 => _12(",")]), argumentsSelector = _optionalChain([opts, 'access', _13 => _13.arguments, 'optionalAccess', _14 => _14.join, 'call', _15 => _15(",")]);
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', _16 => _16.variableDefinitions, 'optionalAccess', _17 => _17.map, 'call', _18 => _18((varDef) => varDef.variable)]));
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;
@@ -85,7 +85,7 @@ const RULE_ID = "require-import-fragment", SUGGESTION_ID = "add-import-expressio
85
85
  ).test(comment.value)) continue;
86
86
  const extractedImportPath = _optionalChain([comment, 'access', _ => _.value, 'access', _2 => _2.match, 'call', _3 => _3(/(["'])((?:\1|.)*?)\1/), 'optionalAccess', _4 => _4[2]]);
87
87
  if (!extractedImportPath) continue;
88
- const importPath = _nodepath2.default.join(_nodepath2.default.dirname(filePath), extractedImportPath);
88
+ const importPath = _nodepath2.default.join(filePath, "..", extractedImportPath);
89
89
  if (fragmentsFromSiblings.some(
90
90
  (source) => source.filePath === importPath
91
91
  )) return;
@@ -93,7 +93,12 @@ const RULE_ID = "require-import-fragment", SUGGESTION_ID = "add-import-expressio
93
93
  if (fragmentsFromSiblings.some(
94
94
  (source) => source.filePath === filePath
95
95
  )) return;
96
- const suggestedFilePaths = fragmentsFromSiblings.length ? fragmentsFromSiblings.map((o) => _nodepath2.default.relative(_nodepath2.default.dirname(filePath), o.filePath)) : ["CHANGE_ME.graphql"];
96
+ const suggestedFilePaths = fragmentsFromSiblings.length ? fragmentsFromSiblings.map(
97
+ (o) => (
98
+ // Use always forward slash for suggested import path
99
+ _utilsjs.slash.call(void 0, _nodepath2.default.relative(_nodepath2.default.dirname(filePath), o.filePath))
100
+ )
101
+ ) : ["CHANGE_ME.graphql"];
97
102
  context.report({
98
103
  node,
99
104
  messageId: RULE_ID,
package/cjs/utils.js CHANGED
@@ -29,7 +29,7 @@ const chalk = {
29
29
  // eslint-disable-next-line no-console
30
30
  console.warn(chalk.yellow("warning"), "[graphql-eslint]", ...args)
31
31
  )
32
- }, slash = exports.slash = (path) => path.replaceAll("\\", "/"), VIRTUAL_DOCUMENT_REGEX = exports.VIRTUAL_DOCUMENT_REGEX = /[\/\\]\d+_document.graphql$/, CWD = exports.CWD = process.cwd(), getTypeName = exports.getTypeName = (node) => "type" in node ? getTypeName(node.type) : "name" in node && node.name ? node.name.value : "", TYPES_KINDS = exports.TYPES_KINDS = [
32
+ }, slash = exports.slash = (path) => path.replaceAll("\\", "/"), VIRTUAL_DOCUMENT_REGEX = exports.VIRTUAL_DOCUMENT_REGEX = /[/\\]\d+_document.graphql$/, CWD = exports.CWD = process.cwd(), getTypeName = exports.getTypeName = (node) => "type" in node ? getTypeName(node.type) : "name" in node && node.name ? node.name.value : "", TYPES_KINDS = exports.TYPES_KINDS = [
33
33
  _graphql.Kind.OBJECT_TYPE_DEFINITION,
34
34
  _graphql.Kind.INTERFACE_TYPE_DEFINITION,
35
35
  _graphql.Kind.ENUM_TYPE_DEFINITION,
@@ -78,26 +78,49 @@ function truthy(value) {
78
78
  return !!value;
79
79
  }
80
80
  const DisplayNodeNameMap = {
81
- [_graphql.Kind.OBJECT_TYPE_DEFINITION]: "type",
82
- [_graphql.Kind.OBJECT_TYPE_EXTENSION]: "type",
83
- [_graphql.Kind.INTERFACE_TYPE_DEFINITION]: "interface",
84
- [_graphql.Kind.INTERFACE_TYPE_EXTENSION]: "interface",
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.SCALAR_TYPE_DEFINITION]: "scalar",
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.ARGUMENT]: "argument",
97
- [_graphql.Kind.VARIABLE]: "variable",
98
- [_graphql.Kind.FRAGMENT_DEFINITION]: "fragment",
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.FIELD]: "field"
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: ["id", "*", "createdAt", "updatedAt"]
16
+ groups: ["...", "id", "*", "{"]
17
17
  }
18
18
  ],
19
19
  "@graphql-eslint/lone-executable-definition": "error",
package/esm/documents.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./chunk-UIAXBAMD.js";
2
- import { resolve } from "node:path";
2
+ import path from "node:path";
3
3
  import debugFactory from "debug";
4
4
  import fg from "fast-glob";
5
5
  import { ModuleCache } from "./cache.js";
@@ -8,12 +8,17 @@ const debug = debugFactory("graphql-eslint:operations"), operationsCache = new M
8
8
  return documents.map((source) => {
9
9
  const location = source.location;
10
10
  if ([".gql", ".graphql"].some((extension) => location.endsWith(extension)))
11
- return source;
11
+ return {
12
+ ...source,
13
+ // When using glob pattern e.g. `**/*.gql` location contains always forward slashes even on
14
+ // Windows
15
+ location: path.resolve(location)
16
+ };
12
17
  filepathMap[location] ??= -1;
13
18
  const index = filepathMap[location] += 1;
14
19
  return {
15
20
  ...source,
16
- location: resolve(location, `${index}_document.graphql`)
21
+ location: path.resolve(location, `${index}_document.graphql`)
17
22
  };
18
23
  });
19
24
  }, getDocuments = (project) => {
package/esm/meta.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./chunk-UIAXBAMD.js";
2
- const version = "4.0.0-alpha.7";
2
+ const version = "4.0.0-alpha.9";
3
3
  export {
4
4
  version
5
5
  };
@@ -58,7 +58,7 @@ declare const schema: {
58
58
  };
59
59
  readonly groups: {
60
60
  readonly minItems: 2;
61
- readonly description: "Custom order group. Example: `['id', '*', 'createdAt', 'updatedAt']` where `*` says for everything else.";
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: "Custom order group. Example: `['id', '*', 'createdAt', 'updatedAt']` where `*` says for everything else."
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: ["id", "*", "createdAt", "updatedAt"]
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 = "alias" in currNode && currNode.alias?.value || "name" in currNode && currNode.name?.value;
231
+ const currNode = nodes[i], currName = getName(currNode);
225
232
  if (!currName)
226
233
  continue;
227
- const prevNode = nodes[i - 1], prevName = "alias" in prevNode && prevNode.alias?.value || "name" in prevNode && prevNode.name?.value;
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
- let indexForPrev = groups.indexOf(prevName);
235
- indexForPrev === -1 && (indexForPrev = groups.indexOf("*"));
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
  };
@@ -1,6 +1,6 @@
1
1
  import "../../chunk-UIAXBAMD.js";
2
2
  import path from "node:path";
3
- import { requireSiblingsOperations } from "../../utils.js";
3
+ import { requireSiblingsOperations, slash } from "../../utils.js";
4
4
  const RULE_ID = "require-import-fragment", SUGGESTION_ID = "add-import-expression", rule = {
5
5
  meta: {
6
6
  type: "suggestion",
@@ -85,7 +85,7 @@ const RULE_ID = "require-import-fragment", SUGGESTION_ID = "add-import-expressio
85
85
  ).test(comment.value)) continue;
86
86
  const extractedImportPath = comment.value.match(/(["'])((?:\1|.)*?)\1/)?.[2];
87
87
  if (!extractedImportPath) continue;
88
- const importPath = path.join(path.dirname(filePath), extractedImportPath);
88
+ const importPath = path.join(filePath, "..", extractedImportPath);
89
89
  if (fragmentsFromSiblings.some(
90
90
  (source) => source.filePath === importPath
91
91
  )) return;
@@ -93,7 +93,12 @@ const RULE_ID = "require-import-fragment", SUGGESTION_ID = "add-import-expressio
93
93
  if (fragmentsFromSiblings.some(
94
94
  (source) => source.filePath === filePath
95
95
  )) return;
96
- const suggestedFilePaths = fragmentsFromSiblings.length ? fragmentsFromSiblings.map((o) => path.relative(path.dirname(filePath), o.filePath)) : ["CHANGE_ME.graphql"];
96
+ const suggestedFilePaths = fragmentsFromSiblings.length ? fragmentsFromSiblings.map(
97
+ (o) => (
98
+ // Use always forward slash for suggested import path
99
+ slash(path.relative(path.dirname(filePath), o.filePath))
100
+ )
101
+ ) : ["CHANGE_ME.graphql"];
97
102
  context.report({
98
103
  node,
99
104
  messageId: RULE_ID,
package/esm/utils.js CHANGED
@@ -29,7 +29,7 @@ const chalk = {
29
29
  // eslint-disable-next-line no-console
30
30
  console.warn(chalk.yellow("warning"), "[graphql-eslint]", ...args)
31
31
  )
32
- }, slash = (path) => path.replaceAll("\\", "/"), VIRTUAL_DOCUMENT_REGEX = /[\/\\]\d+_document.graphql$/, CWD = process.cwd(), getTypeName = (node) => "type" in node ? getTypeName(node.type) : "name" in node && node.name ? node.name.value : "", TYPES_KINDS = [
32
+ }, slash = (path) => path.replaceAll("\\", "/"), VIRTUAL_DOCUMENT_REGEX = /[/\\]\d+_document.graphql$/, CWD = process.cwd(), getTypeName = (node) => "type" in node ? getTypeName(node.type) : "name" in node && node.name ? node.name.value : "", TYPES_KINDS = [
33
33
  Kind.OBJECT_TYPE_DEFINITION,
34
34
  Kind.INTERFACE_TYPE_DEFINITION,
35
35
  Kind.ENUM_TYPE_DEFINITION,
@@ -78,26 +78,49 @@ function truthy(value) {
78
78
  return !!value;
79
79
  }
80
80
  const DisplayNodeNameMap = {
81
- [Kind.OBJECT_TYPE_DEFINITION]: "type",
82
- [Kind.OBJECT_TYPE_EXTENSION]: "type",
83
- [Kind.INTERFACE_TYPE_DEFINITION]: "interface",
84
- [Kind.INTERFACE_TYPE_EXTENSION]: "interface",
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.SCALAR_TYPE_DEFINITION]: "scalar",
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.ARGUMENT]: "argument",
97
- [Kind.VARIABLE]: "variable",
98
- [Kind.FRAGMENT_DEFINITION]: "fragment",
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.FIELD]: "field"
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: ["id", "*", "createdAt", "updatedAt"]
38
+ groups: ["...", "id", "*", "{"]
39
39
  }
40
40
  ],
41
41
  "@graphql-eslint/lone-executable-definition": "error",
@@ -427,7 +427,7 @@ var chalk = {
427
427
  // eslint-disable-next-line no-console
428
428
  console.warn(chalk.yellow("warning"), "[graphql-eslint]", ...args)
429
429
  )
430
- }, slash = (path2) => path2.replaceAll("\\", "/"), VIRTUAL_DOCUMENT_REGEX = /[\/\\]\d+_document.graphql$/, CWD = process.cwd(), getTypeName = (node) => "type" in node ? getTypeName(node.type) : "name" in node && node.name ? node.name.value : "", TYPES_KINDS = [
430
+ }, slash = (path2) => path2.replaceAll("\\", "/"), VIRTUAL_DOCUMENT_REGEX = /[/\\]\d+_document.graphql$/, CWD = process.cwd(), getTypeName = (node) => "type" in node ? getTypeName(node.type) : "name" in node && node.name ? node.name.value : "", TYPES_KINDS = [
431
431
  Kind2.OBJECT_TYPE_DEFINITION,
432
432
  Kind2.INTERFACE_TYPE_DEFINITION,
433
433
  Kind2.ENUM_TYPE_DEFINITION,
@@ -476,26 +476,49 @@ function truthy(value) {
476
476
  return !!value;
477
477
  }
478
478
  var DisplayNodeNameMap = {
479
- [Kind2.OBJECT_TYPE_DEFINITION]: "type",
480
- [Kind2.OBJECT_TYPE_EXTENSION]: "type",
481
- [Kind2.INTERFACE_TYPE_DEFINITION]: "interface",
482
- [Kind2.INTERFACE_TYPE_EXTENSION]: "interface",
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.SCALAR_TYPE_DEFINITION]: "scalar",
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.ARGUMENT]: "argument",
495
- [Kind2.VARIABLE]: "variable",
496
- [Kind2.FRAGMENT_DEFINITION]: "fragment",
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.FIELD]: "field"
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: "Custom order group. Example: `['id', '*', 'createdAt', 'updatedAt']` where `*` says for everything else."
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: ["id", "*", "createdAt", "updatedAt"]
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 = "alias" in currNode && currNode.alias?.value || "name" in currNode && currNode.name?.value;
919
+ let currNode = nodes[i], currName = getName(currNode);
890
920
  if (!currName)
891
921
  continue;
892
- let prevNode = nodes[i - 1], prevName = "alias" in prevNode && prevNode.alias?.value || "name" in prevNode && prevNode.name?.value;
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.indexOf(prevName);
899
- indexForPrev === -1 && (indexForPrev = groups.indexOf("*"));
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 = {
@@ -4348,7 +4387,7 @@ var RULE_ID16 = "require-import-fragment", SUGGESTION_ID = "add-import-expressio
4348
4387
  ).test(comment.value)) continue;
4349
4388
  let extractedImportPath = comment.value.match(/(["'])((?:\1|.)*?)\1/)?.[2];
4350
4389
  if (!extractedImportPath) continue;
4351
- let importPath = path.join(path.dirname(filePath), extractedImportPath);
4390
+ let importPath = path.join(filePath, "..", extractedImportPath);
4352
4391
  if (fragmentsFromSiblings.some(
4353
4392
  (source) => source.filePath === importPath
4354
4393
  )) return;
@@ -4356,7 +4395,12 @@ var RULE_ID16 = "require-import-fragment", SUGGESTION_ID = "add-import-expressio
4356
4395
  if (fragmentsFromSiblings.some(
4357
4396
  (source) => source.filePath === filePath
4358
4397
  )) return;
4359
- let suggestedFilePaths = fragmentsFromSiblings.length ? fragmentsFromSiblings.map((o) => path.relative(path.dirname(filePath), o.filePath)) : ["CHANGE_ME.graphql"];
4398
+ let suggestedFilePaths = fragmentsFromSiblings.length ? fragmentsFromSiblings.map(
4399
+ (o) => (
4400
+ // Use always forward slash for suggested import path
4401
+ slash(path.relative(path.dirname(filePath), o.filePath))
4402
+ )
4403
+ ) : ["CHANGE_ME.graphql"];
4360
4404
  context.report({
4361
4405
  node,
4362
4406
  messageId: RULE_ID16,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-eslint/eslint-plugin",
3
- "version": "4.0.0-alpha.7",
3
+ "version": "4.0.0-alpha.9",
4
4
  "type": "module",
5
5
  "description": "GraphQL plugin for ESLint",
6
6
  "repository": "https://github.com/B2o5T/graphql-eslint",