@graphql-eslint/eslint-plugin 3.14.4-alpha-20230113010120-7556537 → 3.14.4-alpha-20230113031340-573c921

Sign up to get free protection for your applications and to get access to all the features.
package/cjs/parser.js CHANGED
@@ -26,21 +26,12 @@ function parseForESLint(code, options) {
26
26
  const gqlConfig = (0, graphql_config_js_1.loadGraphQLConfig)(options);
27
27
  const realFilepath = filePath.replace(utils_js_1.VIRTUAL_DOCUMENT_REGEX, '');
28
28
  const project = gqlConfig.getProjectForFile(realFilepath);
29
- let schema = null;
30
- try {
31
- schema = project
32
- ? (0, schema_js_1.getSchema)(project, options.schemaOptions)
33
- : typeof options.schema === 'string'
34
- ? (0, graphql_1.buildSchema)(options.schema)
35
- : null;
36
- }
37
- catch (error) {
38
- if (error instanceof Error) {
39
- error.message = `Error while loading schema: ${error.message}`;
40
- }
41
- throw error;
42
- }
43
- const rootTree = (0, index_js_1.convertToESTree)(document, schema);
29
+ const schema = project
30
+ ? (0, schema_js_1.getSchema)(project, options.schemaOptions)
31
+ : typeof options.schema === 'string'
32
+ ? (0, graphql_1.buildSchema)(options.schema)
33
+ : null;
34
+ const rootTree = (0, index_js_1.convertToESTree)(document, schema instanceof graphql_1.GraphQLSchema ? schema : undefined);
44
35
  return {
45
36
  services: {
46
37
  schema,
package/cjs/schema.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getSchema = void 0;
4
4
  const tslib_1 = require("tslib");
5
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
5
6
  const debug_1 = tslib_1.__importDefault(require("debug"));
6
7
  const fast_glob_1 = tslib_1.__importDefault(require("fast-glob"));
7
8
  const graphql_1 = require("graphql");
@@ -17,18 +18,27 @@ function getSchema(project, schemaOptions) {
17
18
  if (cache) {
18
19
  return cache;
19
20
  }
20
- debug('Loading schema from %o', project.schema);
21
- const schema = project.loadSchemaSync(project.schema, 'GraphQLSchema', {
22
- ...schemaOptions,
23
- pluckConfig: project.extensions.pluckConfig,
24
- });
25
- if (debug.enabled) {
26
- debug('Schema loaded: %o', schema instanceof graphql_1.GraphQLSchema);
27
- const schemaPaths = fast_glob_1.default.sync(project.schema, { absolute: true });
28
- debug('Schema pointers %O', schemaPaths);
21
+ let schema;
22
+ try {
23
+ debug('Loading schema from %o', project.schema);
24
+ schema = project.loadSchemaSync(project.schema, 'GraphQLSchema', {
25
+ ...schemaOptions,
26
+ pluckConfig: project.extensions.pluckConfig,
27
+ });
28
+ if (debug.enabled) {
29
+ debug('Schema loaded: %o', schema instanceof graphql_1.GraphQLSchema);
30
+ const schemaPaths = fast_glob_1.default.sync(project.schema, { absolute: true });
31
+ debug('Schema pointers %O', schemaPaths);
32
+ }
33
+ // Do not set error to cache, since cache reload will be done after some `lifetime` seconds
34
+ schemaCache.set(schemaKey, schema);
35
+ }
36
+ catch (error) {
37
+ if (error instanceof Error) {
38
+ error.message = chalk_1.default.red(`Error while loading schema: ${error.message}`);
39
+ }
40
+ schema = error;
29
41
  }
30
- // Do not set error to cache, since cache reload will be done after some `lifetime` seconds
31
- schemaCache.set(schemaKey, schema);
32
42
  return schema;
33
43
  }
34
44
  exports.getSchema = getSchema;
package/cjs/utils.js CHANGED
@@ -18,6 +18,9 @@ function requireGraphQLSchemaFromContext(ruleId, context) {
18
18
  if (!schema) {
19
19
  throw new Error(`Rule \`${ruleId}\` requires \`parserOptions.schema\` to be set and loaded. See https://bit.ly/graphql-eslint-schema for more info`);
20
20
  }
21
+ else if (schema instanceof Error) {
22
+ throw schema;
23
+ }
21
24
  return schema;
22
25
  }
23
26
  exports.requireGraphQLSchemaFromContext = requireGraphQLSchemaFromContext;
package/esm/parser.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { parseGraphQLSDL } from '@graphql-tools/utils';
2
2
  import debugFactory from 'debug';
3
- import { buildSchema, GraphQLError } from 'graphql';
3
+ import { buildSchema, GraphQLError, GraphQLSchema } from 'graphql';
4
4
  import { convertToESTree, extractComments, extractTokens } from './estree-converter/index.js';
5
5
  import { loadGraphQLConfig } from './graphql-config.js';
6
6
  import { getSchema } from './schema.js';
@@ -22,21 +22,12 @@ export function parseForESLint(code, options) {
22
22
  const gqlConfig = loadGraphQLConfig(options);
23
23
  const realFilepath = filePath.replace(VIRTUAL_DOCUMENT_REGEX, '');
24
24
  const project = gqlConfig.getProjectForFile(realFilepath);
25
- let schema = null;
26
- try {
27
- schema = project
28
- ? getSchema(project, options.schemaOptions)
29
- : typeof options.schema === 'string'
30
- ? buildSchema(options.schema)
31
- : null;
32
- }
33
- catch (error) {
34
- if (error instanceof Error) {
35
- error.message = `Error while loading schema: ${error.message}`;
36
- }
37
- throw error;
38
- }
39
- const rootTree = convertToESTree(document, schema);
25
+ const schema = project
26
+ ? getSchema(project, options.schemaOptions)
27
+ : typeof options.schema === 'string'
28
+ ? buildSchema(options.schema)
29
+ : null;
30
+ const rootTree = convertToESTree(document, schema instanceof GraphQLSchema ? schema : undefined);
40
31
  return {
41
32
  services: {
42
33
  schema,
package/esm/schema.js CHANGED
@@ -1,3 +1,4 @@
1
+ import chalk from 'chalk';
1
2
  import debugFactory from 'debug';
2
3
  import fg from 'fast-glob';
3
4
  import { GraphQLSchema } from 'graphql';
@@ -13,17 +14,26 @@ export function getSchema(project, schemaOptions) {
13
14
  if (cache) {
14
15
  return cache;
15
16
  }
16
- debug('Loading schema from %o', project.schema);
17
- const schema = project.loadSchemaSync(project.schema, 'GraphQLSchema', {
18
- ...schemaOptions,
19
- pluckConfig: project.extensions.pluckConfig,
20
- });
21
- if (debug.enabled) {
22
- debug('Schema loaded: %o', schema instanceof GraphQLSchema);
23
- const schemaPaths = fg.sync(project.schema, { absolute: true });
24
- debug('Schema pointers %O', schemaPaths);
17
+ let schema;
18
+ try {
19
+ debug('Loading schema from %o', project.schema);
20
+ schema = project.loadSchemaSync(project.schema, 'GraphQLSchema', {
21
+ ...schemaOptions,
22
+ pluckConfig: project.extensions.pluckConfig,
23
+ });
24
+ if (debug.enabled) {
25
+ debug('Schema loaded: %o', schema instanceof GraphQLSchema);
26
+ const schemaPaths = fg.sync(project.schema, { absolute: true });
27
+ debug('Schema pointers %O', schemaPaths);
28
+ }
29
+ // Do not set error to cache, since cache reload will be done after some `lifetime` seconds
30
+ schemaCache.set(schemaKey, schema);
31
+ }
32
+ catch (error) {
33
+ if (error instanceof Error) {
34
+ error.message = chalk.red(`Error while loading schema: ${error.message}`);
35
+ }
36
+ schema = error;
25
37
  }
26
- // Do not set error to cache, since cache reload will be done after some `lifetime` seconds
27
- schemaCache.set(schemaKey, schema);
28
38
  return schema;
29
39
  }
package/esm/utils.js CHANGED
@@ -13,6 +13,9 @@ export function requireGraphQLSchemaFromContext(ruleId, context) {
13
13
  if (!schema) {
14
14
  throw new Error(`Rule \`${ruleId}\` requires \`parserOptions.schema\` to be set and loaded. See https://bit.ly/graphql-eslint-schema for more info`);
15
15
  }
16
+ else if (schema instanceof Error) {
17
+ throw schema;
18
+ }
16
19
  return schema;
17
20
  }
18
21
  export const logger = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-eslint/eslint-plugin",
3
- "version": "3.14.4-alpha-20230113010120-7556537",
3
+ "version": "3.14.4-alpha-20230113031340-573c921",
4
4
  "description": "GraphQL plugin for ESLint",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
@@ -1,3 +1,3 @@
1
1
  import { DocumentNode, GraphQLSchema } from 'graphql';
2
2
  import { GraphQLESTreeNode } from './types.cjs';
3
- export declare function convertToESTree<T extends DocumentNode>(node: T, schema?: GraphQLSchema | null): GraphQLESTreeNode<T, false>;
3
+ export declare function convertToESTree<T extends DocumentNode>(node: T, schema?: GraphQLSchema): GraphQLESTreeNode<T, false>;
@@ -1,3 +1,3 @@
1
1
  import { DocumentNode, GraphQLSchema } from 'graphql';
2
2
  import { GraphQLESTreeNode } from './types.js';
3
- export declare function convertToESTree<T extends DocumentNode>(node: T, schema?: GraphQLSchema | null): GraphQLESTreeNode<T, false>;
3
+ export declare function convertToESTree<T extends DocumentNode>(node: T, schema?: GraphQLSchema): GraphQLESTreeNode<T, false>;
@@ -6,7 +6,7 @@ import { IExtensions, IGraphQLProject } from 'graphql-config';
6
6
  import { JSONSchema } from 'json-schema-to-ts';
7
7
  import { SiblingOperations } from './siblings.cjs';
8
8
  import { GraphQLESLintRuleListener } from './testkit.cjs';
9
- export type Schema = GraphQLSchema | null;
9
+ export type Schema = GraphQLSchema | Error | null;
10
10
  export type Pointer = string | string[];
11
11
  export interface ParserOptions {
12
12
  schema?: Pointer | Record<string, {
@@ -6,7 +6,7 @@ import { IExtensions, IGraphQLProject } from 'graphql-config';
6
6
  import { JSONSchema } from 'json-schema-to-ts';
7
7
  import { SiblingOperations } from './siblings.js';
8
8
  import { GraphQLESLintRuleListener } from './testkit.js';
9
- export type Schema = GraphQLSchema | null;
9
+ export type Schema = GraphQLSchema | Error | null;
10
10
  export type Pointer = string | string[];
11
11
  export interface ParserOptions {
12
12
  schema?: Pointer | Record<string, {