Skip to content

Commit 31f7447

Browse files
1 parent 86cfa21 commit 31f7447

17 files changed

+2571
-0
lines changed

docs/APIReference-Errors.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
---
2+
title: graphql/error
3+
layout: ../_core/GraphQLJSLayout
4+
category: API Reference
5+
permalink: /graphql-js/error/
6+
sublinks: formatError,GraphQLError,locatedError,syntaxError
7+
next: /graphql-js/execution/
8+
---
9+
10+
The `graphql/error` module is responsible for creating and formatting
11+
GraphQL errors. You can import either from the `graphql/error` module, or from the root `graphql` module. For example:
12+
13+
```js
14+
import { GraphQLError } from 'graphql'; // ES6
15+
var { GraphQLError } = require('graphql'); // CommonJS
16+
```
17+
18+
## Overview
19+
20+
<ul class="apiIndex">
21+
<li>
22+
<a href="#graphqlerror">
23+
<pre>class GraphQLError</pre>
24+
A representation of an error that occurred within GraphQL.
25+
</a>
26+
</li>
27+
<li>
28+
<a href="#syntaxerror">
29+
<pre>function syntaxError</pre>
30+
Produces a GraphQLError representing a syntax error.
31+
</a>
32+
</li>
33+
<li>
34+
<a href="#locatedError">
35+
<pre>function locatedError</pre>
36+
Produces a new GraphQLError aware of the location responsible for the error.
37+
</a>
38+
</li>
39+
<li>
40+
<a href="#formaterror">
41+
<pre>function formatError</pre>
42+
Format an error according to the rules described by the Response Format.
43+
</a>
44+
</li>
45+
</ul>
46+
47+
## Errors
48+
49+
### GraphQLError
50+
51+
```js
52+
class GraphQLError extends Error {
53+
constructor(
54+
message: string,
55+
nodes?: Array<any>,
56+
stack?: ?string,
57+
source?: Source,
58+
positions?: Array<number>,
59+
originalError?: ?Error,
60+
extensions?: ?{ [key: string]: mixed }
61+
)
62+
}
63+
```
64+
65+
A representation of an error that occurred within GraphQL. Contains
66+
information about where in the query the error occurred for debugging. Most
67+
commonly constructed with `locatedError` below.
68+
69+
### syntaxError
70+
71+
```js
72+
function syntaxError(
73+
source: Source,
74+
position: number,
75+
description: string
76+
): GraphQLError;
77+
```
78+
79+
Produces a GraphQLError representing a syntax error, containing useful
80+
descriptive information about the syntax error's position in the source.
81+
82+
### locatedError
83+
84+
```js
85+
function locatedError(error: ?Error, nodes: Array<any>): GraphQLError {
86+
```
87+
88+
Given an arbitrary Error, presumably thrown while attempting to execute a
89+
GraphQL operation, produce a new GraphQLError aware of the location in the
90+
document responsible for the original Error.
91+
92+
### formatError
93+
94+
```js
95+
function formatError(error: GraphQLError): GraphQLFormattedError
96+
97+
type GraphQLFormattedError = {
98+
message: string,
99+
locations: ?Array<GraphQLErrorLocation>
100+
};
101+
102+
type GraphQLErrorLocation = {
103+
line: number,
104+
column: number
105+
};
106+
```
107+
108+
Given a GraphQLError, format it according to the rules described by the
109+
Response Format, Errors section of the GraphQL Specification.

