@graphql-eslint/eslint-plugin 4.3.0 → 4.3.1-alpha-20241207204625-6a4230707a78900a6339b03afe904b9dd6c31561

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.
Files changed (110) hide show
  1. package/cjs/cache.js +6 -2
  2. package/cjs/configs/operations-all.js +2 -2
  3. package/cjs/configs/schema-all.js +2 -2
  4. package/cjs/configs/schema-recommended.js +1 -1
  5. package/cjs/documents.js +13 -7
  6. package/cjs/estree-converter/converter.js +17 -8
  7. package/cjs/estree-converter/utils.js +22 -9
  8. package/cjs/graphql-config.js +13 -6
  9. package/cjs/index.d.cts +18 -4
  10. package/cjs/meta.js +1 -1
  11. package/cjs/parser.js +36 -9
  12. package/cjs/processor.js +48 -20
  13. package/cjs/rules/alphabetize/index.js +99 -47
  14. package/cjs/rules/description-style/index.js +10 -6
  15. package/cjs/rules/graphql-js-validation.js +142 -108
  16. package/cjs/rules/index.d.cts +18 -4
  17. package/cjs/rules/input-name/index.js +51 -38
  18. package/cjs/rules/lone-executable-definition/index.js +15 -6
  19. package/cjs/rules/match-document-filename/index.d.cts +4 -3
  20. package/cjs/rules/match-document-filename/index.js +63 -37
  21. package/cjs/rules/naming-convention/index.d.cts +6 -10
  22. package/cjs/rules/naming-convention/index.js +146 -57
  23. package/cjs/rules/no-anonymous-operations/index.js +8 -5
  24. package/cjs/rules/no-deprecated/index.js +27 -13
  25. package/cjs/rules/no-duplicate-fields/index.js +15 -8
  26. package/cjs/rules/no-hashtag-description/index.js +18 -10
  27. package/cjs/rules/no-one-place-fragments/index.js +17 -10
  28. package/cjs/rules/no-root-type/index.js +15 -8
  29. package/cjs/rules/no-scalar-result-type-on-mutation/index.js +20 -12
  30. package/cjs/rules/no-typename-prefix/index.js +25 -21
  31. package/cjs/rules/no-unreachable-types/index.js +34 -17
  32. package/cjs/rules/no-unused-fields/index.js +56 -30
  33. package/cjs/rules/relay-arguments/index.js +31 -13
  34. package/cjs/rules/relay-connection-types/index.js +31 -9
  35. package/cjs/rules/relay-edge-types/index.js +84 -41
  36. package/cjs/rules/relay-page-info/index.js +31 -14
  37. package/cjs/rules/require-deprecation-date/index.js +20 -9
  38. package/cjs/rules/require-deprecation-reason/index.js +8 -5
  39. package/cjs/rules/require-description/index.d.cts +79 -13
  40. package/cjs/rules/require-description/index.js +67 -49
  41. package/cjs/rules/require-field-of-type-query-in-mutation-result/index.js +21 -10
  42. package/cjs/rules/require-import-fragment/index.js +20 -11
  43. package/cjs/rules/require-nullable-fields-with-oneof/index.js +12 -5
  44. package/cjs/rules/require-nullable-result-in-root/index.js +32 -27
  45. package/cjs/rules/require-selections/index.js +88 -46
  46. package/cjs/rules/require-type-pattern-with-oneof/index.js +14 -10
  47. package/cjs/rules/selection-set-depth/index.js +19 -10
  48. package/cjs/rules/strict-id-in-types/index.js +32 -19
  49. package/cjs/rules/unique-enum-value-names/index.js +4 -3
  50. package/cjs/rules/unique-fragment-name/index.js +25 -18
  51. package/cjs/rules/unique-operation-name/index.js +5 -5
  52. package/cjs/schema.js +14 -8
  53. package/cjs/siblings.js +60 -32
  54. package/cjs/utils.js +23 -9
  55. package/esm/cache.js +6 -2
  56. package/esm/configs/operations-all.js +2 -2
  57. package/esm/configs/schema-all.js +2 -2
  58. package/esm/configs/schema-recommended.js +1 -1
  59. package/esm/documents.js +13 -7
  60. package/esm/estree-converter/converter.js +17 -8
  61. package/esm/estree-converter/utils.js +22 -9
  62. package/esm/graphql-config.js +13 -6
  63. package/esm/index.d.ts +19 -5
  64. package/esm/meta.js +1 -1
  65. package/esm/parser.js +36 -9
  66. package/esm/processor.js +48 -20
  67. package/esm/rules/alphabetize/index.js +99 -47
  68. package/esm/rules/description-style/index.js +10 -6
  69. package/esm/rules/graphql-js-validation.js +142 -108
  70. package/esm/rules/index.d.ts +19 -5
  71. package/esm/rules/input-name/index.js +51 -38
  72. package/esm/rules/lone-executable-definition/index.js +15 -6
  73. package/esm/rules/match-document-filename/index.d.ts +4 -3
  74. package/esm/rules/match-document-filename/index.js +63 -37
  75. package/esm/rules/naming-convention/index.d.ts +6 -10
  76. package/esm/rules/naming-convention/index.js +146 -57
  77. package/esm/rules/no-anonymous-operations/index.js +8 -5
  78. package/esm/rules/no-deprecated/index.js +27 -13
  79. package/esm/rules/no-duplicate-fields/index.js +15 -8
  80. package/esm/rules/no-hashtag-description/index.js +18 -10
  81. package/esm/rules/no-one-place-fragments/index.js +17 -10
  82. package/esm/rules/no-root-type/index.js +15 -8
  83. package/esm/rules/no-scalar-result-type-on-mutation/index.js +20 -12
  84. package/esm/rules/no-typename-prefix/index.js +25 -21
  85. package/esm/rules/no-unreachable-types/index.js +34 -17
  86. package/esm/rules/no-unused-fields/index.js +56 -30
  87. package/esm/rules/relay-arguments/index.js +31 -13
  88. package/esm/rules/relay-connection-types/index.js +31 -9
  89. package/esm/rules/relay-edge-types/index.js +84 -41
  90. package/esm/rules/relay-page-info/index.js +31 -14
  91. package/esm/rules/require-deprecation-date/index.js +20 -9
  92. package/esm/rules/require-deprecation-reason/index.js +8 -5
  93. package/esm/rules/require-description/index.d.ts +79 -13
  94. package/esm/rules/require-description/index.js +67 -49
  95. package/esm/rules/require-field-of-type-query-in-mutation-result/index.js +21 -10
  96. package/esm/rules/require-import-fragment/index.js +20 -11
  97. package/esm/rules/require-nullable-fields-with-oneof/index.js +12 -5
  98. package/esm/rules/require-nullable-result-in-root/index.js +32 -27
  99. package/esm/rules/require-selections/index.js +88 -46
  100. package/esm/rules/require-type-pattern-with-oneof/index.js +14 -10
  101. package/esm/rules/selection-set-depth/index.js +19 -10
  102. package/esm/rules/strict-id-in-types/index.js +32 -19
  103. package/esm/rules/unique-enum-value-names/index.js +4 -3
  104. package/esm/rules/unique-fragment-name/index.js +25 -18
  105. package/esm/rules/unique-operation-name/index.js +5 -5
  106. package/esm/schema.js +15 -8
  107. package/esm/siblings.js +60 -32
  108. package/esm/utils.js +23 -9
  109. package/index.browser.js +1838 -1135
  110. package/package.json +1 -1
