Skip to content

Commit 8e62f93

Browse files
committed
Merge pull request #309 from graphql/babel6
Upgrade to Babel6
2 parents 2d1a4fb + 121564c commit 8e62f93

28 files changed

+183
-149
lines changed

.eslintrc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,11 @@
3939

4040
"rules": {
4141
"babel/arrow-parens": [2, "as-needed"],
42+
"babel/array-bracket-spacing": [2, "always"],
43+
"babel/generator-star-spacing": [2, {"before": true, "after": false}],
44+
"array-bracket-spacing": 0,
45+
"generator-star-spacing": 0,
4246

43-
"array-bracket-spacing": [2, "always"],
4447
"arrow-spacing": 2,
4548
"block-scoped-var": 0,
4649
"brace-style": [2, "1tbs", {"allowSingleLine": true}],
@@ -61,14 +64,14 @@
6164
"eqeqeq": 2,
6265
"func-names": 0,
6366
"func-style": 0,
64-
"generator-star-spacing": [0, {"before": true, "after": false}],
6567
"guard-for-in": 2,
6668
"handle-callback-err": [2, "error"],
6769
"id-length": 0,
6870
"id-match": [2, "^(?:_?[a-zA-Z0-9]*)|[_A-Z0-9]+$"],
6971
"indent": [2, 2, {"SwitchCase": 1}],
7072
"init-declarations": 0,
7173
"key-spacing": [2, {"beforeColon": false, "afterColon": true}],
74+
"keyword-spacing": 2,
7275
"linebreak-style": 2,
7376
"lines-around-comment": 0,
7477
"max-depth": 0,
@@ -100,7 +103,6 @@
100103
"no-else-return": 2,
101104
"no-empty": 2,
102105
"no-empty-character-class": 2,
103-
"no-empty-label": 2,
104106
"no-eq-null": 0,
105107
"no-eval": 2,
106108
"no-ex-assign": 2,
@@ -121,7 +123,7 @@
121123
"no-irregular-whitespace": 2,
122124
"no-iterator": 2,
123125
"no-label-var": 2,
124-
"no-labels": 0,
126+
"no-labels": [2, {"allowLoop": true}],
125127
"no-lone-blocks": 2,
126128
"no-lonely-if": 2,
127129
"no-loop-func": 0,
@@ -194,12 +196,10 @@
194196
"semi": [2, "always"],
195197
"semi-spacing": [2, {"before": false, "after": true}],
196198
"sort-vars": 0,
197-
"space-after-keywords": [2, "always"],
198199
"space-before-blocks": [2, "always"],
199200
"space-before-function-paren": [2, {"anonymous": "always", "named": "never"}],
200201
"space-in-parens": 0,
201202
"space-infix-ops": [2, {"int32Hint": false}],
202-
"space-return-throw-case": 2,
203203
"space-unary-ops": [2, {"words": true, "nonwords": false}],
204204
"spaced-comment": [2, "always"],
205205
"strict": 0,

package.json

Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,36 +18,55 @@
1818
"url": "http://github.com/graphql/graphql-js.git"
1919
},
2020
"options": {
21-
"mocha": "--require resources/mocha-bootload src/**/__tests__/**/*.js"
21+
"mocha": "--require ./resources/mocha-bootload src/**/__tests__/**/*.js"
22+
},
23+
"babel": {
24+
"presets": [
25+
"es2015"
26+
],
27+
"plugins": [
28+
"syntax-async-functions",
29+
"transform-class-properties",
30+
"transform-flow-strip-types",
31+
"transform-object-rest-spread",
32+
"transform-regenerator",
33+
"transform-runtime"
34+
]
2235
},
2336
"scripts": {
2437
"test": "npm run lint && npm run check && npm run testonly",
25-
"testonly": "mocha $npm_package_options_mocha",
26-
"t": "mocha --require resources/mocha-bootload",
38+
"testonly": "babel-node ./node_modules/.bin/_mocha $npm_package_options_mocha",
39+
"t": "babel-node ./node_modules/.bin/_mocha --require ./resources/mocha-bootload",
2740
"lint": "eslint src",
2841
"check": "flow check",
29-
"build": "babel src --optional runtime --ignore __tests__ --out-dir dist/ && cp package.json dist/",
30-
"watch": "babel --optional runtime resources/watch.js | node",
31-
"cover": "babel-node node_modules/.bin/isparta cover --root src --report html node_modules/.bin/_mocha -- $npm_package_options_mocha",
32-
"cover:lcov": "babel-node node_modules/.bin/isparta cover --root src --report lcovonly node_modules/.bin/_mocha -- $npm_package_options_mocha",
42+
"build": "babel src --ignore __tests__ --out-dir dist/ && cp package.json dist/",
43+
"watch": "babel-node ./resources/watch.js",
44+
"cover": "babel-node ./node_modules/.bin/isparta cover --root src --report html _mocha -- $npm_package_options_mocha",
45+
"cover:lcov": "babel-node ./node_modules/.bin/isparta cover --root src --report lcovonly _mocha -- $npm_package_options_mocha",
3346
"preversion": ". ./resources/checkgit.sh && npm test",
3447
"prepublish": ". ./resources/prepublish.sh"
3548
},
3649
"dependencies": {
37-
"babel-runtime": "^5.8.x"
50+
"babel-runtime": ">=6.0.0"
3851
},
3952
"devDependencies": {
40-
"babel": "5.8.21",
41-
"babel-core": "5.8.22",
42-
"babel-eslint": "4.1.7",
43-
"chai": "3.4.1",
44-
"chai-subset": "1.1.0",
45-
"coveralls": "2.11.4",
46-
"eslint": "1.10.1",
47-
"eslint-plugin-babel": "^2.1.1",
53+
"babel-cli": "6.6.5",
54+
"babel-eslint": "6.0.0-beta.5",
55+
"babel-plugin-syntax-async-functions": "6.5.0",
56+
"babel-plugin-transform-class-properties": "6.6.0",
57+
"babel-plugin-transform-flow-strip-types": "6.7.0",
58+
"babel-plugin-transform-object-rest-spread": "6.6.5",
59+
"babel-plugin-transform-regenerator": "6.6.5",
60+
"babel-plugin-transform-runtime": "6.6.0",
61+
"babel-preset-es2015": "6.6.0",
62+
"chai": "3.5.0",
63+
"chai-subset": "1.2.1",
64+
"coveralls": "2.11.8",
65+
"eslint": "2.2.0",
66+
"eslint-plugin-babel": "3.1.0",
4867
"flow-bin": "0.20.1",
49-
"isparta": "3.0.3",
50-
"mocha": "2.3.4",
51-
"sane": "1.3.0"
68+
"isparta": "4.0.0",
69+
"mocha": "2.4.5",
70+
"sane": "1.3.3"
5271
}
5372
}

