Skip to content

Upgrade to Babel6 #309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@

"rules": {
"babel/arrow-parens": [2, "as-needed"],
"babel/array-bracket-spacing": [2, "always"],
"babel/generator-star-spacing": [2, {"before": true, "after": false}],
"array-bracket-spacing": 0,
"generator-star-spacing": 0,

"array-bracket-spacing": [2, "always"],
"arrow-spacing": 2,
"block-scoped-var": 0,
"brace-style": [2, "1tbs", {"allowSingleLine": true}],
Expand All @@ -61,14 +64,14 @@
"eqeqeq": 2,
"func-names": 0,
"func-style": 0,
"generator-star-spacing": [0, {"before": true, "after": false}],
"guard-for-in": 2,
"handle-callback-err": [2, "error"],
"id-length": 0,
"id-match": [2, "^(?:_?[a-zA-Z0-9]*)|[_A-Z0-9]+$"],
"indent": [2, 2, {"SwitchCase": 1}],
"init-declarations": 0,
"key-spacing": [2, {"beforeColon": false, "afterColon": true}],
"keyword-spacing": 2,
"linebreak-style": 2,
"lines-around-comment": 0,
"max-depth": 0,
Expand Down Expand Up @@ -100,7 +103,6 @@
"no-else-return": 2,
"no-empty": 2,
"no-empty-character-class": 2,
"no-empty-label": 2,
"no-eq-null": 0,
"no-eval": 2,
"no-ex-assign": 2,
Expand All @@ -121,7 +123,7 @@
"no-irregular-whitespace": 2,
"no-iterator": 2,
"no-label-var": 2,
"no-labels": 0,
"no-labels": [2, {"allowLoop": true}],
"no-lone-blocks": 2,
"no-lonely-if": 2,
"no-loop-func": 0,
Expand Down Expand Up @@ -194,12 +196,10 @@
"semi": [2, "always"],
"semi-spacing": [2, {"before": false, "after": true}],
"sort-vars": 0,
"space-after-keywords": [2, "always"],
"space-before-blocks": [2, "always"],
"space-before-function-paren": [2, {"anonymous": "always", "named": "never"}],
"space-in-parens": 0,
"space-infix-ops": [2, {"int32Hint": false}],
"space-return-throw-case": 2,
"space-unary-ops": [2, {"words": true, "nonwords": false}],
"spaced-comment": [2, "always"],
"strict": 0,
Expand Down
57 changes: 38 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,55 @@
"url": "http://github.com/graphql/graphql-js.git"
},
"options": {
"mocha": "--require resources/mocha-bootload src/**/__tests__/**/*.js"
"mocha": "--require ./resources/mocha-bootload src/**/__tests__/**/*.js"
},
"babel": {
"presets": [
"es2015"
],
"plugins": [
"syntax-async-functions",
"transform-class-properties",
"transform-flow-strip-types",
"transform-object-rest-spread",
"transform-regenerator",
"transform-runtime"
]
},
"scripts": {
"test": "npm run lint && npm run check && npm run testonly",
"testonly": "mocha $npm_package_options_mocha",
"t": "mocha --require resources/mocha-bootload",
"testonly": "babel-node ./node_modules/.bin/_mocha $npm_package_options_mocha",
"t": "babel-node ./node_modules/.bin/_mocha --require ./resources/mocha-bootload",
"lint": "eslint src",
"check": "flow check",
"build": "babel src --optional runtime --ignore __tests__ --out-dir dist/ && cp package.json dist/",
"watch": "babel --optional runtime resources/watch.js | node",
"cover": "babel-node node_modules/.bin/isparta cover --root src --report html node_modules/.bin/_mocha -- $npm_package_options_mocha",
"cover:lcov": "babel-node node_modules/.bin/isparta cover --root src --report lcovonly node_modules/.bin/_mocha -- $npm_package_options_mocha",
"build": "babel src --ignore __tests__ --out-dir dist/ && cp package.json dist/",
"watch": "babel-node ./resources/watch.js",
"cover": "babel-node ./node_modules/.bin/isparta cover --root src --report html _mocha -- $npm_package_options_mocha",
"cover:lcov": "babel-node ./node_modules/.bin/isparta cover --root src --report lcovonly _mocha -- $npm_package_options_mocha",
"preversion": ". ./resources/checkgit.sh && npm test",
"prepublish": ". ./resources/prepublish.sh"
},
"dependencies": {
"babel-runtime": "^5.8.x"
"babel-runtime": ">=6.0.0"
},
"devDependencies": {
"babel": "5.8.21",
"babel-core": "5.8.22",
"babel-eslint": "4.1.7",
"chai": "3.4.1",
"chai-subset": "1.1.0",
"coveralls": "2.11.4",
"eslint": "1.10.1",
"eslint-plugin-babel": "^2.1.1",
"babel-cli": "6.6.5",
"babel-eslint": "6.0.0-beta.5",
"babel-plugin-syntax-async-functions": "6.5.0",
"babel-plugin-transform-class-properties": "6.6.0",
"babel-plugin-transform-flow-strip-types": "6.7.0",
"babel-plugin-transform-object-rest-spread": "6.6.5",
"babel-plugin-transform-regenerator": "6.6.5",
"babel-plugin-transform-runtime": "6.6.0",
"babel-preset-es2015": "6.6.0",
"chai": "3.5.0",
"chai-subset": "1.2.1",
"coveralls": "2.11.8",
"eslint": "2.2.0",
"eslint-plugin-babel": "3.1.0",
"flow-bin": "0.20.1",
"isparta": "3.0.3",
"mocha": "2.3.4",
"sane": "1.3.0"
"isparta": "4.0.0",
"mocha": "2.4.5",
"sane": "1.3.3"
}
}
4 changes: 0 additions & 4 deletions resources/mocha-bootload.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

