diff --git a/.babelrc.js b/.babelrc.js
index d35eff79a4..4af2b5dae4 100644
--- a/.babelrc.js
+++ b/.babelrc.js
@@ -9,14 +9,10 @@ module.exports = {
],
env: {
cjs: {
- presets: [
- ['@babel/preset-env', { modules: 'commonjs' }],
- ],
+ presets: [['@babel/preset-env', { modules: 'commonjs' }]],
},
mjs: {
- presets: [
- ['@babel/preset-env', { modules: false }],
- ],
+ presets: [['@babel/preset-env', { modules: false }]],
},
},
};
diff --git a/.eslintrc.yml b/.eslintrc.yml
index d9a13b5dac..9f8b14af02 100644
--- a/.eslintrc.yml
+++ b/.eslintrc.yml
@@ -6,12 +6,8 @@ env:
node: true
plugins:
- flowtype
- - prettier
rules:
- # https://github.com/prettier/eslint-plugin-prettier#installation
- prettier/prettier: error
-
# `eslint-plugin-flowtype` rule list based on `v3.11.x`
# https://github.com/gajus/eslint-plugin-flowtype#eslint-plugin-flowtype
@@ -35,7 +31,8 @@ rules:
flowtype/require-readonly-react-props: off
flowtype/require-return-type: off
flowtype/require-types-at-top: off
- flowtype/require-valid-file-annotation: [error, always, { annotationStyle: line, strict: true }]
+ flowtype/require-valid-file-annotation:
+ [error, always, { annotationStyle: line, strict: true }]
flowtype/require-variable-type: off
flowtype/sort-keys: off
flowtype/spread-exact-type: off
@@ -130,7 +127,7 @@ rules:
no-implied-eval: error
no-invalid-this: off
no-iterator: error
- no-labels: [error, {allowLoop: true}]
+ no-labels: [error, { allowLoop: true }]
no-lone-blocks: error
no-loop-func: error
no-magic-numbers: off
@@ -168,7 +165,7 @@ rules:
require-await: off # TODO
require-unicode-regexp: off
vars-on-top: error
- yoda: [error, never, {exceptRange: true}]
+ yoda: [error, never, { exceptRange: true }]
# Strict Mode
# https://eslint.org/docs/rules/#strict-mode
@@ -187,7 +184,8 @@ rules:
no-undef: error
no-undef-init: error
no-undefined: off
- no-unused-vars: [error, {vars: all, args: after-used, argsIgnorePattern: "^_"}]
+ no-unused-vars:
+ [error, { vars: all, args: after-used, argsIgnorePattern: '^_' }]
no-use-before-define: off
# Node.js and CommonJS
@@ -208,7 +206,7 @@ rules:
# Stylistic Issues
# https://eslint.org/docs/rules/#stylistic-issues
- camelcase: [error, {properties: always}]
+ camelcase: [error, { properties: always }]
capitalized-comments: off # maybe
consistent-this: off
func-name-matching: off
@@ -216,7 +214,7 @@ rules:
func-style: off
id-blacklist: off
id-length: off
- id-match: [error, "^(?:_?[a-zA-Z0-9]*)|[_A-Z0-9]+$"]
+ id-match: [error, '^(?:_?[a-zA-Z0-9]*)|[_A-Z0-9]+$']
line-comment-position: off
lines-around-comment: off
lines-between-class-members: [error, always, { exceptAfterSingleLine: true }]
@@ -353,10 +351,10 @@ rules:
yield-star-spacing: off
overrides:
- - files: "**/__tests__/**"
+ - files: '**/__tests__/**'
rules:
no-restricted-syntax: off
- - files: "resources/**"
+ - files: 'resources/**'
parserOptions:
sourceType: script
rules:
diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md
index fdbccf9802..0dd32f2d63 100644
--- a/.github/CONTRIBUTING.md
+++ b/.github/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
@@ -72,23 +71,23 @@ This will watch the file system run any relevant lint, tests, and type checks au
This project uses [Prettier](https://prettier.io/) for standard formatting. To
ensure your pull request matches the style guides, run `npm run prettier`.
-* 2 spaces for indentation (no tabs)
-* 80 character line length strongly preferred.
-* Prefer `'` over `"`
-* ES6 syntax when possible. However do not rely on ES6-specific functions to be available.
-* Use [Flow types](https://flowtype.org/).
-* Use semicolons;
-* Trailing commas,
-* Avd abbr wrds.
+- 2 spaces for indentation (no tabs)
+- 80 character line length strongly preferred.
+- Prefer `'` over `"`
+- ES6 syntax when possible. However do not rely on ES6-specific functions to be available.
+- Use [Flow types](https://flowtype.org/).
+- Use semicolons;
+- Trailing commas,
+- Avd abbr wrds.
## 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](https://semver.org/) to determine which version part to increment.
diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md
index a98cba9c25..d82363189e 100644
--- a/.github/ISSUE_TEMPLATE.md
+++ b/.github/ISSUE_TEMPLATE.md
@@ -10,7 +10,7 @@ Please do not post general questions directly as GitHub issues. They may sit for
Before filing a new issue, make sure an issue for your problem doesn't already exist.
-The best way to get a bug fixed is to provide a *pull request* with a simplified failing test case (or better yet, include a fix).
+The best way to get a bug fixed is to provide a _pull request_ with a simplified failing test case (or better yet, include a fix).
# Feature requests
diff --git a/.nycflowrc.yml b/.nycflowrc.yml
index ad201c4f31..4032fdd014 100644
--- a/.nycflowrc.yml
+++ b/.nycflowrc.yml
@@ -1,10 +1,10 @@
include:
- - "src/"
+ - 'src/'
exclude:
- - "src/polyfills"
+ - 'src/polyfills'
clean: true
-temp-directory: "coverage/flow"
-report-dir: "coverage/flow"
+temp-directory: 'coverage/flow'
+report-dir: 'coverage/flow'
skip-full: true
skip-empty: true
reporter: [json, html, text]
diff --git a/.nycrc.yml b/.nycrc.yml
index c15e75fa60..f6ead2c2e3 100644
--- a/.nycrc.yml
+++ b/.nycrc.yml
@@ -1,9 +1,9 @@
include:
- - "src/"
+ - 'src/'
exclude:
- - "src/polyfills"
+ - 'src/polyfills'
clean: true
-temp-directory: "coverage/tests"
-report-dir: "coverage/tests"
+temp-directory: 'coverage/tests'
+report-dir: 'coverage/tests'
skip-full: true
reporter: [json, html, text]
diff --git a/.travis.yml b/.travis.yml
index 4c7d2a5a74..d0de783f5f 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -5,10 +5,10 @@ cache: yarn
# https://github.com/nodejs/Release
node_js:
-- '12'
-- '10'
-- '8'
-- '6'
+ - '12'
+ - '10'
+ - '8'
+ - '6'
script: |
if [[ "$(node -pe process.version)" == v10.* ]]; then # Is latest LTS?
@@ -20,11 +20,11 @@ script: |
jobs:
include:
- - stage: deploy
- if: type = push AND branch = master
- script: npm run gitpublish
- skip_cleanup: true
- node_js: '10'
+ - stage: deploy
+ if: type = push AND branch = master
+ script: npm run gitpublish
+ skip_cleanup: true
+ node_js: '10'
notifications:
irc:
@@ -33,7 +33,7 @@ notifications:
on_failure: change
skip_join: true
channels:
- - chat.freenode.net#graphql
+ - chat.freenode.net#graphql
slack:
secure: G7fzaXoPI1cyyW7dlpQ8oG/ot73n4kE83HgbyK1iEN1YBfodsytVgh0jS+zB3DhhRAotS/VfGVz9Wj2Oo109U5w/FyxdMGuKvFan/0B/aAws1sPxLGWA5230u1wTKQCHAu17+yppFOODUu1ILDXaD2A//Wj5iru9M4NnKc1bO6VHkfBHPTLQLbdPHmorwuSH02Ocbh7K4XOWzXRxM6VrwamEn1KnyXGu2w3QdJUT31OjGEEdf6FUzvjwzFgXPhngCw5+enpwm71ljHDNu8YHhXvHtS4328O5pYQO8np7j653HNEqi+ZUiYEOWpwC8be1xHdvi/s32tPFZiCx28ZmDoCUrY744tpPtE6tzuncmSKB0Y3EjutdXBpxllNr5l5hpX5092G2MlpokFbv85J+E2ALcZYNYeFOqTYTKwTYkxK6B1x4amBNpM+FXgUhloK4BK9OT0Qh5SiQOsM8cZT0h6QP91n+REljtpugW3VbuIxq5OJAi42FYbHBC27pohhq6ohU1euZfobk9a7ZawnjoEUk1EZHXiJzYKY/QqzyB6dwk0ersBl3l3OX/wnjwKTkqc9aTmDWo2L+lHaUCXuCY1+KQXsRicfnH395szTJXQbvcbN0zz188gdz6sawzi5BxndWo0NRwZyOG2YcyUHFQR4bK1rL7Lo6t6rijQ/XMeQ=
diff --git a/README.md b/README.md
index e682214701..66f1a8af5c 100644
--- a/README.md
+++ b/README.md
@@ -11,7 +11,6 @@ https://graphql.org/graphql-js/.
Looking for help? Find resources [from the community](https://graphql.org/community/).
-
## Getting Started
An overview of GraphQL in general is available in the
@@ -47,7 +46,7 @@ import {
graphql,
GraphQLSchema,
GraphQLObjectType,
- GraphQLString
+ GraphQLString,
} from 'graphql';
var schema = new GraphQLSchema({
@@ -58,10 +57,10 @@ var schema = new GraphQLSchema({
type: GraphQLString,
resolve() {
return 'world';
- }
- }
- }
- })
+ },
+ },
+ },
+ }),
});
```
@@ -76,13 +75,11 @@ Then, serve the result of a query against that type schema.
var query = '{ hello }';
graphql(schema, query).then(result => {
-
// Prints
// {
// data: { hello: "world" }
// }
console.log(result);
-
});
```
@@ -94,7 +91,6 @@ it, reporting errors otherwise.
var query = '{ boyhowdy }';
graphql(schema, query).then(result => {
-
// Prints
// {
// errors: [
@@ -103,7 +99,6 @@ graphql(schema, query).then(result => {
// ]
// }
console.log(result);
-
});
```
diff --git a/docs/APIReference-GraphQL.md b/docs/APIReference-GraphQL.md
index 3db7cdf841..3aea9e87ba 100644
--- a/docs/APIReference-GraphQL.md
+++ b/docs/APIReference-GraphQL.md
@@ -17,7 +17,7 @@ var { graphql } = require('graphql'); // CommonJS
## Overview
-*Entry Point*
+_Entry Point_
-
@@ -28,7 +28,7 @@ var { graphql } = require('graphql'); // CommonJS
-*Schema*
+_Schema_
-
@@ -39,7 +39,7 @@ var { graphql } = require('graphql'); // CommonJS
-*Type Definitions*
+_Type Definitions_
-
@@ -92,7 +92,7 @@ var { graphql } = require('graphql'); // CommonJS
-*Scalars*
+_Scalars_
-
@@ -127,7 +127,7 @@ var { graphql } = require('graphql'); // CommonJS
-*Errors*
+_Errors_
-
diff --git a/docs/APIReference-Language.md b/docs/APIReference-Language.md
index 340a1eab08..9c163cc316 100644
--- a/docs/APIReference-Language.md
+++ b/docs/APIReference-Language.md
@@ -16,7 +16,7 @@ var { Source } = require('graphql'); // CommonJS
## Overview
-*Source*
+_Source_
-
@@ -33,7 +33,7 @@ var { Source } = require('graphql'); // CommonJS
-*Lexer*
+_Lexer_
-
@@ -44,7 +44,7 @@ var { Source } = require('graphql'); // CommonJS
-*Parser*
+_Parser_
-
@@ -67,7 +67,7 @@ var { Source } = require('graphql'); // CommonJS
-*Visitor*
+_Visitor_
-
@@ -84,7 +84,7 @@ var { Source } = require('graphql'); // CommonJS
-*Printer*
+_Printer_
-
@@ -224,7 +224,7 @@ var editedAST = visit(ast, {
// visitor.BREAK: stop visiting altogether
// null: delete this node
// any value: replace this node with the returned value
- }
+ },
});
```
@@ -233,17 +233,17 @@ instead provide functions named the same as the kinds of AST nodes, or
enter/leave visitors at a named key, leading to four permutations of
visitor API:
-1) Named visitors triggered when entering a node a specific kind.
+1. Named visitors triggered when entering a node a specific kind.
```js
visit(ast, {
Kind(node) {
// enter the "Kind" node
- }
-})
+ },
+});
```
-2) Named visitors that trigger upon entering and leaving a node of
+2. Named visitors that trigger upon entering and leaving a node of
a specific kind.
```js
@@ -259,7 +259,7 @@ visit(ast, {
})
```
-3) Generic visitors that trigger upon entering and leaving any node.
+3. Generic visitors that trigger upon entering and leaving any node.
```js
visit(ast, {
@@ -268,25 +268,25 @@ visit(ast, {
},
leave(node) {
// leave any node
- }
-})
+ },
+});
```
-4) Parallel visitors for entering and leaving nodes of a specific kind.
+4. Parallel visitors for entering and leaving nodes of a specific kind.
```js
visit(ast, {
enter: {
Kind(node) {
// enter the "Kind" node
- }
+ },
},
leave: {
Kind(node) {
// leave the "Kind" node
- }
- }
-})
+ },
+ },
+});
```
### BREAK
diff --git a/docs/APIReference-TypeSystem.md b/docs/APIReference-TypeSystem.md
index 0a7ff72520..b777db1ad1 100644
--- a/docs/APIReference-TypeSystem.md
+++ b/docs/APIReference-TypeSystem.md
@@ -16,7 +16,7 @@ var { GraphQLSchema } = require('graphql'); // CommonJS
## Overview
-*Schema*
+_Schema_
-
@@ -27,7 +27,7 @@ var { GraphQLSchema } = require('graphql'); // CommonJS
-*Definitions*
+_Definitions_
-
@@ -80,7 +80,7 @@ var { GraphQLSchema } = require('graphql'); // CommonJS
-*Predicates*
+_Predicates_
-
@@ -114,7 +114,7 @@ var { GraphQLSchema } = require('graphql'); // CommonJS
-*Un-modifiers*
+_Un-modifiers_
-
@@ -131,7 +131,7 @@ var { GraphQLSchema } = require('graphql'); // CommonJS
-*Scalars*
+_Scalars_
-
@@ -228,7 +228,7 @@ var OddType = new GraphQLScalarType({
return oddValue(parseInt(ast.value, 10));
}
return null;
- }
+ },
});
function oddValue(value) {
@@ -305,7 +305,7 @@ When two types need to refer to each other, or a type needs to refer to
itself in a field, you can use a function expression (aka a closure or a
thunk) to supply the fields lazily.
-Note that resolver functions are provided the `source` object as the first parameter.
+Note that resolver functions are provided the `source` object as the first parameter.
However, if a resolver function is not provided, then the default resolver is
used, which looks for a method on `source` of the same name as the field. If found,
the method is called with `(args, context, info)`. Since it is a method on `source`,
@@ -322,10 +322,10 @@ var AddressType = new GraphQLObjectType({
formatted: {
type: GraphQLString,
resolve(obj) {
- return obj.number + ' ' + obj.street
- }
- }
- }
+ return obj.number + ' ' + obj.street;
+ },
+ },
+ },
});
var PersonType = new GraphQLObjectType({
@@ -333,7 +333,7 @@ var PersonType = new GraphQLObjectType({
fields: () => ({
name: { type: GraphQLString },
bestFriend: { type: PersonType },
- })
+ }),
});
```
@@ -363,8 +363,8 @@ when the field is resolved.
var EntityType = new GraphQLInterfaceType({
name: 'Entity',
fields: {
- name: { type: GraphQLString }
- }
+ name: { type: GraphQLString },
+ },
});
```
@@ -394,7 +394,7 @@ to determine which type is actually used when the field is resolved.
```js
var PetType = new GraphQLUnionType({
name: 'Pet',
- types: [ DogType, CatType ],
+ types: [DogType, CatType],
resolveType(value) {
if (value instanceof Dog) {
return DogType;
@@ -402,7 +402,7 @@ var PetType = new GraphQLUnionType({
if (value instanceof Cat) {
return CatType;
}
- }
+ },
});
```
@@ -452,8 +452,8 @@ var RGBType = new GraphQLEnumType({
values: {
RED: { value: 0 },
GREEN: { value: 1 },
- BLUE: { value: 2 }
- }
+ BLUE: { value: 2 },
+ },
});
```
@@ -508,7 +508,7 @@ var GeoPoint = new GraphQLInputObjectType({
lat: { type: new GraphQLNonNull(GraphQLFloat) },
lon: { type: new GraphQLNonNull(GraphQLFloat) },
alt: { type: GraphQLFloat, defaultValue: 0 },
- }
+ },
});
```
@@ -532,7 +532,7 @@ var PersonType = new GraphQLObjectType({
fields: () => ({
parents: { type: new GraphQLList(Person) },
children: { type: new GraphQLList(Person) },
- })
+ }),
});
```
@@ -557,7 +557,7 @@ var RowType = new GraphQLObjectType({
name: 'Row',
fields: () => ({
id: { type: new GraphQLNonNull(String) },
- })
+ }),
});
```
diff --git a/docs/APIReference-Utilities.md b/docs/APIReference-Utilities.md
index 2b0b0625ae..a90f386b58 100644
--- a/docs/APIReference-Utilities.md
+++ b/docs/APIReference-Utilities.md
@@ -17,7 +17,7 @@ var { introspectionQuery } = require('graphql'); // CommonJS
## Overview
-*Introspection*
+_Introspection_
-
@@ -34,7 +34,7 @@ var { introspectionQuery } = require('graphql'); // CommonJS
-*Schema Language*
+_Schema Language_
-
@@ -75,7 +75,7 @@ var { introspectionQuery } = require('graphql'); // CommonJS
-*Visitors*
+_Visitors_
-
@@ -86,7 +86,7 @@ var { introspectionQuery } = require('graphql'); // CommonJS
-*Value Validation*
+_Value Validation_
-
@@ -108,7 +108,7 @@ var { introspectionQuery } = require('graphql'); // CommonJS
### introspectionQuery
```js
-var introspectionQuery: string
+var introspectionQuery: string;
```
A GraphQL query that queries a server's introspection system for enough
@@ -192,6 +192,7 @@ function astFromValue(
type?: ?GraphQLType
): ?Value
```
+
Produces a GraphQL Input Value AST given a JavaScript value.
Optionally, a GraphQL type may be provided, which will be used to
diff --git a/docs/Guides-ConstructingTypes.md b/docs/Guides-ConstructingTypes.md
index 9abd6e100d..b4a5fcb0c0 100644
--- a/docs/Guides-ConstructingTypes.md
+++ b/docs/Guides-ConstructingTypes.md
@@ -30,28 +30,31 @@ var schema = buildSchema(`
// Maps id to User object
var fakeDatabase = {
- 'a': {
+ a: {
id: 'a',
name: 'alice',
},
- 'b': {
+ b: {
id: 'b',
name: 'bob',
},
};
var root = {
- user: function ({id}) {
+ user: function({ id }) {
return fakeDatabase[id];
- }
+ },
};
var app = express();
-app.use('/graphql', graphqlHTTP({
- schema: schema,
- rootValue: root,
- graphiql: true,
-}));
+app.use(
+ '/graphql',
+ graphqlHTTP({
+ schema: schema,
+ rootValue: root,
+ graphiql: true,
+ }),
+);
app.listen(4000);
console.log('Running a GraphQL API server at localhost:4000/graphql');
```
@@ -65,11 +68,11 @@ var graphql = require('graphql');
// Maps id to User object
var fakeDatabase = {
- 'a': {
+ a: {
id: 'a',
name: 'alice',
},
- 'b': {
+ b: {
id: 'b',
name: 'bob',
},
@@ -81,7 +84,7 @@ var userType = new graphql.GraphQLObjectType({
fields: {
id: { type: graphql.GraphQLString },
name: { type: graphql.GraphQLString },
- }
+ },
});
// Define the Query type
@@ -92,22 +95,25 @@ var queryType = new graphql.GraphQLObjectType({
type: userType,
// `args` describes the arguments that the `user` query accepts
args: {
- id: { type: graphql.GraphQLString }
+ id: { type: graphql.GraphQLString },
},
- resolve: function (_, {id}) {
+ resolve: function(_, { id }) {
return fakeDatabase[id];
- }
- }
- }
+ },
+ },
+ },
});
-var schema = new graphql.GraphQLSchema({query: queryType});
+var schema = new graphql.GraphQLSchema({ query: queryType });
var app = express();
-app.use('/graphql', graphqlHTTP({
- schema: schema,
- graphiql: true,
-}));
+app.use(
+ '/graphql',
+ graphqlHTTP({
+ schema: schema,
+ graphiql: true,
+ }),
+);
app.listen(4000);
console.log('Running a GraphQL API server at localhost:4000/graphql');
```
diff --git a/docs/Tutorial-Authentication.md b/docs/Tutorial-Authentication.md
index 2ad93de475..3afe867c97 100644
--- a/docs/Tutorial-Authentication.md
+++ b/docs/Tutorial-Authentication.md
@@ -30,18 +30,21 @@ function loggingMiddleware(req, res, next) {
}
var root = {
- ip: function (args, request) {
+ ip: function(args, request) {
return request.ip;
- }
+ },
};
var app = express();
app.use(loggingMiddleware);
-app.use('/graphql', graphqlHTTP({
- schema: schema,
- rootValue: root,
- graphiql: true,
-}));
+app.use(
+ '/graphql',
+ graphqlHTTP({
+ schema: schema,
+ rootValue: root,
+ graphiql: true,
+ }),
+);
app.listen(4000);
console.log('Running a GraphQL API server at localhost:4000/graphql');
```
diff --git a/docs/Tutorial-BasicTypes.md b/docs/Tutorial-BasicTypes.md
index 4532f03f01..96febfaeac 100644
--- a/docs/Tutorial-BasicTypes.md
+++ b/docs/Tutorial-BasicTypes.md
@@ -44,11 +44,14 @@ var root = {
};
var app = express();
-app.use('/graphql', graphqlHTTP({
- schema: schema,
- rootValue: root,
- graphiql: true,
-}));
+app.use(
+ '/graphql',
+ graphqlHTTP({
+ schema: schema,
+ rootValue: root,
+ graphiql: true,
+ }),
+);
app.listen(4000);
console.log('Running a GraphQL API server at localhost:4000/graphql');
```
diff --git a/docs/Tutorial-ExpressGraphQL.md b/docs/Tutorial-ExpressGraphQL.md
index 6fbfd57c67..b08ee9c70f 100644
--- a/docs/Tutorial-ExpressGraphQL.md
+++ b/docs/Tutorial-ExpressGraphQL.md
@@ -35,11 +35,14 @@ var root = {
};
var app = express();
-app.use('/graphql', graphqlHTTP({
- schema: schema,
- rootValue: root,
- graphiql: true,
-}));
+app.use(
+ '/graphql',
+ graphqlHTTP({
+ schema: schema,
+ rootValue: root,
+ graphiql: true,
+ }),
+);
app.listen(4000);
console.log('Running a GraphQL API server at localhost:4000/graphql');
```
diff --git a/docs/Tutorial-GettingStarted.md b/docs/Tutorial-GettingStarted.md
index 0e492ae00d..bfa4592cce 100644
--- a/docs/Tutorial-GettingStarted.md
+++ b/docs/Tutorial-GettingStarted.md
@@ -40,7 +40,7 @@ var root = {
};
// Run the GraphQL query '{ hello }' and print out the response
-graphql(schema, '{ hello }', root).then((response) => {
+graphql(schema, '{ hello }', root).then(response => {
console.log(response);
});
```
@@ -54,7 +54,11 @@ node server.js
You should see the GraphQL response printed out:
```javascript
-{ data: { hello: 'Hello world!' } }
+{
+ data: {
+ hello: 'Hello world!';
+ }
+}
```
Congratulations - you just executed a GraphQL query!
diff --git a/docs/Tutorial-GraphQLClients.md b/docs/Tutorial-GraphQLClients.md
index 68485e4367..dee39b7c53 100644
--- a/docs/Tutorial-GraphQLClients.md
+++ b/docs/Tutorial-GraphQLClients.md
@@ -32,9 +32,9 @@ fetch('/graphql', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
- 'Accept': 'application/json',
+ Accept: 'application/json',
},
- body: JSON.stringify({query: "{ hello }"})
+ body: JSON.stringify({ query: '{ hello }' }),
})
.then(r => r.json())
.then(data => console.log('data returned:', data));
@@ -69,12 +69,12 @@ fetch('/graphql', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
- 'Accept': 'application/json',
+ Accept: 'application/json',
},
body: JSON.stringify({
query,
variables: { dice, sides },
- })
+ }),
})
.then(r => r.json())
.then(data => console.log('data returned:', data));
diff --git a/docs/Tutorial-Mutations.md b/docs/Tutorial-Mutations.md
index 2ccde6ae68..3fdbd5c918 100644
--- a/docs/Tutorial-Mutations.md
+++ b/docs/Tutorial-Mutations.md
@@ -27,13 +27,13 @@ Both mutations and queries can be handled by root resolvers, so the root that im
```javascript
var fakeDatabase = {};
var root = {
- setMessage: function ({message}) {
+ setMessage: function({ message }) {
fakeDatabase.message = message;
return message;
},
- getMessage: function () {
+ getMessage: function() {
return fakeDatabase.message;
- }
+ },
};
```
@@ -101,7 +101,7 @@ var schema = buildSchema(`
// If Message had any complex fields, we'd put them on this object.
class Message {
- constructor(id, {content, author}) {
+ constructor(id, { content, author }) {
this.id = id;
this.content = content;
this.author = author;
@@ -112,20 +112,22 @@ class Message {
var fakeDatabase = {};
var root = {
- getMessage: function ({id}) {
+ getMessage: function({ id }) {
if (!fakeDatabase[id]) {
throw new Error('no message exists with id ' + id);
}
return new Message(id, fakeDatabase[id]);
},
- createMessage: function ({input}) {
+ createMessage: function({ input }) {
// Create a random id for our "database".
- var id = require('crypto').randomBytes(10).toString('hex');
+ var id = require('crypto')
+ .randomBytes(10)
+ .toString('hex');
fakeDatabase[id] = input;
return new Message(id, input);
},
- updateMessage: function ({id, input}) {
+ updateMessage: function({ id, input }) {
if (!fakeDatabase[id]) {
throw new Error('no message exists with id ' + id);
}
@@ -136,15 +138,17 @@ var root = {
};
var app = express();
-app.use('/graphql', graphqlHTTP({
- schema: schema,
- rootValue: root,
- graphiql: true,
-}));
+app.use(
+ '/graphql',
+ graphqlHTTP({
+ schema: schema,
+ rootValue: root,
+ graphiql: true,
+ }),
+);
app.listen(4000, () => {
console.log('Running a GraphQL API server at localhost:4000/graphql');
});
-
```
To call a mutation, you must use the keyword `mutation` before your GraphQL query. To pass an input type, provide the data written as if it's a JSON object. For example, with the server defined above, you can create a new message and return the `id` of the new message with this operation:
@@ -175,7 +179,7 @@ fetch('/graphql', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
- 'Accept': 'application/json',
+ Accept: 'application/json',
},
body: JSON.stringify({
query,
@@ -183,9 +187,9 @@ fetch('/graphql', {
input: {
author,
content,
- }
- }
- })
+ },
+ },
+ }),
})
.then(r => r.json())
.then(data => console.log('data returned:', data));
diff --git a/docs/Tutorial-ObjectTypes.md b/docs/Tutorial-ObjectTypes.md
index 60a151f3ac..c5b569f292 100644
--- a/docs/Tutorial-ObjectTypes.md
+++ b/docs/Tutorial-ObjectTypes.md
@@ -40,7 +40,7 @@ class RandomDie {
return 1 + Math.floor(Math.random() * this.numSides);
}
- roll({numRolls}) {
+ roll({ numRolls }) {
var output = [];
for (var i = 0; i < numRolls; i++) {
output.push(this.rollOnce());
@@ -50,10 +50,10 @@ class RandomDie {
}
var root = {
- getDie: function ({numSides}) {
+ getDie: function({ numSides }) {
return new RandomDie(numSides || 6);
- }
-}
+ },
+};
```
For fields that don't use any arguments, you can use either properties on the object or instance methods. So for the example code above, both `numSides` and `rollOnce` can actually be used to implement GraphQL fields, so that code also implements the schema of:
@@ -100,7 +100,7 @@ class RandomDie {
return 1 + Math.floor(Math.random() * this.numSides);
}
- roll({numRolls}) {
+ roll({ numRolls }) {
var output = [];
for (var i = 0; i < numRolls; i++) {
output.push(this.rollOnce());
@@ -111,17 +111,20 @@ class RandomDie {
// The root provides the top-level API endpoints
var root = {
- getDie: function ({numSides}) {
+ getDie: function({ numSides }) {
return new RandomDie(numSides || 6);
- }
-}
+ },
+};
var app = express();
-app.use('/graphql', graphqlHTTP({
- schema: schema,
- rootValue: root,
- graphiql: true,
-}));
+app.use(
+ '/graphql',
+ graphqlHTTP({
+ schema: schema,
+ rootValue: root,
+ graphiql: true,
+ }),
+);
app.listen(4000);
console.log('Running a GraphQL API server at localhost:4000/graphql');
```
diff --git a/docs/Tutorial-PassingArguments.md b/docs/Tutorial-PassingArguments.md
index 47154b488b..1660b43425 100644
--- a/docs/Tutorial-PassingArguments.md
+++ b/docs/Tutorial-PassingArguments.md
@@ -28,13 +28,13 @@ So far, our resolver functions took no arguments. When a resolver takes argument
```javascript
var root = {
- rollDice: function (args) {
+ rollDice: function(args) {
var output = [];
for (var i = 0; i < args.numDice; i++) {
output.push(1 + Math.floor(Math.random() * (args.numSides || 6)));
}
return output;
- }
+ },
};
```
@@ -42,13 +42,13 @@ It's convenient to use [ES6 destructuring assignment](https://developer.mozilla.
```javascript
var root = {
- rollDice: function ({numDice, numSides}) {
+ rollDice: function({ numDice, numSides }) {
var output = [];
for (var i = 0; i < numDice; i++) {
output.push(1 + Math.floor(Math.random() * (numSides || 6)));
}
return output;
- }
+ },
};
```
@@ -70,21 +70,24 @@ var schema = buildSchema(`
// The root provides a resolver function for each API endpoint
var root = {
- rollDice: function ({numDice, numSides}) {
+ rollDice: function({ numDice, numSides }) {
var output = [];
for (var i = 0; i < numDice; i++) {
output.push(1 + Math.floor(Math.random() * (numSides || 6)));
}
return output;
- }
+ },
};
var app = express();
-app.use('/graphql', graphqlHTTP({
- schema: schema,
- rootValue: root,
- graphiql: true,
-}));
+app.use(
+ '/graphql',
+ graphqlHTTP({
+ schema: schema,
+ rootValue: root,
+ graphiql: true,
+ }),
+);
app.listen(4000);
console.log('Running a GraphQL API server at localhost:4000/graphql');
```
@@ -114,12 +117,12 @@ fetch('/graphql', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
- 'Accept': 'application/json',
+ Accept: 'application/json',
},
body: JSON.stringify({
query,
variables: { dice, sides },
- })
+ }),
})
.then(r => r.json())
.then(data => console.log('data returned:', data));
diff --git a/package.json b/package.json
index c635dadfbb..358c118da4 100644
--- a/package.json
+++ b/package.json
@@ -23,13 +23,14 @@
"node": ">= 6.x"
},
"scripts": {
- "test": "npm run lint && npm run check && npm run testonly",
- "test:ci": "yarn check --integrity && npm run lint -- --no-cache && npm run check && npm run testonly:cover && npm run build",
+ "test": "npm run prettier:check && npm run lint && npm run check && npm run testonly",
+ "test:ci": "yarn check --integrity && npm run prettier:check && npm run lint -- --no-cache && npm run check && npm run testonly:cover && npm run build",
"testonly": "mocha --full-trace src/**/__tests__/**/*-test.js",
"testonly:cover": "nyc npm run testonly",
"lint": "eslint --cache --report-unused-disable-directives src resources",
"benchmark": "node ./resources/benchmark.js",
- "prettier": "prettier --write --list-different 'src/**/*.js' 'resources/**/*.js'",
+ "prettier": "prettier --ignore-path .gitignore --write --list-different '**/*.{js,md,json,yml}'",
+ "prettier:check": "prettier --ignore-path .gitignore --check '**/*.{js,md,json,yml}'",
"check": "flow check",
"check:cover": "node resources/check-cover.js && nyc report --nycrc-path .nycflowrc.yml",
"build": "node resources/build.js",
@@ -52,7 +53,6 @@
"chai": "4.2.0",
"eslint": "5.16.0",
"eslint-plugin-flowtype": "3.11.1",
- "eslint-plugin-prettier": "3.1.0",
"flow-bin": "0.102.0",
"mocha": "6.1.4",
"nyc": "14.1.1",
diff --git a/src/README.md b/src/README.md
index ae57712060..4fa588f20a 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.
@@ -11,14 +10,14 @@ var GraphQL = require('graphql'); // CommonJS
Each sub directory within is a sub-module of graphql-js:
-* [`graphql/language`](language/README.md): Parse and operate on the GraphQL
+- [`graphql/language`](language/README.md): Parse and operate on the GraphQL
language.
-* [`graphql/type`](type/README.md): Define GraphQL types and schema.
-* [`graphql/validation`](validation/README.md): The Validation phase of
+- [`graphql/type`](type/README.md): Define GraphQL types and schema.
+- [`graphql/validation`](validation/README.md): The Validation phase of
fulfilling a GraphQL result.
-* [`graphql/execution`](execution/README.md): The Execution phase of fulfilling
+- [`graphql/execution`](execution/README.md): The Execution phase of fulfilling
a GraphQL request.
-* [`graphql/error`](error/README.md): Creating and formating GraphQL errors.
-* [`graphql/utilities`](utilities/README.md): Common useful computations upon
+- [`graphql/error`](error/README.md): Creating and formating GraphQL errors.
+- [`graphql/utilities`](utilities/README.md): Common useful computations upon
the GraphQL language and type objects.
-* [`graphql/subscription`](subscription/README.md): Subscribe to data updates.
+- [`graphql/subscription`](subscription/README.md): Subscribe to data updates.
diff --git a/src/__fixtures__/github-schema.json b/src/__fixtures__/github-schema.json
index 2ac97ffd9c..7352a87fa3 100644
--- a/src/__fixtures__/github-schema.json
+++ b/src/__fixtures__/github-schema.json
@@ -56774,11 +56774,7 @@
{
"name": "include",
"description": "Directs the executor to include this field or fragment only when the `if` argument is true.",
- "locations": [
- "FIELD",
- "FRAGMENT_SPREAD",
- "INLINE_FRAGMENT"
- ],
+ "locations": ["FIELD", "FRAGMENT_SPREAD", "INLINE_FRAGMENT"],
"args": [
{
"name": "if",
@@ -56799,11 +56795,7 @@
{
"name": "skip",
"description": "Directs the executor to skip this field or fragment when the `if` argument is true.",
- "locations": [
- "FIELD",
- "FRAGMENT_SPREAD",
- "INLINE_FRAGMENT"
- ],
+ "locations": ["FIELD", "FRAGMENT_SPREAD", "INLINE_FRAGMENT"],
"args": [
{
"name": "if",
@@ -56824,10 +56816,7 @@
{
"name": "deprecated",
"description": "Marks an element of a GraphQL schema as no longer supported.",
- "locations": [
- "FIELD_DEFINITION",
- "ENUM_VALUE"
- ],
+ "locations": ["FIELD_DEFINITION", "ENUM_VALUE"],
"args": [
{
"name": "reason",
diff --git a/src/error/README.md b/src/error/README.md
index 8ecc8303ad..750c351033 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 formatting
GraphQL errors.
diff --git a/src/execution/README.md b/src/execution/README.md
index 7b875646ee..6540f323fe 100644
--- a/src/execution/README.md
+++ b/src/execution/README.md
@@ -1,5 +1,4 @@
-GraphQL Execution
------------------
+## GraphQL Execution
The `graphql/execution` module is responsible for the execution phase of
fulfilling a GraphQL request.
diff --git a/src/jsutils/README.md b/src/jsutils/README.md
index 8c1e5f97d3..9eb96485e1 100644
--- a/src/jsutils/README.md
+++ b/src/jsutils/README.md
@@ -1,5 +1,4 @@
-JavaScript Utils
-----------------
+## JavaScript Utils
This directory contains dependency-free JavaScript utility functions used
throughout the codebase.
diff --git a/src/language/README.md b/src/language/README.md
index d5043f482c..68cc9fd4a7 100644
--- a/src/language/README.md
+++ b/src/language/README.md
@@ -1,5 +1,4 @@
-GraphQL Language
-----------------
+## GraphQL Language
The `graphql/language` module is responsible for parsing and operating on the
GraphQL language.
diff --git a/src/polyfills/README.md b/src/polyfills/README.md
index 55054b2312..20c9f6ee58 100644
--- a/src/polyfills/README.md
+++ b/src/polyfills/README.md
@@ -1,5 +1,4 @@
-Polyfills
----------
+## Polyfills
This directory contains dependency-free polyfills for ES6 & ES7 functions used
throughout the codebase.
diff --git a/src/subscription/README.md b/src/subscription/README.md
index dd47efaf54..c938354c2b 100644
--- a/src/subscription/README.md
+++ b/src/subscription/README.md
@@ -1,5 +1,4 @@
-GraphQL Subscription
------------------
+## GraphQL Subscription
The `graphql/subscription` module is responsible for subscribing to updates on specific data.
diff --git a/src/type/README.md b/src/type/README.md
index 9fd9e8a802..1c03491a3a 100644
--- a/src/type/README.md
+++ b/src/type/README.md
@@ -1,5 +1,4 @@
-GraphQL Type System
--------------------
+## GraphQL Type System
The `graphql/type` module is responsible for defining GraphQL types and schema.
diff --git a/src/utilities/README.md b/src/utilities/README.md
index a48dfce7da..0e626e2325 100644
--- a/src/utilities/README.md
+++ b/src/utilities/README.md
@@ -1,5 +1,4 @@
-GraphQL Utilities
------------------
+## GraphQL Utilities
The `graphql/utilities` module contains common useful computations to use with
the GraphQL language and type objects.
diff --git a/src/validation/README.md b/src/validation/README.md
index ad4a486c58..8a4a1c85f0 100644
--- a/src/validation/README.md
+++ b/src/validation/README.md
@@ -1,5 +1,4 @@
-GraphQL Validation
-------------------
+## GraphQL Validation
The `graphql/validation` module fulfills the Validation phase of fulfilling a
GraphQL result.
diff --git a/yarn.lock b/yarn.lock
index c12e1d923b..d42cb20d2e 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -1103,13 +1103,6 @@ eslint-plugin-flowtype@3.11.1:
dependencies:
lodash "^4.17.11"
-eslint-plugin-prettier@3.1.0:
- version "3.1.0"
- resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-3.1.0.tgz#8695188f95daa93b0dc54b249347ca3b79c4686d"
- integrity sha512-XWX2yVuwVNLOUhQijAkXz+rMPPoCr7WFiAl8ig6I7Xn+pPVhDhzg4DxHpmbeb0iqjO9UronEA3Tb09ChnFVHHA==
- dependencies:
- prettier-linter-helpers "^1.0.0"
-
eslint-scope@3.7.1:
version "3.7.1"
resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-3.7.1.tgz#3d63c3edfda02e06e01a452ad88caacc7cdcb6e8"
@@ -1243,11 +1236,6 @@ fast-deep-equal@^2.0.1:
resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz#7b05218ddf9667bf7f370bf7fdb2cb15fdd0aa49"
integrity sha1-ewUhjd+WZ79/Nwv3/bLLFf3Qqkk=
-fast-diff@^1.1.2:
- version "1.2.0"
- resolved "https://registry.yarnpkg.com/fast-diff/-/fast-diff-1.2.0.tgz#73ee11982d86caaf7959828d519cfe927fac5f03"
- integrity sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w==
-
fast-json-stable-stringify@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz#d5142c0caee6b1189f87d3a76111064f86c8bbf2"
@@ -2153,13 +2141,6 @@ prelude-ls@~1.1.2:
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"
integrity sha1-IZMqVJ9eUv/ZqCf1cOBL5iqX2lQ=
-prettier-linter-helpers@^1.0.0:
- version "1.0.0"
- resolved "https://registry.yarnpkg.com/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz#d23d41fe1375646de2d0104d3454a3008802cf7b"
- integrity sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==
- dependencies:
- fast-diff "^1.1.2"
-
prettier@1.18.2:
version "1.18.2"
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.18.2.tgz#6823e7c5900017b4bd3acf46fe9ac4b4d7bda9ea"