@graphql-eslint/eslint-plugin 3.14.4-alpha-20230113010120-7556537 → 3.14.4-alpha-20230113031536-5775a28
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.
- package/cjs/parser.js +6 -15
- package/cjs/schema.js +21 -11
- package/cjs/utils.js +3 -0
- package/esm/parser.js +7 -16
- package/esm/schema.js +21 -11
- package/esm/utils.js +3 -0
- package/package.json +1 -1
- package/typings/estree-converter/converter.d.cts +1 -1
- package/typings/estree-converter/converter.d.ts +1 -1
- package/typings/types.d.cts +1 -1
- package/typings/types.d.ts +1 -1
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
|
-
|
30
|
-
|
31
|
-
schema
|
32
|
-
? (0,
|
33
|
-
:
|
34
|
-
|
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
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
-
|
26
|
-
|
27
|
-
schema
|
28
|
-
?
|
29
|
-
:
|
30
|
-
|
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
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
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,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
|
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
|
3
|
+
export declare function convertToESTree<T extends DocumentNode>(node: T, schema?: GraphQLSchema): GraphQLESTreeNode<T, false>;
|
package/typings/types.d.cts
CHANGED
@@ -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, {
|
package/typings/types.d.ts
CHANGED
@@ -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, {
|