diff --git a/.eslintrc b/.eslintrc index b83a70cfc2..3a11e64e89 100644 --- a/.eslintrc +++ b/.eslintrc @@ -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}], @@ -61,7 +64,6 @@ "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, @@ -69,6 +71,7 @@ "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, @@ -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, @@ -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, @@ -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, diff --git a/package.json b/package.json index a2741c1c41..62304e3351 100644 --- a/package.json +++ b/package.json @@ -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" } } diff --git a/resources/mocha-bootload.js b/resources/mocha-bootload.js index 09ed1811bc..03cfe05104 100644 --- a/resources/mocha-bootload.js +++ b/resources/mocha-bootload.js @@ -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'); diff --git a/resources/prepublish.sh b/resources/prepublish.sh index e7423e806b..16c8cc432b 100644 --- a/resources/prepublish.sh +++ b/resources/prepublish.sh @@ -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));" diff --git a/resources/watch.js b/resources/watch.js index b13459a506..12a40f9f2a 100644 --- a/resources/watch.js +++ b/resources/watch.js @@ -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) => { @@ -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(); }); @@ -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); diff --git a/src/execution/__tests__/abstract.js b/src/execution/__tests__/abstract.js index 3e27253e46..f2a944b900 100644 --- a/src/execution/__tests__/abstract.js +++ b/src/execution/__tests__/abstract.js @@ -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".' + ) ] }); }); @@ -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".' + ) ] }); }); diff --git a/src/execution/__tests__/executor.js b/src/execution/__tests__/executor.js index 90494c2968..d0b7ea3d59 100644 --- a/src/execution/__tests__/executor.js +++ b/src/execution/__tests__/executor.js @@ -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', @@ -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({ @@ -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({ @@ -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({ @@ -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({ @@ -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({ @@ -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({ @@ -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.' - }); + ) + ); }); }); diff --git a/src/execution/__tests__/union-interface.js b/src/execution/__tests__/union-interface.js index 3719cf3f1f..0d3b205d2b 100644 --- a/src/execution/__tests__/union-interface.js +++ b/src/execution/__tests__/union-interface.js @@ -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) diff --git a/src/execution/execute.js b/src/execution/execute.js index 3fcc86d7a3..47a6c7b433 100644 --- a/src/execution/execute.js +++ b/src/execution/execute.js @@ -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 ); } @@ -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 diff --git a/src/language/__tests__/lexer.js b/src/language/__tests__/lexer.js index 14b9096363..040e6bdf57 100644 --- a/src/language/__tests__/lexer.js +++ b/src/language/__tests__/lexer.js @@ -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, diff --git a/src/language/__tests__/parser.js b/src/language/__tests__/parser.js index 68be061ca1..7d7e968f87 100644 --- a/src/language/__tests__/parser.js +++ b/src/language/__tests__/parser.js @@ -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: diff --git a/src/language/__tests__/printer.js b/src/language/__tests__/printer.js index b70810f20f..2f8a416618 100644 --- a/src/language/__tests__/printer.js +++ b/src/language/__tests__/printer.js @@ -35,7 +35,7 @@ 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 @@ -43,7 +43,7 @@ describe('Printer', () => { } `); - const mutationAst = parse(`mutation { id, name }`); + const mutationAst = parse('mutation { id, name }'); expect(print(mutationAst)).to.equal( `mutation { id @@ -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 @@ -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 diff --git a/src/language/__tests__/schema-parser.js b/src/language/__tests__/schema-parser.js index 018cfa2d0f..dea11e574b 100644 --- a/src/language/__tests__/schema-parser.js +++ b/src/language/__tests__/schema-parser.js @@ -172,7 +172,7 @@ type Hello { it('Simple type inheriting interface', () => { - const body = `type Hello implements World { }`; + const body = 'type Hello implements World { }'; const loc = createLocFn(body); const doc = parse(body); const expected = { @@ -192,7 +192,7 @@ type Hello { }); it('Simple type inheriting multiple interfaces', () => { - const body = `type Hello implements Wo, rld { }`; + const body = 'type Hello implements Wo, rld { }'; const loc = createLocFn(body); const doc = parse(body); const expected = { @@ -215,7 +215,7 @@ type Hello { }); it('Single value enum', () => { - const body = `enum Hello { WORLD }`; + const body = 'enum Hello { WORLD }'; const loc = createLocFn(body); const doc = parse(body); const expected = { @@ -234,7 +234,7 @@ type Hello { }); it('Double value enum', () => { - const body = `enum Hello { WO, RLD }`; + const body = 'enum Hello { WO, RLD }'; const loc = createLocFn(body); const doc = parse(body); const expected = { @@ -446,7 +446,7 @@ type Hello { }); it('Simple union', () => { - const body = `union Hello = World`; + const body = 'union Hello = World'; const doc = parse(body); const loc = createLocFn(body); const expected = { @@ -465,7 +465,7 @@ type Hello { }); it('Union with two types', () => { - const body = `union Hello = Wo | Rld`; + const body = 'union Hello = Wo | Rld'; const doc = parse(body); const loc = createLocFn(body); const expected = { @@ -487,7 +487,7 @@ type Hello { }); it('Scalar', () => { - const body = `scalar Hello`; + const body = 'scalar Hello'; const doc = parse(body); const loc = createLocFn(body); const expected = { diff --git a/src/language/lexer.js b/src/language/lexer.js index 95c6dcd066..c3d783435e 100644 --- a/src/language/lexer.js +++ b/src/language/lexer.js @@ -395,7 +395,7 @@ function readString(source, start) { throw syntaxError( source, position, - `Invalid character escape sequence: ` + + 'Invalid character escape sequence: ' + `\\u${body.slice(position + 1, position + 5)}.` ); } diff --git a/src/type/__tests__/enumType.js b/src/type/__tests__/enumType.js index 3c83c32352..75f4800f5d 100644 --- a/src/type/__tests__/enumType.js +++ b/src/type/__tests__/enumType.js @@ -122,10 +122,10 @@ describe('Type System: Enum Values', () => { await graphql(schema, '{ colorEnum(fromEnum: "GREEN") }') ).to.deep.equal({ errors: [ - { - message: 'Argument "fromEnum" has invalid value "GREEN".' + - '\nExpected type \"Color\", found "GREEN".' - } + new Error( + 'Argument "fromEnum" has invalid value "GREEN".' + + '\nExpected type \"Color\", found "GREEN".' + ) ] }); }); @@ -145,8 +145,10 @@ describe('Type System: Enum Values', () => { await graphql(schema, '{ colorEnum(fromEnum: 1) }') ).to.deep.equal({ errors: [ - { message: 'Argument "fromEnum" has invalid value 1.' + - '\nExpected type "Color", found 1.' } + new Error( + 'Argument "fromEnum" has invalid value 1.' + + '\nExpected type "Color", found 1.' + ) ] }); }); @@ -156,8 +158,10 @@ describe('Type System: Enum Values', () => { await graphql(schema, '{ colorEnum(fromInt: GREEN) }') ).to.deep.equal({ errors: [ - { message: 'Argument "fromInt" has invalid value GREEN.' + - '\nExpected type "Int", found GREEN.' } + new Error( + 'Argument "fromInt" has invalid value GREEN.' + + '\nExpected type "Int", found GREEN.' + ) ] }); }); @@ -217,11 +221,10 @@ describe('Type System: Enum Values', () => { ) ).to.deep.equal({ errors: [ - { - message: - 'Variable "\$color" got invalid value 2.' + - '\nExpected type "Color", found 2.' - } + new Error( + 'Variable "\$color" got invalid value 2.' + + '\nExpected type "Color", found 2.' + ) ] }); }); @@ -236,8 +239,10 @@ describe('Type System: Enum Values', () => { ) ).to.deep.equal({ errors: [ - { message: 'Variable "$color" of type "String!" used in position ' + - 'expecting type "Color".' } + new Error( + 'Variable "$color" of type "String!" used in position ' + + 'expecting type "Color".' + ) ] }); }); @@ -252,8 +257,10 @@ describe('Type System: Enum Values', () => { ) ).to.deep.equal({ errors: [ - { message: 'Variable "$color" of type "Int!" used in position ' + - 'expecting type "Color".' } + new Error( + 'Variable "$color" of type "Int!" used in position ' + + 'expecting type "Color".' + ) ] }); }); diff --git a/src/type/definition.js b/src/type/definition.js index 2fee4566be..556963376e 100644 --- a/src/type/definition.js +++ b/src/type/definition.js @@ -218,8 +218,8 @@ export class GraphQLScalarType { invariant( typeof config.serialize === 'function', `${this} must provide "serialize" function. If this custom Scalar is ` + - `also used as an input type, ensure "parseValue" and "parseLiteral" ` + - `functions are also provided.` + 'also used as an input type, ensure "parseValue" and "parseLiteral" ' + + 'functions are also provided.' ); if (config.parseValue || config.parseLiteral) { invariant( @@ -367,8 +367,8 @@ function defineInterfaces( typeof type.isTypeOf === 'function', `Interface Type ${iface} does not provide a "resolveType" function ` + `and implementing Type ${type} does not provide a "isTypeOf" ` + - `function. There is no way to resolve this implementing type ` + - `during execution.` + 'function. There is no way to resolve this implementing type ' + + 'during execution.' ); } }); @@ -383,14 +383,14 @@ function defineFieldMap( invariant( isPlainObj(fieldMap), `${type} fields must be an object with field names as keys or a ` + - `function which returns such an object.` + 'function which returns such an object.' ); const fieldNames = Object.keys(fieldMap); invariant( fieldNames.length > 0, `${type} fields must be an object with field names as keys or a ` + - `function which returns such an object.` + 'function which returns such an object.' ); const resultFieldMap = {}; @@ -403,7 +403,7 @@ function defineFieldMap( invariant( !field.hasOwnProperty('isDeprecated'), `${type}.${fieldName} should provide "deprecationReason" instead ` + - `of "isDeprecated".` + 'of "isDeprecated".' ); invariant( isOutputType(field.type), @@ -416,7 +416,7 @@ function defineFieldMap( invariant( isPlainObj(field.args), `${type}.${fieldName} args must be an object with argument names ` + - `as keys.` + 'as keys.' ); field.args = Object.keys(field.args).map(argName => { assertValidName(argName); @@ -685,8 +685,8 @@ export class GraphQLUnionType { typeof type.isTypeOf === 'function', `Union Type ${this} does not provide a "resolveType" function ` + `and possible Type ${type} does not provide a "isTypeOf" ` + - `function. There is no way to resolve this possible type ` + - `during execution.` + 'function. There is no way to resolve this possible type ' + + 'during execution.' ); } }); @@ -850,7 +850,7 @@ function defineEnumValues( invariant( !value.hasOwnProperty('isDeprecated'), `${type}.${valueName} should provide "deprecationReason" instead ` + - `of "isDeprecated".` + 'of "isDeprecated".' ); return { name: valueName, @@ -930,13 +930,13 @@ export class GraphQLInputObjectType { invariant( isPlainObj(fieldMap), `${this} fields must be an object with field names as keys or a ` + - `function which returns such an object.` + 'function which returns such an object.' ); const fieldNames = Object.keys(fieldMap); invariant( fieldNames.length > 0, `${this} fields must be an object with field names as keys or a ` + - `function which returns such an object.` + 'function which returns such an object.' ); const resultFieldMap = {}; fieldNames.forEach(fieldName => { diff --git a/src/type/schema.js b/src/type/schema.js index dbb78ea601..dc6f2f93c2 100644 --- a/src/type/schema.js +++ b/src/type/schema.js @@ -64,15 +64,15 @@ export class GraphQLSchema { invariant( !config.mutation || config.mutation instanceof GraphQLObjectType, - `Schema mutation must be Object Type if provided but ` + - `got: ${config.mutation}.` + `Schema mutation must be Object Type if provided but got: ${ + config.mutation}.` ); this._mutationType = config.mutation; invariant( !config.subscription || config.subscription instanceof GraphQLObjectType, - `Schema subscription must be Object Type if provided but ` + - `got: ${config.subscription}.` + `Schema subscription must be Object Type if provided but got: ${ + config.subscription}.` ); this._subscriptionType = config.subscription; @@ -81,8 +81,8 @@ export class GraphQLSchema { Array.isArray(config.directives) && config.directives.every( directive => directive instanceof GraphQLDirective ), - `Schema directives must be Array if provided but ` + - `got: ${config.directives}.` + `Schema directives must be Array if provided but got: ${ + config.directives}.` ); // Provide `@include() and `@skip()` directives by default. this._directives = config.directives || [ @@ -157,7 +157,7 @@ function typeMapReducer(map: TypeMap, type: ?GraphQLType): TypeMap { if (map[type.name]) { invariant( map[type.name] === type, - `Schema must contain unique named types but contains multiple ` + + 'Schema must contain unique named types but contains multiple ' + `types named "${type}".` ); return map; @@ -209,7 +209,7 @@ function assertObjectImplementsInterface( invariant( objectField, `"${iface}" expects field "${fieldName}" but "${object}" does not ` + - `provide it.` + 'provide it.' ); // Assert interface field type is satisfied by object field type, by being diff --git a/src/utilities/__tests__/buildASTSchema.js b/src/utilities/__tests__/buildASTSchema.js index 19a3c3284f..4f6aea1c6b 100644 --- a/src/utilities/__tests__/buildASTSchema.js +++ b/src/utilities/__tests__/buildASTSchema.js @@ -374,14 +374,14 @@ type Wat { }); it('Rejects query names', () => { - const body = `query Foo { field }`; + const body = 'query Foo { field }'; const doc = parse(body); expect(() => buildASTSchema(doc, 'Foo')) .to.throw('Specified query type Foo not found in document.'); }); it('Rejects fragment names', () => { - const body = `fragment Foo on Type { field }`; + const body = 'fragment Foo on Type { field }'; const doc = parse(body); expect(() => buildASTSchema(doc, 'Foo')) .to.throw('Specified query type Foo not found in document.'); diff --git a/src/utilities/__tests__/getOperationAST.js b/src/utilities/__tests__/getOperationAST.js index ab0c0e711c..a6d6589a1d 100644 --- a/src/utilities/__tests__/getOperationAST.js +++ b/src/utilities/__tests__/getOperationAST.js @@ -15,22 +15,22 @@ import { getOperationAST } from '../getOperationAST'; describe('getOperationAST', () => { it('Gets an operation from a simple document', () => { - const doc = parse(`{ field }`); + const doc = parse('{ field }'); expect(getOperationAST(doc)).to.equal(doc.definitions[0]); }); it('Gets an operation from a document with named op (mutation)', () => { - const doc = parse(`mutation Test { field }`); + const doc = parse('mutation Test { field }'); expect(getOperationAST(doc)).to.equal(doc.definitions[0]); }); it('Gets an operation from a document with named op (subscription)', () => { - const doc = parse(`subscription Test { field }`); + const doc = parse('subscription Test { field }'); expect(getOperationAST(doc)).to.equal(doc.definitions[0]); }); it('Does not get missing operation', () => { - const doc = parse(`type Foo { field: String }`); + const doc = parse('type Foo { field: String }'); expect(getOperationAST(doc)).to.equal(null); }); diff --git a/src/utilities/astFromValue.js b/src/utilities/astFromValue.js index 1106910f5b..fa3bb008f7 100644 --- a/src/utilities/astFromValue.js +++ b/src/utilities/astFromValue.js @@ -22,8 +22,8 @@ import { OBJECT, OBJECT_FIELD, } from '../language/kinds'; +import type { GraphQLType } from '../type/definition'; import { - GraphQLType, GraphQLEnumType, GraphQLInputObjectType, GraphQLList, diff --git a/src/utilities/buildASTSchema.js b/src/utilities/buildASTSchema.js index eef03a39bb..fd74a56c0f 100644 --- a/src/utilities/buildASTSchema.js +++ b/src/utilities/buildASTSchema.js @@ -132,18 +132,22 @@ export function buildASTSchema( keyMap(typeDefs, d => d.name.value); if (!astMap[queryTypeName]) { - throw new Error('Specified query type ' + queryTypeName + - ' not found in document.'); + throw new Error( + `Specified query type ${queryTypeName} not found in document.` + ); } if (mutationTypeName && !astMap[mutationTypeName]) { - throw new Error('Specified mutation type ' + mutationTypeName + - ' not found in document.'); + throw new Error( + `Specified mutation type ${mutationTypeName} not found in document.` + ); } if (subscriptionTypeName && !astMap[subscriptionTypeName]) { - throw new Error('Specified subscription type ' + subscriptionTypeName + - ' not found in document.'); + throw new Error( + `Specified subscription type ${ + subscriptionTypeName} not found in document.` + ); } const innerTypeMap = { @@ -167,7 +171,7 @@ export function buildASTSchema( const type = typeDefNamed(typeAST.name.value); invariant( type instanceof GraphQLObjectType, - `AST must provide object type.` + 'AST must provide object type.' ); return (type: any); } @@ -189,7 +193,7 @@ export function buildASTSchema( const innerTypeDef = makeSchemaDef(astMap[typeName]); if (!innerTypeDef) { - throw new Error('Nothing constructed for ' + typeName); + throw new Error(`Nothing constructed for ${typeName}`); } innerTypeMap[typeName] = innerTypeDef; return innerTypeDef; @@ -213,7 +217,7 @@ export function buildASTSchema( case INPUT_OBJECT_TYPE_DEFINITION: return makeInputObjectDef(def); default: - throw new Error(def.kind + ' not supported'); + throw new Error(`${def.kind} not supported`); } } diff --git a/src/utilities/buildClientSchema.js b/src/utilities/buildClientSchema.js index eda13740ec..54960290af 100644 --- a/src/utilities/buildClientSchema.js +++ b/src/utilities/buildClientSchema.js @@ -128,8 +128,8 @@ export function buildClientSchema( if (!typeIntrospection) { throw new Error( `Invalid or incomplete schema, unknown type: ${typeName}. Ensure ` + - `that a full introspection query is used in order to build a ` + - `client schema.` + 'that a full introspection query is used in order to build a ' + + 'client schema.' ); } const typeDef = buildType(typeIntrospection); @@ -141,7 +141,7 @@ export function buildClientSchema( const type = getType(typeRef); invariant( isInputType(type), - `Introspection must provide input type for arguments.` + 'Introspection must provide input type for arguments.' ); return (type: any); } @@ -150,7 +150,7 @@ export function buildClientSchema( const type = getType(typeRef); invariant( isOutputType(type), - `Introspection must provide output type for fields.` + 'Introspection must provide output type for fields.' ); return (type: any); } @@ -159,7 +159,7 @@ export function buildClientSchema( const type = getType(typeRef); invariant( type instanceof GraphQLObjectType, - `Introspection must provide object type for possibleTypes.` + 'Introspection must provide object type for possibleTypes.' ); return (type: any); } @@ -170,7 +170,7 @@ export function buildClientSchema( const type = getType(typeRef); invariant( type instanceof GraphQLInterfaceType, - `Introspection must provide interface type for interfaces.` + 'Introspection must provide interface type for interfaces.' ); return (type: any); } @@ -195,8 +195,8 @@ export function buildClientSchema( default: throw new Error( `Invalid or incomplete schema, unknown kind: ${type.kind}. Ensure ` + - `that a full introspection query is used in order to build a ` + - `client schema.` + 'that a full introspection query is used in order to build a ' + + 'client schema.' ); } } diff --git a/src/utilities/extendSchema.js b/src/utilities/extendSchema.js index 822bcf3835..1985a9b24a 100644 --- a/src/utilities/extendSchema.js +++ b/src/utilities/extendSchema.js @@ -112,7 +112,7 @@ export function extendSchema( if (schema.getType(typeName)) { throw new GraphQLError( `Type "${typeName}" already exists in the schema. It cannot also ` + - `be defined in this type definition.`, + 'be defined in this type definition.', [ def ] ); } @@ -126,7 +126,7 @@ export function extendSchema( if (!existingType) { throw new GraphQLError( `Cannot extend type "${extendedTypeName}" because it does not ` + - `exist in the existing schema.`, + 'exist in the existing schema.', [ def.definition ] ); } @@ -212,7 +212,7 @@ export function extendSchema( if (!type) { throw new GraphQLError( `Unknown type: "${astNode.name.value}". Ensure that this type exists ` + - `either in the original schema, or is added in a type definition.`, + 'either in the original schema, or is added in a type definition.', [ astNode ] ); } @@ -299,8 +299,8 @@ export function extendSchema( const interfaceName = namedType.name.value; if (interfaces.some(def => def.name === interfaceName)) { throw new GraphQLError( - `'Type "${type.name}" already implements "${interfaceName}". ` + - `It cannot also be implemented in this type extension.`, + `Type "${type.name}" already implements "${interfaceName}". ` + + 'It cannot also be implemented in this type extension.', [ namedType ] ); } @@ -335,7 +335,7 @@ export function extendSchema( if (oldFieldMap[fieldName]) { throw new GraphQLError( `Field "${type.name}.${fieldName}" already exists in the ` + - `schema. It cannot also be defined in this type extension.`, + 'schema. It cannot also be defined in this type extension.', [ field ] ); } diff --git a/src/validation/__tests__/validation.js b/src/validation/__tests__/validation.js index b63bbc128b..2a280257f8 100644 --- a/src/validation/__tests__/validation.js +++ b/src/validation/__tests__/validation.js @@ -65,9 +65,9 @@ describe('Validate: Supports full validation', () => { ); expect(errors).to.deep.equal([ - { message: 'Cannot query field "catOrDog" on type "QueryRoot".' }, - { message: 'Cannot query field "furColor" on type "Cat".' }, - { message: 'Cannot query field "isHousetrained" on type "Dog".' } + new Error('Cannot query field "catOrDog" on type "QueryRoot".'), + new Error('Cannot query field "furColor" on type "Cat".'), + new Error('Cannot query field "isHousetrained" on type "Dog".'), ]); }); diff --git a/src/validation/rules/FieldsOnCorrectType.js b/src/validation/rules/FieldsOnCorrectType.js index 8ab60a8c00..2fe05d4225 100644 --- a/src/validation/rules/FieldsOnCorrectType.js +++ b/src/validation/rules/FieldsOnCorrectType.js @@ -11,11 +11,9 @@ import type { ValidationContext } from '../index'; import { GraphQLError } from '../../error'; import type { Field } from '../../language/ast'; -import { - isAbstractType, - GraphQLAbstractType, - GraphQLObjectType, -} from '../../type/definition'; +import type { GraphQLAbstractType } from '../../type/definition'; +import { isAbstractType, GraphQLObjectType } from '../../type/definition'; + export function undefinedFieldMessage( fieldName: string, @@ -33,7 +31,7 @@ export function undefinedFieldMessage( suggestions += `, and ${suggestedTypes.length - MAX_LENGTH} other types`; } message += ` However, this field exists on ${suggestions}.`; - message += ` Perhaps you meant to use an inline fragment?`; + message += ' Perhaps you meant to use an inline fragment?'; } return message; } diff --git a/src/validation/rules/LoneAnonymousOperation.js b/src/validation/rules/LoneAnonymousOperation.js index 37e7988ca0..33e05fd622 100644 --- a/src/validation/rules/LoneAnonymousOperation.js +++ b/src/validation/rules/LoneAnonymousOperation.js @@ -14,7 +14,7 @@ import { OPERATION_DEFINITION } from '../../language/kinds'; export function anonOperationNotAloneMessage(): string { - return `This anonymous operation must be the only defined operation.`; + return 'This anonymous operation must be the only defined operation.'; } /** diff --git a/src/validation/rules/PossibleFragmentSpreads.js b/src/validation/rules/PossibleFragmentSpreads.js index af50fe01f7..aa8263c813 100644 --- a/src/validation/rules/PossibleFragmentSpreads.js +++ b/src/validation/rules/PossibleFragmentSpreads.js @@ -28,7 +28,7 @@ export function typeIncompatibleAnonSpreadMessage( parentType: GraphQLType, fragType: GraphQLType ): string { - return `Fragment cannot be spread here as objects of ` + + return 'Fragment cannot be spread here as objects of ' + `type "${parentType}" can never be of type "${fragType}".`; } diff --git a/src/validation/rules/ProvidedNonNullArguments.js b/src/validation/rules/ProvidedNonNullArguments.js index cdeabf6c32..a02f010036 100644 --- a/src/validation/rules/ProvidedNonNullArguments.js +++ b/src/validation/rules/ProvidedNonNullArguments.js @@ -21,7 +21,7 @@ export function missingFieldArgMessage( type: GraphQLType ): string { return `Field "${fieldName}" argument "${argName}" of type "${type}" ` + - `is required but not provided.`; + 'is required but not provided.'; } export function missingDirectiveArgMessage(