@graphql-eslint/eslint-plugin 4.0.0-alpha.14 → 4.0.0-alpha.15

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.
@@ -8,7 +8,12 @@ import './estree-converter/types.cjs';
8
8
  import './siblings.cjs';
9
9
  import '@graphql-tools/utils';
10
10
 
11
+ /**
12
+ * Filepath can be a virtual file, so we need to find the first existing path
13
+ *
14
+ */
15
+ declare function getFirstExistingPath(filePath: string): string;
11
16
  declare function loadOnDiskGraphQLConfig(filePath: string): GraphQLConfig;
12
17
  declare function loadGraphQLConfig({ graphQLConfig: config, filePath, }: ParserOptions): GraphQLConfig;
13
18
 
14
- export { loadGraphQLConfig, loadOnDiskGraphQLConfig };
19
+ export { getFirstExistingPath, loadGraphQLConfig, loadOnDiskGraphQLConfig };
@@ -1,14 +1,20 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }require('./chunk-UIAXBAMD.js');
2
+ var _nodefs = require('node:fs'); var _nodefs2 = _interopRequireDefault(_nodefs);
2
3
  var _nodepath = require('node:path'); var _nodepath2 = _interopRequireDefault(_nodepath);
3
4
  var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
4
5
  var _graphqlconfig = require('graphql-config');
5
6
  var _codefileloader = require('@graphql-tools/code-file-loader');
6
7
  const debug = _debug2.default.call(void 0, "graphql-eslint:graphql-config");
7
8
  let graphQLConfig;