docs/APIReference-Execution.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
---
2+
title: graphql/execution
3+
layout: ../_core/GraphQLJSLayout
4+
category: API Reference
5+
permalink: /graphql-js/execution/
6+
sublinks: execute
7+
next: /graphql-js/language/
8+
---
9+
10+
The `graphql/execution` module is responsible for the execution phase of
11+
fulfilling a GraphQL request. You can import either from the `graphql/execution` module, or from the root `graphql` module. For example:
12+
13+
```js
14+
import { execute } from 'graphql'; // ES6
15+
var { execute } = require('graphql'); // CommonJS
16+
```
17+
18+
## Overview
19+
20+
<ul class="apiIndex">
21+
<li>
22+
<a href="#execute">
23+
<pre>function execute</pre>
24+
Executes a GraphQL request on the provided schema.
25+
</a>
26+
</li>
27+
</ul>
28+
29+
## Execution
30+
31+
### execute
32+
33+
```js
34+
export function execute(
35+
schema: GraphQLSchema,
36+
documentAST: Document,
37+
rootValue?: mixed,
38+
contextValue?: mixed,
39+
variableValues?: ?{[key: string]: mixed},
40+
operationName?: ?string
41+
): MaybePromise<ExecutionResult>
42+
43+
type MaybePromise<T> = Promise<T> | T;
44+
45+
type ExecutionResult = {
46+
data: ?Object;
47+
errors?: Array<GraphQLError>;
48+
}
49+
```
50+
51+
Implements the "Evaluating requests" section of the GraphQL specification.
52+
53+
Returns a Promise that will eventually be resolved and never rejected.
54+
55+
If the arguments to this function do not result in a legal execution context,
56+
a GraphQLError will be thrown immediately explaining the invalid input.
57+
58+
`ExecutionResult` represents the result of execution. `data` is the result of
59+
executing the query, `errors` is null if no errors occurred, and is a
60+
non-empty array if an error occurred.