resources/mocha-bootload.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
* of patent rights can be found in the PATENTS file in the same directory.
88
*/
99

10-
require('babel/register')({
11-
optional: ['runtime', 'es7.asyncFunctions']
12-
});
13-
1410
var chai = require('chai');
1511

1612
var chaiSubset = require('chai-subset');

resources/prepublish.sh

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,10 @@ fi;
2121
#
2222
# var language = require('graphql/language');
2323
#
24-
babel --optional runtime src --ignore __tests__ --out-dir ./;
24+
babel src --ignore __tests__ --out-dir ./
25+
26+
# Ensure a vanilla package.json before deploying so other tools do not interpret
27+
# The built output as requiring any further transformation.
28+
node -e "var package = require('./package.json'); \
29+
delete package.babel; delete package.scripts; delete package.options; \
30+
require('fs').writeFileSync('package.json', JSON.stringify(package));"

resources/watch.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import flowBinPath from 'flow-bin';
1616
process.env.PATH += ':./node_modules/.bin';
1717

1818
var cmd = resolvePath(__dirname);
19-
var srcDir = resolvePath(cmd, './src');
19+
var srcDir = resolvePath(cmd, '../src');
2020

2121
function exec(command, options) {
2222
return new Promise((resolve, reject) => {
@@ -47,9 +47,9 @@ var watcher = sane(srcDir, { glob: ['**/*.js', '**/*.graphql'] })
4747
.on('change', changeFile);
4848

4949
process.on('SIGINT', () => {
50+
console.log(CLEARLINE + yellow(invert('stopped watching')));
5051
watcher.close();
5152
flowServer.kill();
52-
console.log(CLEARLINE + yellow(invert('stopped watching')));
5353
process.exit();
5454
});
5555

@@ -130,9 +130,10 @@ function parseFiles(filepaths) {
130130
function runTests(filepaths) {
131131
console.log('\nRunning Tests');
132132

133-
return exec('mocha', [
133+
return exec('babel-node', [
134+
'./node_modules/.bin/_mocha',
134135
'--reporter', 'progress',
135-
'--require', 'resources/mocha-bootload'
136+
'--require', './resources/mocha-bootload',
136137
].concat(
137138
allTests(filepaths) ? filepaths.map(srcPath) : ['src/**/__tests__/**/*.js']
138139
)).catch(() => false);

src/execution/__tests__/abstract.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,9 @@ describe('Execute: Handles execution of abstract types', () => {
259259
]
260260
},
261261
errors: [
262-
{ message:
263-
'Runtime Object type "Human" is not a possible type for "Pet".' }
262+
new Error(
263+
'Runtime Object type "Human" is not a possible type for "Pet".'
264+
)
264265
]
265266
});
266267
});
@@ -345,8 +346,9 @@ describe('Execute: Handles execution of abstract types', () => {
345346
]
346347
},
347348
errors: [
348-
{ message:
349-
'Runtime Object type "Human" is not a possible type for "Pet".' }
349+
new Error(
350+
'Runtime Object type "Human" is not a possible type for "Pet".'
351+
)
350352
]
351353
});
352354
});