require('babel/register')({
optional: ['runtime', 'es7.asyncFunctions']
});

var chai = require('chai');

var chaiSubset = require('chai-subset');
Expand Down
8 changes: 7 additions & 1 deletion resources/prepublish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,10 @@ fi;
#
# var language = require('graphql/language');
#
babel --optional runtime src --ignore __tests__ --out-dir ./;
babel src --ignore __tests__ --out-dir ./

# Ensure a vanilla package.json before deploying so other tools do not interpret
# The built output as requiring any further transformation.
node -e "var package = require('./package.json'); \
delete package.babel; delete package.scripts; delete package.options; \
require('fs').writeFileSync('package.json', JSON.stringify(package));"
9 changes: 5 additions & 4 deletions resources/watch.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import flowBinPath from 'flow-bin';
process.env.PATH += ':./node_modules/.bin';

var cmd = resolvePath(__dirname);
var srcDir = resolvePath(cmd, './src');
var srcDir = resolvePath(cmd, '../src');

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

process.on('SIGINT', () => {
console.log(CLEARLINE + yellow(invert('stopped watching')));
watcher.close();
flowServer.kill();
console.log(CLEARLINE + yellow(invert('stopped watching')));
process.exit();
});

Expand Down Expand Up @@ -130,9 +130,10 @@ function parseFiles(filepaths) {
function runTests(filepaths) {
console.log('\nRunning Tests');

return exec('mocha', [
return exec('babel-node', [
'./node_modules/.bin/_mocha',
'--reporter', 'progress',
'--require', 'resources/mocha-bootload'
'--require', './resources/mocha-bootload',
].concat(
allTests(filepaths) ? filepaths.map(srcPath) : ['src/**/__tests__/**/*.js']
)).catch(() => false);
Expand Down
10 changes: 6 additions & 4 deletions src/execution/__tests__/abstract.js
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,9 @@ describe('Execute: Handles execution of abstract types', () => {
]
},
errors: [
{ message:
'Runtime Object type "Human" is not a possible type for "Pet".' }
new Error(
'Runtime Object type "Human" is not a possible type for "Pet".'
)
]
});
});
Expand Down Expand Up @@ -345,8 +346,9 @@ describe('Execute: Handles execution of abstract types', () => {
]
},
errors: [
{ message:
'Runtime Object type "Human" is not a possible type for "Pet".' }
new Error(
'Runtime Object type "Human" is not a possible type for "Pet".'
)
]
});
});
Expand Down
21 changes: 11 additions & 10 deletions src/execution/__tests__/executor.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ describe('Execute: Handles basic execution tasks', () => {
});

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

