@graphql-eslint/eslint-plugin 3.14.4-alpha-20230125194817-6f69222 → 3.15.0-alpha-20230125195254-57d0b30
Sign up to get free protection for your applications and to get access to all the features.
- package/cjs/parser.js +15 -6
- package/cjs/schema.js +11 -21
- package/cjs/utils.js +0 -3
- package/esm/parser.js +16 -7
- package/esm/schema.js +11 -21
- package/esm/utils.js +0 -3
- 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 +2 -2
- package/typings/types.d.ts +2 -2
package/cjs/parser.js
CHANGED
@@ -26,12 +26,21 @@ 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
|
-
|
32
|
-
? (0,
|
33
|
-
:
|
34
|
-
|
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);
|
35
44
|
return {
|
36
45
|
services: {
|
37
46
|
schema,
|
package/cjs/schema.js
CHANGED
@@ -2,7 +2,6 @@
|
|
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"));
|
6
5
|
const debug_1 = tslib_1.__importDefault(require("debug"));
|
7
6
|
const fast_glob_1 = tslib_1.__importDefault(require("fast-glob"));
|
8
7
|
const graphql_1 = require("graphql");
|
@@ -18,27 +17,18 @@ function getSchema(project, schemaOptions) {
|
|
18
17
|
if (cache) {
|
19
18
|
return cache;
|
20
19
|
}
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
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;
|
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);
|
41
29
|
}
|
30
|
+
// Do not set error to cache, since cache reload will be done after some `lifetime` seconds
|
31
|
+
schemaCache.set(schemaKey, schema);
|
42
32
|
return schema;
|
43
33
|
}
|
44
34
|
exports.getSchema = getSchema;
|
package/cjs/utils.js
CHANGED
@@ -18,9 +18,6 @@ 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
|
-
}
|
24
21
|
return schema;
|
25
22
|
}
|
26
23
|
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
|
3
|
+
import { buildSchema, GraphQLError } 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,12 +22,21 @@ 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
|
-
|
28
|
-
?
|
29
|
-
:
|
30
|
-
|
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);
|
31
40
|
return {
|
32
41
|
services: {
|
33
42
|
schema,
|
package/esm/schema.js
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
import chalk from 'chalk';
|
2
1
|
import debugFactory from 'debug';
|
3
2
|
import fg from 'fast-glob';
|
4
3
|
import { GraphQLSchema } from 'graphql';
|
@@ -14,26 +13,17 @@ export function getSchema(project, schemaOptions) {
|
|
14
13
|
if (cache) {
|
15
14
|
return cache;
|
16
15
|
}
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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;
|
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);
|
37
25
|
}
|
26
|
+
// Do not set error to cache, since cache reload will be done after some `lifetime` seconds
|
27
|
+
schemaCache.set(schemaKey, schema);
|
38
28
|
return schema;
|
39
29
|
}
|
package/esm/utils.js
CHANGED
@@ -13,9 +13,6 @@ 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
|
-
}
|
19
16
|
return schema;
|
20
17
|
}
|
21
18
|
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): GraphQLESTreeNode<T, false>;
|
3
|
+
export declare function convertToESTree<T extends DocumentNode>(node: T, schema?: GraphQLSchema | null): 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): GraphQLESTreeNode<T, false>;
|
3
|
+
export declare function convertToESTree<T extends DocumentNode>(node: T, schema?: GraphQLSchema | null): GraphQLESTreeNode<T, false>;
|
package/typings/types.d.cts
CHANGED
@@ -6,8 +6,8 @@ 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 =
|
10
|
-
export type Pointer = string
|
9
|
+
export type Schema = GraphQLSchema | null;
|
10
|
+
export type Pointer = string | string[];
|
11
11
|
export interface ParserOptions {
|
12
12
|
schema?: Pointer | Record<string, {
|
13
13
|
headers: Record<string, string>;
|
package/typings/types.d.ts
CHANGED
@@ -6,8 +6,8 @@ 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 =
|
10
|
-
export type Pointer = string
|
9
|
+
export type Schema = GraphQLSchema | null;
|
10
|
+
export type Pointer = string | string[];
|
11
11
|
export interface ParserOptions {
|
12
12
|
schema?: Pointer | Record<string, {
|
13
13
|
headers: Record<string, string>;
|