@graphql-eslint/eslint-plugin 3.11.2 → 3.11.3-alpha-20221008220048-6ed3933
Sign up to get free protection for your applications and to get access to all the features.
- package/graphql-config.d.ts +1 -1
- package/index.js +41 -26
- package/index.mjs +42 -27
- package/package.json +7 -7
- package/parser.d.ts +1 -1
- package/schema.d.ts +1 -1
- package/testkit.d.ts +2 -2
- package/types.d.ts +1 -1
package/graphql-config.d.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
1
|
import { GraphQLConfig } from 'graphql-config';
|
2
2
|
import { ParserOptions } from './types';
|
3
3
|
export declare function loadOnDiskGraphQLConfig(filePath: string): GraphQLConfig;
|
4
|
-
export declare function loadGraphQLConfig(options
|
4
|
+
export declare function loadGraphQLConfig(options: ParserOptions): GraphQLConfig;
|
package/index.js
CHANGED
@@ -24,15 +24,24 @@ const codeFrame = require('@babel/code-frame');
|
|
24
24
|
const debug = debugFactory('graphql-eslint:graphql-config');
|
25
25
|
let graphQLConfig;
|
26
26
|
function loadOnDiskGraphQLConfig(filePath) {
|
27
|
-
|
27
|
+
const rootDir = path.dirname(filePath);
|
28
|
+
const config = graphqlConfig.loadConfigSync({
|
28
29
|
// load config relative to the file being linted
|
29
|
-
rootDir
|
30
|
+
rootDir,
|
30
31
|
throwOnEmpty: false,
|
31
32
|
throwOnMissing: false,
|
32
|
-
|
33
|
+
});
|
34
|
+
if (!config) {
|
35
|
+
return null;
|
36
|
+
}
|
37
|
+
const project = config.getProjectForFile(filePath);
|
38
|
+
return graphqlConfig.loadConfigSync({
|
39
|
+
rootDir,
|
40
|
+
extensions: [codeFileLoaderExtension(project.extensions.pluckConfig)],
|
33
41
|
});
|
34
42
|
}
|
35
|
-
function loadGraphQLConfig(options
|
43
|
+
function loadGraphQLConfig(options) {
|
44
|
+
var _a;
|
36
45
|
// We don't want cache config on test environment
|
37
46
|
// Otherwise schema and documents will be same for all tests
|
38
47
|
if (process.env.NODE_ENV !== 'test' && graphQLConfig) {
|
@@ -57,31 +66,40 @@ function loadGraphQLConfig(options = {}) {
|
|
57
66
|
new graphqlConfig.GraphQLConfig({
|
58
67
|
config: configOptions,
|
59
68
|
filepath: 'virtual-config',
|
60
|
-
}, [
|
69
|
+
}, [codeFileLoaderExtension((_a = options.extensions) === null || _a === void 0 ? void 0 : _a.pluckConfig)]);
|
61
70
|
return graphQLConfig;
|
62
71
|
}
|
63
|
-
const
|
64
|
-
api.loaders
|
65
|
-
|
72
|
+
const codeFileLoaderExtension = (pluckConfig) => api => {
|
73
|
+
const { schema, documents } = api.loaders;
|
74
|
+
schema.register(new codeFileLoader.CodeFileLoader({ pluckConfig }));
|
75
|
+
documents.register(new codeFileLoader.CodeFileLoader({ pluckConfig }));
|
66
76
|
return { name: 'graphql-eslint-loaders' };
|
67
77
|
};
|
68
78
|
|
69
79
|
const blocksMap = new Map();
|
70
80
|
let onDiskConfig;
|
81
|
+
let pluckConfig;
|
82
|
+
let RELEVANT_KEYWORDS;
|
71
83
|
const processor = {
|
72
84
|
supportsAutofix: true,
|
73
85
|
preprocess(code, filePath) {
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
...utils.asArray(globalGqlIdentifierName),
|
86
|
+
if (!pluckConfig) {
|
87
|
+
onDiskConfig = loadOnDiskGraphQLConfig(filePath);
|
88
|
+
const { modules = [], globalGqlIdentifierName = ['gql', 'graphql'], gqlMagicComment = 'GraphQL', } = (onDiskConfig === null || onDiskConfig === void 0 ? void 0 : onDiskConfig.getProjectForFile(filePath).extensions.pluckConfig) || {};
|
89
|
+
pluckConfig = {
|
90
|
+
skipIndent: true,
|
91
|
+
modules,
|
92
|
+
globalGqlIdentifierName,
|
82
93
|
gqlMagicComment,
|
83
|
-
|
84
|
-
|
94
|
+
};
|
95
|
+
RELEVANT_KEYWORDS = [
|
96
|
+
...new Set([
|
97
|
+
...modules.map(({ identifier }) => identifier),
|
98
|
+
...utils.asArray(globalGqlIdentifierName),
|
99
|
+
gqlMagicComment,
|
100
|
+
].filter(Boolean)),
|
101
|
+
];
|
102
|
+
}
|
85
103
|
if (RELEVANT_KEYWORDS.every(keyword => !code.includes(keyword))) {
|
86
104
|
return [code];
|
87
105
|
}
|
@@ -89,10 +107,7 @@ const processor = {
|
|
89
107
|
const extractedDocuments = graphqlTagPluck.parseCode({
|
90
108
|
code,
|
91
109
|
filePath,
|
92
|
-
options:
|
93
|
-
skipIndent: true,
|
94
|
-
...graphQLTagPluckOptions,
|
95
|
-
},
|
110
|
+
options: pluckConfig,
|
96
111
|
});
|
97
112
|
const blocks = extractedDocuments.map(item => ({
|
98
113
|
filename: 'document.graphql',
|
@@ -103,7 +118,7 @@ const processor = {
|
|
103
118
|
blocksMap.set(filePath, blocks);
|
104
119
|
return [...blocks, code /* source code must be provided and be last */];
|
105
120
|
}
|
106
|
-
catch (
|
121
|
+
catch (_a) {
|
107
122
|
// in case of parsing error return code as is
|
108
123
|
return [code];
|
109
124
|
}
|
@@ -4441,10 +4456,10 @@ function getSiblingOperations(projectForFile) {
|
|
4441
4456
|
|
4442
4457
|
const debug$3 = debugFactory('graphql-eslint:parser');
|
4443
4458
|
debug$3('cwd %o', process.cwd());
|
4444
|
-
function parseForESLint(code, options
|
4459
|
+
function parseForESLint(code, options) {
|
4445
4460
|
try {
|
4446
|
-
const filePath = options
|
4447
|
-
const realFilepath =
|
4461
|
+
const { filePath } = options;
|
4462
|
+
const realFilepath = getOnDiskFilepath(filePath);
|
4448
4463
|
const gqlConfig = loadGraphQLConfig(options);
|
4449
4464
|
const projectForFile = realFilepath
|
4450
4465
|
? gqlConfig.getProjectForFile(realFilepath)
|
package/index.mjs
CHANGED
@@ -2,7 +2,7 @@ import { parseCode } from '@graphql-tools/graphql-tag-pluck';
|
|
2
2
|
import { asArray, getDocumentNodeFromSchema, parseGraphQLSDL } from '@graphql-tools/utils';
|
3
3
|
import { dirname, extname, basename, relative, resolve } from 'path';
|
4
4
|
import debugFactory from 'debug';
|
5
|
-
import {
|
5
|
+
import { GraphQLConfig, loadConfigSync } from 'graphql-config';
|
6
6
|
import { CodeFileLoader } from '@graphql-tools/code-file-loader';
|
7
7
|
import { Kind, visit, validate, TokenKind, isScalarType, DirectiveLocation, isInterfaceType, TypeInfo, visitWithTypeInfo, isObjectType as isObjectType$1, Source, isNonNullType, isListType, GraphQLObjectType, GraphQLInterfaceType, GraphQLSchema, GraphQLError } from 'graphql';
|
8
8
|
import { validateSDL } from 'graphql/validation/validate';
|
@@ -18,15 +18,24 @@ import { codeFrameColumns } from '@babel/code-frame';
|
|
18
18
|
const debug = debugFactory('graphql-eslint:graphql-config');
|
19
19
|
let graphQLConfig;
|
20
20
|
function loadOnDiskGraphQLConfig(filePath) {
|
21
|
-
|
21
|
+
const rootDir = dirname(filePath);
|
22
|
+
const config = loadConfigSync({
|
22
23
|
// load config relative to the file being linted
|
23
|
-
rootDir
|
24
|
+
rootDir,
|
24
25
|
throwOnEmpty: false,
|
25
26
|
throwOnMissing: false,
|
26
|
-
|
27
|
+
});
|
28
|
+
if (!config) {
|
29
|
+
return null;
|
30
|
+
}
|
31
|
+
const project = config.getProjectForFile(filePath);
|
32
|
+
return loadConfigSync({
|
33
|
+
rootDir,
|
34
|
+
extensions: [codeFileLoaderExtension(project.extensions.pluckConfig)],
|
27
35
|
});
|
28
36
|
}
|
29
|
-
function loadGraphQLConfig(options
|
37
|
+
function loadGraphQLConfig(options) {
|
38
|
+
var _a;
|
30
39
|
// We don't want cache config on test environment
|
31
40
|
// Otherwise schema and documents will be same for all tests
|
32
41
|
if (process.env.NODE_ENV !== 'test' && graphQLConfig) {
|
@@ -51,31 +60,40 @@ function loadGraphQLConfig(options = {}) {
|
|
51
60
|
new GraphQLConfig({
|
52
61
|
config: configOptions,
|
53
62
|
filepath: 'virtual-config',
|
54
|
-
}, [
|
63
|
+
}, [codeFileLoaderExtension((_a = options.extensions) === null || _a === void 0 ? void 0 : _a.pluckConfig)]);
|
55
64
|
return graphQLConfig;
|
56
65
|
}
|
57
|
-
const
|
58
|
-
api.loaders
|
59
|
-
|
66
|
+
const codeFileLoaderExtension = (pluckConfig) => api => {
|
67
|
+
const { schema, documents } = api.loaders;
|
68
|
+
schema.register(new CodeFileLoader({ pluckConfig }));
|
69
|
+
documents.register(new CodeFileLoader({ pluckConfig }));
|
60
70
|
return { name: 'graphql-eslint-loaders' };
|
61
71
|
};
|
62
72
|
|
63
73
|
const blocksMap = new Map();
|
64
74
|
let onDiskConfig;
|
75
|
+
let pluckConfig;
|
76
|
+
let RELEVANT_KEYWORDS;
|
65
77
|
const processor = {
|
66
78
|
supportsAutofix: true,
|
67
79
|
preprocess(code, filePath) {
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
...asArray(globalGqlIdentifierName),
|
80
|
+
if (!pluckConfig) {
|
81
|
+
onDiskConfig = loadOnDiskGraphQLConfig(filePath);
|
82
|
+
const { modules = [], globalGqlIdentifierName = ['gql', 'graphql'], gqlMagicComment = 'GraphQL', } = (onDiskConfig === null || onDiskConfig === void 0 ? void 0 : onDiskConfig.getProjectForFile(filePath).extensions.pluckConfig) || {};
|
83
|
+
pluckConfig = {
|
84
|
+
skipIndent: true,
|
85
|
+
modules,
|
86
|
+
globalGqlIdentifierName,
|
76
87
|
gqlMagicComment,
|
77
|
-
|
78
|
-
|
88
|
+
};
|
89
|
+
RELEVANT_KEYWORDS = [
|
90
|
+
...new Set([
|
91
|
+
...modules.map(({ identifier }) => identifier),
|
92
|
+
...asArray(globalGqlIdentifierName),
|
93
|
+
gqlMagicComment,
|
94
|
+
].filter(Boolean)),
|
95
|
+
];
|
96
|
+
}
|
79
97
|
if (RELEVANT_KEYWORDS.every(keyword => !code.includes(keyword))) {
|
80
98
|
return [code];
|
81
99
|
}
|
@@ -83,10 +101,7 @@ const processor = {
|
|
83
101
|
const extractedDocuments = parseCode({
|
84
102
|
code,
|
85
103
|
filePath,
|
86
|
-
options:
|
87
|
-
skipIndent: true,
|
88
|
-
...graphQLTagPluckOptions,
|
89
|
-
},
|
104
|
+
options: pluckConfig,
|
90
105
|
});
|
91
106
|
const blocks = extractedDocuments.map(item => ({
|
92
107
|
filename: 'document.graphql',
|
@@ -97,7 +112,7 @@ const processor = {
|
|
97
112
|
blocksMap.set(filePath, blocks);
|
98
113
|
return [...blocks, code /* source code must be provided and be last */];
|
99
114
|
}
|
100
|
-
catch (
|
115
|
+
catch (_a) {
|
101
116
|
// in case of parsing error return code as is
|
102
117
|
return [code];
|
103
118
|
}
|
@@ -4435,10 +4450,10 @@ function getSiblingOperations(projectForFile) {
|
|
4435
4450
|
|
4436
4451
|
const debug$3 = debugFactory('graphql-eslint:parser');
|
4437
4452
|
debug$3('cwd %o', process.cwd());
|
4438
|
-
function parseForESLint(code, options
|
4453
|
+
function parseForESLint(code, options) {
|
4439
4454
|
try {
|
4440
|
-
const filePath = options
|
4441
|
-
const realFilepath =
|
4455
|
+
const { filePath } = options;
|
4456
|
+
const realFilepath = getOnDiskFilepath(filePath);
|
4442
4457
|
const gqlConfig = loadGraphQLConfig(options);
|
4443
4458
|
const projectForFile = realFilepath
|
4444
4459
|
? gqlConfig.getProjectForFile(realFilepath)
|
package/package.json
CHANGED
@@ -1,20 +1,20 @@
|
|
1
1
|
{
|
2
2
|
"name": "@graphql-eslint/eslint-plugin",
|
3
|
-
"version": "3.11.
|
3
|
+
"version": "3.11.3-alpha-20221008220048-6ed3933",
|
4
4
|
"description": "GraphQL plugin for ESLint",
|
5
5
|
"sideEffects": false,
|
6
6
|
"peerDependencies": {
|
7
7
|
"graphql": "^0.8.0 || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0 || ^16.0.0"
|
8
8
|
},
|
9
9
|
"dependencies": {
|
10
|
-
"@babel/code-frame": "^7.
|
11
|
-
"@graphql-tools/code-file-loader": "^7.
|
12
|
-
"@graphql-tools/graphql-tag-pluck": "^7.
|
13
|
-
"@graphql-tools/utils": "^8.
|
10
|
+
"@babel/code-frame": "^7.18.6",
|
11
|
+
"@graphql-tools/code-file-loader": "^7.3.6",
|
12
|
+
"@graphql-tools/graphql-tag-pluck": "^7.3.6",
|
13
|
+
"@graphql-tools/utils": "^8.12.0",
|
14
14
|
"chalk": "^4.1.2",
|
15
15
|
"debug": "^4.3.4",
|
16
|
-
"fast-glob": "^3.2.
|
17
|
-
"graphql-config": "^4.3.
|
16
|
+
"fast-glob": "^3.2.12",
|
17
|
+
"graphql-config": "^4.3.5",
|
18
18
|
"graphql-depth-limit": "^1.1.0",
|
19
19
|
"lodash.lowercase": "^4.3.0"
|
20
20
|
},
|
package/parser.d.ts
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
import { GraphQLESLintParseResult, ParserOptions } from './types';
|
2
|
-
export declare function parseForESLint(code: string, options
|
2
|
+
export declare function parseForESLint(code: string, options: ParserOptions): GraphQLESLintParseResult;
|
package/schema.d.ts
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
import { GraphQLProjectConfig } from 'graphql-config';
|
2
2
|
import type { ParserOptions, Schema } from './types';
|
3
|
-
export declare function getSchema(projectForFile: GraphQLProjectConfig, options?: ParserOptions): Schema;
|
3
|
+
export declare function getSchema(projectForFile: GraphQLProjectConfig, options?: Omit<ParserOptions, 'filePath'>): Schema;
|
package/testkit.d.ts
CHANGED
@@ -16,9 +16,9 @@ export declare type GraphQLInvalidTestCase<T> = GraphQLValidTestCase<T> & {
|
|
16
16
|
export declare class GraphQLRuleTester extends RuleTester {
|
17
17
|
config: {
|
18
18
|
parser: string;
|
19
|
-
parserOptions: ParserOptions
|
19
|
+
parserOptions: Omit<ParserOptions, 'filePath'>;
|
20
20
|
};
|
21
|
-
constructor(parserOptions?: ParserOptions);
|
21
|
+
constructor(parserOptions?: Omit<ParserOptions, 'filePath'>);
|
22
22
|
fromMockFile(path: string): string;
|
23
23
|
runGraphQLTests<Options, WithTypeInfo extends boolean = false>(ruleId: string, rule: GraphQLESLintRule<Options, WithTypeInfo>, tests: {
|
24
24
|
valid: (string | GraphQLValidTestCase<Options>)[];
|
package/types.d.ts
CHANGED