src/execution/__tests__/executor.js

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ describe('Execute: Handles basic execution tasks', () => {
184184
});
185185

186186
it('threads context correctly', async () => {
187-
const doc = `query Example { a }`;
187+
const doc = 'query Example { a }';
188188

189189
const data = {
190190
contextThing: 'thing',
@@ -379,7 +379,7 @@ describe('Execute: Handles basic execution tasks', () => {
379379
});
380380

381381
it('uses the inline operation if no operation is provided', async () => {
382-
const doc = `{ a }`;
382+
const doc = '{ a }';
383383
const data = { a: 'b' };
384384
const ast = parse(doc);
385385
const schema = new GraphQLSchema({
@@ -397,7 +397,7 @@ describe('Execute: Handles basic execution tasks', () => {
397397
});
398398

399399
it('uses the only operation if no operation is provided', async () => {
400-
const doc = `query Example { a }`;
400+
const doc = 'query Example { a }';
401401
const data = { a: 'b' };
402402
const ast = parse(doc);
403403
const schema = new GraphQLSchema({
@@ -415,7 +415,7 @@ describe('Execute: Handles basic execution tasks', () => {
415415
});
416416

417417
it('throws if no operation is provided with multiple operations', () => {
418-
const doc = `query Example { a } query OtherExample { a }`;
418+
const doc = 'query Example { a } query OtherExample { a }';
419419
const data = { a: 'b' };
420420
const ast = parse(doc);
421421
const schema = new GraphQLSchema({
@@ -433,7 +433,7 @@ describe('Execute: Handles basic execution tasks', () => {
433433
});
434434

435435
it('uses the query schema for queries', async () => {
436-
const doc = `query Q { a } mutation M { c } subscription S { a }`;
436+
const doc = 'query Q { a } mutation M { c } subscription S { a }';
437437
const data = { a: 'b', c: 'd' };
438438
const ast = parse(doc);
439439
const schema = new GraphQLSchema({
@@ -463,7 +463,7 @@ describe('Execute: Handles basic execution tasks', () => {
463463
});
464464

465465
it('uses the mutation schema for mutations', async () => {
466-
const doc = `query Q { a } mutation M { c }`;
466+
const doc = 'query Q { a } mutation M { c }';
467467
const data = { a: 'b', c: 'd' };
468468
const ast = parse(doc);
469469
const schema = new GraphQLSchema({
@@ -487,7 +487,7 @@ describe('Execute: Handles basic execution tasks', () => {
487487
});
488488

489489
it('uses the subscription schema for subscriptions', async () => {
490-
const doc = `query Q { a } subscription S { a }`;
490+
const doc = 'query Q { a } subscription S { a }';
491491
const data = { a: 'b', c: 'd' };
492492
const ast = parse(doc);
493493
const schema = new GraphQLSchema({
@@ -731,10 +731,11 @@ describe('Execute: Handles basic execution tasks', () => {
731731
caughtError = error;
732732
}
733733

734-
expect(caughtError).to.deep.equal({
735-
message:
734+
expect(caughtError).to.deep.equal(
735+
new Error(
736736
'GraphQL cannot execute a request containing a ObjectTypeDefinition.'
737-
});
737+
)
738+
);
738739
});
739740

740741
});

src/execution/__tests__/union-interface.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ describe('Execute: Union and intersection types', () => {
378378

379379
const john2 = new Person('John', [], [ liz ]);
380380

381-
const ast = parse(`{ name, friends { name } }`);
381+
const ast = parse('{ name, friends { name } }');
382382

383383
expect(
384384
await execute(schema2, ast, john2)

src/execution/execute.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -679,8 +679,8 @@ function completeValue(
679679
);
680680
if (completed === null) {
681681
throw new GraphQLError(
682-
`Cannot return null for non-nullable ` +
683-
`field ${info.parentType}.${info.fieldName}.`,
682+
`Cannot return null for non-nullable field ${
683+
info.parentType}.${info.fieldName}.`,
684684
fieldASTs
685685
);
686686
}
@@ -696,8 +696,8 @@ function completeValue(
696696
if (returnType instanceof GraphQLList) {
697697
invariant(
698698
Array.isArray(result),
699-
'User Error: expected iterable, but did not find one ' +
700-
`for field ${info.parentType}.${info.fieldName}.`
699+
`User Error: expected iterable, but did not find one for field ${
700+
info.parentType}.${info.fieldName}.`
701701
);
702702

703703
// This is specified as a simple map, however we're optimizing the path

src/language/__tests__/lexer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ describe('Lexer', () => {
6767
value: 'foo'
6868
});
6969

70-
expect(lexOne(`,,,foo,,,`)).to.deep.equal({
70+
expect(lexOne(',,,foo,,,')).to.deep.equal({
7171
kind: TokenKind.NAME,
7272
start: 3,
7373
end: 6,

src/language/__tests__/parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { join } from 'path';
1818
describe('Parser', () => {
1919

2020
it('accepts option to not include source', () => {
21-
expect(parse(`{ field }`, { noSource: true })).to.deep.equal({
21+
expect(parse('{ field }', { noSource: true })).to.deep.equal({
2222
kind: 'Document',
2323
loc: { start: 0, end: 9 },
2424
definitions:

src/language/__tests__/printer.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ describe('Printer', () => {
3535
});
3636

3737
it('correctly prints non-query operations without name', () => {
38-
const queryAstShorthanded = parse(`query { id, name }`);
38+
const queryAstShorthanded = parse('query { id, name }');
3939
expect(print(queryAstShorthanded)).to.equal(
4040
`{
4141
id
4242
name
4343
}
4444
`);
4545

46-
const mutationAst = parse(`mutation { id, name }`);
46+
const mutationAst = parse('mutation { id, name }');
4747
expect(print(mutationAst)).to.equal(
4848
`mutation {
4949
id
@@ -52,8 +52,8 @@ describe('Printer', () => {
5252
`);
5353

5454
const queryAstWithArtifacts = parse(
55-
`query ($foo: TestType) @testDirective { id, name }`
56-
);
55+
'query ($foo: TestType) @testDirective { id, name }'
56+
);
5757
expect(print(queryAstWithArtifacts)).to.equal(
5858
`query ($foo: TestType) @testDirective {
5959
id
@@ -62,8 +62,8 @@ describe('Printer', () => {
6262
`);
6363

6464
const mutationAstWithArtifacts = parse(
65-
`mutation ($foo: TestType) @testDirective { id, name }`
66-
);
65+
'mutation ($foo: TestType) @testDirective { id, name }'
66+
);
6767
expect(print(mutationAstWithArtifacts)).to.equal(
6868
`mutation ($foo: TestType) @testDirective {
6969
id

0 commit comments

Comments
 (0)