@graphql-eslint/eslint-plugin 3.4.0-alpha-c01d913.0 → 3.4.0-alpha-735b6ae.0
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/docs/rules/unique-enum-value-names.md +1 -1
- package/docs/rules/unique-field-definition-names.md +1 -1
- package/graphql-config.d.ts +0 -1
- package/index.js +45 -91
- package/index.mjs +45 -91
- package/package.json +2 -2
- package/types.d.ts +0 -1
- package/utils.d.ts +0 -6
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
- Category: `Schema`
|
4
4
|
- Rule name: `@graphql-eslint/unique-enum-value-names`
|
5
|
-
- Requires GraphQL Schema: `
|
5
|
+
- Requires GraphQL Schema: `false` [ℹ️](../../README.md#extended-linting-rules-with-graphql-schema)
|
6
6
|
- Requires GraphQL Operations: `false` [ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)
|
7
7
|
|
8
8
|
A GraphQL enum type is only valid if all its values are uniquely named.
|
@@ -4,7 +4,7 @@
|
|
4
4
|
|
5
5
|
- Category: `Schema`
|
6
6
|
- Rule name: `@graphql-eslint/unique-field-definition-names`
|
7
|
-
- Requires GraphQL Schema: `
|
7
|
+
- Requires GraphQL Schema: `false` [ℹ️](../../README.md#extended-linting-rules-with-graphql-schema)
|
8
8
|
- Requires GraphQL Operations: `false` [ℹ️](../../README.md#extended-linting-rules-with-siblings-operations)
|
9
9
|
|
10
10
|
A GraphQL complex type is only valid if all its fields are uniquely named.
|
package/graphql-config.d.ts
CHANGED
package/index.js
CHANGED
@@ -11,10 +11,10 @@ const path = require('path');
|
|
11
11
|
const utils = require('@graphql-tools/utils');
|
12
12
|
const lowerCase = _interopDefault(require('lodash.lowercase'));
|
13
13
|
const chalk = _interopDefault(require('chalk'));
|
14
|
-
const graphqlConfig = require('graphql-config');
|
15
|
-
const codeFileLoader = require('@graphql-tools/code-file-loader');
|
16
14
|
const depthLimit = _interopDefault(require('graphql-depth-limit'));
|
17
15
|
const graphqlTagPluck = require('@graphql-tools/graphql-tag-pluck');
|
16
|
+
const graphqlConfig = require('graphql-config');
|
17
|
+
const codeFileLoader = require('@graphql-tools/code-file-loader');
|
18
18
|
const eslint = require('eslint');
|
19
19
|
const codeFrame = require('@babel/code-frame');
|
20
20
|
|
@@ -175,47 +175,6 @@ const configs = {
|
|
175
175
|
'operations-all': operationsAllConfig,
|
176
176
|
};
|
177
177
|
|
178
|
-
let graphQLConfig;
|
179
|
-
function loadCachedGraphQLConfig(options) {
|
180
|
-
// We don't want cache config on test environment
|
181
|
-
// Otherwise schema and documents will be same for all tests
|
182
|
-
if (process.env.NODE_ENV !== 'test' && graphQLConfig) {
|
183
|
-
return graphQLConfig;
|
184
|
-
}
|
185
|
-
graphQLConfig = loadGraphQLConfig(options);
|
186
|
-
return graphQLConfig;
|
187
|
-
}
|
188
|
-
function loadGraphQLConfig(options) {
|
189
|
-
const onDiskConfig = options.skipGraphQLConfig
|
190
|
-
? null
|
191
|
-
: graphqlConfig.loadConfigSync({
|
192
|
-
throwOnEmpty: false,
|
193
|
-
throwOnMissing: false,
|
194
|
-
extensions: [addCodeFileLoaderExtension],
|
195
|
-
});
|
196
|
-
const configOptions = options.projects
|
197
|
-
? { projects: options.projects }
|
198
|
-
: {
|
199
|
-
schema: (options.schema || ''),
|
200
|
-
documents: options.documents || options.operations,
|
201
|
-
extensions: options.extensions,
|
202
|
-
include: options.include,
|
203
|
-
exclude: options.exclude,
|
204
|
-
};
|
205
|
-
graphQLConfig =
|
206
|
-
onDiskConfig ||
|
207
|
-
new graphqlConfig.GraphQLConfig({
|
208
|
-
config: configOptions,
|
209
|
-
filepath: 'virtual-config',
|
210
|
-
}, [addCodeFileLoaderExtension]);
|
211
|
-
return graphQLConfig;
|
212
|
-
}
|
213
|
-
const addCodeFileLoaderExtension = api => {
|
214
|
-
api.loaders.schema.register(new codeFileLoader.CodeFileLoader());
|
215
|
-
api.loaders.documents.register(new codeFileLoader.CodeFileLoader());
|
216
|
-
return { name: 'graphql-eslint-loaders' };
|
217
|
-
};
|
218
|
-
|
219
178
|
function requireSiblingsOperations(ruleName, context) {
|
220
179
|
if (!context.parserServices) {
|
221
180
|
throw new Error(`Rule '${ruleName}' requires 'parserOptions.operations' to be set and loaded. See http://bit.ly/graphql-eslint-operations for more info`);
|
@@ -240,37 +199,6 @@ const logger = {
|
|
240
199
|
// eslint-disable-next-line no-console
|
241
200
|
warn: (...args) => console.warn(chalk.yellow('warning'), '[graphql-eslint]', chalk(...args)),
|
242
201
|
};
|
243
|
-
const schemaToExtendCache = new Map();
|
244
|
-
const getGraphQLSchemaToExtend = (ruleId, context) => {
|
245
|
-
// If schema is not loaded, there is no reason to make partial schema aka schemaToExtend
|
246
|
-
if (!context.parserServices.hasTypeInfo) {
|
247
|
-
if (!getGraphQLSchemaToExtend.warningPrintedMap[ruleId]) {
|
248
|
-
logger.warn(`Rule "${ruleId}" works best with schema loaded. See http://bit.ly/graphql-eslint-schema for more info`);
|
249
|
-
getGraphQLSchemaToExtend.warningPrintedMap[ruleId] = true;
|
250
|
-
}
|
251
|
-
return null;
|
252
|
-
}
|
253
|
-
const filename = context.getPhysicalFilename();
|
254
|
-
if (!schemaToExtendCache.has(filename)) {
|
255
|
-
const { schema, schemaOptions } = context.parserOptions;
|
256
|
-
const gqlConfig = loadGraphQLConfig({ schema });
|
257
|
-
const projectForFile = gqlConfig.getProjectForFile(filename);
|
258
|
-
let schemaToExtend;
|
259
|
-
try {
|
260
|
-
schemaToExtend = projectForFile.loadSchemaSync(projectForFile.schema, 'GraphQLSchema', {
|
261
|
-
...schemaOptions,
|
262
|
-
ignore: filename,
|
263
|
-
});
|
264
|
-
}
|
265
|
-
catch (_a) {
|
266
|
-
// If error throws just ignore it because maybe schema is located in 1 file
|
267
|
-
schemaToExtend = null;
|
268
|
-
}
|
269
|
-
schemaToExtendCache.set(filename, schemaToExtend);
|
270
|
-
}
|
271
|
-
return schemaToExtendCache.get(filename);
|
272
|
-
};
|
273
|
-
getGraphQLSchemaToExtend.warningPrintedMap = Object.create(null);
|
274
202
|
function requireReachableTypesFromContext(ruleName, context) {
|
275
203
|
const schema = requireGraphQLSchemaFromContext(ruleName, context);
|
276
204
|
return context.parserServices.reachableTypes(schema);
|
@@ -405,14 +333,14 @@ function getLocation(loc, fieldName = '', offset) {
|
|
405
333
|
};
|
406
334
|
}
|
407
335
|
|
408
|
-
function validateDocument(context, schema = null, documentNode, rule
|
336
|
+
function validateDocument(context, schema = null, documentNode, rule) {
|
409
337
|
if (documentNode.definitions.length === 0) {
|
410
338
|
return;
|
411
339
|
}
|
412
340
|
try {
|
413
|
-
const validationErrors = schema
|
341
|
+
const validationErrors = schema
|
414
342
|
? graphql.validate(schema, documentNode, [rule])
|
415
|
-
: validate.validateSDL(documentNode,
|
343
|
+
: validate.validateSDL(documentNode, null, [rule]);
|
416
344
|
for (const error of validationErrors) {
|
417
345
|
/*
|
418
346
|
* TODO: Fix ESTree-AST converter because currently it's incorrectly convert loc.end
|
@@ -524,19 +452,13 @@ const validationToRule = (ruleId, ruleName, docs, getDocumentNode) => {
|
|
524
452
|
logger.warn(`You rule "${ruleId}" depends on a GraphQL validation rule "${ruleName}" but it's not available in the "graphql-js" version you are using. Skipping...`);
|
525
453
|
return {};
|
526
454
|
}
|
527
|
-
let schema;
|
528
|
-
if (docs.requiresSchemaToExtend) {
|
529
|
-
schema = getGraphQLSchemaToExtend(ruleId, context);
|
530
|
-
}
|
531
|
-
else if (docs.requiresSchema) {
|
532
|
-
schema = requireGraphQLSchemaFromContext(ruleId, context);
|
533
|
-
}
|
534
455
|
return {
|
535
456
|
Document(node) {
|
457
|
+
const schema = docs.requiresSchema ? requireGraphQLSchemaFromContext(ruleId, context) : null;
|
536
458
|
const documentNode = getDocumentNode
|
537
459
|
? getDocumentNode({ ruleId, context, schema, node: node.rawNode() })
|
538
460
|
: node.rawNode();
|
539
|
-
validateDocument(context, schema, documentNode, ruleFn
|
461
|
+
validateDocument(context, schema, documentNode, ruleFn);
|
540
462
|
},
|
541
463
|
};
|
542
464
|
},
|
@@ -688,7 +610,6 @@ const GRAPHQL_JS_VALIDATIONS = Object.assign({}, validationToRule('executable-de
|
|
688
610
|
description: `A type extension is only valid if the type is defined and has the same kind.`,
|
689
611
|
recommended: false,
|
690
612
|
requiresSchema: true,
|
691
|
-
requiresSchemaToExtend: true,
|
692
613
|
}), validationToRule('provided-required-arguments', 'ProvidedRequiredArguments', {
|
693
614
|
category: ['Schema', 'Operations'],
|
694
615
|
description: `A field or directive is only valid if all required (non-null without a default value) field arguments have been provided.`,
|
@@ -716,13 +637,9 @@ const GRAPHQL_JS_VALIDATIONS = Object.assign({}, validationToRule('executable-de
|
|
716
637
|
category: 'Schema',
|
717
638
|
description: `A GraphQL enum type is only valid if all its values are uniquely named.`,
|
718
639
|
recommended: false,
|
719
|
-
requiresSchema: true,
|
720
|
-
requiresSchemaToExtend: true,
|
721
640
|
}), validationToRule('unique-field-definition-names', 'UniqueFieldDefinitionNames', {
|
722
641
|
category: 'Schema',
|
723
642
|
description: `A GraphQL complex type is only valid if all its fields are uniquely named.`,
|
724
|
-
requiresSchema: true,
|
725
|
-
requiresSchemaToExtend: true,
|
726
643
|
}), validationToRule('unique-input-field-names', 'UniqueInputFieldNames', {
|
727
644
|
category: 'Operations',
|
728
645
|
description: `A GraphQL input object value is only valid if all supplied fields are uniquely named.`,
|
@@ -3813,6 +3730,43 @@ function getSiblingOperations(options, gqlConfig) {
|
|
3813
3730
|
return siblingOperations;
|
3814
3731
|
}
|
3815
3732
|
|
3733
|
+
let graphQLConfig;
|
3734
|
+
function loadGraphQLConfig(options) {
|
3735
|
+
// We don't want cache config on test environment
|
3736
|
+
// Otherwise schema and documents will be same for all tests
|
3737
|
+
if (process.env.NODE_ENV !== 'test' && graphQLConfig) {
|
3738
|
+
return graphQLConfig;
|
3739
|
+
}
|
3740
|
+
const onDiskConfig = options.skipGraphQLConfig
|
3741
|
+
? null
|
3742
|
+
: graphqlConfig.loadConfigSync({
|
3743
|
+
throwOnEmpty: false,
|
3744
|
+
throwOnMissing: false,
|
3745
|
+
extensions: [addCodeFileLoaderExtension],
|
3746
|
+
});
|
3747
|
+
const configOptions = options.projects
|
3748
|
+
? { projects: options.projects }
|
3749
|
+
: {
|
3750
|
+
schema: (options.schema || ''),
|
3751
|
+
documents: options.documents || options.operations,
|
3752
|
+
extensions: options.extensions,
|
3753
|
+
include: options.include,
|
3754
|
+
exclude: options.exclude,
|
3755
|
+
};
|
3756
|
+
graphQLConfig =
|
3757
|
+
onDiskConfig ||
|
3758
|
+
new graphqlConfig.GraphQLConfig({
|
3759
|
+
config: configOptions,
|
3760
|
+
filepath: 'virtual-config',
|
3761
|
+
}, [addCodeFileLoaderExtension]);
|
3762
|
+
return graphQLConfig;
|
3763
|
+
}
|
3764
|
+
const addCodeFileLoaderExtension = api => {
|
3765
|
+
api.loaders.schema.register(new codeFileLoader.CodeFileLoader());
|
3766
|
+
api.loaders.documents.register(new codeFileLoader.CodeFileLoader());
|
3767
|
+
return { name: 'graphql-eslint-loaders' };
|
3768
|
+
};
|
3769
|
+
|
3816
3770
|
let reachableTypesCache;
|
3817
3771
|
function getReachableTypes(schema) {
|
3818
3772
|
// We don't want cache reachableTypes on test environment
|
@@ -3895,7 +3849,7 @@ function parse(code, options) {
|
|
3895
3849
|
return parseForESLint(code, options).ast;
|
3896
3850
|
}
|
3897
3851
|
function parseForESLint(code, options = {}) {
|
3898
|
-
const gqlConfig =
|
3852
|
+
const gqlConfig = loadGraphQLConfig(options);
|
3899
3853
|
const schema = getSchema(options, gqlConfig);
|
3900
3854
|
const parserServices = {
|
3901
3855
|
hasTypeInfo: schema !== null,
|
package/index.mjs
CHANGED
@@ -5,10 +5,10 @@ import { dirname, extname, basename, relative, resolve } from 'path';
|
|
5
5
|
import { asArray, parseGraphQLSDL } from '@graphql-tools/utils';
|
6
6
|
import lowerCase from 'lodash.lowercase';
|
7
7
|
import chalk from 'chalk';
|
8
|
-
import { loadConfigSync, GraphQLConfig } from 'graphql-config';
|
9
|
-
import { CodeFileLoader } from '@graphql-tools/code-file-loader';
|
10
8
|
import depthLimit from 'graphql-depth-limit';
|
11
9
|
import { parseCode } from '@graphql-tools/graphql-tag-pluck';
|
10
|
+
import { loadConfigSync, GraphQLConfig } from 'graphql-config';
|
11
|
+
import { CodeFileLoader } from '@graphql-tools/code-file-loader';
|
12
12
|
import { RuleTester, Linter } from 'eslint';
|
13
13
|
import { codeFrameColumns } from '@babel/code-frame';
|
14
14
|
|
@@ -169,47 +169,6 @@ const configs = {
|
|
169
169
|
'operations-all': operationsAllConfig,
|
170
170
|
};
|
171
171
|
|
172
|
-
let graphQLConfig;
|
173
|
-
function loadCachedGraphQLConfig(options) {
|
174
|
-
// We don't want cache config on test environment
|
175
|
-
// Otherwise schema and documents will be same for all tests
|
176
|
-
if (process.env.NODE_ENV !== 'test' && graphQLConfig) {
|
177
|
-
return graphQLConfig;
|
178
|
-
}
|
179
|
-
graphQLConfig = loadGraphQLConfig(options);
|
180
|
-
return graphQLConfig;
|
181
|
-
}
|
182
|
-
function loadGraphQLConfig(options) {
|
183
|
-
const onDiskConfig = options.skipGraphQLConfig
|
184
|
-
? null
|
185
|
-
: loadConfigSync({
|
186
|
-
throwOnEmpty: false,
|
187
|
-
throwOnMissing: false,
|
188
|
-
extensions: [addCodeFileLoaderExtension],
|
189
|
-
});
|
190
|
-
const configOptions = options.projects
|
191
|
-
? { projects: options.projects }
|
192
|
-
: {
|
193
|
-
schema: (options.schema || ''),
|
194
|
-
documents: options.documents || options.operations,
|
195
|
-
extensions: options.extensions,
|
196
|
-
include: options.include,
|
197
|
-
exclude: options.exclude,
|
198
|
-
};
|
199
|
-
graphQLConfig =
|
200
|
-
onDiskConfig ||
|
201
|
-
new GraphQLConfig({
|
202
|
-
config: configOptions,
|
203
|
-
filepath: 'virtual-config',
|
204
|
-
}, [addCodeFileLoaderExtension]);
|
205
|
-
return graphQLConfig;
|
206
|
-
}
|
207
|
-
const addCodeFileLoaderExtension = api => {
|
208
|
-
api.loaders.schema.register(new CodeFileLoader());
|
209
|
-
api.loaders.documents.register(new CodeFileLoader());
|
210
|
-
return { name: 'graphql-eslint-loaders' };
|
211
|
-
};
|
212
|
-
|
213
172
|
function requireSiblingsOperations(ruleName, context) {
|
214
173
|
if (!context.parserServices) {
|
215
174
|
throw new Error(`Rule '${ruleName}' requires 'parserOptions.operations' to be set and loaded. See http://bit.ly/graphql-eslint-operations for more info`);
|
@@ -234,37 +193,6 @@ const logger = {
|
|
234
193
|
// eslint-disable-next-line no-console
|
235
194
|
warn: (...args) => console.warn(chalk.yellow('warning'), '[graphql-eslint]', chalk(...args)),
|
236
195
|
};
|
237
|
-
const schemaToExtendCache = new Map();
|
238
|
-
const getGraphQLSchemaToExtend = (ruleId, context) => {
|
239
|
-
// If schema is not loaded, there is no reason to make partial schema aka schemaToExtend
|
240
|
-
if (!context.parserServices.hasTypeInfo) {
|
241
|
-
if (!getGraphQLSchemaToExtend.warningPrintedMap[ruleId]) {
|
242
|
-
logger.warn(`Rule "${ruleId}" works best with schema loaded. See http://bit.ly/graphql-eslint-schema for more info`);
|
243
|
-
getGraphQLSchemaToExtend.warningPrintedMap[ruleId] = true;
|
244
|
-
}
|
245
|
-
return null;
|
246
|
-
}
|
247
|
-
const filename = context.getPhysicalFilename();
|
248
|
-
if (!schemaToExtendCache.has(filename)) {
|
249
|
-
const { schema, schemaOptions } = context.parserOptions;
|
250
|
-
const gqlConfig = loadGraphQLConfig({ schema });
|
251
|
-
const projectForFile = gqlConfig.getProjectForFile(filename);
|
252
|
-
let schemaToExtend;
|
253
|
-
try {
|
254
|
-
schemaToExtend = projectForFile.loadSchemaSync(projectForFile.schema, 'GraphQLSchema', {
|
255
|
-
...schemaOptions,
|
256
|
-
ignore: filename,
|
257
|
-
});
|
258
|
-
}
|
259
|
-
catch (_a) {
|
260
|
-
// If error throws just ignore it because maybe schema is located in 1 file
|
261
|
-
schemaToExtend = null;
|
262
|
-
}
|
263
|
-
schemaToExtendCache.set(filename, schemaToExtend);
|
264
|
-
}
|
265
|
-
return schemaToExtendCache.get(filename);
|
266
|
-
};
|
267
|
-
getGraphQLSchemaToExtend.warningPrintedMap = Object.create(null);
|
268
196
|
function requireReachableTypesFromContext(ruleName, context) {
|
269
197
|
const schema = requireGraphQLSchemaFromContext(ruleName, context);
|
270
198
|
return context.parserServices.reachableTypes(schema);
|
@@ -399,14 +327,14 @@ function getLocation(loc, fieldName = '', offset) {
|
|
399
327
|
};
|
400
328
|
}
|
401
329
|
|
402
|
-
function validateDocument(context, schema = null, documentNode, rule
|
330
|
+
function validateDocument(context, schema = null, documentNode, rule) {
|
403
331
|
if (documentNode.definitions.length === 0) {
|
404
332
|
return;
|
405
333
|
}
|
406
334
|
try {
|
407
|
-
const validationErrors = schema
|
335
|
+
const validationErrors = schema
|
408
336
|
? validate(schema, documentNode, [rule])
|
409
|
-
: validateSDL(documentNode,
|
337
|
+
: validateSDL(documentNode, null, [rule]);
|
410
338
|
for (const error of validationErrors) {
|
411
339
|
/*
|
412
340
|
* TODO: Fix ESTree-AST converter because currently it's incorrectly convert loc.end
|
@@ -518,19 +446,13 @@ const validationToRule = (ruleId, ruleName, docs, getDocumentNode) => {
|
|
518
446
|
logger.warn(`You rule "${ruleId}" depends on a GraphQL validation rule "${ruleName}" but it's not available in the "graphql-js" version you are using. Skipping...`);
|
519
447
|
return {};
|
520
448
|
}
|
521
|
-
let schema;
|
522
|
-
if (docs.requiresSchemaToExtend) {
|
523
|
-
schema = getGraphQLSchemaToExtend(ruleId, context);
|
524
|
-
}
|
525
|
-
else if (docs.requiresSchema) {
|
526
|
-
schema = requireGraphQLSchemaFromContext(ruleId, context);
|
527
|
-
}
|
528
449
|
return {
|
529
450
|
Document(node) {
|
451
|
+
const schema = docs.requiresSchema ? requireGraphQLSchemaFromContext(ruleId, context) : null;
|
530
452
|
const documentNode = getDocumentNode
|
531
453
|
? getDocumentNode({ ruleId, context, schema, node: node.rawNode() })
|
532
454
|
: node.rawNode();
|
533
|
-
validateDocument(context, schema, documentNode, ruleFn
|
455
|
+
validateDocument(context, schema, documentNode, ruleFn);
|
534
456
|
},
|
535
457
|
};
|
536
458
|
},
|
@@ -682,7 +604,6 @@ const GRAPHQL_JS_VALIDATIONS = Object.assign({}, validationToRule('executable-de
|
|
682
604
|
description: `A type extension is only valid if the type is defined and has the same kind.`,
|
683
605
|
recommended: false,
|
684
606
|
requiresSchema: true,
|
685
|
-
requiresSchemaToExtend: true,
|
686
607
|
}), validationToRule('provided-required-arguments', 'ProvidedRequiredArguments', {
|
687
608
|
category: ['Schema', 'Operations'],
|
688
609
|
description: `A field or directive is only valid if all required (non-null without a default value) field arguments have been provided.`,
|
@@ -710,13 +631,9 @@ const GRAPHQL_JS_VALIDATIONS = Object.assign({}, validationToRule('executable-de
|
|
710
631
|
category: 'Schema',
|
711
632
|
description: `A GraphQL enum type is only valid if all its values are uniquely named.`,
|
712
633
|
recommended: false,
|
713
|
-
requiresSchema: true,
|
714
|
-
requiresSchemaToExtend: true,
|
715
634
|
}), validationToRule('unique-field-definition-names', 'UniqueFieldDefinitionNames', {
|
716
635
|
category: 'Schema',
|
717
636
|
description: `A GraphQL complex type is only valid if all its fields are uniquely named.`,
|
718
|
-
requiresSchema: true,
|
719
|
-
requiresSchemaToExtend: true,
|
720
637
|
}), validationToRule('unique-input-field-names', 'UniqueInputFieldNames', {
|
721
638
|
category: 'Operations',
|
722
639
|
description: `A GraphQL input object value is only valid if all supplied fields are uniquely named.`,
|
@@ -3807,6 +3724,43 @@ function getSiblingOperations(options, gqlConfig) {
|
|
3807
3724
|
return siblingOperations;
|
3808
3725
|
}
|
3809
3726
|
|
3727
|
+
let graphQLConfig;
|
3728
|
+
function loadGraphQLConfig(options) {
|
3729
|
+
// We don't want cache config on test environment
|
3730
|
+
// Otherwise schema and documents will be same for all tests
|
3731
|
+
if (process.env.NODE_ENV !== 'test' && graphQLConfig) {
|
3732
|
+
return graphQLConfig;
|
3733
|
+
}
|
3734
|
+
const onDiskConfig = options.skipGraphQLConfig
|
3735
|
+
? null
|
3736
|
+
: loadConfigSync({
|
3737
|
+
throwOnEmpty: false,
|
3738
|
+
throwOnMissing: false,
|
3739
|
+
extensions: [addCodeFileLoaderExtension],
|
3740
|
+
});
|
3741
|
+
const configOptions = options.projects
|
3742
|
+
? { projects: options.projects }
|
3743
|
+
: {
|
3744
|
+
schema: (options.schema || ''),
|
3745
|
+
documents: options.documents || options.operations,
|
3746
|
+
extensions: options.extensions,
|
3747
|
+
include: options.include,
|
3748
|
+
exclude: options.exclude,
|
3749
|
+
};
|
3750
|
+
graphQLConfig =
|
3751
|
+
onDiskConfig ||
|
3752
|
+
new GraphQLConfig({
|
3753
|
+
config: configOptions,
|
3754
|
+
filepath: 'virtual-config',
|
3755
|
+
}, [addCodeFileLoaderExtension]);
|
3756
|
+
return graphQLConfig;
|
3757
|
+
}
|
3758
|
+
const addCodeFileLoaderExtension = api => {
|
3759
|
+
api.loaders.schema.register(new CodeFileLoader());
|
3760
|
+
api.loaders.documents.register(new CodeFileLoader());
|
3761
|
+
return { name: 'graphql-eslint-loaders' };
|
3762
|
+
};
|
3763
|
+
|
3810
3764
|
let reachableTypesCache;
|
3811
3765
|
function getReachableTypes(schema) {
|
3812
3766
|
// We don't want cache reachableTypes on test environment
|
@@ -3889,7 +3843,7 @@ function parse(code, options) {
|
|
3889
3843
|
return parseForESLint(code, options).ast;
|
3890
3844
|
}
|
3891
3845
|
function parseForESLint(code, options = {}) {
|
3892
|
-
const gqlConfig =
|
3846
|
+
const gqlConfig = loadGraphQLConfig(options);
|
3893
3847
|
const schema = getSchema(options, gqlConfig);
|
3894
3848
|
const parserServices = {
|
3895
3849
|
hasTypeInfo: schema !== null,
|
package/package.json
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
{
|
2
2
|
"name": "@graphql-eslint/eslint-plugin",
|
3
|
-
"version": "3.4.0-alpha-
|
3
|
+
"version": "3.4.0-alpha-735b6ae.0",
|
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.16.
|
10
|
+
"@babel/code-frame": "7.16.7",
|
11
11
|
"@graphql-tools/code-file-loader": "7.2.3",
|
12
12
|
"@graphql-tools/graphql-tag-pluck": "7.1.4",
|
13
13
|
"@graphql-tools/utils": "8.5.5",
|
package/types.d.ts
CHANGED
package/utils.d.ts
CHANGED
@@ -10,11 +10,6 @@ export declare const logger: {
|
|
10
10
|
error: (...args: any[]) => void;
|
11
11
|
warn: (...args: any[]) => void;
|
12
12
|
};
|
13
|
-
declare type GetGraphQLSchemaToExtend = {
|
14
|
-
(ruleId: string, ctx: GraphQLESLintRuleContext): GraphQLSchema | null;
|
15
|
-
warningPrintedMap: Record<string, boolean>;
|
16
|
-
};
|
17
|
-
export declare const getGraphQLSchemaToExtend: GetGraphQLSchemaToExtend;
|
18
13
|
export declare function requireReachableTypesFromContext(ruleName: string, context: GraphQLESLintRuleContext): ReachableTypes | never;
|
19
14
|
export declare function requireUsedFieldsFromContext(ruleName: string, context: GraphQLESLintRuleContext): UsedFields | never;
|
20
15
|
export declare function extractTokens(source: Source): AST.Token[];
|
@@ -36,4 +31,3 @@ export declare function getLocation(loc: Partial<AST.SourceLocation>, fieldName?
|
|
36
31
|
offsetStart?: number;
|
37
32
|
offsetEnd?: number;
|
38
33
|
}): AST.SourceLocation;
|
39
|
-
export {};
|