package/cjs/cache.js CHANGED
@@ -3,20 +3,24 @@ const log = _debug2.default.call(void 0, "graphql-eslint:ModuleCache");
3
3
  class ModuleCache {constructor() { ModuleCache.prototype.__init.call(this); }
4
4
  __init() {this.map = /* @__PURE__ */ new Map()}
5
5
  set(cacheKey, result) {
6
- this.map.set(cacheKey, { lastSeen: process.hrtime(), result }), log("setting entry for", cacheKey);
6
+ if (false) return;
7
+ this.map.set(cacheKey, { lastSeen: process.hrtime(), result });
8
+ log("setting entry for", cacheKey);
7
9
  }
8
10
  get(cacheKey, settings = {
9
11
  lifetime: 10
10
12
  /* seconds */
11
13
  }) {
14
+ if (false) return;
12
15
  const value = this.map.get(cacheKey);
13
16
  if (!value) {
14
17
  log("cache miss for", cacheKey);
15
18
  return;
16
19
  }
17
20
  const { lastSeen, result } = value;
18
- if (process.env.NODE || process.hrtime(lastSeen)[0] < settings.lifetime)
21
+ if (process.env.NODE || process.hrtime(lastSeen)[0] < settings.lifetime) {
19
22
  return result;
23
+ }
20
24
  }
21
25
  }