9
+ function getFirstExistingPath(filePath) {
10
+ for (; !_nodefs2.default.existsSync(filePath); )
11
+ filePath = _nodepath2.default.dirname(filePath);
12
+ return filePath;
13
+ }
8
14
  function loadOnDiskGraphQLConfig(filePath) {
9
15
  return _graphqlconfig.loadConfigSync.call(void 0, {
10
16
  // load config relative to the file being linted
11
- rootDir: _nodepath2.default.dirname(filePath),
17
+ rootDir: getFirstExistingPath(_nodepath2.default.dirname(filePath)),
12
18
  throwOnMissing: !1,
13
19
  extensions: [codeFileLoaderExtension]
14
20
  });
@@ -36,4 +42,5 @@ const codeFileLoaderExtension = (api) => {
36
42
 
37
43
 
38
44
 
39
- exports.loadGraphQLConfig = loadGraphQLConfig; exports.loadOnDiskGraphQLConfig = loadOnDiskGraphQLConfig;
45
+
46
+ exports.getFirstExistingPath = getFirstExistingPath; exports.loadGraphQLConfig = loadGraphQLConfig; exports.loadOnDiskGraphQLConfig = loadOnDiskGraphQLConfig;
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.14";
2
+ const version = "4.0.0-alpha.15";
3
3
 
4
4
 
5
5
  exports.version = version;
package/cjs/parser.js CHANGED
@@ -32,10 +32,7 @@ function parseForESLint(code, options) {
32
32
  try {
33
33
  const { filePath } = options, { document } = _utils.parseGraphQLSDL.call(void 0, filePath, code, { noLocation: !1 });
34
34
  let project, schema, documents;
35
- {
36
- const gqlConfig = _graphqlconfigjs.loadGraphQLConfig.call(void 0, options), realFilepath = filePath.replace(_utilsjs.VIRTUAL_DOCUMENT_REGEX, "");
37
- project = gqlConfig.getProjectForFile(realFilepath), documents = _documentsjs.getDocuments.call(void 0, project);
38
- }
35
+ project = _graphqlconfigjs.loadGraphQLConfig.call(void 0, options).getProjectForFile(_graphqlconfigjs.getFirstExistingPath.call(void 0, filePath)), documents = _documentsjs.getDocuments.call(void 0, project);
39
36
  try {
40
37
  schema = _schemajs.getSchema.call(void 0, project);
41
38
  } catch (error) {
package/cjs/processor.js CHANGED
@@ -16,6 +16,10 @@ const RELEVANT_KEYWORDS = ["gql", "graphql", "GraphQL"], processor = exports.pro
16
16
  },
17
17
  supportsAutofix: !0,
18
18
  preprocess(code, filePath) {
19
+ if (process.env.ESLINT_USE_FLAT_CONFIG !== "false" && filePath.endsWith(".vue"))
20
+ throw new Error(
21
+ "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"
22
+ );
19
23
  onDiskConfigLoaded || (onDiskConfig = _graphqlconfigjs.loadOnDiskGraphQLConfig.call(void 0, filePath), onDiskConfigLoaded = !0);
20
24
  let keywords = RELEVANT_KEYWORDS;
21
25
  const pluckConfig = _optionalChain([onDiskConfig, 'optionalAccess', _ => _.getProjectForFile, 'call', _2 => _2(filePath), 'access', _3 => _3.extensions, 'access', _4 => _4.pluckConfig]);
@@ -120,10 +120,13 @@ const RULE_ID = "no-deprecated", rule = exports.rule = {
120
120
  reason && report(node, reason);
121
121
  },
122
122
  ObjectValue(node) {
123
- const fields = node.typeInfo().inputType.getFields();
124
- for (const field of node.fields) {
125
- const fieldName = field.name.value, reason = fields[fieldName].deprecationReason;
126
- reason && report(field, reason);
123
+ const { inputType } = node.typeInfo();
124
+ if (inputType && "getFields" in inputType) {
125
+ const fields = inputType.getFields();
126
+ for (const field of node.fields) {
127
+ const fieldName = field.name.value, reason = fields[fieldName].deprecationReason;
128
+ reason && report(field, reason);
129
+ }
127
130
  }
128
131
  }
129
132
  };
@@ -8,7 +8,12 @@ import './estree-converter/types.js';
8
8
  import './siblings.js';
9
9
  import '@graphql-tools/utils';
10
10
 
11
+ /**
12
+ * Filepath can be a virtual file, so we need to find the first existing path
13
+ *
14
+ */
15
+ declare function getFirstExistingPath(filePath: string): string;
11
16
  declare function loadOnDiskGraphQLConfig(filePath: string): GraphQLConfig;
12
17
  declare function loadGraphQLConfig({ graphQLConfig: config, filePath, }: ParserOptions): GraphQLConfig;
13
18
 
14
- export { loadGraphQLConfig, loadOnDiskGraphQLConfig };
19
+ export { getFirstExistingPath, loadGraphQLConfig, loadOnDiskGraphQLConfig };
@@ -1,14 +1,20 @@
1
1
  import "./chunk-UIAXBAMD.js";
2
+ import fs from "node:fs";
2
3
  import path from "node:path";
3
4
  import debugFactory from "debug";
4
5
  import { GraphQLConfig, loadConfigSync } from "graphql-config";
5
6
  import { CodeFileLoader } from "@graphql-tools/code-file-loader";
6
7
  const debug = debugFactory("graphql-eslint:graphql-config");
7
8
  let graphQLConfig;
9
+ function getFirstExistingPath(filePath) {
10
+ for (; !fs.existsSync(filePath); )
11
+ filePath = path.dirname(filePath);
12
+ return filePath;
13
+ }
8
14
  function loadOnDiskGraphQLConfig(filePath) {
9
15
  return loadConfigSync({
10
16
  // load config relative to the file being linted
11
- rootDir: path.dirname(filePath),
17
+ rootDir: getFirstExistingPath(path.dirname(filePath)),
12
18
  throwOnMissing: !1,
13
19
  extensions: [codeFileLoaderExtension]
14
20
  });
@@ -34,6 +40,7 @@ const codeFileLoaderExtension = (api) => {
34
40
  return schema.register(new CodeFileLoader()), documents.register(new CodeFileLoader()), { name: "code-file-loaders" };
35
41
  };
36
42
  export {
43
+ getFirstExistingPath,
37
44
  loadGraphQLConfig,
38
45
  loadOnDiskGraphQLConfig
39
46
  };
package/esm/meta.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import "./chunk-UIAXBAMD.js";
2
- const version = "4.0.0-alpha.14";
2
+ const version = "4.0.0-alpha.15";
3
3
  export {
4
4
  version
5
5
  };
package/esm/parser.js CHANGED
@@ -4,11 +4,11 @@ import { GraphQLError } from "graphql";
4
4
  import { parseGraphQLSDL } from "@graphql-tools/utils";
5
5
  import { getDocuments } from "./documents.js";
6
6
  import { convertToESTree, extractComments, extractTokens } from "./estree-converter/index.js";
7
- import { loadGraphQLConfig } from "./graphql-config.js";
7
+ import { getFirstExistingPath, loadGraphQLConfig } from "./graphql-config.js";
8
8
  import { version } from "./meta.js";
9
9
  import { getSchema } from "./schema.js";
10
10
  import { getSiblings } from "./siblings.js";
11
- import { CWD, VIRTUAL_DOCUMENT_REGEX } from "./utils.js";
11
+ import { CWD } from "./utils.js";
12
12
  const debug = debugFactory("graphql-eslint:parser");
13
13
  debug("cwd %o", CWD);
14
14
  const LEGACY_PARSER_OPTIONS_KEYS = [
@@ -32,10 +32,7 @@ function parseForESLint(code, options) {
32
32
  try {
33
33
  const { filePath } = options, { document } = parseGraphQLSDL(filePath, code, { noLocation: !1 });
34
34
  let project, schema, documents;
35
- {
36
- const gqlConfig = loadGraphQLConfig(options), realFilepath = filePath.replace(VIRTUAL_DOCUMENT_REGEX, "");
37
- project = gqlConfig.getProjectForFile(realFilepath), documents = getDocuments(project);
38
- }
35
+ project = loadGraphQLConfig(options).getProjectForFile(getFirstExistingPath(filePath)), documents = getDocuments(project);
39
36
  try {
40
37
  schema = getSchema(project);
41
38
  } catch (error) {
package/esm/processor.js CHANGED
@@ -16,6 +16,10 @@ const RELEVANT_KEYWORDS = ["gql", "graphql", "GraphQL"], processor = {
16
16
  },
17
17
  supportsAutofix: !0,
18
18
  preprocess(code, filePath) {
19
+ if (process.env.ESLINT_USE_FLAT_CONFIG !== "false" && filePath.endsWith(".vue"))
20
+ throw new Error(
21
+ "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"
22
+ );
19
23
  onDiskConfigLoaded || (onDiskConfig = loadOnDiskGraphQLConfig(filePath), onDiskConfigLoaded = !0);
20
24
  let keywords = RELEVANT_KEYWORDS;
21
25
  const pluckConfig = onDiskConfig?.getProjectForFile(filePath).extensions.pluckConfig;
@@ -120,10 +120,13 @@ const RULE_ID = "no-deprecated", rule = {
120
120
  reason && report(node, reason);
121
121
  },
122
122
  ObjectValue(node) {
123
- const fields = node.typeInfo().inputType.getFields();
124
- for (const field of node.fields) {
125
- const fieldName = field.name.value, reason = fields[fieldName].deprecationReason;
126
- reason && report(field, reason);
123
+ const { inputType } = node.typeInfo();
124
+ if (inputType && "getFields" in inputType) {
125
+ const fields = inputType.getFields();
126
+ for (const field of node.fields) {
127
+ const fieldName = field.name.value, reason = fields[fieldName].deprecationReason;
128
+ reason && report(field, reason);
129
+ }
127
130
  }
128
131
  }
129
132
  };
package/index.browser.js CHANGED
@@ -2716,10 +2716,13 @@ var RULE_ID4 = "no-deprecated", rule8 = {
2716
2716
  reason && report(node, reason);
2717
2717
  },
2718
2718
  ObjectValue(node) {
2719
- let fields = node.typeInfo().inputType.getFields();
2720
- for (let field of node.fields) {
2721
- let fieldName = field.name.value, reason = fields[fieldName].deprecationReason;
2722
- reason && report(field, reason);
2719
+ let { inputType } = node.typeInfo();
2720
+ if (inputType && "getFields" in inputType) {
2721
+ let fields = inputType.getFields();
2722
+ for (let field of node.fields) {
2723
+ let fieldName = field.name.value, reason = fields[fieldName].deprecationReason;
2724
+ reason && report(field, reason);
2725
+ }
2723
2726
  }
2724
2727
  }
2725
2728
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-eslint/eslint-plugin",
3
- "version": "4.0.0-alpha.14",
3
+ "version": "4.0.0-alpha.15",
4
4
  "type": "module",
5
5
  "description": "GraphQL plugin for ESLint",
6
6
  "repository": "https://github.com/B2o5T/graphql-eslint",