@graphql-eslint/eslint-plugin 3.3.0-alpha-1c01242.0 → 3.3.0-alpha-d255c2b.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/naming-convention.md +16 -0
- package/docs/rules/possible-type-extension.md +1 -1
- package/graphql-config.d.ts +1 -1
- package/index.js +62 -52
- package/index.mjs +59 -49
- package/package.json +1 -1
- package/rules/naming-convention.d.ts +1 -0
- package/types.d.ts +0 -1
@@ -71,6 +71,18 @@ type Query {
|
|
71
71
|
}
|
72
72
|
```
|
73
73
|
|
74
|
+
### Correct
|
75
|
+
|
76
|
+
```graphql
|
77
|
+
# eslint @graphql-eslint/naming-convention: ['error', { FieldDefinition: { style: 'camelCase', ignorePattern: '^(EAN13|UPC|UK)' } }]
|
78
|
+
|
79
|
+
type Product {
|
80
|
+
EAN13: String
|
81
|
+
UPC: String
|
82
|
+
UKFlag: String
|
83
|
+
}
|
84
|
+
```
|
85
|
+
|
74
86
|
## Config Schema
|
75
87
|
|
76
88
|
> It's possible to use a [`selector`](https://eslint.org/docs/developer-guide/selectors) that starts with allowed `ASTNode` names which are described below.
|
@@ -276,6 +288,10 @@ Additional restrictions:
|
|
276
288
|
* Minimum items: `1`
|
277
289
|
* Unique items: `true`
|
278
290
|
|
291
|
+
### `ignorePattern` (string)
|
292
|
+
|
293
|
+
Option to skip validation of some words, e.g. acronyms
|
294
|
+
|
279
295
|
## Resources
|
280
296
|
|
281
297
|
- [Rule source](../../packages/plugin/src/rules/naming-convention.ts)
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
- Category: `Schema`
|
4
4
|
- Rule name: `@graphql-eslint/possible-type-extension`
|
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 type extension is only valid if the type is defined and has the same kind.
|
package/graphql-config.d.ts
CHANGED
package/index.js
CHANGED
@@ -12,7 +12,7 @@ const utils = require('@graphql-tools/utils');
|
|
12
12
|
const lowerCase = _interopDefault(require('lodash.lowercase'));
|
13
13
|
const depthLimit = _interopDefault(require('graphql-depth-limit'));
|
14
14
|
const graphqlTagPluck = require('@graphql-tools/graphql-tag-pluck');
|
15
|
-
const graphqlConfig = require('graphql-config');
|
15
|
+
const graphqlConfig$1 = require('graphql-config');
|
16
16
|
const codeFileLoader = require('@graphql-tools/code-file-loader');
|
17
17
|
const eslint = require('eslint');
|
18
18
|
const codeFrame = require('@babel/code-frame');
|
@@ -326,14 +326,14 @@ function getLocation(loc, fieldName = '', offset) {
|
|
326
326
|
};
|
327
327
|
}
|
328
328
|
|
329
|
-
function validateDocument(context, schema
|
329
|
+
function validateDocument(sourceNode, context, schema, documentNode, rule) {
|
330
330
|
if (documentNode.definitions.length === 0) {
|
331
331
|
return;
|
332
332
|
}
|
333
333
|
try {
|
334
|
-
const validationErrors = schema
|
334
|
+
const validationErrors = schema
|
335
335
|
? graphql.validate(schema, documentNode, [rule])
|
336
|
-
: validate.validateSDL(documentNode,
|
336
|
+
: validate.validateSDL(documentNode, null, [rule]);
|
337
337
|
for (const error of validationErrors) {
|
338
338
|
/*
|
339
339
|
* TODO: Fix ESTree-AST converter because currently it's incorrectly convert loc.end
|
@@ -358,8 +358,7 @@ function validateDocument(context, schema = null, documentNode, rule, isSchemaTo
|
|
358
358
|
}
|
359
359
|
catch (e) {
|
360
360
|
context.report({
|
361
|
-
|
362
|
-
loc: { column: 0, line: 1 },
|
361
|
+
node: sourceNode,
|
363
362
|
message: e.message,
|
364
363
|
});
|
365
364
|
}
|
@@ -441,18 +440,18 @@ const validationToRule = (ruleId, ruleName, docs, getDocumentNode) => {
|
|
441
440
|
},
|
442
441
|
},
|
443
442
|
create(context) {
|
444
|
-
if (!ruleFn) {
|
445
|
-
// eslint-disable-next-line no-console
|
446
|
-
console.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...`);
|
447
|
-
return {};
|
448
|
-
}
|
449
|
-
const schema = docs.requiresSchema ? requireGraphQLSchemaFromContext(ruleId, context) : null;
|
450
443
|
return {
|
451
444
|
Document(node) {
|
445
|
+
if (!ruleFn) {
|
446
|
+
// eslint-disable-next-line no-console
|
447
|
+
console.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...`);
|
448
|
+
return;
|
449
|
+
}
|
450
|
+
const schema = docs.requiresSchema ? requireGraphQLSchemaFromContext(ruleId, context) : null;
|
452
451
|
const documentNode = getDocumentNode
|
453
452
|
? getDocumentNode({ ruleId, context, schema, node: node.rawNode() })
|
454
453
|
: node.rawNode();
|
455
|
-
validateDocument(context, schema, documentNode, ruleFn
|
454
|
+
validateDocument(node, context, schema, documentNode, ruleFn);
|
456
455
|
},
|
457
456
|
};
|
458
457
|
},
|
@@ -602,9 +601,7 @@ const GRAPHQL_JS_VALIDATIONS = Object.assign({}, validationToRule('executable-de
|
|
602
601
|
}), validationToRule('possible-type-extension', 'PossibleTypeExtensions', {
|
603
602
|
category: 'Schema',
|
604
603
|
description: `A type extension is only valid if the type is defined and has the same kind.`,
|
605
|
-
recommended: false,
|
606
|
-
requiresSchema: true,
|
607
|
-
requiresSchemaToExtend: true,
|
604
|
+
recommended: false, // TODO: enable after https://github.com/dotansimha/graphql-eslint/issues/787 will be fixed
|
608
605
|
}), validationToRule('provided-required-arguments', 'ProvidedRequiredArguments', {
|
609
606
|
category: ['Schema', 'Operations'],
|
610
607
|
description: `A field or directive is only valid if all required (non-null without a default value) field arguments have been provided.`,
|
@@ -1376,6 +1373,17 @@ const rule$4 = {
|
|
1376
1373
|
type Query {
|
1377
1374
|
users: [User!]!
|
1378
1375
|
}
|
1376
|
+
`,
|
1377
|
+
},
|
1378
|
+
{
|
1379
|
+
title: 'Correct',
|
1380
|
+
usage: [{ FieldDefinition: { style: 'camelCase', ignorePattern: '^(EAN13|UPC|UK)' } }],
|
1381
|
+
code: /* GraphQL */ `
|
1382
|
+
type Product {
|
1383
|
+
EAN13: String
|
1384
|
+
UPC: String
|
1385
|
+
UKFlag: String
|
1386
|
+
}
|
1379
1387
|
`,
|
1380
1388
|
},
|
1381
1389
|
],
|
@@ -1445,6 +1453,10 @@ const rule$4 = {
|
|
1445
1453
|
minItems: 1,
|
1446
1454
|
items: { type: 'string' },
|
1447
1455
|
},
|
1456
|
+
ignorePattern: {
|
1457
|
+
type: 'string',
|
1458
|
+
description: 'Option to skip validation of some words, e.g. acronyms',
|
1459
|
+
},
|
1448
1460
|
},
|
1449
1461
|
},
|
1450
1462
|
},
|
@@ -1499,15 +1511,15 @@ const rule$4 = {
|
|
1499
1511
|
if (!node) {
|
1500
1512
|
return;
|
1501
1513
|
}
|
1502
|
-
const { prefix, suffix, forbiddenPrefixes, forbiddenSuffixes, style } = normalisePropertyOption(selector);
|
1514
|
+
const { prefix, suffix, forbiddenPrefixes, forbiddenSuffixes, style, ignorePattern } = normalisePropertyOption(selector);
|
1503
1515
|
const nodeType = KindToDisplayName[n.kind] || n.kind;
|
1504
1516
|
const nodeName = node.value;
|
1505
1517
|
const error = getError();
|
1506
1518
|
if (error) {
|
1507
1519
|
const { errorMessage, renameToName } = error;
|
1508
|
-
const [
|
1509
|
-
const [
|
1510
|
-
const suggestedName =
|
1520
|
+
const [leadingUnderscores] = nodeName.match(/^_*/);
|
1521
|
+
const [trailingUnderscores] = nodeName.match(/_*$/);
|
1522
|
+
const suggestedName = leadingUnderscores + renameToName + trailingUnderscores;
|
1511
1523
|
context.report({
|
1512
1524
|
loc: getLocation(node.loc, node.value),
|
1513
1525
|
message: `${nodeType} "${nodeName}" should ${errorMessage}`,
|
@@ -1521,6 +1533,9 @@ const rule$4 = {
|
|
1521
1533
|
}
|
1522
1534
|
function getError() {
|
1523
1535
|
const name = nodeName.replace(/(^_+)|(_+$)/g, '');
|
1536
|
+
if (ignorePattern && new RegExp(ignorePattern, 'u').test(name)) {
|
1537
|
+
return;
|
1538
|
+
}
|
1524
1539
|
if (prefix && !name.startsWith(prefix)) {
|
1525
1540
|
return {
|
1526
1541
|
errorMessage: `have "${prefix}" prefix`,
|
@@ -1547,8 +1562,12 @@ const rule$4 = {
|
|
1547
1562
|
renameToName: name.replace(new RegExp(`${forbiddenSuffix}$`), ''),
|
1548
1563
|
};
|
1549
1564
|
}
|
1565
|
+
// Style is optional
|
1566
|
+
if (!style) {
|
1567
|
+
return;
|
1568
|
+
}
|
1550
1569
|
const caseRegex = StyleToRegex[style];
|
1551
|
-
if (
|
1570
|
+
if (!caseRegex.test(name)) {
|
1552
1571
|
return {
|
1553
1572
|
errorMessage: `be in ${style} format`,
|
1554
1573
|
renameToName: convertCase(style, name),
|
@@ -3704,36 +3723,35 @@ function getSiblingOperations(options, gqlConfig) {
|
|
3704
3723
|
return siblingOperations;
|
3705
3724
|
}
|
3706
3725
|
|
3707
|
-
let
|
3708
|
-
function
|
3726
|
+
let graphqlConfig;
|
3727
|
+
function loadGraphqlConfig(options) {
|
3709
3728
|
// We don't want cache config on test environment
|
3710
3729
|
// Otherwise schema and documents will be same for all tests
|
3711
|
-
if (process.env.NODE_ENV !== 'test' &&
|
3712
|
-
return
|
3730
|
+
if (process.env.NODE_ENV !== 'test' && graphqlConfig) {
|
3731
|
+
return graphqlConfig;
|
3713
3732
|
}
|
3714
3733
|
const onDiskConfig = options.skipGraphQLConfig
|
3715
3734
|
? null
|
3716
|
-
: graphqlConfig.loadConfigSync({
|
3735
|
+
: graphqlConfig$1.loadConfigSync({
|
3717
3736
|
throwOnEmpty: false,
|
3718
3737
|
throwOnMissing: false,
|
3719
3738
|
extensions: [addCodeFileLoaderExtension],
|
3720
3739
|
});
|
3721
|
-
|
3722
|
-
? { projects: options.projects }
|
3723
|
-
: {
|
3724
|
-
schema: (options.schema || ''),
|
3725
|
-
documents: options.documents || options.operations,
|
3726
|
-
extensions: options.extensions,
|
3727
|
-
include: options.include,
|
3728
|
-
exclude: options.exclude,
|
3729
|
-
};
|
3730
|
-
graphQLConfig =
|
3740
|
+
graphqlConfig =
|
3731
3741
|
onDiskConfig ||
|
3732
|
-
new graphqlConfig.GraphQLConfig({
|
3733
|
-
config:
|
3742
|
+
new graphqlConfig$1.GraphQLConfig({
|
3743
|
+
config: options.projects
|
3744
|
+
? { projects: options.projects }
|
3745
|
+
: {
|
3746
|
+
schema: (options.schema || ''),
|
3747
|
+
documents: options.documents || options.operations,
|
3748
|
+
extensions: options.extensions,
|
3749
|
+
include: options.include,
|
3750
|
+
exclude: options.exclude,
|
3751
|
+
},
|
3734
3752
|
filepath: 'virtual-config',
|
3735
3753
|
}, [addCodeFileLoaderExtension]);
|
3736
|
-
return
|
3754
|
+
return graphqlConfig;
|
3737
3755
|
}
|
3738
3756
|
const addCodeFileLoaderExtension = api => {
|
3739
3757
|
api.loaders.schema.register(new codeFileLoader.CodeFileLoader());
|
@@ -3823,18 +3841,10 @@ function parse(code, options) {
|
|
3823
3841
|
return parseForESLint(code, options).ast;
|
3824
3842
|
}
|
3825
3843
|
function parseForESLint(code, options = {}) {
|
3826
|
-
const gqlConfig =
|
3827
|
-
|
3828
|
-
try {
|
3829
|
-
schema = getSchema(options, gqlConfig);
|
3830
|
-
}
|
3831
|
-
catch (e) {
|
3832
|
-
e.message = `[graphql-eslint] Error while loading schema: ${e.message}`;
|
3833
|
-
// eslint-disable-next-line no-console
|
3834
|
-
console.error(e);
|
3835
|
-
}
|
3844
|
+
const gqlConfig = loadGraphqlConfig(options);
|
3845
|
+
const schema = getSchema(options, gqlConfig);
|
3836
3846
|
const parserServices = {
|
3837
|
-
hasTypeInfo:
|
3847
|
+
hasTypeInfo: schema !== null,
|
3838
3848
|
schema,
|
3839
3849
|
siblingOperations: getSiblingOperations(options, gqlConfig),
|
3840
3850
|
reachableTypes: getReachableTypes,
|
@@ -3863,7 +3873,6 @@ function parseForESLint(code, options = {}) {
|
|
3863
3873
|
};
|
3864
3874
|
}
|
3865
3875
|
catch (e) {
|
3866
|
-
e.message = `[graphql-eslint] ${e.message}`;
|
3867
3876
|
// In case of GraphQL parser error, we report it to ESLint as a parser error that matches the requirements
|
3868
3877
|
// of ESLint. This will make sure to display it correctly in IDEs and lint results.
|
3869
3878
|
if (e instanceof graphql.GraphQLError) {
|
@@ -3871,10 +3880,11 @@ function parseForESLint(code, options = {}) {
|
|
3871
3880
|
index: e.positions[0],
|
3872
3881
|
lineNumber: e.locations[0].line,
|
3873
3882
|
column: e.locations[0].column,
|
3874
|
-
message: e.message
|
3883
|
+
message: `[graphql-eslint]: ${e.message}`,
|
3875
3884
|
};
|
3876
3885
|
throw eslintError;
|
3877
3886
|
}
|
3887
|
+
e.message = `[graphql-eslint]: ${e.message}`;
|
3878
3888
|
throw e;
|
3879
3889
|
}
|
3880
3890
|
}
|
package/index.mjs
CHANGED
@@ -320,14 +320,14 @@ function getLocation(loc, fieldName = '', offset) {
|
|
320
320
|
};
|
321
321
|
}
|
322
322
|
|
323
|
-
function validateDocument(context, schema
|
323
|
+
function validateDocument(sourceNode, context, schema, documentNode, rule) {
|
324
324
|
if (documentNode.definitions.length === 0) {
|
325
325
|
return;
|
326
326
|
}
|
327
327
|
try {
|
328
|
-
const validationErrors = schema
|
328
|
+
const validationErrors = schema
|
329
329
|
? validate(schema, documentNode, [rule])
|
330
|
-
: validateSDL(documentNode,
|
330
|
+
: validateSDL(documentNode, null, [rule]);
|
331
331
|
for (const error of validationErrors) {
|
332
332
|
/*
|
333
333
|
* TODO: Fix ESTree-AST converter because currently it's incorrectly convert loc.end
|
@@ -352,8 +352,7 @@ function validateDocument(context, schema = null, documentNode, rule, isSchemaTo
|
|
352
352
|
}
|
353
353
|
catch (e) {
|
354
354
|
context.report({
|
355
|
-
|
356
|
-
loc: { column: 0, line: 1 },
|
355
|
+
node: sourceNode,
|
357
356
|
message: e.message,
|
358
357
|
});
|
359
358
|
}
|
@@ -435,18 +434,18 @@ const validationToRule = (ruleId, ruleName, docs, getDocumentNode) => {
|
|
435
434
|
},
|
436
435
|
},
|
437
436
|
create(context) {
|
438
|
-
if (!ruleFn) {
|
439
|
-
// eslint-disable-next-line no-console
|
440
|
-
console.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...`);
|
441
|
-
return {};
|
442
|
-
}
|
443
|
-
const schema = docs.requiresSchema ? requireGraphQLSchemaFromContext(ruleId, context) : null;
|
444
437
|
return {
|
445
438
|
Document(node) {
|
439
|
+
if (!ruleFn) {
|
440
|
+
// eslint-disable-next-line no-console
|
441
|
+
console.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...`);
|
442
|
+
return;
|
443
|
+
}
|
444
|
+
const schema = docs.requiresSchema ? requireGraphQLSchemaFromContext(ruleId, context) : null;
|
446
445
|
const documentNode = getDocumentNode
|
447
446
|
? getDocumentNode({ ruleId, context, schema, node: node.rawNode() })
|
448
447
|
: node.rawNode();
|
449
|
-
validateDocument(context, schema, documentNode, ruleFn
|
448
|
+
validateDocument(node, context, schema, documentNode, ruleFn);
|
450
449
|
},
|
451
450
|
};
|
452
451
|
},
|
@@ -596,9 +595,7 @@ const GRAPHQL_JS_VALIDATIONS = Object.assign({}, validationToRule('executable-de
|
|
596
595
|
}), validationToRule('possible-type-extension', 'PossibleTypeExtensions', {
|
597
596
|
category: 'Schema',
|
598
597
|
description: `A type extension is only valid if the type is defined and has the same kind.`,
|
599
|
-
recommended: false,
|
600
|
-
requiresSchema: true,
|
601
|
-
requiresSchemaToExtend: true,
|
598
|
+
recommended: false, // TODO: enable after https://github.com/dotansimha/graphql-eslint/issues/787 will be fixed
|
602
599
|
}), validationToRule('provided-required-arguments', 'ProvidedRequiredArguments', {
|
603
600
|
category: ['Schema', 'Operations'],
|
604
601
|
description: `A field or directive is only valid if all required (non-null without a default value) field arguments have been provided.`,
|
@@ -1370,6 +1367,17 @@ const rule$4 = {
|
|
1370
1367
|
type Query {
|
1371
1368
|
users: [User!]!
|
1372
1369
|
}
|
1370
|
+
`,
|
1371
|
+
},
|
1372
|
+
{
|
1373
|
+
title: 'Correct',
|
1374
|
+
usage: [{ FieldDefinition: { style: 'camelCase', ignorePattern: '^(EAN13|UPC|UK)' } }],
|
1375
|
+
code: /* GraphQL */ `
|
1376
|
+
type Product {
|
1377
|
+
EAN13: String
|
1378
|
+
UPC: String
|
1379
|
+
UKFlag: String
|
1380
|
+
}
|
1373
1381
|
`,
|
1374
1382
|
},
|
1375
1383
|
],
|
@@ -1439,6 +1447,10 @@ const rule$4 = {
|
|
1439
1447
|
minItems: 1,
|
1440
1448
|
items: { type: 'string' },
|
1441
1449
|
},
|
1450
|
+
ignorePattern: {
|
1451
|
+
type: 'string',
|
1452
|
+
description: 'Option to skip validation of some words, e.g. acronyms',
|
1453
|
+
},
|
1442
1454
|
},
|
1443
1455
|
},
|
1444
1456
|
},
|
@@ -1493,15 +1505,15 @@ const rule$4 = {
|
|
1493
1505
|
if (!node) {
|
1494
1506
|
return;
|
1495
1507
|
}
|
1496
|
-
const { prefix, suffix, forbiddenPrefixes, forbiddenSuffixes, style } = normalisePropertyOption(selector);
|
1508
|
+
const { prefix, suffix, forbiddenPrefixes, forbiddenSuffixes, style, ignorePattern } = normalisePropertyOption(selector);
|
1497
1509
|
const nodeType = KindToDisplayName[n.kind] || n.kind;
|
1498
1510
|
const nodeName = node.value;
|
1499
1511
|
const error = getError();
|
1500
1512
|
if (error) {
|
1501
1513
|
const { errorMessage, renameToName } = error;
|
1502
|
-
const [
|
1503
|
-
const [
|
1504
|
-
const suggestedName =
|
1514
|
+
const [leadingUnderscores] = nodeName.match(/^_*/);
|
1515
|
+
const [trailingUnderscores] = nodeName.match(/_*$/);
|
1516
|
+
const suggestedName = leadingUnderscores + renameToName + trailingUnderscores;
|
1505
1517
|
context.report({
|
1506
1518
|
loc: getLocation(node.loc, node.value),
|
1507
1519
|
message: `${nodeType} "${nodeName}" should ${errorMessage}`,
|
@@ -1515,6 +1527,9 @@ const rule$4 = {
|
|
1515
1527
|
}
|
1516
1528
|
function getError() {
|
1517
1529
|
const name = nodeName.replace(/(^_+)|(_+$)/g, '');
|
1530
|
+
if (ignorePattern && new RegExp(ignorePattern, 'u').test(name)) {
|
1531
|
+
return;
|
1532
|
+
}
|
1518
1533
|
if (prefix && !name.startsWith(prefix)) {
|
1519
1534
|
return {
|
1520
1535
|
errorMessage: `have "${prefix}" prefix`,
|
@@ -1541,8 +1556,12 @@ const rule$4 = {
|
|
1541
1556
|
renameToName: name.replace(new RegExp(`${forbiddenSuffix}$`), ''),
|
1542
1557
|
};
|
1543
1558
|
}
|
1559
|
+
// Style is optional
|
1560
|
+
if (!style) {
|
1561
|
+
return;
|
1562
|
+
}
|
1544
1563
|
const caseRegex = StyleToRegex[style];
|
1545
|
-
if (
|
1564
|
+
if (!caseRegex.test(name)) {
|
1546
1565
|
return {
|
1547
1566
|
errorMessage: `be in ${style} format`,
|
1548
1567
|
renameToName: convertCase(style, name),
|
@@ -3698,12 +3717,12 @@ function getSiblingOperations(options, gqlConfig) {
|
|
3698
3717
|
return siblingOperations;
|
3699
3718
|
}
|
3700
3719
|
|
3701
|
-
let
|
3702
|
-
function
|
3720
|
+
let graphqlConfig;
|
3721
|
+
function loadGraphqlConfig(options) {
|
3703
3722
|
// We don't want cache config on test environment
|
3704
3723
|
// Otherwise schema and documents will be same for all tests
|
3705
|
-
if (process.env.NODE_ENV !== 'test' &&
|
3706
|
-
return
|
3724
|
+
if (process.env.NODE_ENV !== 'test' && graphqlConfig) {
|
3725
|
+
return graphqlConfig;
|
3707
3726
|
}
|
3708
3727
|
const onDiskConfig = options.skipGraphQLConfig
|
3709
3728
|
? null
|
@@ -3712,22 +3731,21 @@ function loadGraphQLConfig(options) {
|
|
3712
3731
|
throwOnMissing: false,
|
3713
3732
|
extensions: [addCodeFileLoaderExtension],
|
3714
3733
|
});
|
3715
|
-
|
3716
|
-
? { projects: options.projects }
|
3717
|
-
: {
|
3718
|
-
schema: (options.schema || ''),
|
3719
|
-
documents: options.documents || options.operations,
|
3720
|
-
extensions: options.extensions,
|
3721
|
-
include: options.include,
|
3722
|
-
exclude: options.exclude,
|
3723
|
-
};
|
3724
|
-
graphQLConfig =
|
3734
|
+
graphqlConfig =
|
3725
3735
|
onDiskConfig ||
|
3726
3736
|
new GraphQLConfig({
|
3727
|
-
config:
|
3737
|
+
config: options.projects
|
3738
|
+
? { projects: options.projects }
|
3739
|
+
: {
|
3740
|
+
schema: (options.schema || ''),
|
3741
|
+
documents: options.documents || options.operations,
|
3742
|
+
extensions: options.extensions,
|
3743
|
+
include: options.include,
|
3744
|
+
exclude: options.exclude,
|
3745
|
+
},
|
3728
3746
|
filepath: 'virtual-config',
|
3729
3747
|
}, [addCodeFileLoaderExtension]);
|
3730
|
-
return
|
3748
|
+
return graphqlConfig;
|
3731
3749
|
}
|
3732
3750
|
const addCodeFileLoaderExtension = api => {
|
3733
3751
|
api.loaders.schema.register(new CodeFileLoader());
|
@@ -3817,18 +3835,10 @@ function parse(code, options) {
|
|
3817
3835
|
return parseForESLint(code, options).ast;
|
3818
3836
|
}
|
3819
3837
|
function parseForESLint(code, options = {}) {
|
3820
|
-
const gqlConfig =
|
3821
|
-
|
3822
|
-
try {
|
3823
|
-
schema = getSchema(options, gqlConfig);
|
3824
|
-
}
|
3825
|
-
catch (e) {
|
3826
|
-
e.message = `[graphql-eslint] Error while loading schema: ${e.message}`;
|
3827
|
-
// eslint-disable-next-line no-console
|
3828
|
-
console.error(e);
|
3829
|
-
}
|
3838
|
+
const gqlConfig = loadGraphqlConfig(options);
|
3839
|
+
const schema = getSchema(options, gqlConfig);
|
3830
3840
|
const parserServices = {
|
3831
|
-
hasTypeInfo:
|
3841
|
+
hasTypeInfo: schema !== null,
|
3832
3842
|
schema,
|
3833
3843
|
siblingOperations: getSiblingOperations(options, gqlConfig),
|
3834
3844
|
reachableTypes: getReachableTypes,
|
@@ -3857,7 +3867,6 @@ function parseForESLint(code, options = {}) {
|
|
3857
3867
|
};
|
3858
3868
|
}
|
3859
3869
|
catch (e) {
|
3860
|
-
e.message = `[graphql-eslint] ${e.message}`;
|
3861
3870
|
// In case of GraphQL parser error, we report it to ESLint as a parser error that matches the requirements
|
3862
3871
|
// of ESLint. This will make sure to display it correctly in IDEs and lint results.
|
3863
3872
|
if (e instanceof GraphQLError) {
|
@@ -3865,10 +3874,11 @@ function parseForESLint(code, options = {}) {
|
|
3865
3874
|
index: e.positions[0],
|
3866
3875
|
lineNumber: e.locations[0].line,
|
3867
3876
|
column: e.locations[0].column,
|
3868
|
-
message: e.message
|
3877
|
+
message: `[graphql-eslint]: ${e.message}`,
|
3869
3878
|
};
|
3870
3879
|
throw eslintError;
|
3871
3880
|
}
|
3881
|
+
e.message = `[graphql-eslint]: ${e.message}`;
|
3872
3882
|
throw e;
|
3873
3883
|
}
|
3874
3884
|
}
|
package/package.json
CHANGED