const data = {
contextThing: 'thing',
Expand Down Expand Up @@ -379,7 +379,7 @@ describe('Execute: Handles basic execution tasks', () => {
});

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

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

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

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

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

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

expect(caughtError).to.deep.equal({
message:
expect(caughtError).to.deep.equal(
new Error(
'GraphQL cannot execute a request containing a ObjectTypeDefinition.'
});
)
);
});

});
2 changes: 1 addition & 1 deletion src/execution/__tests__/union-interface.js
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ describe('Execute: Union and intersection types', () => {

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

const ast = parse(`{ name, friends { name } }`);
const ast = parse('{ name, friends { name } }');

expect(
await execute(schema2, ast, john2)
Expand Down
8 changes: 4 additions & 4 deletions src/execution/execute.js
Original file line number Diff line number Diff line change
Expand Up @@ -679,8 +679,8 @@ function completeValue(
);
if (completed === null) {
throw new GraphQLError(
`Cannot return null for non-nullable ` +
`field ${info.parentType}.${info.fieldName}.`,
`Cannot return null for non-nullable field ${
info.parentType}.${info.fieldName}.`,
fieldASTs
);
}
Expand All @@ -696,8 +696,8 @@ function completeValue(
if (returnType instanceof GraphQLList) {
invariant(
Array.isArray(result),
'User Error: expected iterable, but did not find one ' +
`for field ${info.parentType}.${info.fieldName}.`
`User Error: expected iterable, but did not find one for field ${
info.parentType}.${info.fieldName}.`
);

// This is specified as a simple map, however we're optimizing the path
Expand Down
2 changes: 1 addition & 1 deletion src/language/__tests__/lexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ describe('Lexer', () => {
value: 'foo'
});

expect(lexOne(`,,,foo,,,`)).to.deep.equal({
expect(lexOne(',,,foo,,,')).to.deep.equal({
kind: TokenKind.NAME,
start: 3,
end: 6,
Expand Down
2 changes: 1 addition & 1 deletion src/language/__tests__/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { join } from 'path';
describe('Parser', () => {

it('accepts option to not include source', () => {
expect(parse(`{ field }`, { noSource: true })).to.deep.equal({
expect(parse('{ field }', { noSource: true })).to.deep.equal({
kind: 'Document',
loc: { start: 0, end: 9 },
definitions:
Expand Down
12 changes: 6 additions & 6 deletions src/language/__tests__/printer.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ describe('Printer', () => {
});

it('correctly prints non-query operations without name', () => {
const queryAstShorthanded = parse(`query { id, name }`);
const queryAstShorthanded = parse('query { id, name }');
expect(print(queryAstShorthanded)).to.equal(
`{
id
name
}
`);

const mutationAst = parse(`mutation { id, name }`);
const mutationAst = parse('mutation { id, name }');
expect(print(mutationAst)).to.equal(
`mutation {
id
Expand All @@ -52,8 +52,8 @@ describe('Printer', () => {
`);

const queryAstWithArtifacts = parse(
`query ($foo: TestType) @testDirective { id, name }`
);
'query ($foo: TestType) @testDirective { id, name }'
);
expect(print(queryAstWithArtifacts)).to.equal(
`query ($foo: TestType) @testDirective {
id
Expand All @@ -62,8 +62,8 @@ describe('Printer', () => {
`);

const mutationAstWithArtifacts = parse(
`mutation ($foo: TestType) @testDirective { id, name }`
);
'mutation ($foo: TestType) @testDirective { id, name }'
);
expect(print(mutationAstWithArtifacts)).to.equal(
`mutation ($foo: TestType) @testDirective {
id
Expand Down
Loading