@graphql-eslint/eslint-plugin 3.12.0-alpha-20221010010740-0fc38bd → 3.12.0-alpha-20221010131634-608c49a
Sign up to get free protection for your applications and to get access to all the features.
- package/index.js +38 -40
- package/index.mjs +39 -41
- package/package.json +1 -1
- package/schema.d.ts +1 -1
- package/sibling-operations.d.ts +1 -1
package/index.js
CHANGED
@@ -24,24 +24,15 @@ 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
|
-
|
28
|
-
const config = graphqlConfig.loadConfigSync({
|
27
|
+
return graphqlConfig.loadConfigSync({
|
29
28
|
// load config relative to the file being linted
|
30
|
-
rootDir,
|
29
|
+
rootDir: path.dirname(filePath),
|
31
30
|
throwOnEmpty: false,
|
32
31
|
throwOnMissing: false,
|
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)],
|
32
|
+
extensions: [codeFileLoaderExtension],
|
41
33
|
});
|
42
34
|
}
|
43
35
|
function loadGraphQLConfig(options) {
|
44
|
-
var _a;
|
45
36
|
// We don't want cache config on test environment
|
46
37
|
// Otherwise schema and documents will be same for all tests
|
47
38
|
if (process.env.NODE_ENV !== 'test' && graphQLConfig) {
|
@@ -66,37 +57,40 @@ function loadGraphQLConfig(options) {
|
|
66
57
|
new graphqlConfig.GraphQLConfig({
|
67
58
|
config: configOptions,
|
68
59
|
filepath: 'virtual-config',
|
69
|
-
}, [codeFileLoaderExtension
|
60
|
+
}, [codeFileLoaderExtension]);
|
70
61
|
return graphQLConfig;
|
71
62
|
}
|
72
|
-
const codeFileLoaderExtension =
|
63
|
+
const codeFileLoaderExtension = api => {
|
73
64
|
const { schema, documents } = api.loaders;
|
74
|
-
schema.register(new codeFileLoader.CodeFileLoader(
|
75
|
-
documents.register(new codeFileLoader.CodeFileLoader(
|
65
|
+
schema.register(new codeFileLoader.CodeFileLoader());
|
66
|
+
documents.register(new codeFileLoader.CodeFileLoader());
|
76
67
|
return { name: 'graphql-eslint-loaders' };
|
77
68
|
};
|
78
69
|
|
79
70
|
const blocksMap = new Map();
|
80
71
|
let onDiskConfig;
|
81
72
|
let onDiskConfigLoaded = false;
|
73
|
+
const RELEVANT_KEYWORDS = ['gql', 'graphql', 'GraphQL'];
|
82
74
|
const processor = {
|
83
75
|
supportsAutofix: true,
|
84
76
|
preprocess(code, filePath) {
|
85
|
-
var _a;
|
86
77
|
if (!onDiskConfigLoaded) {
|
87
78
|
onDiskConfig = loadOnDiskGraphQLConfig(filePath);
|
88
79
|
onDiskConfigLoaded = true;
|
89
80
|
}
|
90
|
-
|
91
|
-
const
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
...
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
81
|
+
let keywords = RELEVANT_KEYWORDS;
|
82
|
+
const pluckConfig = onDiskConfig === null || onDiskConfig === void 0 ? void 0 : onDiskConfig.getProjectForFile(filePath).extensions.pluckConfig;
|
83
|
+
if (pluckConfig) {
|
84
|
+
const { modules = [], globalGqlIdentifierName = ['gql', 'graphql'], gqlMagicComment = 'GraphQL', } = pluckConfig || {};
|
85
|
+
keywords = [
|
86
|
+
...new Set([
|
87
|
+
...modules.map(({ identifier }) => identifier),
|
88
|
+
...utils.asArray(globalGqlIdentifierName),
|
89
|
+
gqlMagicComment,
|
90
|
+
].filter(Boolean)),
|
91
|
+
];
|
92
|
+
}
|
93
|
+
if (keywords.every(keyword => !code.includes(keyword))) {
|
100
94
|
return [code];
|
101
95
|
}
|
102
96
|
try {
|
@@ -115,7 +109,7 @@ const processor = {
|
|
115
109
|
blocksMap.set(filePath, blocks);
|
116
110
|
return [...blocks, code /* source code must be provided and be last */];
|
117
111
|
}
|
118
|
-
catch (
|
112
|
+
catch (_a) {
|
119
113
|
// in case of parsing error return code as is
|
120
114
|
return [code];
|
121
115
|
}
|
@@ -4283,8 +4277,8 @@ const rules = {
|
|
4283
4277
|
|
4284
4278
|
const schemaCache = new Map();
|
4285
4279
|
const debug$1 = debugFactory('graphql-eslint:schema');
|
4286
|
-
function getSchema(
|
4287
|
-
const schemaKey = utils.asArray(
|
4280
|
+
function getSchema(project, options = {}) {
|
4281
|
+
const schemaKey = utils.asArray(project.schema).sort().join(',');
|
4288
4282
|
if (!schemaKey) {
|
4289
4283
|
return null;
|
4290
4284
|
}
|
@@ -4293,11 +4287,14 @@ function getSchema(projectForFile, options = {}) {
|
|
4293
4287
|
}
|
4294
4288
|
let schema;
|
4295
4289
|
try {
|
4296
|
-
debug$1('Loading schema from %o',
|
4297
|
-
schema =
|
4290
|
+
debug$1('Loading schema from %o', project.schema);
|
4291
|
+
schema = project.loadSchemaSync(project.schema, 'GraphQLSchema', {
|
4292
|
+
...options.schemaOptions,
|
4293
|
+
pluckConfig: project.extensions.pluckConfig,
|
4294
|
+
});
|
4298
4295
|
if (debug$1.enabled) {
|
4299
4296
|
debug$1('Schema loaded: %o', schema instanceof graphql.GraphQLSchema);
|
4300
|
-
const schemaPaths = fastGlob.sync(
|
4297
|
+
const schemaPaths = fastGlob.sync(project.schema, {
|
4301
4298
|
absolute: true,
|
4302
4299
|
});
|
4303
4300
|
debug$1('Schema pointers %O', schemaPaths);
|
@@ -4330,20 +4327,21 @@ const handleVirtualPath = (documents) => {
|
|
4330
4327
|
};
|
4331
4328
|
const operationsCache = new Map();
|
4332
4329
|
const siblingOperationsCache = new Map();
|
4333
|
-
const getSiblings = (
|
4334
|
-
const documentsKey = utils.asArray(
|
4330
|
+
const getSiblings = (project) => {
|
4331
|
+
const documentsKey = utils.asArray(project.documents).sort().join(',');
|
4335
4332
|
if (!documentsKey) {
|
4336
4333
|
return [];
|
4337
4334
|
}
|
4338
4335
|
let siblings = operationsCache.get(documentsKey);
|
4339
4336
|
if (!siblings) {
|
4340
|
-
debug$2('Loading operations from %o',
|
4341
|
-
const documents =
|
4337
|
+
debug$2('Loading operations from %o', project.documents);
|
4338
|
+
const documents = project.loadDocumentsSync(project.documents, {
|
4342
4339
|
skipGraphQLImport: true,
|
4340
|
+
pluckConfig: project.extensions.pluckConfig,
|
4343
4341
|
});
|
4344
4342
|
if (debug$2.enabled) {
|
4345
4343
|
debug$2('Loaded %d operations', documents.length);
|
4346
|
-
const operationsPaths = fastGlob.sync(
|
4344
|
+
const operationsPaths = fastGlob.sync(project.documents, {
|
4347
4345
|
absolute: true,
|
4348
4346
|
});
|
4349
4347
|
debug$2('Operations pointers %O', operationsPaths);
|
@@ -4353,8 +4351,8 @@ const getSiblings = (projectForFile) => {
|
|
4353
4351
|
}
|
4354
4352
|
return siblings;
|
4355
4353
|
};
|
4356
|
-
function getSiblingOperations(
|
4357
|
-
const siblings = getSiblings(
|
4354
|
+
function getSiblingOperations(project) {
|
4355
|
+
const siblings = getSiblings(project);
|
4358
4356
|
if (siblings.length === 0) {
|
4359
4357
|
let printed = false;
|
4360
4358
|
const noopWarn = () => {
|
package/index.mjs
CHANGED
@@ -2,7 +2,7 @@ import { gqlPluckFromCodeStringSync } 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 { loadConfigSync, GraphQLConfig } 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,24 +18,15 @@ 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
|
-
|
22
|
-
const config = loadConfigSync({
|
21
|
+
return loadConfigSync({
|
23
22
|
// load config relative to the file being linted
|
24
|
-
rootDir,
|
23
|
+
rootDir: dirname(filePath),
|
25
24
|
throwOnEmpty: false,
|
26
25
|
throwOnMissing: false,
|
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)],
|
26
|
+
extensions: [codeFileLoaderExtension],
|
35
27
|
});
|
36
28
|
}
|
37
29
|
function loadGraphQLConfig(options) {
|
38
|
-
var _a;
|
39
30
|
// We don't want cache config on test environment
|
40
31
|
// Otherwise schema and documents will be same for all tests
|
41
32
|
if (process.env.NODE_ENV !== 'test' && graphQLConfig) {
|
@@ -60,37 +51,40 @@ function loadGraphQLConfig(options) {
|
|
60
51
|
new GraphQLConfig({
|
61
52
|
config: configOptions,
|
62
53
|
filepath: 'virtual-config',
|
63
|
-
}, [codeFileLoaderExtension
|
54
|
+
}, [codeFileLoaderExtension]);
|
64
55
|
return graphQLConfig;
|
65
56
|
}
|
66
|
-
const codeFileLoaderExtension =
|
57
|
+
const codeFileLoaderExtension = api => {
|
67
58
|
const { schema, documents } = api.loaders;
|
68
|
-
schema.register(new CodeFileLoader(
|
69
|
-
documents.register(new CodeFileLoader(
|
59
|
+
schema.register(new CodeFileLoader());
|
60
|
+
documents.register(new CodeFileLoader());
|
70
61
|
return { name: 'graphql-eslint-loaders' };
|
71
62
|
};
|
72
63
|
|
73
64
|
const blocksMap = new Map();
|
74
65
|
let onDiskConfig;
|
75
66
|
let onDiskConfigLoaded = false;
|
67
|
+
const RELEVANT_KEYWORDS = ['gql', 'graphql', 'GraphQL'];
|
76
68
|
const processor = {
|
77
69
|
supportsAutofix: true,
|
78
70
|
preprocess(code, filePath) {
|
79
|
-
var _a;
|
80
71
|
if (!onDiskConfigLoaded) {
|
81
72
|
onDiskConfig = loadOnDiskGraphQLConfig(filePath);
|
82
73
|
onDiskConfigLoaded = true;
|
83
74
|
}
|
84
|
-
|
85
|
-
const
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
...
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
75
|
+
let keywords = RELEVANT_KEYWORDS;
|
76
|
+
const pluckConfig = onDiskConfig === null || onDiskConfig === void 0 ? void 0 : onDiskConfig.getProjectForFile(filePath).extensions.pluckConfig;
|
77
|
+
if (pluckConfig) {
|
78
|
+
const { modules = [], globalGqlIdentifierName = ['gql', 'graphql'], gqlMagicComment = 'GraphQL', } = pluckConfig || {};
|
79
|
+
keywords = [
|
80
|
+
...new Set([
|
81
|
+
...modules.map(({ identifier }) => identifier),
|
82
|
+
...asArray(globalGqlIdentifierName),
|
83
|
+
gqlMagicComment,
|
84
|
+
].filter(Boolean)),
|
85
|
+
];
|
86
|
+
}
|
87
|
+
if (keywords.every(keyword => !code.includes(keyword))) {
|
94
88
|
return [code];
|
95
89
|
}
|
96
90
|
try {
|
@@ -109,7 +103,7 @@ const processor = {
|
|
109
103
|
blocksMap.set(filePath, blocks);
|
110
104
|
return [...blocks, code /* source code must be provided and be last */];
|
111
105
|
}
|
112
|
-
catch (
|
106
|
+
catch (_a) {
|
113
107
|
// in case of parsing error return code as is
|
114
108
|
return [code];
|
115
109
|
}
|
@@ -4277,8 +4271,8 @@ const rules = {
|
|
4277
4271
|
|
4278
4272
|
const schemaCache = new Map();
|
4279
4273
|
const debug$1 = debugFactory('graphql-eslint:schema');
|
4280
|
-
function getSchema(
|
4281
|
-
const schemaKey = asArray(
|
4274
|
+
function getSchema(project, options = {}) {
|
4275
|
+
const schemaKey = asArray(project.schema).sort().join(',');
|
4282
4276
|
if (!schemaKey) {
|
4283
4277
|
return null;
|
4284
4278
|
}
|
@@ -4287,11 +4281,14 @@ function getSchema(projectForFile, options = {}) {
|
|
4287
4281
|
}
|
4288
4282
|
let schema;
|
4289
4283
|
try {
|
4290
|
-
debug$1('Loading schema from %o',
|
4291
|
-
schema =
|
4284
|
+
debug$1('Loading schema from %o', project.schema);
|
4285
|
+
schema = project.loadSchemaSync(project.schema, 'GraphQLSchema', {
|
4286
|
+
...options.schemaOptions,
|
4287
|
+
pluckConfig: project.extensions.pluckConfig,
|
4288
|
+
});
|
4292
4289
|
if (debug$1.enabled) {
|
4293
4290
|
debug$1('Schema loaded: %o', schema instanceof GraphQLSchema);
|
4294
|
-
const schemaPaths = fastGlob.sync(
|
4291
|
+
const schemaPaths = fastGlob.sync(project.schema, {
|
4295
4292
|
absolute: true,
|
4296
4293
|
});
|
4297
4294
|
debug$1('Schema pointers %O', schemaPaths);
|
@@ -4324,20 +4321,21 @@ const handleVirtualPath = (documents) => {
|
|
4324
4321
|
};
|
4325
4322
|
const operationsCache = new Map();
|
4326
4323
|
const siblingOperationsCache = new Map();
|
4327
|
-
const getSiblings = (
|
4328
|
-
const documentsKey = asArray(
|
4324
|
+
const getSiblings = (project) => {
|
4325
|
+
const documentsKey = asArray(project.documents).sort().join(',');
|
4329
4326
|
if (!documentsKey) {
|
4330
4327
|
return [];
|
4331
4328
|
}
|
4332
4329
|
let siblings = operationsCache.get(documentsKey);
|
4333
4330
|
if (!siblings) {
|
4334
|
-
debug$2('Loading operations from %o',
|
4335
|
-
const documents =
|
4331
|
+
debug$2('Loading operations from %o', project.documents);
|
4332
|
+
const documents = project.loadDocumentsSync(project.documents, {
|
4336
4333
|
skipGraphQLImport: true,
|
4334
|
+
pluckConfig: project.extensions.pluckConfig,
|
4337
4335
|
});
|
4338
4336
|
if (debug$2.enabled) {
|
4339
4337
|
debug$2('Loaded %d operations', documents.length);
|
4340
|
-
const operationsPaths = fastGlob.sync(
|
4338
|
+
const operationsPaths = fastGlob.sync(project.documents, {
|
4341
4339
|
absolute: true,
|
4342
4340
|
});
|
4343
4341
|
debug$2('Operations pointers %O', operationsPaths);
|
@@ -4347,8 +4345,8 @@ const getSiblings = (projectForFile) => {
|
|
4347
4345
|
}
|
4348
4346
|
return siblings;
|
4349
4347
|
};
|
4350
|
-
function getSiblingOperations(
|
4351
|
-
const siblings = getSiblings(
|
4348
|
+
function getSiblingOperations(project) {
|
4349
|
+
const siblings = getSiblings(project);
|
4352
4350
|
if (siblings.length === 0) {
|
4353
4351
|
let printed = false;
|
4354
4352
|
const noopWarn = () => {
|
package/package.json
CHANGED
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(
|
3
|
+
export declare function getSchema(project: GraphQLProjectConfig, options?: Omit<ParserOptions, 'filePath'>): Schema;
|
package/sibling-operations.d.ts
CHANGED
@@ -18,4 +18,4 @@ export declare type SiblingOperations = {
|
|
18
18
|
getOperations(): OperationSource[];
|
19
19
|
getOperationByType(operationType: OperationTypeNode): OperationSource[];
|
20
20
|
};
|
21
|
-
export declare function getSiblingOperations(
|
21
|
+
export declare function getSiblingOperations(project: GraphQLProjectConfig): SiblingOperations;
|