diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 74c72e3529..5a0fdfdbc9 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -1,5 +1,4 @@
-Contributing to graphql-js
-==========================
+# Contributing to graphql-js
We want to make contributing to this project as easy and transparent as
possible. Hopefully this document makes the process for contributing clear and
@@ -80,12 +79,12 @@ This will watch the file system run any relevant lint, tests, and type checks au
## Release on NPM
-*Only core contributors may release to NPM.*
+_Only core contributors may release to NPM._
To release a new version on NPM, first ensure all tests pass with `npm test`,
then use `npm version patch|minor|major` in order to increment the version in
package.json and tag and commit a release. Then `git push && git push --tags`
-this change so Travis CI can deploy to NPM. *Do not run `npm publish` directly.*
+this change so Travis CI can deploy to NPM. _Do not run `npm publish` directly._
Once published, add [release notes](https://github.com/graphql/graphql-js/tags).
Use [semver](http://semver.org/) to determine which version part to increment.
diff --git a/README.md b/README.md
index 1cd8377c3c..a9682a9a5c 100644
--- a/README.md
+++ b/README.md
@@ -17,8 +17,7 @@ For discussion, join [#graphql on Discord](http://join.reactiflux.com/).
## Technical Preview Contents
-This technical preview contains a [draft specification for GraphQL]
-(https://github.com/facebook/graphql) and a reference implementation in
+This technical preview contains a [draft specification for GraphQL](https://github.com/facebook/graphql) and a reference implementation in
JavaScript that implements that draft, GraphQL.js.
The reference implementation provides base libraries in JavaScript that would
@@ -71,16 +70,16 @@ import {
GraphQLSchema,
GraphQLObjectType,
GraphQLString
-} from 'graphql';
+} from "graphql";
var schema = new GraphQLSchema({
query: new GraphQLObjectType({
- name: 'RootQueryType',
+ name: "RootQueryType",
fields: {
hello: {
type: GraphQLString,
resolve() {
- return 'world';
+ return "world";
}
}
}
@@ -96,16 +95,14 @@ level [tests](src/__tests__) directory.
Then, serve the result of a query against that type schema.
```js
-var query = '{ hello }';
+var query = "{ hello }";
graphql(schema, query).then(result => {
-
// Prints
// {
// data: { hello: "world" }
// }
console.log(result);
-
});
```
@@ -114,10 +111,9 @@ first ensure the query is syntactically and semantically valid before executing
it, reporting errors otherwise.
```js
-var query = '{ boyhowdy }';
+var query = "{ boyhowdy }";
graphql(schema, query).then(result => {
-
// Prints
// {
// errors: [
@@ -126,7 +122,6 @@ graphql(schema, query).then(result => {
// ]
// }
console.log(result);
-
});
```
diff --git a/package.json b/package.json
index c8d24cee72..a8b19bef8a 100644
--- a/package.json
+++ b/package.json
@@ -18,12 +18,11 @@
"url": "http://github.com/graphql/graphql-js.git"
},
"options": {
- "mocha": "--require ./resources/mocha-bootload --check-leaks --full-trace src/**/__tests__/**/*-test.js"
+ "mocha":
+ "--require ./resources/mocha-bootload --check-leaks --full-trace src/**/__tests__/**/*-test.js"
},
"babel": {
- "presets": [
- "es2015"
- ],
+ "presets": ["es2015"],
"plugins": [
"syntax-async-functions",
"transform-class-properties",
@@ -35,15 +34,21 @@
},
"scripts": {
"test": "npm run lint && npm run check && npm run testonly",
- "testonly": "babel-node ./node_modules/.bin/_mocha $npm_package_options_mocha",
- "t": "babel-node ./node_modules/.bin/_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",
- "check-cover": "for file in {src/*.js,src/**/*.js}; do echo $file; flow coverage $file; done",
- "build": "babel src --ignore __tests__ --out-dir dist/ && cp package.json dist/",
+ "check-cover":
+ "for file in {src/*.js,src/**/*.js}; do echo $file; flow coverage $file; done",
+ "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",
+ "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"
},
diff --git a/resources/mocha-bootload.js b/resources/mocha-bootload.js
index 03cfe05104..8879cc7fb7 100644
--- a/resources/mocha-bootload.js
+++ b/resources/mocha-bootload.js
@@ -7,12 +7,12 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
-var chai = require('chai');
+var chai = require("chai");
-var chaiSubset = require('chai-subset');
+var chaiSubset = require("chai-subset");
chai.use(chaiSubset);
-process.on('unhandledRejection', function (error) {
- console.error('Unhandled Promise Rejection:');
- console.error(error && error.stack || error);
+process.on("unhandledRejection", function(error) {
+ console.error("Unhandled Promise Rejection:");
+ console.error((error && error.stack) || error);
});
diff --git a/resources/watch.js b/resources/watch.js
index a5bc789fc4..4671cda51a 100644
--- a/resources/watch.js
+++ b/resources/watch.js
@@ -7,47 +7,46 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
-import sane from 'sane';
-import { resolve as resolvePath } from 'path';
-import { spawn } from 'child_process';
-import flowBinPath from 'flow-bin';
+import sane from "sane";
+import { resolve as resolvePath } from "path";
+import { spawn } from "child_process";
+import flowBinPath from "flow-bin";
-
-process.env.PATH += ':./node_modules/.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) => {
var child = spawn(command, options, {
cmd: cmd,
env: process.env,
- stdio: 'inherit'
+ stdio: "inherit"
});
- child.on('exit', code => {
+ child.on("exit", code => {
if (code === 0) {
resolve(true);
} else {
- reject(new Error('Error code: ' + code));
+ reject(new Error("Error code: " + code));
}
});
});
}
-var flowServer = spawn(flowBinPath, ['server'], {
+var flowServer = spawn(flowBinPath, ["server"], {
cmd: cmd,
env: process.env
});
-var watcher = sane(srcDir, { glob: ['**/*.js', '**/*.graphql'] })
- .on('ready', startWatch)
- .on('add', changeFile)
- .on('delete', deleteFile)
- .on('change', changeFile);
+var watcher = sane(srcDir, { glob: ["**/*.js", "**/*.graphql"] })
+ .on("ready", startWatch)
+ .on("add", changeFile)
+ .on("delete", deleteFile)
+ .on("change", changeFile);
-process.on('SIGINT', () => {
- console.log(CLEARLINE + yellow(invert('stopped watching')));
+process.on("SIGINT", () => {
+ console.log(CLEARLINE + yellow(invert("stopped watching")));
watcher.close();
flowServer.kill();
process.exit();
@@ -59,7 +58,7 @@ var toCheck = {};
var timeout;
function startWatch() {
- process.stdout.write(CLEARSCREEN + green(invert('watching...')));
+ process.stdout.write(CLEARSCREEN + green(invert("watching...")));
}
function changeFile(filepath, root, stat) {
@@ -95,18 +94,21 @@ function guardedCheck() {
}
function checkFiles(filepaths) {
- console.log('\u001b[2J');
+ console.log("\u001b[2J");
return parseFiles(filepaths)
.then(() => runTests(filepaths))
- .then(testSuccess => lintFiles(filepaths)
- .then(lintSuccess => typecheckStatus()
- .then(typecheckSuccess =>
- testSuccess && lintSuccess && typecheckSuccess)))
+ .then(testSuccess =>
+ lintFiles(filepaths).then(lintSuccess =>
+ typecheckStatus().then(
+ typecheckSuccess => testSuccess && lintSuccess && typecheckSuccess
+ )
+ )
+ )
.catch(() => false)
.then(success => {
process.stdout.write(
- '\n' + (success ? '' : '\x07') + green(invert('watching...'))
+ "\n" + (success ? "" : "\x07") + green(invert("watching..."))
);
});
}
@@ -114,54 +116,68 @@ function checkFiles(filepaths) {
// Checking steps
function parseFiles(filepaths) {
- console.log('Checking Syntax');
-
- return Promise.all(filepaths.map(filepath => {
- if (isJS(filepath) && !isTest(filepath)) {
- return exec('babel', [
- '--optional', 'runtime',
- '--out-file', '/dev/null',
- srcPath(filepath)
- ]);
- }
- }));
+ console.log("Checking Syntax");
+
+ return Promise.all(
+ filepaths.map(filepath => {
+ if (isJS(filepath) && !isTest(filepath)) {
+ return exec("babel", [
+ "--optional",
+ "runtime",
+ "--out-file",
+ "/dev/null",
+ srcPath(filepath)
+ ]);
+ }
+ })
+ );
}
function runTests(filepaths) {
- console.log('\nRunning Tests');
-
- return exec('babel-node', [
- './node_modules/.bin/_mocha',
- '--reporter', 'progress',
- '--require', './resources/mocha-bootload',
- ].concat(
- allTests(filepaths) ?
- filepaths.map(srcPath) :
- ['src/**/__tests__/**/*-test.js']
- )).catch(() => false);
+ console.log("\nRunning Tests");
+
+ return exec(
+ "babel-node",
+ [
+ "./node_modules/.bin/_mocha",
+ "--reporter",
+ "progress",
+ "--require",
+ "./resources/mocha-bootload"
+ ].concat(
+ allTests(filepaths)
+ ? filepaths.map(srcPath)
+ : ["src/**/__tests__/**/*-test.js"]
+ )
+ ).catch(() => false);
}
function lintFiles(filepaths) {
- console.log('Linting Code\n');
-
- return filepaths.reduce((prev, filepath) => prev.then(prevSuccess => {
- if (isJS(filepath)) {
- process.stdout.write(' ' + filepath + ' ...');
- return exec('eslint', [srcPath(filepath)])
- .catch(() => false)
- .then(success => {
- console.log(CLEARLINE + ' ' + (success ? CHECK : X)
- + ' ' + filepath);
- return prevSuccess && success;
- });
- }
- return prevSuccess;
- }), Promise.resolve(true));
+ console.log("Linting Code\n");
+
+ return filepaths.reduce(
+ (prev, filepath) =>
+ prev.then(prevSuccess => {
+ if (isJS(filepath)) {
+ process.stdout.write(" " + filepath + " ...");
+ return exec("eslint", [srcPath(filepath)])
+ .catch(() => false)
+ .then(success => {
+ console.log(
+ CLEARLINE + " " + (success ? CHECK : X) + " " + filepath
+ );
+ return prevSuccess && success;
+ });
+ }
+ return prevSuccess;
+ }),
+ Promise.resolve(true)
+ );
}
function typecheckStatus() {
- console.log('\nType Checking\n');
- return exec(flowBinPath, ['status']).catch(() => false);
+ console.log("\nType Checking\n");
+ return exec(flowBinPath, ["status"]).catch(() => false);
}
// Filepath
@@ -173,7 +189,7 @@ function srcPath(filepath) {
// Predicates
function isJS(filepath) {
- return filepath.indexOf('.js') === filepath.length - 3;
+ return filepath.indexOf(".js") === filepath.length - 3;
}
function allTests(filepaths) {
@@ -188,10 +204,10 @@ function isTest(filepath) {
// Print helpers
-var CLEARSCREEN = '\u001b[2J';
-var CLEARLINE = '\r\x1B[K';
-var CHECK = green('\u2713');
-var X = red('\u2718');
+var CLEARSCREEN = "\u001b[2J";
+var CLEARLINE = "\r\x1B[K";
+var CHECK = green("\u2713");
+var X = red("\u2718");
function invert(str) {
return `\u001b[7m ${str} \u001b[27m`;
diff --git a/src/README.md b/src/README.md
index ba7b7cd5b3..62b8a7bf9b 100644
--- a/src/README.md
+++ b/src/README.md
@@ -1,5 +1,4 @@
-GraphQL JS
-----------
+## GraphQL JS
The primary `graphql` module includes everything you need to define a GraphQL
schema and fulfill GraphQL requests.
diff --git a/src/__tests__/starWarsData.js b/src/__tests__/starWarsData.js
index 7bda5c039c..cc2425eccf 100644
--- a/src/__tests__/starWarsData.js
+++ b/src/__tests__/starWarsData.js
@@ -14,41 +14,41 @@
*/
const luke = {
- id: '1000',
- name: 'Luke Skywalker',
- friends: [ '1002', '1003', '2000', '2001' ],
- appearsIn: [ 4, 5, 6 ],
- homePlanet: 'Tatooine',
+ id: "1000",
+ name: "Luke Skywalker",
+ friends: ["1002", "1003", "2000", "2001"],
+ appearsIn: [4, 5, 6],
+ homePlanet: "Tatooine"
};
const vader = {
- id: '1001',
- name: 'Darth Vader',
- friends: [ '1004' ],
- appearsIn: [ 4, 5, 6 ],
- homePlanet: 'Tatooine',
+ id: "1001",
+ name: "Darth Vader",
+ friends: ["1004"],
+ appearsIn: [4, 5, 6],
+ homePlanet: "Tatooine"
};
const han = {
- id: '1002',
- name: 'Han Solo',
- friends: [ '1000', '1003', '2001' ],
- appearsIn: [ 4, 5, 6 ],
+ id: "1002",
+ name: "Han Solo",
+ friends: ["1000", "1003", "2001"],
+ appearsIn: [4, 5, 6]
};
const leia = {
- id: '1003',
- name: 'Leia Organa',
- friends: [ '1000', '1002', '2000', '2001' ],
- appearsIn: [ 4, 5, 6 ],
- homePlanet: 'Alderaan',
+ id: "1003",
+ name: "Leia Organa",
+ friends: ["1000", "1002", "2000", "2001"],
+ appearsIn: [4, 5, 6],
+ homePlanet: "Alderaan"
};
const tarkin = {
- id: '1004',
- name: 'Wilhuff Tarkin',
- friends: [ '1001' ],
- appearsIn: [ 4 ],
+ id: "1004",
+ name: "Wilhuff Tarkin",
+ friends: ["1001"],
+ appearsIn: [4]
};
const humanData = {
@@ -56,28 +56,28 @@ const humanData = {
1001: vader,
1002: han,
1003: leia,
- 1004: tarkin,
+ 1004: tarkin
};
const threepio = {
- id: '2000',
- name: 'C-3PO',
- friends: [ '1000', '1002', '1003', '2001' ],
- appearsIn: [ 4, 5, 6 ],
- primaryFunction: 'Protocol',
+ id: "2000",
+ name: "C-3PO",
+ friends: ["1000", "1002", "1003", "2001"],
+ appearsIn: [4, 5, 6],
+ primaryFunction: "Protocol"
};
const artoo = {
- id: '2001',
- name: 'R2-D2',
- friends: [ '1000', '1002', '1003' ],
- appearsIn: [ 4, 5, 6 ],
- primaryFunction: 'Astromech',
+ id: "2001",
+ name: "R2-D2",
+ friends: ["1000", "1002", "1003"],
+ appearsIn: [4, 5, 6],
+ primaryFunction: "Astromech"
};
const droidData = {
2000: threepio,
- 2001: artoo,
+ 2001: artoo
};
/**
diff --git a/src/__tests__/starWarsIntrospection-test.js b/src/__tests__/starWarsIntrospection-test.js
index 6646825e34..2d4a369977 100644
--- a/src/__tests__/starWarsIntrospection-test.js
+++ b/src/__tests__/starWarsIntrospection-test.js
@@ -7,17 +7,17 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
-import { expect } from 'chai';
-import { describe, it } from 'mocha';
-import { StarWarsSchema } from './starWarsSchema.js';
-import { graphql } from '../graphql';
+import { expect } from "chai";
+import { describe, it } from "mocha";
+import { StarWarsSchema } from "./starWarsSchema.js";
+import { graphql } from "../graphql";
// 80+ char lines are useful in describe/it, so ignore in this file.
/* eslint-disable max-len */
-describe('Star Wars Introspection Tests', () => {
- describe('Basic Introspection', () => {
- it('Allows querying the schema for types', async () => {
+describe("Star Wars Introspection Tests", () => {
+ describe("Basic Introspection", () => {
+ it("Allows querying the schema for types", async () => {
const query = `
query IntrospectionTypeQuery {
__schema {
@@ -31,49 +31,49 @@ describe('Star Wars Introspection Tests', () => {
__schema: {
types: [
{
- name: 'Query'
+ name: "Query"
},
{
- name: 'Episode'
+ name: "Episode"
},
{
- name: 'Character'
+ name: "Character"
},
{
- name: 'String'
+ name: "String"
},
{
- name: 'Human'
+ name: "Human"
},
{
- name: 'Droid'
+ name: "Droid"
},
{
- name: '__Schema'
+ name: "__Schema"
},
{
- name: '__Type'
+ name: "__Type"
},
{
- name: '__TypeKind'
+ name: "__TypeKind"
},
{
- name: 'Boolean'
+ name: "Boolean"
},
{
- name: '__Field'
+ name: "__Field"
},
{
- name: '__InputValue'
+ name: "__InputValue"
},
{
- name: '__EnumValue'
+ name: "__EnumValue"
},
{
- name: '__Directive'
+ name: "__Directive"
},
{
- name: '__DirectiveLocation'
+ name: "__DirectiveLocation"
}
]
}
@@ -82,7 +82,7 @@ describe('Star Wars Introspection Tests', () => {
expect(result).to.deep.equal({ data: expected });
});
- it('Allows querying the schema for query type', async () => {
+ it("Allows querying the schema for query type", async () => {
const query = `
query IntrospectionQueryTypeQuery {
__schema {
@@ -95,15 +95,15 @@ describe('Star Wars Introspection Tests', () => {
const expected = {
__schema: {
queryType: {
- name: 'Query'
- },
+ name: "Query"
+ }
}
};
const result = await graphql(StarWarsSchema, query);
expect(result).to.deep.equal({ data: expected });
});
- it('Allows querying the schema for a specific type', async () => {
+ it("Allows querying the schema for a specific type", async () => {
const query = `
query IntrospectionDroidTypeQuery {
__type(name: "Droid") {
@@ -113,14 +113,14 @@ describe('Star Wars Introspection Tests', () => {
`;
const expected = {
__type: {
- name: 'Droid'
+ name: "Droid"
}
};
const result = await graphql(StarWarsSchema, query);
expect(result).to.deep.equal({ data: expected });
});
- it('Allows querying the schema for an object kind', async () => {
+ it("Allows querying the schema for an object kind", async () => {
const query = `
query IntrospectionDroidKindQuery {
__type(name: "Droid") {
@@ -131,15 +131,15 @@ describe('Star Wars Introspection Tests', () => {
`;
const expected = {
__type: {
- name: 'Droid',
- kind: 'OBJECT'
+ name: "Droid",
+ kind: "OBJECT"
}
};
const result = await graphql(StarWarsSchema, query);
expect(result).to.deep.equal({ data: expected });
});
- it('Allows querying the schema for an interface kind', async () => {
+ it("Allows querying the schema for an interface kind", async () => {
const query = `
query IntrospectionCharacterKindQuery {
__type(name: "Character") {
@@ -150,15 +150,15 @@ describe('Star Wars Introspection Tests', () => {
`;
const expected = {
__type: {
- name: 'Character',
- kind: 'INTERFACE'
+ name: "Character",
+ kind: "INTERFACE"
}
};
const result = await graphql(StarWarsSchema, query);
expect(result).to.deep.equal({ data: expected });
});
- it('Allows querying the schema for object fields', async () => {
+ it("Allows querying the schema for object fields", async () => {
const query = `
query IntrospectionDroidFieldsQuery {
__type(name: "Droid") {
@@ -175,41 +175,41 @@ describe('Star Wars Introspection Tests', () => {
`;
const expected = {
__type: {
- name: 'Droid',
+ name: "Droid",
fields: [
{
- name: 'id',
+ name: "id",
type: {
name: null,
- kind: 'NON_NULL'
+ kind: "NON_NULL"
}
},
{
- name: 'name',
+ name: "name",
type: {
- name: 'String',
- kind: 'SCALAR'
+ name: "String",
+ kind: "SCALAR"
}
},
{
- name: 'friends',
+ name: "friends",
type: {
name: null,
- kind: 'LIST'
+ kind: "LIST"
}
},
{
- name: 'appearsIn',
+ name: "appearsIn",
type: {
name: null,
- kind: 'LIST'
+ kind: "LIST"
}
},
{
- name: 'primaryFunction',
+ name: "primaryFunction",
type: {
- name: 'String',
- kind: 'SCALAR'
+ name: "String",
+ kind: "SCALAR"
}
}
]
@@ -220,7 +220,7 @@ describe('Star Wars Introspection Tests', () => {
expect(result).to.deep.equal({ data: expected });
});
- it('Allows querying the schema for nested object fields', async () => {
+ it("Allows querying the schema for nested object fields", async () => {
const query = `
query IntrospectionDroidNestedFieldsQuery {
__type(name: "Droid") {
@@ -241,54 +241,54 @@ describe('Star Wars Introspection Tests', () => {
`;
const expected = {
__type: {
- name: 'Droid',
+ name: "Droid",
fields: [
{
- name: 'id',
+ name: "id",
type: {
name: null,
- kind: 'NON_NULL',
+ kind: "NON_NULL",
ofType: {
- name: 'String',
- kind: 'SCALAR'
+ name: "String",
+ kind: "SCALAR"
}
}
},
{
- name: 'name',
+ name: "name",
type: {
- name: 'String',
- kind: 'SCALAR',
+ name: "String",
+ kind: "SCALAR",
ofType: null
}
},
{
- name: 'friends',
+ name: "friends",
type: {
name: null,
- kind: 'LIST',
+ kind: "LIST",
ofType: {
- name: 'Character',
- kind: 'INTERFACE'
+ name: "Character",
+ kind: "INTERFACE"
}
}
},
{
- name: 'appearsIn',
+ name: "appearsIn",
type: {
name: null,
- kind: 'LIST',
+ kind: "LIST",
ofType: {
- name: 'Episode',
- kind: 'ENUM'
+ name: "Episode",
+ kind: "ENUM"
}
}
},
{
- name: 'primaryFunction',
+ name: "primaryFunction",
type: {
- name: 'String',
- kind: 'SCALAR',
+ name: "String",
+ kind: "SCALAR",
ofType: null
}
}
@@ -299,7 +299,7 @@ describe('Star Wars Introspection Tests', () => {
expect(result).to.deep.equal({ data: expected });
});
- it('Allows querying the schema for field args', async () => {
+ it("Allows querying the schema for field args", async () => {
const query = `
query IntrospectionQueryTypeQuery {
__schema {
@@ -329,34 +329,35 @@ describe('Star Wars Introspection Tests', () => {
queryType: {
fields: [
{
- name: 'hero',
+ name: "hero",
args: [
{
defaultValue: null,
- description: 'If omitted, returns the hero of the whole ' +
- 'saga. If provided, returns the hero of ' +
- 'that particular episode.',
- name: 'episode',
+ description:
+ "If omitted, returns the hero of the whole " +
+ "saga. If provided, returns the hero of " +
+ "that particular episode.",
+ name: "episode",
type: {
- kind: 'ENUM',
- name: 'Episode',
+ kind: "ENUM",
+ name: "Episode",
ofType: null
}
}
]
},
{
- name: 'human',
+ name: "human",
args: [
{
- name: 'id',
- description: 'id of the human',
+ name: "id",
+ description: "id of the human",
type: {
- kind: 'NON_NULL',
+ kind: "NON_NULL",
name: null,
ofType: {
- kind: 'SCALAR',
- name: 'String'
+ kind: "SCALAR",
+ name: "String"
}
},
defaultValue: null
@@ -364,17 +365,17 @@ describe('Star Wars Introspection Tests', () => {
]
},
{
- name: 'droid',
+ name: "droid",
args: [
{
- name: 'id',
- description: 'id of the droid',
+ name: "id",
+ description: "id of the droid",
type: {
- kind: 'NON_NULL',
+ kind: "NON_NULL",
name: null,
ofType: {
- kind: 'SCALAR',
- name: 'String'
+ kind: "SCALAR",
+ name: "String"
}
},
defaultValue: null
@@ -386,12 +387,11 @@ describe('Star Wars Introspection Tests', () => {
}
};
-
const result = await graphql(StarWarsSchema, query);
expect(result).to.deep.equal({ data: expected });
});
- it('Allows querying the schema for documentation', async () => {
+ it("Allows querying the schema for documentation", async () => {
const query = `
query IntrospectionDroidDescriptionQuery {
__type(name: "Droid") {
@@ -402,8 +402,8 @@ describe('Star Wars Introspection Tests', () => {
`;
const expected = {
__type: {
- name: 'Droid',
- description: 'A mechanical creature in the Star Wars universe.'
+ name: "Droid",
+ description: "A mechanical creature in the Star Wars universe."
}
};
const result = await graphql(StarWarsSchema, query);
diff --git a/src/__tests__/starWarsQuery-test.js b/src/__tests__/starWarsQuery-test.js
index 180e12b3af..73cd0fcf34 100644
--- a/src/__tests__/starWarsQuery-test.js
+++ b/src/__tests__/starWarsQuery-test.js
@@ -7,17 +7,17 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
-import { expect } from 'chai';
-import { describe, it } from 'mocha';
-import { StarWarsSchema } from './starWarsSchema.js';
-import { graphql } from '../graphql';
+import { expect } from "chai";
+import { describe, it } from "mocha";
+import { StarWarsSchema } from "./starWarsSchema.js";
+import { graphql } from "../graphql";
// 80+ char lines are useful in describe/it, so ignore in this file.
/* eslint-disable max-len */
-describe('Star Wars Query Tests', () => {
- describe('Basic Queries', () => {
- it('Correctly identifies R2-D2 as the hero of the Star Wars Saga', async () => {
+describe("Star Wars Query Tests", () => {
+ describe("Basic Queries", () => {
+ it("Correctly identifies R2-D2 as the hero of the Star Wars Saga", async () => {
const query = `
query HeroNameQuery {
hero {
@@ -27,14 +27,14 @@ describe('Star Wars Query Tests', () => {
`;
const expected = {
hero: {
- name: 'R2-D2'
+ name: "R2-D2"
}
};
const result = await graphql(StarWarsSchema, query);
expect(result).to.deep.equal({ data: expected });
});
- it('Allows us to query for the ID and friends of R2-D2', async () => {
+ it("Allows us to query for the ID and friends of R2-D2", async () => {
const query = `
query HeroNameAndFriendsQuery {
hero {
@@ -48,18 +48,18 @@ describe('Star Wars Query Tests', () => {
`;
const expected = {
hero: {
- id: '2001',
- name: 'R2-D2',
+ id: "2001",
+ name: "R2-D2",
friends: [
{
- name: 'Luke Skywalker',
+ name: "Luke Skywalker"
},
{
- name: 'Han Solo',
+ name: "Han Solo"
},
{
- name: 'Leia Organa',
- },
+ name: "Leia Organa"
+ }
]
}
};
@@ -68,8 +68,8 @@ describe('Star Wars Query Tests', () => {
});
});
- describe('Nested Queries', () => {
- it('Allows us to query for the friends of friends of R2-D2', async () => {
+ describe("Nested Queries", () => {
+ it("Allows us to query for the friends of friends of R2-D2", async () => {
const query = `
query NestedQuery {
hero {
@@ -86,59 +86,59 @@ describe('Star Wars Query Tests', () => {
`;
const expected = {
hero: {
- name: 'R2-D2',
+ name: "R2-D2",
friends: [
{
- name: 'Luke Skywalker',
- appearsIn: [ 'NEWHOPE', 'EMPIRE', 'JEDI' ],
+ name: "Luke Skywalker",
+ appearsIn: ["NEWHOPE", "EMPIRE", "JEDI"],
friends: [
{
- name: 'Han Solo',
+ name: "Han Solo"
},
{
- name: 'Leia Organa',
+ name: "Leia Organa"
},
{
- name: 'C-3PO',
+ name: "C-3PO"
},
{
- name: 'R2-D2',
- },
+ name: "R2-D2"
+ }
]
},
{
- name: 'Han Solo',
- appearsIn: [ 'NEWHOPE', 'EMPIRE', 'JEDI' ],
+ name: "Han Solo",
+ appearsIn: ["NEWHOPE", "EMPIRE", "JEDI"],
friends: [
{
- name: 'Luke Skywalker',
+ name: "Luke Skywalker"
},
{
- name: 'Leia Organa',
+ name: "Leia Organa"
},
{
- name: 'R2-D2',
- },
+ name: "R2-D2"
+ }
]
},
{
- name: 'Leia Organa',
- appearsIn: [ 'NEWHOPE', 'EMPIRE', 'JEDI' ],
+ name: "Leia Organa",
+ appearsIn: ["NEWHOPE", "EMPIRE", "JEDI"],
friends: [
{
- name: 'Luke Skywalker',
+ name: "Luke Skywalker"
},
{
- name: 'Han Solo',
+ name: "Han Solo"
},
{
- name: 'C-3PO',
+ name: "C-3PO"
},
{
- name: 'R2-D2',
- },
+ name: "R2-D2"
+ }
]
- },
+ }
]
}
};
@@ -147,8 +147,8 @@ describe('Star Wars Query Tests', () => {
});
});
- describe('Using IDs and query parameters to refetch objects', () => {
- it('Allows us to query for Luke Skywalker directly, using his ID', async () => {
+ describe("Using IDs and query parameters to refetch objects", () => {
+ it("Allows us to query for Luke Skywalker directly, using his ID", async () => {
const query = `
query FetchLukeQuery {
human(id: "1000") {
@@ -158,14 +158,14 @@ describe('Star Wars Query Tests', () => {
`;
const expected = {
human: {
- name: 'Luke Skywalker'
+ name: "Luke Skywalker"
}
};
const result = await graphql(StarWarsSchema, query);
expect(result).to.deep.equal({ data: expected });
});
- it('Allows us to create a generic query, then use it to fetch Luke Skywalker using his ID', async () => {
+ it("Allows us to create a generic query, then use it to fetch Luke Skywalker using his ID", async () => {
const query = `
query FetchSomeIDQuery($someId: String!) {
human(id: $someId) {
@@ -174,18 +174,18 @@ describe('Star Wars Query Tests', () => {
}
`;
const params = {
- someId: '1000'
+ someId: "1000"
};
const expected = {
human: {
- name: 'Luke Skywalker'
+ name: "Luke Skywalker"
}
};
const result = await graphql(StarWarsSchema, query, null, null, params);
expect(result).to.deep.equal({ data: expected });
});
- it('Allows us to create a generic query, then use it to fetch Han Solo using his ID', async () => {
+ it("Allows us to create a generic query, then use it to fetch Han Solo using his ID", async () => {
const query = `
query FetchSomeIDQuery($someId: String!) {
human(id: $someId) {
@@ -194,18 +194,18 @@ describe('Star Wars Query Tests', () => {
}
`;
const params = {
- someId: '1002'
+ someId: "1002"
};
const expected = {
human: {
- name: 'Han Solo'
+ name: "Han Solo"
}
};
const result = await graphql(StarWarsSchema, query, null, null, params);
expect(result).to.deep.equal({ data: expected });
});
- it('Allows us to create a generic query, then pass an invalid ID to get null back', async () => {
+ it("Allows us to create a generic query, then pass an invalid ID to get null back", async () => {
const query = `
query humanQuery($id: String!) {
human(id: $id) {
@@ -214,7 +214,7 @@ describe('Star Wars Query Tests', () => {
}
`;
const params = {
- id: 'not a valid id'
+ id: "not a valid id"
};
const expected = {
human: null
@@ -224,8 +224,8 @@ describe('Star Wars Query Tests', () => {
});
});
- describe('Using aliases to change the key in the response', () => {
- it('Allows us to query for Luke, changing his key with an alias', async () => {
+ describe("Using aliases to change the key in the response", () => {
+ it("Allows us to query for Luke, changing his key with an alias", async () => {
const query = `
query FetchLukeAliased {
luke: human(id: "1000") {
@@ -235,14 +235,14 @@ describe('Star Wars Query Tests', () => {
`;
const expected = {
luke: {
- name: 'Luke Skywalker'
- },
+ name: "Luke Skywalker"
+ }
};
const result = await graphql(StarWarsSchema, query);
expect(result).to.deep.equal({ data: expected });
});
- it('Allows us to query for both Luke and Leia, using two root fields and an alias', async () => {
+ it("Allows us to query for both Luke and Leia, using two root fields and an alias", async () => {
const query = `
query FetchLukeAndLeiaAliased {
luke: human(id: "1000") {
@@ -255,10 +255,10 @@ describe('Star Wars Query Tests', () => {
`;
const expected = {
luke: {
- name: 'Luke Skywalker'
+ name: "Luke Skywalker"
},
leia: {
- name: 'Leia Organa'
+ name: "Leia Organa"
}
};
const result = await graphql(StarWarsSchema, query);
@@ -266,8 +266,8 @@ describe('Star Wars Query Tests', () => {
});
});
- describe('Uses fragments to express more complex queries', () => {
- it('Allows us to query using duplicated content', async () => {
+ describe("Uses fragments to express more complex queries", () => {
+ it("Allows us to query using duplicated content", async () => {
const query = `
query DuplicateFields {
luke: human(id: "1000") {
@@ -282,19 +282,19 @@ describe('Star Wars Query Tests', () => {
`;
const expected = {
luke: {
- name: 'Luke Skywalker',
- homePlanet: 'Tatooine'
+ name: "Luke Skywalker",
+ homePlanet: "Tatooine"
},
leia: {
- name: 'Leia Organa',
- homePlanet: 'Alderaan'
+ name: "Leia Organa",
+ homePlanet: "Alderaan"
}
};
const result = await graphql(StarWarsSchema, query);
expect(result).to.deep.equal({ data: expected });
});
- it('Allows us to use a fragment to avoid duplicating content', async () => {
+ it("Allows us to use a fragment to avoid duplicating content", async () => {
const query = `
query UseFragment {
luke: human(id: "1000") {
@@ -312,12 +312,12 @@ describe('Star Wars Query Tests', () => {
`;
const expected = {
luke: {
- name: 'Luke Skywalker',
- homePlanet: 'Tatooine'
+ name: "Luke Skywalker",
+ homePlanet: "Tatooine"
},
leia: {
- name: 'Leia Organa',
- homePlanet: 'Alderaan'
+ name: "Leia Organa",
+ homePlanet: "Alderaan"
}
};
const result = await graphql(StarWarsSchema, query);
@@ -325,8 +325,8 @@ describe('Star Wars Query Tests', () => {
});
});
- describe('Using __typename to find the type of an object', () => {
- it('Allows us to verify that R2-D2 is a droid', async () => {
+ describe("Using __typename to find the type of an object", () => {
+ it("Allows us to verify that R2-D2 is a droid", async () => {
const query = `
query CheckTypeOfR2 {
hero {
@@ -337,15 +337,15 @@ describe('Star Wars Query Tests', () => {
`;
const expected = {
hero: {
- __typename: 'Droid',
- name: 'R2-D2'
- },
+ __typename: "Droid",
+ name: "R2-D2"
+ }
};
const result = await graphql(StarWarsSchema, query);
expect(result).to.deep.equal({ data: expected });
});
- it('Allows us to verify that Luke is a human', async () => {
+ it("Allows us to verify that Luke is a human", async () => {
const query = `
query CheckTypeOfLuke {
hero(episode: EMPIRE) {
@@ -356,9 +356,9 @@ describe('Star Wars Query Tests', () => {
`;
const expected = {
hero: {
- __typename: 'Human',
- name: 'Luke Skywalker'
- },
+ __typename: "Human",
+ name: "Luke Skywalker"
+ }
};
const result = await graphql(StarWarsSchema, query);
expect(result).to.deep.equal({ data: expected });
diff --git a/src/__tests__/starWarsSchema.js b/src/__tests__/starWarsSchema.js
index e315986a66..b47273cd73 100644
--- a/src/__tests__/starWarsSchema.js
+++ b/src/__tests__/starWarsSchema.js
@@ -14,10 +14,10 @@ import {
GraphQLList,
GraphQLNonNull,
GraphQLSchema,
- GraphQLString,
-} from '../type';
+ GraphQLString
+} from "../type";
-import { getFriends, getHero, getHuman, getDroid } from './starWarsData.js';
+import { getFriends, getHero, getHuman, getDroid } from "./starWarsData.js";
/**
* This is designed to be an end-to-end test, demonstrating
@@ -75,21 +75,21 @@ import { getFriends, getHero, getHuman, getDroid } from './starWarsData.js';
* enum Episode { NEWHOPE, EMPIRE, JEDI }
*/
const episodeEnum = new GraphQLEnumType({
- name: 'Episode',
- description: 'One of the films in the Star Wars Trilogy',
+ name: "Episode",
+ description: "One of the films in the Star Wars Trilogy",
values: {
NEWHOPE: {
value: 4,
- description: 'Released in 1977.',
+ description: "Released in 1977."
},
EMPIRE: {
value: 5,
- description: 'Released in 1980.',
+ description: "Released in 1980."
},
JEDI: {
value: 6,
- description: 'Released in 1983.',
- },
+ description: "Released in 1983."
+ }
}
});
@@ -105,26 +105,26 @@ const episodeEnum = new GraphQLEnumType({
* }
*/
const characterInterface = new GraphQLInterfaceType({
- name: 'Character',
- description: 'A character in the Star Wars Trilogy',
+ name: "Character",
+ description: "A character in the Star Wars Trilogy",
fields: () => ({
id: {
type: new GraphQLNonNull(GraphQLString),
- description: 'The id of the character.',
+ description: "The id of the character."
},
name: {
type: GraphQLString,
- description: 'The name of the character.',
+ description: "The name of the character."
},
friends: {
type: new GraphQLList(characterInterface),
- description: 'The friends of the character, or an empty list if they ' +
- 'have none.',
+ description:
+ "The friends of the character, or an empty list if they " + "have none."
},
appearsIn: {
type: new GraphQLList(episodeEnum),
- description: 'Which movies they appear in.',
- },
+ description: "Which movies they appear in."
+ }
}),
resolveType: character => {
return getHuman(character.id) ? humanType : droidType;
@@ -143,33 +143,33 @@ const characterInterface = new GraphQLInterfaceType({
* }
*/
const humanType = new GraphQLObjectType({
- name: 'Human',
- description: 'A humanoid creature in the Star Wars universe.',
+ name: "Human",
+ description: "A humanoid creature in the Star Wars universe.",
fields: () => ({
id: {
type: new GraphQLNonNull(GraphQLString),
- description: 'The id of the human.',
+ description: "The id of the human."
},
name: {
type: GraphQLString,
- description: 'The name of the human.',
+ description: "The name of the human."
},
friends: {
type: new GraphQLList(characterInterface),
- description: 'The friends of the human, or an empty list if they ' +
- 'have none.',
- resolve: human => getFriends(human),
+ description:
+ "The friends of the human, or an empty list if they " + "have none.",
+ resolve: human => getFriends(human)
},
appearsIn: {
type: new GraphQLList(episodeEnum),
- description: 'Which movies they appear in.',
+ description: "Which movies they appear in."
},
homePlanet: {
type: GraphQLString,
- description: 'The home planet of the human, or null if unknown.',
- },
+ description: "The home planet of the human, or null if unknown."
+ }
}),
- interfaces: [ characterInterface ]
+ interfaces: [characterInterface]
});
/**
@@ -185,33 +185,33 @@ const humanType = new GraphQLObjectType({
* }
*/
const droidType = new GraphQLObjectType({
- name: 'Droid',
- description: 'A mechanical creature in the Star Wars universe.',
+ name: "Droid",
+ description: "A mechanical creature in the Star Wars universe.",
fields: () => ({
id: {
type: new GraphQLNonNull(GraphQLString),
- description: 'The id of the droid.',
+ description: "The id of the droid."
},
name: {
type: GraphQLString,
- description: 'The name of the droid.',
+ description: "The name of the droid."
},
friends: {
type: new GraphQLList(characterInterface),
- description: 'The friends of the droid, or an empty list if they ' +
- 'have none.',
- resolve: droid => getFriends(droid),
+ description:
+ "The friends of the droid, or an empty list if they " + "have none.",
+ resolve: droid => getFriends(droid)
},
appearsIn: {
type: new GraphQLList(episodeEnum),
- description: 'Which movies they appear in.',
+ description: "Which movies they appear in."
},
primaryFunction: {
type: GraphQLString,
- description: 'The primary function of the droid.',
- },
+ description: "The primary function of the droid."
+ }
}),
- interfaces: [ characterInterface ]
+ interfaces: [characterInterface]
});
/**
@@ -229,39 +229,40 @@ const droidType = new GraphQLObjectType({
*
*/
const queryType = new GraphQLObjectType({
- name: 'Query',
+ name: "Query",
fields: () => ({
hero: {
type: characterInterface,
args: {
episode: {
- description: 'If omitted, returns the hero of the whole saga. If ' +
- 'provided, returns the hero of that particular episode.',
+ description:
+ "If omitted, returns the hero of the whole saga. If " +
+ "provided, returns the hero of that particular episode.",
type: episodeEnum
}
},
- resolve: (root, { episode }) => getHero(episode),
+ resolve: (root, { episode }) => getHero(episode)
},
human: {
type: humanType,
args: {
id: {
- description: 'id of the human',
+ description: "id of the human",
type: new GraphQLNonNull(GraphQLString)
}
},
- resolve: (root, { id }) => getHuman(id),
+ resolve: (root, { id }) => getHuman(id)
},
droid: {
type: droidType,
args: {
id: {
- description: 'id of the droid',
+ description: "id of the droid",
type: new GraphQLNonNull(GraphQLString)
}
},
- resolve: (root, { id }) => getDroid(id),
- },
+ resolve: (root, { id }) => getDroid(id)
+ }
})
});
@@ -271,5 +272,5 @@ const queryType = new GraphQLObjectType({
*/
export const StarWarsSchema = new GraphQLSchema({
query: queryType,
- types: [ humanType, droidType ]
+ types: [humanType, droidType]
});
diff --git a/src/__tests__/starWarsValidation-test.js b/src/__tests__/starWarsValidation-test.js
index 45f3eddb98..14441172c4 100644
--- a/src/__tests__/starWarsValidation-test.js
+++ b/src/__tests__/starWarsValidation-test.js
@@ -7,26 +7,25 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
-import { expect } from 'chai';
-import { describe, it } from 'mocha';
-import { StarWarsSchema } from './starWarsSchema.js';
-import { Source } from '../language/source';
-import { parse } from '../language/parser';
-import { validate } from '../validation/validate';
-
+import { expect } from "chai";
+import { describe, it } from "mocha";
+import { StarWarsSchema } from "./starWarsSchema.js";
+import { Source } from "../language/source";
+import { parse } from "../language/parser";
+import { validate } from "../validation/validate";
/**
* Helper function to test a query and the expected response.
*/
function validationErrors(query) {
- const source = new Source(query, 'StarWars.graphql');
+ const source = new Source(query, "StarWars.graphql");
const ast = parse(source);
return validate(StarWarsSchema, ast);
}
-describe('Star Wars Validation Tests', () => {
- describe('Basic Queries', () => {
- it('Validates a complex but valid query', () => {
+describe("Star Wars Validation Tests", () => {
+ describe("Basic Queries", () => {
+ it("Validates a complex but valid query", () => {
const query = `
query NestedQueryWithFragment {
hero {
@@ -48,7 +47,7 @@ describe('Star Wars Validation Tests', () => {
return expect(validationErrors(query)).to.be.empty;
});
- it('Notes that non-existent fields are invalid', () => {
+ it("Notes that non-existent fields are invalid", () => {
const query = `
query HeroSpaceshipQuery {
hero {
@@ -59,7 +58,7 @@ describe('Star Wars Validation Tests', () => {
return expect(validationErrors(query)).to.not.be.empty;
});
- it('Requires fields on objects', () => {
+ it("Requires fields on objects", () => {
const query = `
query HeroNoFieldsQuery {
hero
@@ -68,7 +67,7 @@ describe('Star Wars Validation Tests', () => {
return expect(validationErrors(query)).to.not.be.empty;
});
- it('Disallows fields on scalars', () => {
+ it("Disallows fields on scalars", () => {
const query = `
query HeroFieldsOnScalarQuery {
hero {
@@ -81,7 +80,7 @@ describe('Star Wars Validation Tests', () => {
return expect(validationErrors(query)).to.not.be.empty;
});
- it('Disallows object fields on interfaces', () => {
+ it("Disallows object fields on interfaces", () => {
const query = `
query DroidFieldOnCharacter {
hero {
@@ -93,7 +92,7 @@ describe('Star Wars Validation Tests', () => {
return expect(validationErrors(query)).to.not.be.empty;
});
- it('Allows object fields in fragments', () => {
+ it("Allows object fields in fragments", () => {
const query = `
query DroidFieldInFragment {
hero {
@@ -109,7 +108,7 @@ describe('Star Wars Validation Tests', () => {
return expect(validationErrors(query)).to.be.empty;
});
- it('Allows object fields in inline fragments', () => {
+ it("Allows object fields in inline fragments", () => {
const query = `
query DroidFieldInFragment {
hero {
diff --git a/src/error/GraphQLError.js b/src/error/GraphQLError.js
index 08fc5b883d..a1bde98e82 100644
--- a/src/error/GraphQLError.js
+++ b/src/error/GraphQLError.js
@@ -8,10 +8,9 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
-import { getLocation } from '../language';
-import type { Node } from '../language/ast';
-import type { Source } from '../language/source';
-
+import { getLocation } from "../language";
+import type { Node } from "../language/ast";
+import type { Source } from "../language/source";
export class GraphQLError extends Error {
message: string;
@@ -25,7 +24,7 @@ export class GraphQLError extends Error {
constructor(
message: string,
// A flow bug keeps us from declaring nodes as an array of Node
- nodes?: Array,
+ nodes?: Array,
stack?: ?string,
source?: Source,
positions?: Array
@@ -33,42 +32,54 @@ export class GraphQLError extends Error {
super(message);
this.message = message;
- Object.defineProperty(this, 'stack', { value: stack || message });
- Object.defineProperty(this, 'nodes', { value: nodes });
+ Object.defineProperty(this, "stack", { value: stack || message });
+ Object.defineProperty(this, "nodes", { value: nodes });
// Note: flow does not yet know about Object.defineProperty with `get`.
- Object.defineProperty(this, 'source', ({
- get() {
- if (source) {
- return source;
- }
- if (nodes && nodes.length > 0) {
- const node = nodes[0];
- return node && node.loc && node.loc.source;
+ Object.defineProperty(
+ this,
+ "source",
+ ({
+ get() {
+ if (source) {
+ return source;
+ }
+ if (nodes && nodes.length > 0) {
+ const node = nodes[0];
+ return node && node.loc && node.loc.source;
+ }
}
- }
- }: any));
+ }: any)
+ );
- Object.defineProperty(this, 'positions', ({
- get() {
- if (positions) {
- return positions;
- }
- if (nodes) {
- const nodePositions = nodes.map(node => node.loc && node.loc.start);
- if (nodePositions.some(p => p)) {
- return nodePositions;
+ Object.defineProperty(
+ this,
+ "positions",
+ ({
+ get() {
+ if (positions) {
+ return positions;
+ }
+ if (nodes) {
+ const nodePositions = nodes.map(node => node.loc && node.loc.start);
+ if (nodePositions.some(p => p)) {
+ return nodePositions;
+ }
}
}
- }
- }: any));
+ }: any)
+ );
- Object.defineProperty(this, 'locations', ({
- get() {
- if (this.positions && this.source) {
- return this.positions.map(pos => getLocation(this.source, pos));
+ Object.defineProperty(
+ this,
+ "locations",
+ ({
+ get() {
+ if (this.positions && this.source) {
+ return this.positions.map(pos => getLocation(this.source, pos));
+ }
}
- }
- }: any));
+ }: any)
+ );
}
}
diff --git a/src/error/README.md b/src/error/README.md
index 9f4460676d..3898d77780 100644
--- a/src/error/README.md
+++ b/src/error/README.md
@@ -1,5 +1,4 @@
-GraphQL Errors
---------------
+## GraphQL Errors
The `graphql/error` module is responsible for creating and formating
GraphQL errors.
diff --git a/src/error/formatError.js b/src/error/formatError.js
index 320afcf60f..9e7354e4e7 100644
--- a/src/error/formatError.js
+++ b/src/error/formatError.js
@@ -8,16 +8,15 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
-import invariant from '../jsutils/invariant';
-import type { GraphQLError } from './GraphQLError';
-
+import invariant from "../jsutils/invariant";
+import type { GraphQLError } from "./GraphQLError";
/**
* Given a GraphQLError, format it according to the rules described by the
* Response Format, Errors section of the GraphQL Specification.
*/
export function formatError(error: GraphQLError): GraphQLFormattedError {
- invariant(error, 'Received null or undefined error.');
+ invariant(error, "Received null or undefined error.");
return {
message: error.message,
locations: error.locations
diff --git a/src/error/index.js b/src/error/index.js
index 3419e8ea3e..3270d57de0 100644
--- a/src/error/index.js
+++ b/src/error/index.js
@@ -8,7 +8,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
-export { GraphQLError } from './GraphQLError';
-export { syntaxError } from './syntaxError';
-export { locatedError } from './locatedError';
-export { formatError } from './formatError';
+export { GraphQLError } from "./GraphQLError";
+export { syntaxError } from "./syntaxError";
+export { locatedError } from "./locatedError";
+export { formatError } from "./formatError";
diff --git a/src/error/locatedError.js b/src/error/locatedError.js
index 6bab9071ac..da7af10011 100644
--- a/src/error/locatedError.js
+++ b/src/error/locatedError.js
@@ -8,8 +8,7 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
-import { GraphQLError } from './GraphQLError';
-
+import { GraphQLError } from "./GraphQLError";
/**
* Given an arbitrary Error, presumably thrown while attempting to execute a
@@ -20,9 +19,9 @@ export function locatedError(
originalError: ?Error,
nodes: Array
): GraphQLError {
- const message = originalError ?
- originalError.message || String(originalError) :
- 'An unknown error occurred.';
+ const message = originalError
+ ? originalError.message || String(originalError)
+ : "An unknown error occurred.";
const stack = originalError ? originalError.stack : null;
const error = new GraphQLError(message, nodes, stack);
error.originalError = originalError;
diff --git a/src/error/syntaxError.js b/src/error/syntaxError.js
index bfa129b8f1..79f661b924 100644
--- a/src/error/syntaxError.js
+++ b/src/error/syntaxError.js
@@ -8,9 +8,9 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
-import { getLocation } from '../language/location';
-import type { Source } from '../language/source';
-import { GraphQLError } from './GraphQLError';
+import { getLocation } from "../language/location";
+import type { Source } from "../language/source";
+import { GraphQLError } from "./GraphQLError";
/**
* Produces a GraphQLError representing a syntax error, containing useful
@@ -24,11 +24,13 @@ export function syntaxError(
const location = getLocation(source, position);
const error = new GraphQLError(
`Syntax Error ${source.name} (${location.line}:${location.column}) ` +
- description + '\n\n' + highlightSourceAtLocation(source, location),
+ description +
+ "\n\n" +
+ highlightSourceAtLocation(source, location),
undefined,
undefined,
source,
- [ position ]
+ [position]
);
return error;
}
@@ -45,15 +47,21 @@ function highlightSourceAtLocation(source, location) {
const padLen = nextLineNum.length;
const lines = source.body.split(/\r\n|[\n\r]/g);
return (
- (line >= 2 ?
- lpad(padLen, prevLineNum) + ': ' + lines[line - 2] + '\n' : '') +
- lpad(padLen, lineNum) + ': ' + lines[line - 1] + '\n' +
- Array(2 + padLen + location.column).join(' ') + '^\n' +
- (line < lines.length ?
- lpad(padLen, nextLineNum) + ': ' + lines[line] + '\n' : '')
+ (line >= 2
+ ? lpad(padLen, prevLineNum) + ": " + lines[line - 2] + "\n"
+ : "") +
+ lpad(padLen, lineNum) +
+ ": " +
+ lines[line - 1] +
+ "\n" +
+ Array(2 + padLen + location.column).join(" ") +
+ "^\n" +
+ (line < lines.length
+ ? lpad(padLen, nextLineNum) + ": " + lines[line] + "\n"
+ : "")
);
}
function lpad(len, str) {
- return Array(len - str.length + 1).join(' ') + str;
+ return Array(len - str.length + 1).join(" ") + str;
}
diff --git a/src/execution/README.md b/src/execution/README.md
index 7b875646ee..55ed0cb5e6 100644
--- a/src/execution/README.md
+++ b/src/execution/README.md
@@ -1,10 +1,9 @@
-GraphQL Execution
------------------
+## GraphQL Execution
The `graphql/execution` module is responsible for the execution phase of
fulfilling a GraphQL request.
```js
-import { execute } from 'graphql/execution'; // ES6
-var GraphQLExecution = require('graphql/execution'); // CommonJS
+import { execute } from "graphql/execution"; // ES6
+var GraphQLExecution = require("graphql/execution"); // CommonJS
```
diff --git a/src/execution/__tests__/abstract-test.js b/src/execution/__tests__/abstract-test.js
index e839a580f2..0d07e5700d 100644
--- a/src/execution/__tests__/abstract-test.js
+++ b/src/execution/__tests__/abstract-test.js
@@ -7,8 +7,8 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
-import { expect } from 'chai';
-import { describe, it } from 'mocha';
+import { expect } from "chai";
+import { describe, it } from "mocha";
import {
graphql,
GraphQLSchema,
@@ -17,9 +17,8 @@ import {
GraphQLUnionType,
GraphQLList,
GraphQLString,
- GraphQLBoolean,
-} from '../../';
-
+ GraphQLBoolean
+} from "../../";
class Dog {
constructor(name, woofs) {
@@ -41,49 +40,48 @@ class Human {
}
}
-describe('Execute: Handles execution of abstract types', () => {
-
- it('isTypeOf used to resolve runtime type for Interface', async () => {
+describe("Execute: Handles execution of abstract types", () => {
+ it("isTypeOf used to resolve runtime type for Interface", async () => {
const PetType = new GraphQLInterfaceType({
- name: 'Pet',
+ name: "Pet",
fields: {
name: { type: GraphQLString }
}
});
const DogType = new GraphQLObjectType({
- name: 'Dog',
- interfaces: [ PetType ],
+ name: "Dog",
+ interfaces: [PetType],
isTypeOf: obj => obj instanceof Dog,
fields: {
name: { type: GraphQLString },
- woofs: { type: GraphQLBoolean },
+ woofs: { type: GraphQLBoolean }
}
});
const CatType = new GraphQLObjectType({
- name: 'Cat',
- interfaces: [ PetType ],
+ name: "Cat",
+ interfaces: [PetType],
isTypeOf: obj => obj instanceof Cat,
fields: {
name: { type: GraphQLString },
- meows: { type: GraphQLBoolean },
+ meows: { type: GraphQLBoolean }
}
});
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
- name: 'Query',
+ name: "Query",
fields: {
pets: {
type: new GraphQLList(PetType),
resolve() {
- return [ new Dog('Odie', true), new Cat('Garfield', false) ];
+ return [new Dog("Odie", true), new Cat("Garfield", false)];
}
}
}
}),
- types: [ CatType, DogType ]
+ types: [CatType, DogType]
});
const query = `{
@@ -103,45 +101,51 @@ describe('Execute: Handles execution of abstract types', () => {
expect(result).to.deep.equal({
data: {
pets: [
- { name: 'Odie',
- woofs: true },
- { name: 'Garfield',
- meows: false } ] }
+ {
+ name: "Odie",
+ woofs: true
+ },
+ {
+ name: "Garfield",
+ meows: false
+ }
+ ]
+ }
});
});
- it('isTypeOf used to resolve runtime type for Union', async () => {
+ it("isTypeOf used to resolve runtime type for Union", async () => {
const DogType = new GraphQLObjectType({
- name: 'Dog',
+ name: "Dog",
isTypeOf: obj => obj instanceof Dog,
fields: {
name: { type: GraphQLString },
- woofs: { type: GraphQLBoolean },
+ woofs: { type: GraphQLBoolean }
}
});
const CatType = new GraphQLObjectType({
- name: 'Cat',
+ name: "Cat",
isTypeOf: obj => obj instanceof Cat,
fields: {
name: { type: GraphQLString },
- meows: { type: GraphQLBoolean },
+ meows: { type: GraphQLBoolean }
}
});
const PetType = new GraphQLUnionType({
- name: 'Pet',
- types: [ DogType, CatType ]
+ name: "Pet",
+ types: [DogType, CatType]
});
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
- name: 'Query',
+ name: "Query",
fields: {
pets: {
type: new GraphQLList(PetType),
resolve() {
- return [ new Dog('Odie', true), new Cat('Garfield', false) ];
+ return [new Dog("Odie", true), new Cat("Garfield", false)];
}
}
}
@@ -166,21 +170,28 @@ describe('Execute: Handles execution of abstract types', () => {
expect(result).to.deep.equal({
data: {
pets: [
- { name: 'Odie',
- woofs: true },
- { name: 'Garfield',
- meows: false } ] }
+ {
+ name: "Odie",
+ woofs: true
+ },
+ {
+ name: "Garfield",
+ meows: false
+ }
+ ]
+ }
});
});
- it('resolveType on Interface yields useful error', async () => {
+ it("resolveType on Interface yields useful error", async () => {
const PetType = new GraphQLInterfaceType({
- name: 'Pet',
+ name: "Pet",
resolveType(obj) {
- return obj instanceof Dog ? DogType :
- obj instanceof Cat ? CatType :
- obj instanceof Human ? HumanType :
- null;
+ return obj instanceof Dog
+ ? DogType
+ : obj instanceof Cat
+ ? CatType
+ : obj instanceof Human ? HumanType : null;
},
fields: {
name: { type: GraphQLString }
@@ -188,47 +199,47 @@ describe('Execute: Handles execution of abstract types', () => {
});
const HumanType = new GraphQLObjectType({
- name: 'Human',
+ name: "Human",
fields: {
- name: { type: GraphQLString },
+ name: { type: GraphQLString }
}
});
const DogType = new GraphQLObjectType({
- name: 'Dog',
- interfaces: [ PetType ],
+ name: "Dog",
+ interfaces: [PetType],
fields: {
name: { type: GraphQLString },
- woofs: { type: GraphQLBoolean },
+ woofs: { type: GraphQLBoolean }
}
});
const CatType = new GraphQLObjectType({
- name: 'Cat',
- interfaces: [ PetType ],
+ name: "Cat",
+ interfaces: [PetType],
fields: {
name: { type: GraphQLString },
- meows: { type: GraphQLBoolean },
+ meows: { type: GraphQLBoolean }
}
});
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
- name: 'Query',
+ name: "Query",
fields: {
pets: {
type: new GraphQLList(PetType),
resolve() {
return [
- new Dog('Odie', true),
- new Cat('Garfield', false),
- new Human('Jon')
+ new Dog("Odie", true),
+ new Cat("Garfield", false),
+ new Human("Jon")
];
}
}
}
}),
- types: [ CatType, DogType ]
+ types: [CatType, DogType]
});
const query = `{
@@ -248,10 +259,14 @@ describe('Execute: Handles execution of abstract types', () => {
expect(result).to.deep.equal({
data: {
pets: [
- { name: 'Odie',
- woofs: true },
- { name: 'Garfield',
- meows: false },
+ {
+ name: "Odie",
+ woofs: true
+ },
+ {
+ name: "Garfield",
+ meows: false
+ },
null
]
},
@@ -263,53 +278,53 @@ describe('Execute: Handles execution of abstract types', () => {
});
});
- it('resolveType on Union yields useful error', async () => {
+ it("resolveType on Union yields useful error", async () => {
const HumanType = new GraphQLObjectType({
- name: 'Human',
+ name: "Human",
fields: {
- name: { type: GraphQLString },
+ name: { type: GraphQLString }
}
});
const DogType = new GraphQLObjectType({
- name: 'Dog',
+ name: "Dog",
fields: {
name: { type: GraphQLString },
- woofs: { type: GraphQLBoolean },
+ woofs: { type: GraphQLBoolean }
}
});
const CatType = new GraphQLObjectType({
- name: 'Cat',
+ name: "Cat",
fields: {
name: { type: GraphQLString },
- meows: { type: GraphQLBoolean },
+ meows: { type: GraphQLBoolean }
}
});
const PetType = new GraphQLUnionType({
- name: 'Pet',
+ name: "Pet",
resolveType(obj) {
- return obj instanceof Dog ? DogType :
- obj instanceof Cat ? CatType :
- obj instanceof Human ? HumanType :
- null;
+ return obj instanceof Dog
+ ? DogType
+ : obj instanceof Cat
+ ? CatType
+ : obj instanceof Human ? HumanType : null;
},
- types: [ DogType, CatType ]
+ types: [DogType, CatType]
});
-
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
- name: 'Query',
+ name: "Query",
fields: {
pets: {
type: new GraphQLList(PetType),
resolve() {
return [
- new Dog('Odie', true),
- new Cat('Garfield', false),
- new Human('Jon')
+ new Dog("Odie", true),
+ new Cat("Garfield", false),
+ new Human("Jon")
];
}
}
@@ -335,10 +350,14 @@ describe('Execute: Handles execution of abstract types', () => {
expect(result).to.deep.equal({
data: {
pets: [
- { name: 'Odie',
- woofs: true },
- { name: 'Garfield',
- meows: false },
+ {
+ name: "Odie",
+ woofs: true
+ },
+ {
+ name: "Garfield",
+ meows: false
+ },
null
]
},
@@ -349,5 +368,4 @@ describe('Execute: Handles execution of abstract types', () => {
]
});
});
-
});
diff --git a/src/execution/__tests__/directives-test.js b/src/execution/__tests__/directives-test.js
index 814147c858..72b5c547bc 100644
--- a/src/execution/__tests__/directives-test.js
+++ b/src/execution/__tests__/directives-test.js
@@ -7,83 +7,80 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
-import { expect } from 'chai';
-import { execute } from '../execute';
-import { describe, it } from 'mocha';
-import { parse } from '../../language';
-import {
- GraphQLSchema,
- GraphQLObjectType,
- GraphQLString,
-} from '../../type';
-
+import { expect } from "chai";
+import { execute } from "../execute";
+import { describe, it } from "mocha";
+import { parse } from "../../language";
+import { GraphQLSchema, GraphQLObjectType, GraphQLString } from "../../type";
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
- name: 'TestType',
+ name: "TestType",
fields: {
a: { type: GraphQLString },
- b: { type: GraphQLString },
+ b: { type: GraphQLString }
}
- }),
+ })
});
const data = {
- a() { return 'a'; },
- b() { return 'b'; }
+ a() {
+ return "a";
+ },
+ b() {
+ return "b";
+ }
};
async function executeTestQuery(doc) {
return await execute(schema, parse(doc), data);
}
-describe('Execute: handles directives', () => {
- describe('works without directives', () => {
- it('basic query works', async () => {
- expect(
- await executeTestQuery('{ a, b }')
- ).to.deep.equal({
- data: { a: 'a', b: 'b' }
+describe("Execute: handles directives", () => {
+ describe("works without directives", () => {
+ it("basic query works", async () => {
+ expect(await executeTestQuery("{ a, b }")).to.deep.equal({
+ data: { a: "a", b: "b" }
});
});
});
- describe('works on scalars', () => {
- it('if true includes scalar', async () => {
+ describe("works on scalars", () => {
+ it("if true includes scalar", async () => {
return expect(
- await executeTestQuery('{ a, b @include(if: true) }')
+ await executeTestQuery("{ a, b @include(if: true) }")
).to.deep.equal({
- data: { a: 'a', b: 'b' }
+ data: { a: "a", b: "b" }
});
});
- it('if false omits on scalar', async () => {
+ it("if false omits on scalar", async () => {
return expect(
- await executeTestQuery('{ a, b @include(if: false) }')
+ await executeTestQuery("{ a, b @include(if: false) }")
).to.deep.equal({
- data: { a: 'a' }
+ data: { a: "a" }
});
});
- it('unless false includes scalar', async () => {
+ it("unless false includes scalar", async () => {
return expect(
- await executeTestQuery('{ a, b @skip(if: false) }')
+ await executeTestQuery("{ a, b @skip(if: false) }")
).to.deep.equal({
- data: { a: 'a', b: 'b' }
+ data: { a: "a", b: "b" }
});
});
- it('unless true omits scalar', async () => {
+ it("unless true omits scalar", async () => {
return expect(
- await executeTestQuery('{ a, b @skip(if: true) }')
+ await executeTestQuery("{ a, b @skip(if: true) }")
).to.deep.equal({
- data: { a: 'a' }
+ data: { a: "a" }
});
});
});
- describe('works on fragment spreads', () => {
- it('if false omits fragment spread', async () => {
+ describe("works on fragment spreads", () => {
+ it("if false omits fragment spread", async () => {
const q = `
query Q {
a
@@ -94,11 +91,11 @@ describe('Execute: handles directives', () => {
}
`;
return expect(await executeTestQuery(q)).to.deep.equal({
- data: { a: 'a' }
+ data: { a: "a" }
});
});
- it('if true includes fragment spread', async () => {
+ it("if true includes fragment spread", async () => {
const q = `
query Q {
a
@@ -109,11 +106,11 @@ describe('Execute: handles directives', () => {
}
`;
return expect(await executeTestQuery(q)).to.deep.equal({
- data: { a: 'a', b: 'b' }
+ data: { a: "a", b: "b" }
});
});
- it('unless false includes fragment spread', async () => {
+ it("unless false includes fragment spread", async () => {
const q = `
query Q {
a
@@ -124,11 +121,11 @@ describe('Execute: handles directives', () => {
}
`;
return expect(await executeTestQuery(q)).to.deep.equal({
- data: { a: 'a', b: 'b' }
+ data: { a: "a", b: "b" }
});
});
- it('unless true omits fragment spread', async () => {
+ it("unless true omits fragment spread", async () => {
const q = `
query Q {
a
@@ -139,13 +136,13 @@ describe('Execute: handles directives', () => {
}
`;
return expect(await executeTestQuery(q)).to.deep.equal({
- data: { a: 'a' }
+ data: { a: "a" }
});
});
});
- describe('works on inline fragment', () => {
- it('if false omits inline fragment', async () => {
+ describe("works on inline fragment", () => {
+ it("if false omits inline fragment", async () => {
const q = `
query Q {
a
@@ -158,11 +155,11 @@ describe('Execute: handles directives', () => {
}
`;
return expect(await executeTestQuery(q)).to.deep.equal({
- data: { a: 'a' }
+ data: { a: "a" }
});
});
- it('if true includes inline fragment', async () => {
+ it("if true includes inline fragment", async () => {
const q = `
query Q {
a
@@ -175,10 +172,10 @@ describe('Execute: handles directives', () => {
}
`;
return expect(await executeTestQuery(q)).to.deep.equal({
- data: { a: 'a', b: 'b' }
+ data: { a: "a", b: "b" }
});
});
- it('unless false includes inline fragment', async () => {
+ it("unless false includes inline fragment", async () => {
const q = `
query Q {
a
@@ -191,10 +188,10 @@ describe('Execute: handles directives', () => {
}
`;
return expect(await executeTestQuery(q)).to.deep.equal({
- data: { a: 'a', b: 'b' }
+ data: { a: "a", b: "b" }
});
});
- it('unless true includes inline fragment', async () => {
+ it("unless true includes inline fragment", async () => {
const q = `
query Q {
a
@@ -207,13 +204,13 @@ describe('Execute: handles directives', () => {
}
`;
return expect(await executeTestQuery(q)).to.deep.equal({
- data: { a: 'a' }
+ data: { a: "a" }
});
});
});
- describe('works on anonymous inline fragment', () => {
- it('if false omits anonymous inline fragment', async () => {
+ describe("works on anonymous inline fragment", () => {
+ it("if false omits anonymous inline fragment", async () => {
const q = `
query Q {
a
@@ -223,11 +220,11 @@ describe('Execute: handles directives', () => {
}
`;
return expect(await executeTestQuery(q)).to.deep.equal({
- data: { a: 'a' }
+ data: { a: "a" }
});
});
- it('if true includes anonymous inline fragment', async () => {
+ it("if true includes anonymous inline fragment", async () => {
const q = `
query Q {
a
@@ -237,10 +234,10 @@ describe('Execute: handles directives', () => {
}
`;
return expect(await executeTestQuery(q)).to.deep.equal({
- data: { a: 'a', b: 'b' }
+ data: { a: "a", b: "b" }
});
});
- it('unless false includes anonymous inline fragment', async () => {
+ it("unless false includes anonymous inline fragment", async () => {
const q = `
query Q {
a
@@ -250,10 +247,10 @@ describe('Execute: handles directives', () => {
}
`;
return expect(await executeTestQuery(q)).to.deep.equal({
- data: { a: 'a', b: 'b' }
+ data: { a: "a", b: "b" }
});
});
- it('unless true includes anonymous inline fragment', async () => {
+ it("unless true includes anonymous inline fragment", async () => {
const q = `
query Q {
a
@@ -263,33 +260,33 @@ describe('Execute: handles directives', () => {
}
`;
return expect(await executeTestQuery(q)).to.deep.equal({
- data: { a: 'a' }
+ data: { a: "a" }
});
});
});
- describe('works with skip and include directives', () => {
- it('include and no skip', async () => {
+ describe("works with skip and include directives", () => {
+ it("include and no skip", async () => {
return expect(
- await executeTestQuery('{ a, b @include(if: true) @skip(if: false) }')
+ await executeTestQuery("{ a, b @include(if: true) @skip(if: false) }")
).to.deep.equal({
- data: { a: 'a', b: 'b' }
+ data: { a: "a", b: "b" }
});
});
- it('include and skip', async () => {
+ it("include and skip", async () => {
return expect(
- await executeTestQuery('{ a, b @include(if: true) @skip(if: true) }')
+ await executeTestQuery("{ a, b @include(if: true) @skip(if: true) }")
).to.deep.equal({
- data: { a: 'a' }
+ data: { a: "a" }
});
});
- it('no include or skip', async () => {
+ it("no include or skip", async () => {
return expect(
- await executeTestQuery('{ a, b @include(if: false) @skip(if: false) }')
+ await executeTestQuery("{ a, b @include(if: false) @skip(if: false) }")
).to.deep.equal({
- data: { a: 'a' }
+ data: { a: "a" }
});
});
});
diff --git a/src/execution/__tests__/executor-test.js b/src/execution/__tests__/executor-test.js
index e46d57ac0b..07df591dd9 100644
--- a/src/execution/__tests__/executor-test.js
+++ b/src/execution/__tests__/executor-test.js
@@ -7,41 +7,63 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/
-import { expect } from 'chai';
-import { describe, it } from 'mocha';
-import { execute } from '../execute';
-import { formatError } from '../../error';
-import { parse } from '../../language';
+import { expect } from "chai";
+import { describe, it } from "mocha";
+import { execute } from "../execute";
+import { formatError } from "../../error";
+import { parse } from "../../language";
import {
GraphQLSchema,
GraphQLObjectType,
GraphQLList,
GraphQLBoolean,
GraphQLInt,
- GraphQLString,
-} from '../../type';
+ GraphQLString
+} from "../../type";
-describe('Execute: Handles basic execution tasks', () => {
- it('executes arbitrary code', async () => {
+describe("Execute: Handles basic execution tasks", () => {
+ it("executes arbitrary code", async () => {
const data = {
- a() { return 'Apple'; },
- b() { return 'Banana'; },
- c() { return 'Cookie'; },
- d() { return 'Donut'; },
- e() { return 'Egg'; },
- f: 'Fish',
+ a() {
+ return "Apple";
+ },
+ b() {
+ return "Banana";
+ },
+ c() {
+ return "Cookie";
+ },
+ d() {
+ return "Donut";
+ },
+ e() {
+ return "Egg";
+ },
+ f: "Fish",
pic(size) {
- return 'Pic of size: ' + (size || 50);
+ return "Pic of size: " + (size || 50);
+ },
+ deep() {
+ return deepData;
},
- deep() { return deepData; },
- promise() { return promiseData(); }
+ promise() {
+ return promiseData();
+ }
};
const deepData = {
- a() { return 'Already Been Done'; },
- b() { return 'Boring'; },
- c() { return [ 'Contrived', undefined, 'Confusing' ]; },
- deeper() { return [ data, null, data ]; }
+ a() {
+ return "Already Been Done";
+ },
+ b() {
+ return "Boring";
+ },
+ c() {
+ return ["Contrived", undefined, "Confusing"];
+ },
+ deeper() {
+ return [data, null, data];
+ }
};
function promiseData() {
@@ -85,26 +107,29 @@ describe('Execute: Handles basic execution tasks', () => {
const ast = parse(doc);
const expected = {
data: {
- a: 'Apple',
- b: 'Banana',
- x: 'Cookie',
- d: 'Donut',
- e: 'Egg',
- f: 'Fish',
- pic: 'Pic of size: 100',
- promise: { a: 'Apple' },
+ a: "Apple",
+ b: "Banana",
+ x: "Cookie",
+ d: "Donut",
+ e: "Egg",
+ f: "Fish",
+ pic: "Pic of size: 100",
+ promise: { a: "Apple" },
deep: {
- a: 'Already Been Done',
- b: 'Boring',
- c: [ 'Contrived', null, 'Confusing' ],
+ a: "Already Been Done",
+ b: "Boring",
+ c: ["Contrived", null, "Confusing"],
deeper: [
- { a: 'Apple', b: 'Banana' },
+ { a: "Apple", b: "Banana" },
null,
- { a: 'Apple', b: 'Banana' } ] } }
+ { a: "Apple", b: "Banana" }
+ ]
+ }
+ }
};
const DataType = new GraphQLObjectType({
- name: 'DataType',
+ name: "DataType",
fields: () => ({
a: { type: GraphQLString },
b: { type: GraphQLString },
@@ -118,17 +143,17 @@ describe('Execute: Handles basic execution tasks', () => {
resolve: (obj, { size }) => obj.pic(size)
},
deep: { type: DeepDataType },
- promise: { type: DataType },
+ promise: { type: DataType }
})
});
const DeepDataType = new GraphQLObjectType({
- name: 'DeepDataType',
+ name: "DeepDataType",
fields: {
a: { type: GraphQLString },
b: { type: GraphQLString },
c: { type: new GraphQLList(GraphQLString) },
- deeper: { type: new GraphQLList(DataType) },
+ deeper: { type: new GraphQLList(DataType) }
}
});
@@ -137,11 +162,11 @@ describe('Execute: Handles basic execution tasks', () => {
});
expect(
- await execute(schema, ast, data, null, { size: 100 }, 'Example')
+ await execute(schema, ast, data, null, { size: 100 }, "Example")
).to.deep.equal(expected);
});
- it('merges parallel fragments', async () => {
+ it("merges parallel fragments", async () => {
const ast = parse(`
{ a, ...FragOne, ...FragTwo }
@@ -157,44 +182,45 @@ describe('Execute: Handles basic execution tasks', () => {
`);
const Type = new GraphQLObjectType({
- name: 'Type',
+ name: "Type",
fields: () => ({
- a: { type: GraphQLString, resolve: () => 'Apple' },
- b: { type: GraphQLString, resolve: () => 'Banana' },
- c: { type: GraphQLString, resolve: () => 'Cherry' },
- deep: { type: Type, resolve: () => ({}) },
+ a: { type: GraphQLString, resolve: () => "Apple" },
+ b: { type: GraphQLString, resolve: () => "Banana" },
+ c: { type: GraphQLString, resolve: () => "Cherry" },
+ deep: { type: Type, resolve: () => ({}) }
})
});
const schema = new GraphQLSchema({ query: Type });
- expect(
- await execute(schema, ast)
- ).to.deep.equal({
+ expect(await execute(schema, ast)).to.deep.equal({
data: {
- a: 'Apple',
- b: 'Banana',
- c: 'Cherry',
+ a: "Apple",
+ b: "Banana",
+ c: "Cherry",
deep: {
- b: 'Banana',
- c: 'Cherry',
+ b: "Banana",
+ c: "Cherry",
deeper: {
- b: 'Banana',
- c: 'Cherry' } } }
+ b: "Banana",
+ c: "Cherry"
+ }
+ }
+ }
});
});
- it('threads root value context correctly', async () => {
- const doc = 'query Example { a }';
+ it("threads root value context correctly", async () => {
+ const doc = "query Example { a }";
const data = {
- contextThing: 'thing',
+ contextThing: "thing"
};
let resolvedRootValue;
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
- name: 'Type',
+ name: "Type",
fields: {
a: {
type: GraphQLString,
@@ -208,10 +234,10 @@ describe('Execute: Handles basic execution tasks', () => {
await execute(schema, parse(doc), data);
- expect(resolvedRootValue.contextThing).to.equal('thing');
+ expect(resolvedRootValue.contextThing).to.equal("thing");
});
- it('correctly threads arguments', async () => {
+ it("correctly threads arguments", async () => {
const doc = `
query Example {
b(numArg: 123, stringArg: "foo")
@@ -222,7 +248,7 @@ describe('Execute: Handles basic execution tasks', () => {
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
- name: 'Type',
+ name: "Type",
fields: {
b: {
args: {
@@ -241,10 +267,10 @@ describe('Execute: Handles basic execution tasks', () => {
await execute(schema, parse(doc));
expect(resolvedArgs.numArg).to.equal(123);
- expect(resolvedArgs.stringArg).to.equal('foo');
+ expect(resolvedArgs.stringArg).to.equal("foo");
});
- it('nulls out error subtrees', async () => {
+ it("nulls out error subtrees", async () => {
const doc = `{
sync
syncError
@@ -262,62 +288,62 @@ describe('Execute: Handles basic execution tasks', () => {
const data = {
sync() {
- return 'sync';
+ return "sync";
},
syncError() {
- throw new Error('Error getting syncError');
+ throw new Error("Error getting syncError");
},
syncRawError() {
/* eslint-disable */
- throw 'Error getting syncRawError';
+ throw "Error getting syncRawError";
/* eslint-enable */
},
syncReturnError() {
- return new Error('Error getting syncReturnError');
+ return new Error("Error getting syncReturnError");
},
syncReturnErrorList() {
return [
- 'sync0',
- new Error('Error getting syncReturnErrorList1'),
- 'sync2',
- new Error('Error getting syncReturnErrorList3')
+ "sync0",
+ new Error("Error getting syncReturnErrorList1"),
+ "sync2",
+ new Error("Error getting syncReturnErrorList3")
];
},
async() {
- return new Promise(resolve => resolve('async'));
+ return new Promise(resolve => resolve("async"));
},
asyncReject() {
return new Promise((_, reject) =>
- reject(new Error('Error getting asyncReject'))
+ reject(new Error("Error getting asyncReject"))
);
},
asyncRawReject() {
- return Promise.reject('Error getting asyncRawReject');
+ return Promise.reject("Error getting asyncRawReject");
},
asyncEmptyReject() {
return Promise.reject();
},
asyncError() {
return new Promise(() => {
- throw new Error('Error getting asyncError');
+ throw new Error("Error getting asyncError");
});
},
asyncRawError() {
return new Promise(() => {
/* eslint-disable */
- throw 'Error getting asyncRawError';
+ throw "Error getting asyncRawError";
/* eslint-enable */
});
},
asyncReturnError() {
- return Promise.resolve(new Error('Error getting asyncReturnError'));
- },
+ return Promise.resolve(new Error("Error getting asyncReturnError"));
+ }
};
const ast = parse(doc);
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
- name: 'Type',
+ name: "Type",
fields: {
sync: { type: GraphQLString },
syncError: { type: GraphQLString },
@@ -330,7 +356,7 @@ describe('Execute: Handles basic execution tasks', () => {
asyncEmptyReject: { type: GraphQLString },
asyncError: { type: GraphQLString },
asyncRawError: { type: GraphQLString },
- asyncReturnError: { type: GraphQLString },
+ asyncReturnError: { type: GraphQLString }
}
})
});
@@ -338,235 +364,255 @@ describe('Execute: Handles basic execution tasks', () => {
const result = await execute(schema, ast, data);
expect(result.data).to.deep.equal({
- sync: 'sync',
+ sync: "sync",
syncError: null,
syncRawError: null,
syncReturnError: null,
- syncReturnErrorList: [ 'sync0', null, 'sync2', null ],
- async: 'async',
+ syncReturnErrorList: ["sync0", null, "sync2", null],
+ async: "async",
asyncReject: null,
asyncRawReject: null,
asyncEmptyReject: null,
asyncError: null,
asyncRawError: null,
- asyncReturnError: null,
+ asyncReturnError: null
});
expect(result.errors && result.errors.map(formatError)).to.deep.equal([
- { message: 'Error getting syncError',
- locations: [ { line: 3, column: 7 } ] },
- { message: 'Error getting syncRawError',
- locations: [ { line: 4, column: 7 } ] },
- { message: 'Error getting syncReturnError',
- locations: [ { line: 5, column: 7 } ] },
- { message: 'Error getting syncReturnErrorList1',
- locations: [ { line: 6, column: 7 } ] },
- { message: 'Error getting syncReturnErrorList3',
- locations: [ { line: 6, column: 7 } ] },
- { message: 'Error getting asyncReturnError',
- locations: [ { line: 13, column: 7 } ] },
- { message: 'Error getting asyncReject',
- locations: [ { line: 8, column: 7 } ] },
- { message: 'Error getting asyncRawReject',
- locations: [ { line: 9, column: 7 } ] },
- { message: 'An unknown error occurred.',
- locations: [ { line: 10, column: 7 } ] },
- { message: 'Error getting asyncError',
- locations: [ { line: 11, column: 7 } ] },
- { message: 'Error getting asyncRawError',
- locations: [ { line: 12, column: 7 } ] },
+ {
+ message: "Error getting syncError",
+ locations: [{ line: 3, column: 7 }]
+ },
+ {
+ message: "Error getting syncRawError",
+ locations: [{ line: 4, column: 7 }]
+ },
+ {
+ message: "Error getting syncReturnError",
+ locations: [{ line: 5, column: 7 }]
+ },
+ {
+ message: "Error getting syncReturnErrorList1",
+ locations: [{ line: 6, column: 7 }]
+ },
+ {
+ message: "Error getting syncReturnErrorList3",
+ locations: [{ line: 6, column: 7 }]
+ },
+ {
+ message: "Error getting asyncReturnError",
+ locations: [{ line: 13, column: 7 }]
+ },
+ {
+ message: "Error getting asyncReject",
+ locations: [{ line: 8, column: 7 }]
+ },
+ {
+ message: "Error getting asyncRawReject",
+ locations: [{ line: 9, column: 7 }]
+ },
+ {
+ message: "An unknown error occurred.",
+ locations: [{ line: 10, column: 7 }]
+ },
+ {
+ message: "Error getting asyncError",
+ locations: [{ line: 11, column: 7 }]
+ },
+ {
+ message: "Error getting asyncRawError",
+ locations: [{ line: 12, column: 7 }]
+ }
]);
});
- it('uses the inline operation if no operation name is provided', async () => {
- const doc = '{ a }';
- const data = { a: 'b' };
+ it("uses the inline operation if no operation name is provided", async () => {
+ const doc = "{ a }";
+ const data = { a: "b" };
const ast = parse(doc);
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
- name: 'Type',
+ name: "Type",
fields: {
- a: { type: GraphQLString },
+ a: { type: GraphQLString }
}
})
});
const result = await execute(schema, ast, data);
- expect(result).to.deep.equal({ data: { a: 'b' } });
+ expect(result).to.deep.equal({ data: { a: "b" } });
});
- it('uses the only operation if no operation name is provided', async () => {
- const doc = 'query Example { a }';
- const data = { a: 'b' };
+ it("uses the only operation if no operation name is provided", async () => {
+ const doc = "query Example { a }";
+ const data = { a: "b" };
const ast = parse(doc);
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
- name: 'Type',
+ name: "Type",
fields: {
- a: { type: GraphQLString },
+ a: { type: GraphQLString }
}
})
});
const result = await execute(schema, ast, data);
- expect(result).to.deep.equal({ data: { a: 'b' } });
+ expect(result).to.deep.equal({ data: { a: "b" } });
});
- it('uses the named operation if operation name is provided', async () => {
- const doc = 'query Example { first: a } query OtherExample { second: a }';
- const data = { a: 'b' };
+ it("uses the named operation if operation name is provided", async () => {
+ const doc = "query Example { first: a } query OtherExample { second: a }";
+ const data = { a: "b" };
const ast = parse(doc);
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
- name: 'Type',
+ name: "Type",
fields: {
- a: { type: GraphQLString },
+ a: { type: GraphQLString }
}
})
});
- const result = await execute(schema, ast, data, null, null, 'OtherExample');
+ const result = await execute(schema, ast, data, null, null, "OtherExample");
- expect(result).to.deep.equal({ data: { second: 'b' } });
+ expect(result).to.deep.equal({ data: { second: "b" } });
});
- it('throws if no operation is provided', () => {
- const doc = 'fragment Example on Type { a }';
- const data = { a: 'b' };
+ it("throws if no operation is provided", () => {
+ const doc = "fragment Example on Type { a }";
+ const data = { a: "b" };
const ast = parse(doc);
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
- name: 'Type',
+ name: "Type",
fields: {
- a: { type: GraphQLString },
+ a: { type: GraphQLString }
}
})
});
expect(() => execute(schema, ast, data)).to.throw(
- 'Must provide an operation.'
+ "Must provide an operation."
);
});
- it('throws if no operation name is provided with multiple operations', () => {
- const doc = 'query Example { a } query OtherExample { a }';
- const data = { a: 'b' };
+ it("throws if no operation name is provided with multiple operations", () => {
+ const doc = "query Example { a } query OtherExample { a }";
+ const data = { a: "b" };
const ast = parse(doc);
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
- name: 'Type',
+ name: "Type",
fields: {
- a: { type: GraphQLString },
+ a: { type: GraphQLString }
}
})
});
expect(() => execute(schema, ast, data)).to.throw(
- 'Must provide operation name if query contains multiple operations.'
+ "Must provide operation name if query contains multiple operations."
);
});
- it('throws if unknown operation name is provided', () => {
- const doc = 'query Example { a } query OtherExample { a }';
- const data = { a: 'b' };
+ it("throws if unknown operation name is provided", () => {
+ const doc = "query Example { a } query OtherExample { a }";
+ const data = { a: "b" };
const ast = parse(doc);
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
- name: 'Type',
+ name: "Type",
fields: {
- a: { type: GraphQLString },
+ a: { type: GraphQLString }
}
})
});
expect(() =>
- execute(schema, ast, data, null, null, 'UnknownExample')
- ).to.throw(
- 'Unknown operation named "UnknownExample".'
- );
+ execute(schema, ast, data, null, null, "UnknownExample")
+ ).to.throw('Unknown operation named "UnknownExample".');
});
- it('uses the query schema for queries', async () => {
- const doc = 'query Q { a } mutation M { c } subscription S { a }';
- const data = { a: 'b', c: 'd' };
+ it("uses the query schema for queries", async () => {
+ 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({
query: new GraphQLObjectType({
- name: 'Q',
+ name: "Q",
fields: {
- a: { type: GraphQLString },
+ a: { type: GraphQLString }
}
}),
mutation: new GraphQLObjectType({
- name: 'M',
+ name: "M",
fields: {
- c: { type: GraphQLString },
+ c: { type: GraphQLString }
}
}),
subscription: new GraphQLObjectType({
- name: 'S',
+ name: "S",
fields: {
- a: { type: GraphQLString },
+ a: { type: GraphQLString }
}
})
});
- const queryResult = await execute(schema, ast, data, null, {}, 'Q');
+ const queryResult = await execute(schema, ast, data, null, {}, "Q");
- expect(queryResult).to.deep.equal({ data: { a: 'b' } });
+ expect(queryResult).to.deep.equal({ data: { a: "b" } });
});
- it('uses the mutation schema for mutations', async () => {
- const doc = 'query Q { a } mutation M { c }';
- const data = { a: 'b', c: 'd' };
+ it("uses the mutation schema for mutations", async () => {
+ const doc = "query Q { a } mutation M { c }";
+ const data = { a: "b", c: "d" };
const ast = parse(doc);
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
- name: 'Q',
+ name: "Q",
fields: {
- a: { type: GraphQLString },
+ a: { type: GraphQLString }
}
}),
mutation: new GraphQLObjectType({
- name: 'M',
+ name: "M",
fields: {
- c: { type: GraphQLString },
+ c: { type: GraphQLString }
}
})
});
- const mutationResult = await execute(schema, ast, data, null, {}, 'M');
+ const mutationResult = await execute(schema, ast, data, null, {}, "M");
- expect(mutationResult).to.deep.equal({ data: { c: 'd' } });
+ expect(mutationResult).to.deep.equal({ data: { c: "d" } });
});
- it('uses the subscription schema for subscriptions', async () => {
- const doc = 'query Q { a } subscription S { a }';
- const data = { a: 'b', c: 'd' };
+ it("uses the subscription schema for subscriptions", async () => {
+ const doc = "query Q { a } subscription S { a }";
+ const data = { a: "b", c: "d" };
const ast = parse(doc);
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
- name: 'Q',
+ name: "Q",
fields: {
- a: { type: GraphQLString },
+ a: { type: GraphQLString }
}
}),
subscription: new GraphQLObjectType({
- name: 'S',
+ name: "S",
fields: {
- a: { type: GraphQLString },
+ a: { type: GraphQLString }
}
})
});
- const subscriptionResult = await execute(schema, ast, data, null, {}, 'S');
+ const subscriptionResult = await execute(schema, ast, data, null, {}, "S");
- expect(subscriptionResult).to.deep.equal({ data: { a: 'b' } });
+ expect(subscriptionResult).to.deep.equal({ data: { a: "b" } });
});
- it('correct field ordering despite execution order', async () => {
+ it("correct field ordering despite execution order", async () => {
const doc = `{
a,
b,
@@ -577,32 +623,32 @@ describe('Execute: Handles basic execution tasks', () => {
const data = {
a() {
- return 'a';
+ return "a";
},
b() {
- return new Promise(resolve => resolve('b'));
+ return new Promise(resolve => resolve("b"));
},
c() {
- return 'c';
+ return "c";
},
d() {
- return new Promise(resolve => resolve('d'));
+ return new Promise(resolve => resolve("d"));
},
e() {
- return 'e';
- },
+ return "e";
+ }
};
const ast = parse(doc);
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
- name: 'Type',
+ name: "Type",
fields: {
a: { type: GraphQLString },
b: { type: GraphQLString },
c: { type: GraphQLString },
d: { type: GraphQLString },
- e: { type: GraphQLString },
+ e: { type: GraphQLString }
}
})
});
@@ -611,18 +657,18 @@ describe('Execute: Handles basic execution tasks', () => {
expect(result).to.deep.equal({
data: {
- a: 'a',
- b: 'b',
- c: 'c',
- d: 'd',
- e: 'e',
+ a: "a",
+ b: "b",
+ c: "c",
+ d: "d",
+ e: "e"
}
});
- expect(Object.keys(result.data)).to.deep.equal([ 'a', 'b', 'c', 'd', 'e' ]);
+ expect(Object.keys(result.data)).to.deep.equal(["a", "b", "c", "d", "e"]);
});
- it('Avoids recursion', async () => {
+ it("Avoids recursion", async () => {
const doc = `
query Q {
a
@@ -635,54 +681,53 @@ describe('Execute: Handles basic execution tasks', () => {
...Frag
}
`;
- const data = { a: 'b' };
+ const data = { a: "b" };
const ast = parse(doc);
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
- name: 'Type',
+ name: "Type",
fields: {
- a: { type: GraphQLString },
+ a: { type: GraphQLString }
}
- }),
+ })
});
- const queryResult = await execute(schema, ast, data, null, {}, 'Q');
+ const queryResult = await execute(schema, ast, data, null, {}, "Q");
- expect(queryResult).to.deep.equal({ data: { a: 'b' } });
+ expect(queryResult).to.deep.equal({ data: { a: "b" } });
});
- it('does not include illegal fields in output', async () => {
+ it("does not include illegal fields in output", async () => {
const doc = `mutation M {
thisIsIllegalDontIncludeMe
}`;
const ast = parse(doc);
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
- name: 'Q',
+ name: "Q",
fields: {
- a: { type: GraphQLString },
+ a: { type: GraphQLString }
}
}),
mutation: new GraphQLObjectType({
- name: 'M',
+ name: "M",
fields: {
- c: { type: GraphQLString },
+ c: { type: GraphQLString }
}
- }),
+ })
});
const mutationResult = await execute(schema, ast);
expect(mutationResult).to.deep.equal({
- data: {
- }
+ data: {}
});
});
- it('does not include arguments that were not set', async () => {
+ it("does not include arguments that were not set", async () => {
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
- name: 'Type',
+ name: "Type",
fields: {
field: {
type: GraphQLString,
@@ -692,14 +737,14 @@ describe('Execute: Handles basic execution tasks', () => {
b: { type: GraphQLBoolean },
c: { type: GraphQLBoolean },
d: { type: GraphQLInt },
- e: { type: GraphQLInt },
- },
+ e: { type: GraphQLInt }
+ }
}
}
})
});
- const query = parse('{ field(a: true, c: false, e: 0) }');
+ const query = parse("{ field(a: true, c: false, e: 0) }");
const result = await execute(schema, query);
expect(result).to.deep.equal({
@@ -709,7 +754,7 @@ describe('Execute: Handles basic execution tasks', () => {
});
});
- it('fails when an isTypeOf check is not met', async () => {
+ it("fails when an isTypeOf check is not met", async () => {
class Special {
constructor(value) {
this.value = value;
@@ -723,7 +768,7 @@ describe('Execute: Handles basic execution tasks', () => {
}
const SpecialType = new GraphQLObjectType({
- name: 'SpecialType',
+ name: "SpecialType",
isTypeOf(obj) {
return obj instanceof Special;
},
@@ -734,7 +779,7 @@ describe('Execute: Handles basic execution tasks', () => {
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
- name: 'Query',
+ name: "Query",
fields: {
specials: {
type: new GraphQLList(SpecialType),
@@ -744,27 +789,26 @@ describe('Execute: Handles basic execution tasks', () => {
})
});
- const query = parse('{ specials { value } }');
+ const query = parse("{ specials { value } }");
const value = {
- specials: [ new Special('foo'), new NotSpecial('bar') ]
+ specials: [new Special("foo"), new NotSpecial("bar")]
};
const result = await execute(schema, query, value);
expect(result.data).to.deep.equal({
- specials: [
- { value: 'foo' },
- null
- ]
+ specials: [{ value: "foo" }, null]
});
expect(result.errors).to.have.lengthOf(1);
expect(result.errors).to.containSubset([
- { message:
+ {
+ message:
'Expected value of type "SpecialType" but got: [object Object].',
- locations: [ { line: 1, column: 3 } ] }
+ locations: [{ line: 1, column: 3 }]
+ }
]);
});
- it('fails to execute a query containing a type definition', async () => {
+ it("fails to execute a query containing a type definition", async () => {
const query = parse(`
{ foo }
@@ -773,7 +817,7 @@ describe('Execute: Handles basic execution tasks', () => {
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
- name: 'Query',
+ name: "Query",
fields: {
foo: { type: GraphQLString }
}
@@ -789,9 +833,8 @@ describe('Execute: Handles basic execution tasks', () => {
expect(caughtError).to.deep.equal(
new Error(
- 'GraphQL cannot execute a request containing a ObjectTypeDefinition.'
+ "GraphQL cannot execute a request containing a ObjectTypeDefinition."
)
);
});
-
});
diff --git a/src/execution/__tests__/lists-test.js b/src/execution/__tests__/lists-test.js
index 31c6a364ee..c6c91a22bd 100644
--- a/src/execution/__tests__/lists-test.js
+++ b/src/execution/__tests__/lists-test.js
@@ -10,18 +10,18 @@
// 80+ char lines are useful in describe/it, so ignore in this file.
/* eslint-disable max-len */
-import { expect } from 'chai';
-import { describe, it } from 'mocha';
-import { formatError } from '../../error';
-import { execute } from '../execute';
-import { parse } from '../../language';
+import { expect } from "chai";
+import { describe, it } from "mocha";
+import { formatError } from "../../error";
+import { execute } from "../execute";
+import { parse } from "../../language";
import {
GraphQLSchema,
GraphQLObjectType,
GraphQLInt,
GraphQLList,
GraphQLNonNull
-} from '../../type';
+} from "../../type";
// resolved() is shorthand for Promise.resolve()
const resolved = Promise.resolve.bind(Promise);
@@ -40,16 +40,16 @@ function check(testType, testData, expected) {
const data = { test: testData };
const dataType = new GraphQLObjectType({
- name: 'DataType',
+ name: "DataType",
fields: () => ({
test: { type: testType },
- nest: { type: dataType, resolve: () => data },
+ nest: { type: dataType, resolve: () => data }
})
});
const schema = new GraphQLSchema({ query: dataType });
- const ast = parse('{ nest { test } }');
+ const ast = parse("{ nest { test } }");
const response = await execute(schema, ast, data);
@@ -67,349 +67,426 @@ function check(testType, testData, expected) {
};
}
-describe('Execute: Handles list nullability', () => {
-
- describe('[T]', () => {
+describe("Execute: Handles list nullability", () => {
+ describe("[T]", () => {
const type = new GraphQLList(GraphQLInt);
- describe('Array', () => {
-
- it('Contains values', check(type,
- [ 1, 2 ],
- { data: { nest: { test: [ 1, 2 ] } } }
- ));
+ describe("Array", () => {
+ it(
+ "Contains values",
+ check(type, [1, 2], { data: { nest: { test: [1, 2] } } })
+ );
- it('Contains null', check(type,
- [ 1, null, 2 ],
- { data: { nest: { test: [ 1, null, 2 ] } } }
- ));
-
- it('Returns null', check(type,
- null,
- { data: { nest: { test: null } } }
- ));
+ it(
+ "Contains null",
+ check(type, [1, null, 2], { data: { nest: { test: [1, null, 2] } } })
+ );
+ it("Returns null", check(type, null, { data: { nest: { test: null } } }));
});
- describe('Promise>', () => {
-
- it('Contains values', check(type,
- resolved([ 1, 2 ]),
- { data: { nest: { test: [ 1, 2 ] } } }
- ));
-
- it('Contains null', check(type,
- resolved([ 1, null, 2 ]),
- { data: { nest: { test: [ 1, null, 2 ] } } }
- ));
-
-
- it('Returns null', check(type,
- resolved(null),
- { data: { nest: { test: null } } }
- ));
-
- it('Rejected', check(type,
- () => rejected(new Error('bad')),
- { data: { nest: { test: null } },
+ describe("Promise>", () => {
+ it(
+ "Contains values",
+ check(type, resolved([1, 2]), { data: { nest: { test: [1, 2] } } })
+ );
+
+ it(
+ "Contains null",
+ check(type, resolved([1, null, 2]), {
+ data: { nest: { test: [1, null, 2] } }
+ })
+ );
+
+ it(
+ "Returns null",
+ check(type, resolved(null), { data: { nest: { test: null } } })
+ );
+
+ it(
+ "Rejected",
+ check(type, () => rejected(new Error("bad")), {
+ data: { nest: { test: null } },
errors: [
- { message: 'bad',
- locations: [ { line: 1, column: 10 } ] }
- ] }
- ));
-
+ {
+ message: "bad",
+ locations: [{ line: 1, column: 10 }]
+ }
+ ]
+ })
+ );
});
- describe('Array>', () => {
-
- it('Contains values', check(type,
- [ resolved(1), resolved(2) ],
- { data: { nest: { test: [ 1, 2 ] } } }
- ));
-
- it('Contains null', check(type,
- [ resolved(1), resolved(null), resolved(2) ],
- { data: { nest: { test: [ 1, null, 2 ] } } }
- ));
-
- it('Contains reject', check(type,
- () => [ resolved(1), rejected(new Error('bad')), resolved(2) ],
- { data: { nest: { test: [ 1, null, 2 ] } },
- errors: [
- { message: 'bad',
- locations: [ { line: 1, column: 10 } ] }
- ] }
- ));
-
+ describe("Array>", () => {
+ it(
+ "Contains values",
+ check(type, [resolved(1), resolved(2)], {
+ data: { nest: { test: [1, 2] } }
+ })
+ );
+
+ it(
+ "Contains null",
+ check(type, [resolved(1), resolved(null), resolved(2)], {
+ data: { nest: { test: [1, null, 2] } }
+ })
+ );
+
+ it(
+ "Contains reject",
+ check(
+ type,
+ () => [resolved(1), rejected(new Error("bad")), resolved(2)],
+ {
+ data: { nest: { test: [1, null, 2] } },
+ errors: [
+ {
+ message: "bad",
+ locations: [{ line: 1, column: 10 }]
+ }
+ ]
+ }
+ )
+ );
});
-
});
- describe('[T]!', () => {
+ describe("[T]!", () => {
const type = new GraphQLNonNull(new GraphQLList(GraphQLInt));
- describe('Array', () => {
-
- it('Contains values', check(type,
- [ 1, 2 ],
- { data: { nest: { test: [ 1, 2 ] } } }
- ));
-
- it('Contains null', check(type,
- [ 1, null, 2 ],
- { data: { nest: { test: [ 1, null, 2 ] } } }
- ));
-
- it('Returns null', check(type,
- null,
- { data: { nest: null },
+ describe("Array", () => {
+ it(
+ "Contains values",
+ check(type, [1, 2], { data: { nest: { test: [1, 2] } } })
+ );
+
+ it(
+ "Contains null",
+ check(type, [1, null, 2], { data: { nest: { test: [1, null, 2] } } })
+ );
+
+ it(
+ "Returns null",
+ check(type, null, {
+ data: { nest: null },
errors: [
- { message: 'Cannot return null for non-nullable field DataType.test.',
- locations: [ { line: 1, column: 10 } ] }
- ] }
- ));
-
+ {
+ message:
+ "Cannot return null for non-nullable field DataType.test.",
+ locations: [{ line: 1, column: 10 }]
+ }
+ ]
+ })
+ );
});
- describe('Promise>', () => {
-
- it('Contains values', check(type,
- resolved([ 1, 2 ]),
- { data: { nest: { test: [ 1, 2 ] } } }
- ));
-
- it('Contains null', check(type,
- resolved([ 1, null, 2 ]),
- { data: { nest: { test: [ 1, null, 2 ] } } }
- ));
-
- it('Returns null', check(type,
- resolved(null),
- { data: { nest: null },
+ describe("Promise>", () => {
+ it(
+ "Contains values",
+ check(type, resolved([1, 2]), { data: { nest: { test: [1, 2] } } })
+ );
+
+ it(
+ "Contains null",
+ check(type, resolved([1, null, 2]), {
+ data: { nest: { test: [1, null, 2] } }
+ })
+ );
+
+ it(
+ "Returns null",
+ check(type, resolved(null), {
+ data: { nest: null },
errors: [
- { message: 'Cannot return null for non-nullable field DataType.test.',
- locations: [ { line: 1, column: 10 } ] }
- ] }
- ));
-
- it('Rejected', check(type,
- () => rejected(new Error('bad')),
- { data: { nest: null },
+ {
+ message:
+ "Cannot return null for non-nullable field DataType.test.",
+ locations: [{ line: 1, column: 10 }]
+ }
+ ]
+ })
+ );
+
+ it(
+ "Rejected",
+ check(type, () => rejected(new Error("bad")), {
+ data: { nest: null },
errors: [
- { message: 'bad',
- locations: [ { line: 1, column: 10 } ] }
- ] }
- ));
-
+ {
+ message: "bad",
+ locations: [{ line: 1, column: 10 }]
+ }
+ ]
+ })
+ );
});
- describe('Array>', () => {
-
- it('Contains values', check(type,
- [ resolved(1), resolved(2) ],
- { data: { nest: { test: [ 1, 2 ] } } }
- ));
-
- it('Contains null', check(type,
- [ resolved(1), resolved(null), resolved(2) ],
- { data: { nest: { test: [ 1, null, 2 ] } } }
- ));
-
- it('Contains reject', check(type,
- () => [ resolved(1), rejected(new Error('bad')), resolved(2) ],
- { data: { nest: { test: [ 1, null, 2 ] } },
- errors: [
- { message: 'bad',
- locations: [ { line: 1, column: 10 } ] }
- ] }
- ));
-
+ describe("Array>", () => {
+ it(
+ "Contains values",
+ check(type, [resolved(1), resolved(2)], {
+ data: { nest: { test: [1, 2] } }
+ })
+ );
+
+ it(
+ "Contains null",
+ check(type, [resolved(1), resolved(null), resolved(2)], {
+ data: { nest: { test: [1, null, 2] } }
+ })
+ );
+
+ it(
+ "Contains reject",
+ check(
+ type,
+ () => [resolved(1), rejected(new Error("bad")), resolved(2)],
+ {
+ data: { nest: { test: [1, null, 2] } },
+ errors: [
+ {
+ message: "bad",
+ locations: [{ line: 1, column: 10 }]
+ }
+ ]
+ }
+ )
+ );
});
-
});
- describe('[T!]', () => {
+ describe("[T!]", () => {
const type = new GraphQLList(new GraphQLNonNull(GraphQLInt));
- describe('Array', () => {
-
- it('Contains values', check(type,
- [ 1, 2 ],
- { data: { nest: { test: [ 1, 2 ] } } }
- ));
+ describe("Array", () => {
+ it(
+ "Contains values",
+ check(type, [1, 2], { data: { nest: { test: [1, 2] } } })
+ );
- it('Contains null', check(type,
- [ 1, null, 2 ],
- { data: { nest: { test: null } },
+ it(
+ "Contains null",
+ check(type, [1, null, 2], {
+ data: { nest: { test: null } },
errors: [
- { message: 'Cannot return null for non-nullable field DataType.test.',
- locations: [ { line: 1, column: 10 } ] }
- ] }
- ));
-
- it('Returns null', check(type,
- null,
- { data: { nest: { test: null } } }
- ));
-
+ {
+ message:
+ "Cannot return null for non-nullable field DataType.test.",
+ locations: [{ line: 1, column: 10 }]
+ }
+ ]
+ })
+ );
+
+ it("Returns null", check(type, null, { data: { nest: { test: null } } }));
});
- describe('Promise>', () => {
-
- it('Contains values', check(type,
- resolved([ 1, 2 ]),
- { data: { nest: { test: [ 1, 2 ] } } }
- ));
+ describe("Promise>", () => {
+ it(
+ "Contains values",
+ check(type, resolved([1, 2]), { data: { nest: { test: [1, 2] } } })
+ );
- it('Contains null', check(type,
- resolved([ 1, null, 2 ]),
- { data: { nest: { test: null } },
+ it(
+ "Contains null",
+ check(type, resolved([1, null, 2]), {
+ data: { nest: { test: null } },
errors: [
- { message: 'Cannot return null for non-nullable field DataType.test.',
- locations: [ { line: 1, column: 10 } ] }
- ] }
- ));
-
- it('Returns null', check(type,
- resolved(null),
- { data: { nest: { test: null } } }
- ));
-
- it('Rejected', check(type,
- () => rejected(new Error('bad')),
- { data: { nest: { test: null } },
+ {
+ message:
+ "Cannot return null for non-nullable field DataType.test.",
+ locations: [{ line: 1, column: 10 }]
+ }
+ ]
+ })
+ );
+
+ it(
+ "Returns null",
+ check(type, resolved(null), { data: { nest: { test: null } } })
+ );
+
+ it(
+ "Rejected",
+ check(type, () => rejected(new Error("bad")), {
+ data: { nest: { test: null } },
errors: [
- { message: 'bad',
- locations: [ { line: 1, column: 10 } ] }
- ] }
- ));
-
+ {
+ message: "bad",
+ locations: [{ line: 1, column: 10 }]
+ }
+ ]
+ })
+ );
});
- describe('Array>', () => {
-
- it('Contains values', check(type,
- [ resolved(1), resolved(2) ],
- { data: { nest: { test: [ 1, 2 ] } } }
- ));
-
- it('Contains null', check(type,
- [ resolved(1), resolved(null), resolved(2) ],
- { data: { nest: { test: null } },
+ describe("Array>", () => {
+ it(
+ "Contains values",
+ check(type, [resolved(1), resolved(2)], {
+ data: { nest: { test: [1, 2] } }
+ })
+ );
+
+ it(
+ "Contains null",
+ check(type, [resolved(1), resolved(null), resolved(2)], {
+ data: { nest: { test: null } },
errors: [
- { message: 'Cannot return null for non-nullable field DataType.test.',
- locations: [ { line: 1, column: 10 } ] }
- ] }
- ));
-
- it('Contains reject', check(type,
- () => [ resolved(1), rejected(new Error('bad')), resolved(2) ],
- { data: { nest: { test: null } },
- errors: [
- { message: 'bad',
- locations: [ { line: 1, column: 10 } ] }
- ] }
- ));
-
+ {
+ message:
+ "Cannot return null for non-nullable field DataType.test.",
+ locations: [{ line: 1, column: 10 }]
+ }
+ ]
+ })
+ );
+
+ it(
+ "Contains reject",
+ check(
+ type,
+ () => [resolved(1), rejected(new Error("bad")), resolved(2)],
+ {
+ data: { nest: { test: null } },
+ errors: [
+ {
+ message: "bad",
+ locations: [{ line: 1, column: 10 }]
+ }
+ ]
+ }
+ )
+ );
});
-
});
- describe('[T!]!', () => {
- const type =
- new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(GraphQLInt)));
-
- describe('Array', () => {
-
- it('Contains values', check(type,
- [ 1, 2 ],
- { data: { nest: { test: [ 1, 2 ] } } }
- ));
-
-
- it('Contains null', check(type,
- [ 1, null, 2 ],
- { data: { nest: null },
+ describe("[T!]!", () => {
+ const type = new GraphQLNonNull(
+ new GraphQLList(new GraphQLNonNull(GraphQLInt))
+ );
+
+ describe("Array", () => {
+ it(
+ "Contains values",
+ check(type, [1, 2], { data: { nest: { test: [1, 2] } } })
+ );
+
+ it(
+ "Contains null",
+ check(type, [1, null, 2], {
+ data: { nest: null },
errors: [
- { message: 'Cannot return null for non-nullable field DataType.test.',
- locations: [ { line: 1, column: 10 } ] }
- ] }
- ));
-
- it('Returns null', check(type,
- null,
- { data: { nest: null },
+ {
+ message:
+ "Cannot return null for non-nullable field DataType.test.",
+ locations: [{ line: 1, column: 10 }]
+ }
+ ]
+ })
+ );
+
+ it(
+ "Returns null",
+ check(type, null, {
+ data: { nest: null },
errors: [
- { message: 'Cannot return null for non-nullable field DataType.test.',
- locations: [ { line: 1, column: 10 } ] }
- ] }
- ));
-
+ {
+ message:
+ "Cannot return null for non-nullable field DataType.test.",
+ locations: [{ line: 1, column: 10 }]
+ }
+ ]
+ })
+ );
});
- describe('Promise>', () => {
-
- it('Contains values', check(type,
- resolved([ 1, 2 ]),
- { data: { nest: { test: [ 1, 2 ] } } }
- ));
+ describe("Promise>", () => {
+ it(
+ "Contains values",
+ check(type, resolved([1, 2]), { data: { nest: { test: [1, 2] } } })
+ );
- it('Contains null', check(type,
- resolved([ 1, null, 2 ]),
- { data: { nest: null },
+ it(
+ "Contains null",
+ check(type, resolved([1, null, 2]), {
+ data: { nest: null },
errors: [
- { message: 'Cannot return null for non-nullable field DataType.test.',
- locations: [ { line: 1, column: 10 } ] }
- ] }
- ));
-
- it('Returns null', check(type,
- resolved(null),
- { data: { nest: null },
+ {
+ message:
+ "Cannot return null for non-nullable field DataType.test.",
+ locations: [{ line: 1, column: 10 }]
+ }
+ ]
+ })
+ );
+
+ it(
+ "Returns null",
+ check(type, resolved(null), {
+ data: { nest: null },
errors: [
- { message: 'Cannot return null for non-nullable field DataType.test.',
- locations: [ { line: 1, column: 10 } ] }
- ] }
- ));
-
- it('Rejected', check(type,
- () => rejected(new Error('bad')),
- { data: { nest: null },
+ {
+ message:
+ "Cannot return null for non-nullable field DataType.test.",
+ locations: [{ line: 1, column: 10 }]
+ }
+ ]
+ })
+ );
+
+ it(
+ "Rejected",
+ check(type, () => rejected(new Error("bad")), {
+ data: { nest: null },
errors: [
- { message: 'bad',
- locations: [ { line: 1, column: 10 } ] }
- ] }
- ));
-
+ {
+ message: "bad",
+ locations: [{ line: 1, column: 10 }]
+ }
+ ]
+ })
+ );
});
- describe('Array>', () => {
-
- it('Contains values', check(type,
- [ resolved(1), resolved(2) ],
- { data: { nest: { test: [ 1, 2 ] } } }
- ));
-
- it('Contains null', check(type,
- [ resolved(1), resolved(null), resolved(2) ],
- { data: { nest: null },
- errors: [
- { message: 'Cannot return null for non-nullable field DataType.test.',
- locations: [ { line: 1, column: 10 } ] }
- ] }
- ));
-
- it('Contains reject', check(type,
- () => [ resolved(1), rejected(new Error('bad')), resolved(2) ],
- { data: { nest: null },
+ describe("Array>", () => {
+ it(
+ "Contains values",
+ check(type, [resolved(1), resolved(2)], {
+ data: { nest: { test: [1, 2] } }
+ })
+ );
+
+ it(
+ "Contains null",
+ check(type, [resolved(1), resolved(null), resolved(2)], {
+ data: { nest: null },
errors: [
- { message: 'bad',
- locations: [ { line: 1, column: 10 } ] }
- ] }
- ));
-
+ {
+ message:
+ "Cannot return null for non-nullable field DataType.test.",
+ locations: [{ line: 1, column: 10 }]
+ }
+ ]
+ })
+ );
+
+ it(
+ "Contains reject",
+ check(
+ type,
+ () => [resolved(1), rejected(new Error("bad")), resolved(2)],
+ {
+ data: { nest: null },
+ errors: [
+ {
+ message: "bad",
+ locations: [{ line: 1, column: 10 }]
+ }
+ ]
+ }
+ )
+ );
});
-
});
-
});
diff --git a/src/execution/__tests__/mutations-test.js b/src/execution/__tests__/mutations-test.js
index 7632d9a880..9c875212e0 100644
--- a/src/execution/__tests__/mutations-test.js
+++ b/src/execution/__tests__/mutations-test.js
@@ -10,15 +10,11 @@
// 80+ char lines are useful in describe/it, so ignore in this file.
/* eslint-disable max-len */
-import { expect } from 'chai';
-import { describe, it } from 'mocha';
-import { execute } from '../execute';
-import { parse } from '../../language';
-import {
- GraphQLSchema,
- GraphQLObjectType,
- GraphQLInt,
-} from '../../type';
+import { expect } from "chai";
+import { describe, it } from "mocha";
+import { execute } from "../execute";
+import { parse } from "../../language";
+import { GraphQLSchema, GraphQLObjectType, GraphQLInt } from "../../type";
class NumberHolder {
theNumber: number;
@@ -49,13 +45,13 @@ class Root {
}
failToChangeTheNumber(): Object {
- throw new Error('Cannot change the number');
+ throw new Error("Cannot change the number");
}
promiseAndFailToChangeTheNumber(): Promise