Skip to content

Commit 95aeda5

Browse files
authored
Drop Node 8. Support GraphQL 15. Update Babel 7 & ESLint 6.8 (#271)
1 parent a1a7517 commit 95aeda5

25 files changed

+8202
-2893
lines changed

.babelrc.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
presets: ['@babel/preset-env'],
3+
plugins: ['@babel/plugin-transform-runtime'],
4+
};

.tav.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11

22
graphql:
3-
versions: ^0.12.0 || ^0.13.0 || ^14.0.0
3+
versions: ^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0
44
commands: mocha test/index.js

.travis.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: node_js
22
node_js:
3-
- "8"
43
- "10"
4+
- "12"
55
install:
66
- npm install
77

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
### vNEXT
44

55
- Improve identity template literal tag docs. [PR #254](https://github.com/apollographql/eslint-plugin-graphql/pull/254) by [Jayden Seric](https://github.com/jaydenseric).
6+
- Add support for GraphQL 15. [PR #271](https://github.com/apollographql/eslint-plugin-graphql/pull/271) by [Scott Taylor](https://github.com/staylor).
7+
- Update all `devDependencies` - upgrades the project to use Babel 7 and ESLint 6. [PR #271](https://github.com/apollographql/eslint-plugin-graphql/pull/271) by [Scott Taylor](https://github.com/staylor).
8+
- **BREAKING**: Minimum supported Node.js version is now Node.js 10; Dropped support for Node.js 8. [PR #271](https://github.com/apollographql/eslint-plugin-graphql/pull/271) by [Scott Taylor](https://github.com/staylor).
69

710
### v3.1.1
811

package-lock.json

+8,028-2,784
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+20-22
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"scripts": {
88
"test": "tav --ci && mocha test/index.js",
99
"prepublish": "babel ./src --ignore test --out-dir ./lib",
10-
"pretest": "node test/updateSchemaJson.js",
10+
"pretest": "babel-node test/updateSchemaJson.js",
1111
"tav": "tav",
1212
"lint": "eslint 'src/**/*.js' 'test/**/*.js'"
1313
},
@@ -17,39 +17,37 @@
1717
"url": "git+https://github.com/apollostack/eslint-plugin-graphql.git"
1818
},
1919
"devDependencies": {
20-
"babel-cli": "6.26.0",
21-
"babel-core": "6.26.3",
22-
"babel-eslint": "10.0.1",
23-
"babel-plugin-transform-runtime": "6.23.0",
24-
"babel-preset-es2015": "6.24.1",
25-
"babel-preset-stage-0": "6.24.1",
26-
"eslint": "5.16.0",
27-
"graphql": "14.4.2",
28-
"graphql-tools": "4.0.5",
29-
"mocha": "6.2.0",
30-
"pretty-quick": "1.11.1",
20+
"@babel/cli": "7.10.1",
21+
"@babel/core": "7.10.1",
22+
"@babel/node": "7.10.1",
23+
"@babel/plugin-transform-runtime": "7.10.1",
24+
"@babel/preset-env": "7.10.1",
25+
"@babel/register": "7.9.0",
26+
"babel-eslint": "10.1.0",
27+
"eslint": "6.8.0",
28+
"graphql": "15.0.0",
29+
"graphql-tools": "6.0.3",
30+
"mocha": "7.2.0",
31+
"pretty-quick": "2.0.1",
3132
"test-all-versions": "4.1.1"
3233
},
33-
"babel": {
34-
"presets": [
35-
"es2015",
36-
"stage-0"
37-
]
38-
},
3934
"husky": {
4035
"hooks": {
4136
"pre-commit": "pretty-quick --staged"
4237
}
4338
},
4439
"engines": {
45-
"node": ">=6.0"
40+
"node": ">=10.0"
4641
},
42+
"browserslist": "node 10",
4743
"license": "MIT",
4844
"dependencies": {
49-
"graphql-config": "^2.0.1",
50-
"lodash": "^4.11.1"
45+
"@babel/runtime": "^7.10.0",
46+
"graphql-config": "^3.0.2",
47+
"lodash.flatten": "^4.4.0",
48+
"lodash.without": "^4.4.0"
5149
},
5250
"peerDependencies": {
53-
"graphql": "^0.12.0 || ^0.13.0 || ^14.0.0"
51+
"graphql": "^0.12.0 || ^0.13.0 || ^14.0.0 || ^15.0.0"
5452
}
5553
}

src/index.js

+50-19
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import {
66
specifiedRules as allGraphQLValidators
77
} from "graphql";
88

9-
import { flatten, keys, reduce, without, includes } from "lodash";
9+
import flatten from "lodash.flatten";
10+
import without from "lodash.without";
1011

11-
import { getGraphQLConfig, ConfigNotFoundError } from "graphql-config";
12+
import { loadConfigSync, ConfigNotFoundError, ProjectNotFoundError } from "graphql-config";
1213

1314
import * as customRules from "./customGraphQLValidationRules";
1415
import { internalTag } from "./constants";
@@ -21,34 +22,54 @@ const envGraphQLValidatorNames = {
2122
apollo: without(
2223
allGraphQLValidatorNames,
2324
"KnownFragmentNames",
24-
"NoUnusedFragments"
25+
"NoUnusedFragments",
26+
// `graphql`@15
27+
"KnownFragmentNamesRule",
28+
"NoUnusedFragmentsRule"
2529
),
2630
lokka: without(
2731
allGraphQLValidatorNames,
2832
"KnownFragmentNames",
29-
"NoUnusedFragments"
33+
"NoUnusedFragments",
34+
// `graphql`@15
35+
"KnownFragmentNamesRule",
36+
"NoUnusedFragmentsRule"
3037
),
3138
fraql: without(
3239
allGraphQLValidatorNames,
3340
"KnownFragmentNames",
34-
"NoUnusedFragments"
41+
"NoUnusedFragments",
42+
// `graphql`@15
43+
"KnownFragmentNamesRule",
44+
"NoUnusedFragmentsRule"
3545
),
3646
relay: without(
3747
allGraphQLValidatorNames,
3848
"KnownDirectives",
3949
"KnownFragmentNames",
4050
"NoUndefinedVariables",
4151
"NoUnusedFragments",
52+
// `graphql`@15
53+
"KnownDirectivesRule",
54+
"KnownFragmentNamesRule",
55+
"NoUndefinedVariablesRule",
56+
"NoUnusedFragmentsRule",
4257
// `graphql` < 14
4358
"ProvidedNonNullArguments",
4459
// `graphql`@14
4560
"ProvidedRequiredArguments",
46-
"ScalarLeafs"
61+
"ScalarLeafs",
62+
// `graphql`@15
63+
"ProvidedRequiredArgumentsRule",
64+
"ScalarLeafsRule"
4765
),
4866
literal: without(
4967
allGraphQLValidatorNames,
5068
"KnownFragmentNames",
51-
"NoUnusedFragments"
69+
"NoUnusedFragments",
70+
// `graphql`@15
71+
"KnownFragmentNamesRule",
72+
"NoUnusedFragmentsRule"
5273
)
5374
};
5475

@@ -268,23 +289,34 @@ function parseOptions(optionGroup, context) {
268289
schema = initSchemaFromString(schemaString);
269290
} else {
270291
try {
271-
const config = getGraphQLConfig(path.dirname(context.getFilename()));
292+
const config = loadConfigSync({
293+
rootDir: path.resolve(
294+
process.cwd(),
295+
path.dirname(context.getFilename())
296+
)
297+
});
272298
let projectConfig;
273299
if (projectName) {
274-
projectConfig = config.getProjects()[projectName];
300+
projectConfig = config.getProject(projectName);
275301
if (!projectConfig) {
276302
throw new Error(
277-
`Project with name "${projectName}" not found in ${config.configPath}.`
303+
`Project with name "${projectName}" not found in ${config.filepath}.`
278304
);
279305
}
280306
} else {
281-
projectConfig = config.getConfigForFile(context.getFilename());
307+
try {
308+
projectConfig = config.getProjectForFile(context.getFilename());
309+
} catch (e) {
310+
if (!(e instanceof ProjectNotFoundError)) {
311+
throw e;
312+
}
313+
}
282314
}
283315
if (projectConfig) {
284-
const key = `${config.configPath}[${projectConfig.projectName}]`;
316+
const key = `${config.filepath}[${projectConfig.name}]`;
285317
schema = projectCache[key];
286318
if (!schema) {
287-
schema = projectConfig.getSchema();
319+
schema = projectConfig.getSchemaSync();
288320
projectCache[key] = schema;
289321
}
290322
}
@@ -294,7 +326,7 @@ function parseOptions(optionGroup, context) {
294326
} catch (e) {
295327
if (e instanceof ConfigNotFoundError) {
296328
throw new Error(
297-
"Must provide .graphqlconfig file or pass in `schemaJson` option " +
329+
"Must provide GraphQL Config file or pass in `schemaJson` option " +
298330
"with schema object or `schemaJsonFilepath` with absolute path to the json file."
299331
);
300332
}
@@ -385,14 +417,13 @@ const gqlProcessor = {
385417
},
386418
postprocess: function(messages) {
387419
// only report graphql-errors
388-
return flatten(messages).filter(message => {
389-
return includes(keys(rules).map(key => `graphql/${key}`), message.ruleId);
390-
});
420+
return flatten(messages).filter(message =>
421+
Object.keys(rules).map(key => `graphql/${key}`).includes(message.ruleId)
422+
);
391423
}
392424
};
393425

394-
export const processors = reduce(
395-
gqlFiles,
426+
export const processors = gqlFiles.reduce(
396427
(result, value) => {
397428
return { ...result, [`.${value}`]: gqlProcessor };
398429
},

test/customTagName.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import schemaJson from './schema.json';
2+
import { isAtLeastGraphQL15 } from './helpers';
23

34
import {
45
rule,
@@ -25,7 +26,7 @@ ruleTester.run('custom tag name', rule, {
2526
parserOptions,
2627
code: 'const x = myGraphQLTag``',
2728
errors: [{
28-
message: 'Syntax Error: Unexpected <EOF>',
29+
message: isAtLeastGraphQL15 ? 'Syntax Error: Unexpected <EOF>.' : 'Syntax Error: Unexpected <EOF>',
2930
type: 'TaggedTemplateExpression'
3031
}]
3132
},

test/default.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isAtLeastGraphQL15 } from './helpers';
12
import schemaJson from './schema.json';
23

34
import {
@@ -45,7 +46,7 @@ ruleTester.run('default options', rule, {
4546
parserOptions,
4647
code: 'const x = gql``',
4748
errors: [{
48-
message: 'Syntax Error: Unexpected <EOF>',
49+
message: isAtLeastGraphQL15 ? 'Syntax Error: Unexpected <EOF>.' : 'Syntax Error: Unexpected <EOF>',
4950
type: 'TaggedTemplateExpression'
5051
}]
5152
},

test/env/apollo.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isAtLeastGraphQL15 } from '../helpers';
12
import schemaJson from '../schema.json';
23

34
import {
@@ -34,7 +35,7 @@ ruleTester.run('apollo', rule, {
3435
parserOptions,
3536
code: 'const x = gql`query }{ ${x}`',
3637
errors: [{
37-
message: 'Syntax Error: Expected {, found }',
38+
message: isAtLeastGraphQL15 ? 'Syntax Error: Expected "{", found "}".' : 'Syntax Error: Expected {, found }',
3839
type: 'TaggedTemplateExpression'
3940
}]
4041
}

test/env/lokka.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { isAtLeastGraphQL15 } from '../helpers';
12
import schemaJson from '../schema.json';
23

34
import {
@@ -111,7 +112,9 @@ ruleTester.run('lokka', rule, {
111112
\`);
112113
`,
113114
errors: [{
114-
message: 'Unknown argument "wrongArg" on field "director" of type "Film".',
115+
message: isAtLeastGraphQL15 ?
116+
'Unknown argument "wrongArg" on field "Film.director".' :
117+
'Unknown argument "wrongArg" on field "director" of type "Film".',
115118
type: 'TaggedTemplateExpression',
116119
line: 5,
117120
column: 22

test/env/relay.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const options = [
1313
];
1414

1515
// Need this to support statics
16-
const parser = 'babel-eslint';
16+
const parser = require.resolve('babel-eslint');
1717

1818
ruleTester.run('relay', rule, {
1919
valid: [

test/graphqlconfig/multiproject-literal/.graphqlconfig

-12
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"projects": {
3+
"gql": {
4+
"schema": "../../schema.graphql",
5+
"include": ["first.graphql"]
6+
},
7+
"swapi": {
8+
"schema": "../../second-schema.graphql",
9+
"include": ["second.graphql"]
10+
}
11+
}
12+
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"projects": {
33
"gql": {
4-
"schemaPath": "../../schema.graphql"
4+
"schema": "../../schema.graphql"
55
},
66
"swapi": {
7-
"schemaPath": "../../second-schema.graphql"
7+
"schema": "../../second-schema.graphql"
88
}
99
}
1010
}

test/graphqlconfig/simple/.graphqlconfig

-3
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"schema": "../../schema.graphql"
3+
}

test/helpers.js

+13-3
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,26 @@ import { rules } from '../src';
22
import { RuleTester } from 'eslint';
33
import schemaJson from './schema.json';
44
import path from 'path';
5-
import { printSchema, buildClientSchema, specifiedRules as allGraphQLValidators } from 'graphql';
5+
import * as graphql from 'graphql';
66

7+
const { printSchema, buildClientSchema, specifiedRules: allGraphQLValidators } = graphql;
8+
9+
export const isAtLeastGraphQL15 = graphql.versionInfo && graphql.versionInfo.major >= 15;
710

811
export const schemaJsonFilepath = path.resolve(__dirname, './schema.json');
912
export const secondSchemaJsonFilepath = path.resolve(__dirname, './second-schema.json');
1013
export const schemaString = printSchema(buildClientSchema(schemaJson.data))
1114

1215
const allGraphQLValidatorNames = allGraphQLValidators.map(rule => rule.name);
13-
export const requiredArgumentRuleName = allGraphQLValidatorNames.includes('ProvidedRequiredArguments') ?
14-
'ProvidedRequiredArguments':'ProvidedNonNullArguments';
16+
17+
let requiredArgumentRule = 'ProvidedNonNullArguments';
18+
if (allGraphQLValidatorNames.includes('ProvidedRequiredArgumentsRule')) {
19+
requiredArgumentRule = 'ProvidedRequiredArgumentsRule';
20+
} else if (allGraphQLValidatorNames.includes('ProvidedRequiredArguments')) {
21+
requiredArgumentRule = 'ProvidedRequiredArguments';
22+
}
23+
24+
export const requiredArgumentRuleName = requiredArgumentRule;
1525

1626
// Init rule
1727

test/index.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
1-
// This file cannot be written with ECMAScript 2015 because it has to load
2-
// the Babel require hook to enable ECMAScript 2015 features!
3-
require('babel-core/register');
4-
require('babel-core').transform('code', {
5-
plugins: ['transform-runtime']
6-
});
1+
require('@babel/register');
72

8-
// The tests, however, can and should be written with ECMAScript 2015.
93
require('./makeProcessors');
104
require('./graphqlconfig/');
115
require('./env');

0 commit comments

Comments
 (0)