22
26
 
@@ -4,9 +4,9 @@
4
4
  "@graphql-eslint/alphabetize": [
5
5
  "error",
6
6
  {
7
- definitions: !0,
7
+ definitions: true,
8
8
  selections: ["OperationDefinition", "FragmentDefinition"],
9
- variables: !0,
9
+ variables: true,
10
10
  arguments: ["Field", "Directive"],
11
11
  groups: ["...", "id", "*", "{"]
12
12
  }
@@ -4,9 +4,9 @@
4
4
  "@graphql-eslint/alphabetize": [
5
5
  "error",
6
6
  {
7
- definitions: !0,
7
+ definitions: true,
8
8
  fields: ["ObjectTypeDefinition", "InterfaceTypeDefinition", "InputObjectTypeDefinition"],
9
- values: !0,
9
+ values: true,
10
10
  arguments: ["FieldDefinition", "Field", "DirectiveDefinition", "Directive"],
11
11
  groups: ["id", "*", "createdAt", "updatedAt"]
12
12
  }
@@ -54,7 +54,7 @@
54
54
  "@graphql-eslint/require-deprecation-reason": "error",
55
55
  "@graphql-eslint/require-description": [
56
56
  "error",
57
- { types: !0, DirectiveDefinition: !0, rootField: !0 }
57
+ { types: true, DirectiveDefinition: true, rootField: true }
58
58
  ],
59
59
  "@graphql-eslint/strict-id-in-types": "error",
60
60
  "@graphql-eslint/unique-directive-names": "error",
package/cjs/documents.js CHANGED
@@ -2,17 +2,20 @@
2
2
  var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
3
3
  var _fastglob = require('fast-glob'); var _fastglob2 = _interopRequireDefault(_fastglob);
4
4
  var _cachejs = require('./cache.js');
5
- const debug = _debug2.default.call(void 0, "graphql-eslint:operations"), operationsCache = new (0, _cachejs.ModuleCache)(), handleVirtualPath = (documents) => {
5
+ const debug = _debug2.default.call(void 0, "graphql-eslint:operations");
6
+ const operationsCache = new (0, _cachejs.ModuleCache)();
7
+ const handleVirtualPath = (documents) => {
6
8
  const filepathMap = /* @__PURE__ */ Object.create(null);
7
9
  return documents.map((source) => {
8
10
  const location = source.location;
9
- if ([".gql", ".graphql"].some((extension) => location.endsWith(extension)))
11
+ if ([".gql", ".graphql"].some((extension) => location.endsWith(extension))) {
10
12
  return {
11
13
  ...source,
12
14
  // When using glob pattern e.g. `**/*.gql` location contains always forward slashes even on
13
15
  // Windows
14
16
  location: _nodepath2.default.resolve(location)
15
17
  };
18
+ }
16
19
  filepathMap[location] ??= -1;
17
20
  const index = filepathMap[location] += 1;
18
21
  return {
@@ -20,23 +23,26 @@ const debug = _debug2.default.call(void 0, "graphql-eslint:operations"), operati
20
23
  location: _nodepath2.default.resolve(location, `${index}_document.graphql`)
21
24
  };
22
25
  });
23
- }, getDocuments = exports.getDocuments = (project) => {
26
+ };
27
+ const getDocuments = (project) => {
24
28
  const documentsKey = project.documents;
25
- if (!documentsKey)
29
+ if (!documentsKey) {
26
30
  return [];
31
+ }
27
32
  let siblings = operationsCache.get(documentsKey);
28
33
  if (!siblings) {
29
34
  debug("Loading operations from %o", project.documents);
30
35
  const documents = project.loadDocumentsSync(project.documents, {
31
- skipGraphQLImport: !0,
36
+ skipGraphQLImport: true,
32
37
  pluckConfig: project.extensions.pluckConfig
33
38
  });
34
39
  if (debug.enabled) {
35
40
  debug("Loaded %d operations", documents.length);
36
- const operationsPaths = _fastglob2.default.sync(project.documents, { absolute: !0 });
41
+ const operationsPaths = _fastglob2.default.sync(project.documents, { absolute: true });
37
42
  debug("Operations pointers %O", operationsPaths);
38
43
  }
39
- siblings = handleVirtualPath(documents), operationsCache.set(documentsKey, siblings);
44
+ siblings = handleVirtualPath(documents);
45
+ operationsCache.set(documentsKey, siblings);
40
46
  }
41
47
  return siblings;
42
48
  };
@@ -6,14 +6,16 @@
6
6
  var _graphql = require('graphql');
7
7
  var _utilsjs = require('./utils.js');
8
8
  function convertToESTree(node, schema) {
9
- const typeInfo = schema && new (0, _graphql.TypeInfo)(schema), visitor = {
9
+ const typeInfo = schema && new (0, _graphql.TypeInfo)(schema);
10
+ const visitor = {
10
11
  leave(node2, key, parent) {
11
12
  const leadingComments = "description" in node2 && node2.description ? [
12
13
  {
13
14
  type: node2.description.block ? "Block" : "Line",
14
15
  value: node2.description.value
15
16
  }
16
- ] : [], calculatedTypeInfo = typeInfo ? {
17
+ ] : [];
18
+ const calculatedTypeInfo = typeInfo ? {
17
19
  argument: typeInfo.getArgument(),
18
20
  defaultValue: typeInfo.getDefaultValue(),
19
21
  directive: typeInfo.getDirective(),
@@ -23,12 +25,19 @@ function convertToESTree(node, schema) {
23
25
  parentInputType: typeInfo.getParentInputType(),
24
26
  parentType: typeInfo.getParentType(),
25
27
  gqlType: typeInfo.getType()
26
- } : {}, rawNode = () => parent && key !== void 0 ? parent[key] : node2.kind === _graphql.Kind.DOCUMENT ? {
27
- ...node2,
28
- definitions: node2.definitions.map(
29
- (definition) => definition.rawNode()
30
- )
31
- } : node2, commonFields = {
28
+ } : {};
29
+ const rawNode = () => {
30
+ if (parent && key !== void 0) {
31
+ return parent[key];
32
+ }
33
+ return node2.kind === _graphql.Kind.DOCUMENT ? {
34
+ ...node2,
35
+ definitions: node2.definitions.map(
36
+ (definition) => definition.rawNode()
37
+ )
38
+ } : node2;
39
+ };
40
+ const commonFields = {
32
41
  ...node2,
33
42
  type: node2.kind,
34
43
  loc: _utilsjs.convertLocation.call(void 0, node2.loc),
@@ -6,9 +6,14 @@
6
6
 
7
7
  var _graphql = require('graphql');
8
8
  var _valueFromASTUntypedjs = require('graphql/utilities/valueFromASTUntyped.js');
9
- const valueFromNode = (...args) => _valueFromASTUntypedjs.valueFromASTUntyped.call(void 0, ...args);
9
+ const valueFromNode = (...args) => {
10
+ return _valueFromASTUntypedjs.valueFromASTUntyped.call(void 0, ...args);
11
+ };
10
12
  function getBaseType(type) {
11
- return _graphql.isNonNullType.call(void 0, type) || _graphql.isListType.call(void 0, type) ? getBaseType(type.ofType) : type;
13
+ if (_graphql.isNonNullType.call(void 0, type) || _graphql.isListType.call(void 0, type)) {
14
+ return getBaseType(type.ofType);
15
+ }
16
+ return type;
12
17
  }
13
18
  function convertToken(token, type) {
14
19
  const { line, column, end, start, value } = token;
@@ -33,20 +38,24 @@ function convertToken(token, type) {
33
38
  };
34
39
  }
35
40
  function extractTokens(filePath, code) {
36
- const source = new (0, _graphql.Source)(code, filePath), lexer = new (0, _graphql.Lexer)(source), tokens = [];
41
+ const source = new (0, _graphql.Source)(code, filePath);
42
+ const lexer = new (0, _graphql.Lexer)(source);
43
+ const tokens = [];
37
44
  let token = lexer.advance();
38
- for (; token && token.kind !== _graphql.TokenKind.EOF; ) {
45
+ while (token && token.kind !== _graphql.TokenKind.EOF) {
39
46
  const result = convertToken(token, token.kind);
40
- tokens.push(result), token = lexer.advance();
47
+ tokens.push(result);
48
+ token = lexer.advance();
41
49
  }
42
50
  return tokens;
43
51
  }
44
52
  function extractComments(loc) {
45
- if (!loc)
53
+ if (!loc) {
46
54
  return [];
55
+ }
47
56
  const comments = [];
48
57
  let token = loc.startToken;
49
- for (; token; ) {
58
+ while (token) {
50
59
  if (token.kind === _graphql.TokenKind.COMMENT) {
51
60
  const comment = convertToken(
52
61
  token,
@@ -60,7 +69,8 @@ function extractComments(loc) {
60
69
  return comments;
61
70
  }
62
71
  function convertLocation(location) {
63
- const { startToken, endToken, source, start, end } = location, loc = {
72
+ const { startToken, endToken, source, start, end } = location;
73
+ const loc = {
64
74
  start: {
65
75
  /*
66
76
  * Kind.Document has startToken: { line: 0, column: 0 }, we set line as 1 and column as 0
@@ -74,7 +84,10 @@ function convertLocation(location) {
74
84
  },
75
85
  source: source.body
76
86
  };
77
- return loc.start.column === loc.end.column && (loc.end.column += end - start), loc;
87
+ if (loc.start.column === loc.end.column) {
88
+ loc.end.column += end - start;
89
+ }
90
+ return loc;
78
91
  }
79
92
 
80
93
 
@@ -6,15 +6,16 @@ var _codefileloader = require('@graphql-tools/code-file-loader');
6
6
  const debug = _debug2.default.call(void 0, "graphql-eslint:graphql-config");
7
7
  let graphQLConfig;
8
8
  function getFirstExistingPath(filePath) {
9
- for (; !_nodefs2.default.existsSync(filePath); )
9
+ while (!_nodefs2.default.existsSync(filePath)) {
10
10
  filePath = _nodepath2.default.dirname(filePath);
11
+ }
11
12
  return filePath;
12
13
  }
13
14
  function loadOnDiskGraphQLConfig(filePath) {
14
15
  return _graphqlconfig.loadConfigSync.call(void 0, {
15
16
  // load config relative to the file being linted
16
17
  rootDir: getFirstExistingPath(_nodepath2.default.dirname(filePath)),
17
- throwOnMissing: !1,
18
+ throwOnMissing: false,
18
19
  extensions: [codeFileLoaderExtension]
19
20
  });
20
21
  }
@@ -22,21 +23,27 @@ function loadGraphQLConfig({
22
23
  graphQLConfig: config,
23
24
  filePath
24
25
  }) {
25
- if (process.env.NODE_ENV !== "test" && graphQLConfig)
26
+ if (process.env.NODE_ENV !== "test" && graphQLConfig) {
26
27
  return graphQLConfig;
28
+ }
27
29
  debug("parserOptions.graphQLConfig: %o", config);
28
30
  const onDiskConfig = !config && loadOnDiskGraphQLConfig(filePath);
29
- onDiskConfig && debug("GraphQL-Config path %o", onDiskConfig.filepath);
31
+ if (onDiskConfig) {
32
+ debug("GraphQL-Config path %o", onDiskConfig.filepath);
33
+ }
30
34
  const configOptions = config && ("projects" in config || "schemaPath" in config) ? config : {
31
35
  // if `schema` is `undefined` will throw error `Project 'default' not found`
32
36
  schema: _nullishCoalesce(_optionalChain([config, 'optionalAccess', _ => _.schema]), () => ( "")),
33
37
  ...config
34
38
  };
35
- return graphQLConfig = onDiskConfig || new (0, _graphqlconfig.GraphQLConfig)({ config: configOptions, filepath: "" }, [codeFileLoaderExtension]), graphQLConfig;
39
+ graphQLConfig = onDiskConfig || new (0, _graphqlconfig.GraphQLConfig)({ config: configOptions, filepath: "" }, [codeFileLoaderExtension]);
40
+ return graphQLConfig;
36
41
  }
37
42
  const codeFileLoaderExtension = (api) => {
38
43
  const { schema, documents } = api.loaders;
39
- return schema.register(new (0, _codefileloader.CodeFileLoader)()), documents.register(new (0, _codefileloader.CodeFileLoader)()), { name: "code-file-loaders" };
44
+ schema.register(new (0, _codefileloader.CodeFileLoader)());
45
+ documents.register(new (0, _codefileloader.CodeFileLoader)());
46
+ return { name: "code-file-loaders" };
40
47
  };
41
48
 
42
49
 
package/cjs/index.d.cts CHANGED
@@ -1,4 +1,3 @@
1
- import { RuleOptions } from './rules/require-description/index.cjs';
2
1
  import { CaseStyle } from './utils.cjs';
3
2
  export { requireGraphQLOperations, requireGraphQLSchema } from './utils.cjs';
4
3
  import * as graphql from 'graphql';
@@ -101,9 +100,9 @@ declare const _default: {
101
100
  forbiddenPatterns?: {
102
101
  [x: string]: unknown;
103
102
  }[] | undefined;
104
- requiredPatterns?: {
103
+ requiredPattern?: {
105
104
  [x: string]: unknown;
106
- }[] | undefined;
105
+ } | undefined;
107
106
  forbiddenPrefixes?: string[] | undefined;
108
107
  forbiddenSuffixes?: string[] | undefined;
109
108
  requiredPrefixes?: string[] | undefined;
@@ -141,7 +140,22 @@ declare const _default: {
141
140
  argumentName?: string | undefined;
142
141
  }[]>;
143
142
  'require-deprecation-reason': GraphQLESLintRule;
144
- 'require-description': GraphQLESLintRule<RuleOptions>;
143
+ 'require-description': GraphQLESLintRule<{
144
+ types?: true | undefined;
145
+ OperationDefinition?: boolean | undefined;
146
+ ScalarTypeDefinition?: boolean | undefined;
147
+ ObjectTypeDefinition?: boolean | undefined;
148
+ FieldDefinition?: boolean | undefined;
149
+ InputValueDefinition?: boolean | undefined;
150
+ InterfaceTypeDefinition?: boolean | undefined;
151
+ UnionTypeDefinition?: boolean | undefined;
152
+ EnumTypeDefinition?: boolean | undefined;
153
+ EnumValueDefinition?: boolean | undefined;
154
+ InputObjectTypeDefinition?: boolean | undefined;
155
+ DirectiveDefinition?: boolean | undefined;
156
+ rootField?: true | undefined;
157
+ ignoredSelectors?: string[] | undefined;
158
+ }[]>;
145
159
  'require-field-of-type-query-in-mutation-result': GraphQLESLintRule;
146
160
  'require-import-fragment': GraphQLESLintRule;
147
161
  'require-nullable-fields-with-oneof': GraphQLESLintRule;
package/cjs/meta.js CHANGED
@@ -1,4 +1,4 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});const version = "4.3.0";
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});const version = "4.3.1-alpha-20241207204625-6a4230707a78900a6339b03afe904b9dd6c31561";
2
2
 
3
3
 
4
4
  exports.version = version;
package/cjs/parser.js CHANGED
@@ -23,19 +23,42 @@ const LEGACY_PARSER_OPTIONS_KEYS = [
23
23
  "operations"
24
24
  ];
25
25
  function parseForESLint(code, options) {
26
- for (const key of LEGACY_PARSER_OPTIONS_KEYS)
27
- if (key in options)
26
+ for (const key of LEGACY_PARSER_OPTIONS_KEYS) {
27
+ if (key in options) {
28
28
  throw new Error(
29
29
  `\`parserOptions.${key}\` was removed in graphql-eslint@4. Use physical graphql-config for setting schema and documents or \`parserOptions.graphQLConfig\` for programmatic usage.`
30
30
  );
31
+ }
32
+ }
31
33
  try {
32
- const { filePath } = options, { document } = _utils.parseGraphQLSDL.call(void 0, filePath, code, { noLocation: !1 });
33
- let project, schema, documents;
34
- project = _graphqlconfigjs.loadGraphQLConfig.call(void 0, options).getProjectForFile(_graphqlconfigjs.getFirstExistingPath.call(void 0, filePath)), documents = _documentsjs.getDocuments.call(void 0, project);
34
+ const { filePath } = options;
35
+ const { document } = _utils.parseGraphQLSDL.call(void 0, filePath, code, { noLocation: false });
36
+ let project;
37
+ let schema, documents;
38
+ if (true) {
39
+ const gqlConfig = _graphqlconfigjs.loadGraphQLConfig.call(void 0, options);
40
+ project = gqlConfig.getProjectForFile(_graphqlconfigjs.getFirstExistingPath.call(void 0, filePath));
41
+ documents = _documentsjs.getDocuments.call(void 0, project);
42
+ } else {
43
+ documents = [
44
+ _utils.parseGraphQLSDL.call(void 0,
45
+ "operation.graphql",
46
+ options.graphQLConfig.documents,
47
+ { noLocation: true }
48
+ )
49
+ ];
50
+ }
35
51
  try {
36
- schema = _schemajs.getSchema.call(void 0, project);
52
+ if (true) {
53
+ schema = _schemajs.getSchema.call(void 0, project);
54
+ } else {
55
+ schema = buildSchema(options.graphQLConfig.schema);
56
+ }
37
57
  } catch (error) {
38
- throw error instanceof Error && (error.message = `Error while loading schema: ${error.message}`), error;
58
+ if (error instanceof Error) {
59
+ error.message = `Error while loading schema: ${error.message}`;
60
+ }
61
+ throw error;
39
62
  }
40
63
  const rootTree = _indexjs.convertToESTree.call(void 0, document, schema);
41
64
  return {
@@ -54,9 +77,12 @@ function parseForESLint(code, options) {
54
77
  }
55
78
  };
56
79
  } catch (error) {
57
- if (error instanceof Error && (error.message = `[graphql-eslint] ${error.message}`), error instanceof _graphql.GraphQLError) {
80
+ if (error instanceof Error) {
81
+ error.message = `[graphql-eslint] ${error.message}`;
82
+ }
83
+ if (error instanceof _graphql.GraphQLError) {
58
84
  const location = _optionalChain([error, 'access', _ => _.locations, 'optionalAccess', _2 => _2[0]]);
59
- throw {
85
+ const eslintError = {
60
86
  index: _optionalChain([error, 'access', _3 => _3.positions, 'optionalAccess', _4 => _4[0]]),
61
87
  ...location && {
62
88
  lineNumber: location.line,
@@ -64,6 +90,7 @@ function parseForESLint(code, options) {
64
90
  },
65
91
  message: error.message
66
92
  };
93
+ throw eslintError;
67
94
  }
68
95
  throw error;
69
96
  }
package/cjs/processor.js CHANGED
@@ -7,19 +7,25 @@ var _graphqlconfigjs = require('./graphql-config.js');
7
7
  var _metajs = require('./meta.js');
8
8
  var _utilsjs = require('./utils.js');
9
9
  const blocksMap = /* @__PURE__ */ new Map();
10
- let onDiskConfig, onDiskConfigLoaded = !1;
11
- const RELEVANT_KEYWORDS = ["gql", "graphql", "GraphQL"], processor = exports.processor = {
10
+ let onDiskConfig;
11
+ let onDiskConfigLoaded = false;
12
+ const RELEVANT_KEYWORDS = ["gql", "graphql", "GraphQL"];
13
+ const processor = {
12
14
  meta: {
13
15
  name: "@graphql-eslint/processor",
14
16
  version: _metajs.version
15
17
  },
16
- supportsAutofix: !0,
18
+ supportsAutofix: true,
17
19
  preprocess(code, filePath) {
18
- if (process.env.ESLINT_USE_FLAT_CONFIG !== "false" && filePath.endsWith(".vue"))
20
+ if (process.env.ESLINT_USE_FLAT_CONFIG !== "false" && filePath.endsWith(".vue")) {
19
21
  throw new Error(
20
22
  "Processing of `.vue` files is no longer supported, follow the new official vue example for ESLint's flat config https://github.com/dimaMachina/graphql-eslint/tree/master/examples/vue-code-file"
21
23
  );
22
- onDiskConfigLoaded || (onDiskConfig = _graphqlconfigjs.loadOnDiskGraphQLConfig.call(void 0, filePath), onDiskConfigLoaded = !0);
24
+ }
25
+ if (!onDiskConfigLoaded) {
26
+ onDiskConfig = _graphqlconfigjs.loadOnDiskGraphQLConfig.call(void 0, filePath);
27
+ onDiskConfigLoaded = true;
28
+ }
23
29
  let keywords = RELEVANT_KEYWORDS;
24
30
  const pluckConfig = _optionalChain([onDiskConfig, 'optionalAccess', _ => _.getProjectForFile, 'call', _2 => _2(filePath), 'access', _3 => _3.extensions, 'access', _4 => _4.pluckConfig]);
25
31
  if (pluckConfig) {
@@ -27,34 +33,43 @@ const RELEVANT_KEYWORDS = ["gql", "graphql", "GraphQL"], processor = exports.pro
27
33
  modules = [],
28
34
  globalGqlIdentifierName = ["gql", "graphql"],
29
35
  gqlMagicComment = "GraphQL"
30
- } = pluckConfig, result = [...modules.map(({ identifier }) => identifier).filter((v) => !!v), ..._utils.asArray.call(void 0, globalGqlIdentifierName), gqlMagicComment];
36
+ } = pluckConfig;
37
+ const mods = modules.map(({ identifier }) => identifier).filter((v) => !!v);
38
+ const result = [...mods, ..._utils.asArray.call(void 0, globalGqlIdentifierName), gqlMagicComment];
31
39
  keywords = [...new Set(result)];
32
40
  }
33
- if (keywords.every((keyword) => !code.includes(keyword)))
41
+ if (keywords.every((keyword) => !code.includes(keyword))) {
34
42
  return [code];
43
+ }
35
44
  try {
36
- const blocks = _graphqltagpluck.gqlPluckFromCodeStringSync.call(void 0, filePath, code, {
37
- skipIndent: !0,
45
+ const sources = _graphqltagpluck.gqlPluckFromCodeStringSync.call(void 0, filePath, code, {
46
+ skipIndent: true,
38
47
  ...pluckConfig
39
- }).map((item) => ({
48
+ });
49
+ const blocks = sources.map((item) => ({
40
50
  filename: "document.graphql",
41
51
  text: item.body,
42
52
  lineOffset: item.locationOffset.line - 1,
43
53
  // @ts-expect-error -- `index` field exist but show ts error
44
54
  offset: item.locationOffset.index + 1
45
55
  }));
46
- return blocksMap.set(filePath, blocks), [
56
+ blocksMap.set(filePath, blocks);
57
+ return [
47
58
  ...blocks,
48
59
  code
49
60
  /* source code must be provided and be last */
50
61
  ];
51
62
  } catch (error) {
52
- return error instanceof Error && (error.message = `[graphql-eslint] Error while preprocessing "${_nodepath.relative.call(void 0,
53
- _utilsjs.CWD,
54
- filePath
55
- )}" file
63
+ if (error instanceof Error) {
64
+ error.message = `[graphql-eslint] Error while preprocessing "${_nodepath.relative.call(void 0,
65
+ _utilsjs.CWD,
66
+ filePath
67
+ )}" file
56
68
 
57
- ${error.message}`), console.error(error), [code];
69
+ ${error.message}`;
70
+ }
71
+ console.error(error);
72
+ return [code];
58
73
  }
59
74
  },
60
75
  postprocess(messages, filePath) {
@@ -62,18 +77,31 @@ ${error.message}`), console.error(error), [code];
62
77
  for (let i = 0; i < blocks.length; i += 1) {
63
78
  const { lineOffset, offset } = blocks[i];
64
79
  for (const message of messages[i] || []) {
65
- if (/\.(vue|svelte)$/.test(filePath)) {
66
- delete message.endLine, delete message.endColumn, delete message.fix, delete message.suggestions, Object.assign(message, _utilsjs.REPORT_ON_FIRST_CHARACTER);
80
+ const isVueOrSvelte = /\.(vue|svelte)$/.test(filePath);
81
+ if (isVueOrSvelte) {
82
+ delete message.endLine;
83
+ delete message.endColumn;
84
+ delete message.fix;
85
+ delete message.suggestions;
86
+ Object.assign(message, _utilsjs.REPORT_ON_FIRST_CHARACTER);
67
87
  continue;
68
88
  }
69
- message.line += lineOffset, typeof message.endLine == "number" && (message.endLine += lineOffset), message.fix && (message.fix.range[0] += offset, message.fix.range[1] += offset);
89
+ message.line += lineOffset;
90
+ if (typeof message.endLine === "number") {
91
+ message.endLine += lineOffset;
92
+ }
93
+ if (message.fix) {
94
+ message.fix.range[0] += offset;
95
+ message.fix.range[1] += offset;
96
+ }
70
97
  for (const suggestion of message.suggestions || []) {
71
98
  const [start, end] = suggestion.fix.range;
72
99
  suggestion.fix.range = [start + offset, end + offset];
73
100
  }
74
101
  }
75
102
  }
76
- return messages.flat().sort((a, b) => a.line - b.line || a.column - b.column);
103
+ const result = messages.flat();
104
+ return result.sort((a, b) => a.line - b.line || a.column - b.column);
77
105
  }
78
106
  };
79
107