docs/APIReference-ExpressGraphQL.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
title: express-graphql
3+
layout: ../_core/GraphQLJSLayout
4+
category: API Reference
5+
permalink: /graphql-js/express-graphql/
6+
sublinks: graphqlHTTP
7+
next: /graphql-js/graphql/
8+
---
9+
10+
The `express-graphql` module provides a simple way to create an [Express](https://expressjs.com/) server that runs a GraphQL API.
11+
12+
```js
13+
import graphqlHTTP from 'express-graphql'; // ES6
14+
var graphqlHTTP = require('express-graphql'); // CommonJS
15+
```
16+
17+
### graphqlHTTP
18+
19+
```js
20+
graphqlHTTP({
21+
schema: GraphQLSchema,
22+
graphiql?: ?boolean,
23+
rootValue?: ?any,
24+
context?: ?any,
25+
pretty?: ?boolean,
26+
formatError?: ?Function,
27+
validationRules?: ?Array<any>,
28+
}): Middleware
29+
```
30+
31+
Constructs an Express application based on a GraphQL schema.
32+
33+
See the [express-graphql tutorial](/graphql-js/running-an-express-graphql-server/) for sample usage.
34+
35+
See the [GitHub README](https://github.com/graphql/express-graphql) for more extensive documentation of the details of this method.

docs/APIReference-GraphQL.md

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
---
2+
title: graphql
3+
layout: ../_core/GraphQLJSLayout
4+
category: API Reference
5+
permalink: /graphql-js/graphql/
6+
sublinks: graphql
7+
next: /graphql-js/error/
8+
---
9+
10+
The `graphql` module exports a core subset of GraphQL functionality for creation
11+
of GraphQL type systems and servers.
12+
13+
```js
14+
import { graphql } from 'graphql'; // ES6
15+
var { graphql } = require('graphql'); // CommonJS
16+
```
17+
18+
## Overview
19+
20+
*Entry Point*
21+
22+
<ul class="apiIndex">
23+
<li>
24+
<a href="#graphql">
25+
<pre>function graphql</pre>
26+
Lexes, parses, validates, and executes a GraphQL request on a schema.
27+
</a>
28+
</li>
29+
</ul>
30+
31+
*Schema*
32+
33+
<ul class="apiIndex">
34+
<li>
35+
<a href="../type/#graphqlschema">
36+
<pre>class GraphQLSchema</pre>
37+
A representation of the capabilities of a GraphQL Server.
38+
</a>
39+
</li>
40+
</ul>
41+
42+
*Type Definitions*
43+
44+
<ul class="apiIndex">
45+
<li>
46+
<a href="../type/#graphqlscalartype">
47+
<pre>class GraphQLScalarType</pre>
48+
A scalar type within GraphQL.
49+
</a>
50+
</li>
51+
<li>
52+
<a href="../type/#graphqlobjecttype">
53+
<pre>class GraphQLObjectType</pre>
54+
An object type within GraphQL that contains fields.
55+
</a>
56+
</li>
57+
<li>
58+
<a href="../type/#graphqlinterfacetype">
59+
<pre>class GraphQLInterfaceType</pre>
60+
An interface type within GraphQL that defines fields implementations will contain.
61+
</a>
62+
</li>
63+
<li>
64+
<a href="../type/#graphqluniontype">
65+
<pre>class GraphQLUnionType</pre>
66+
A union type within GraphQL that defines a list of implementations.
67+
</a>
68+
</li>
69+
<li>
70+
<a href="../type/#graphqlenumtype">
71+
<pre>class GraphQLEnumType</pre>
72+
An enum type within GraphQL that defines a list of valid values.
73+
</a>
74+
</li>
75+
<li>
76+
<a href="../type/#graphqlinputobjecttype">
77+
<pre>class GraphQLInputObjectType</pre>
78+
An input object type within GraphQL that represents structured inputs.
79+
</a>
80+
</li>
81+
<li>
82+
<a href="../type/#graphqllist">
83+
<pre>class GraphQLList</pre>
84+
A type wrapper around other types that represents a list of those types.
85+
</a>
86+
</li>
87+
<li>
88+
<a href="../type/#graphqlnonnull">
89+
<pre>class GraphQLNonNull</pre>
90+
A type wrapper around other types that represents a non-null version of those types.
91+
</a>
92+
</li>
93+
</ul>
94+
95+
*Scalars*
96+
97+
<ul class="apiIndex">
98+
<li>
99+
<a href="../type/#graphqlint">
100+
<pre>var GraphQLInt</pre>
101+
A scalar type representing integers.
102+
</a>
103+
</li>
104+
<li>
105+
<a href="../type/#graphqlfloat">
106+
<pre>var GraphQLFloat</pre>
107+
A scalar type representing floats.
108+
</a>
109+
</li>
110+
<li>
111+
<a href="../type/#graphqlstring">
112+
<pre>var GraphQLString</pre>
113+
A scalar type representing strings.
114+
</a>
115+
</li>
116+
<li>
117+
<a href="../type/#graphqlboolean">
118+
<pre>var GraphQLBoolean</pre>
119+
A scalar type representing booleans.
120+
</a>
121+
</li>
122+
<li>
123+
<a href="../type/#graphqlid">
124+
<pre>var GraphQLID</pre>
125+
A scalar type representing IDs.
126+
</a>
127+
</li>
128+
</ul>
129+
130+
*Errors*
131+
132+
<ul class="apiIndex">
133+
<li>
134+
<a href="../error/#formaterror">
135+
<pre>function formatError</pre>
136+
Format an error according to the rules described by the Response Format.
137+
</a>
138+
</li>
139+
</ul>
140+
141+
## Entry Point
142+
143+
### graphql
144+
145+
```js
146+
graphql(
147+
schema: GraphQLSchema,
148+
requestString: string,
149+
rootValue?: ?any,
150+
contextValue?: ?any,
151+
variableValues?: ?{[key: string]: any},
152+
operationName?: ?string
153+
): Promise<GraphQLResult>
154+
```
155+
156+
The `graphql` function lexes, parses, validates and executes a GraphQL request.
157+
It requires a `schema` and a `requestString`. Optional arguments include a
158+
`rootValue`, which will get passed as the root value to the executor, a `contextValue`,
159+
which will get passed to all resolve functions,
160+
`variableValues`, which will get passed to the executor to provide values for
161+
any variables in `requestString`, and `operationName`, which allows the caller
162+
to specify which operation in `requestString` will be run, in cases where
163+
`requestString` contains multiple top-level operations.
164+
165+
## Schema
166+
167+
See the [Type System API Reference](../type#schema).
168+
169+
## Type Definitions
170+
171+
See the [Type System API Reference](../type#definitions).
172+
173+
## Scalars
174+
175+
See the [Type System API Reference](../type#scalars).
176+
177+
## Errors
178+
179+
See the [Errors API Reference](../error)

0 commit comments

Comments
 (0)