Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Copy 'site/graphql-js' folder from 'graphql.github.io' repo #1923

Merged
merged 1 commit into from May 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
109 changes: 109 additions & 0 deletions docs/APIReference-Errors.md
@@ -0,0 +1,109 @@
---
title: graphql/error
layout: ../_core/GraphQLJSLayout
category: API Reference
permalink: /graphql-js/error/
sublinks: formatError,GraphQLError,locatedError,syntaxError
next: /graphql-js/execution/
---

The `graphql/error` module is responsible for creating and formatting
GraphQL errors. You can import either from the `graphql/error` module, or from the root `graphql` module. For example:

```js
import { GraphQLError } from 'graphql'; // ES6
var { GraphQLError } = require('graphql'); // CommonJS
```

## Overview

<ul class="apiIndex">
<li>
<a href="#graphqlerror">
<pre>class GraphQLError</pre>
A representation of an error that occurred within GraphQL.
</a>
</li>
<li>
<a href="#syntaxerror">
<pre>function syntaxError</pre>
Produces a GraphQLError representing a syntax error.
</a>
</li>
<li>
<a href="#locatedError">
<pre>function locatedError</pre>
Produces a new GraphQLError aware of the location responsible for the error.
</a>
</li>
<li>
<a href="#formaterror">
<pre>function formatError</pre>
Format an error according to the rules described by the Response Format.
</a>
</li>
</ul>

## Errors

### GraphQLError

```js
class GraphQLError extends Error {
constructor(
message: string,
nodes?: Array<any>,
stack?: ?string,
source?: Source,
positions?: Array<number>,
originalError?: ?Error,
extensions?: ?{ [key: string]: mixed }
)
}
```

A representation of an error that occurred within GraphQL. Contains
information about where in the query the error occurred for debugging. Most
commonly constructed with `locatedError` below.

### syntaxError

```js
function syntaxError(
source: Source,
position: number,
description: string
): GraphQLError;
```

Produces a GraphQLError representing a syntax error, containing useful
descriptive information about the syntax error's position in the source.

### locatedError

```js
function locatedError(error: ?Error, nodes: Array<any>): GraphQLError {
```

Given an arbitrary Error, presumably thrown while attempting to execute a
GraphQL operation, produce a new GraphQLError aware of the location in the
document responsible for the original Error.

### formatError

```js
function formatError(error: GraphQLError): GraphQLFormattedError

type GraphQLFormattedError = {
message: string,
locations: ?Array<GraphQLErrorLocation>
};

type GraphQLErrorLocation = {
line: number,
column: number
};
```

Given a GraphQLError, format it according to the rules described by the
Response Format, Errors section of the GraphQL Specification.
60 changes: 60 additions & 0 deletions docs/APIReference-Execution.md
@@ -0,0 +1,60 @@
---
title: graphql/execution
layout: ../_core/GraphQLJSLayout
category: API Reference
permalink: /graphql-js/execution/
sublinks: execute
next: /graphql-js/language/
---

The `graphql/execution` module is responsible for the execution phase of
fulfilling a GraphQL request. You can import either from the `graphql/execution` module, or from the root `graphql` module. For example:

```js
import { execute } from 'graphql'; // ES6
var { execute } = require('graphql'); // CommonJS
```

## Overview

<ul class="apiIndex">
<li>
<a href="#execute">
<pre>function execute</pre>
Executes a GraphQL request on the provided schema.
</a>
</li>
</ul>

## Execution

### execute

```js
export function execute(
schema: GraphQLSchema,
documentAST: Document,
rootValue?: mixed,
contextValue?: mixed,
variableValues?: ?{[key: string]: mixed},
operationName?: ?string
): MaybePromise<ExecutionResult>

type MaybePromise<T> = Promise<T> | T;

type ExecutionResult = {
data: ?Object;
errors?: Array<GraphQLError>;
}
```

Implements the "Evaluating requests" section of the GraphQL specification.

Returns a Promise that will eventually be resolved and never rejected.

If the arguments to this function do not result in a legal execution context,
a GraphQLError will be thrown immediately explaining the invalid input.

`ExecutionResult` represents the result of execution. `data` is the result of
executing the query, `errors` is null if no errors occurred, and is a
non-empty array if an error occurred.
35 changes: 35 additions & 0 deletions docs/APIReference-ExpressGraphQL.md
@@ -0,0 +1,35 @@
---
title: express-graphql
layout: ../_core/GraphQLJSLayout
category: API Reference
permalink: /graphql-js/express-graphql/
sublinks: graphqlHTTP
next: /graphql-js/graphql/
---

The `express-graphql` module provides a simple way to create an [Express](https://expressjs.com/) server that runs a GraphQL API.

```js
import graphqlHTTP from 'express-graphql'; // ES6
var graphqlHTTP = require('express-graphql'); // CommonJS
```

### graphqlHTTP

```js
graphqlHTTP({
schema: GraphQLSchema,
graphiql?: ?boolean,
rootValue?: ?any,
context?: ?any,
pretty?: ?boolean,
formatError?: ?Function,
validationRules?: ?Array<any>,
}): Middleware
```

Constructs an Express application based on a GraphQL schema.

See the [express-graphql tutorial](/graphql-js/running-an-express-graphql-server/) for sample usage.

See the [GitHub README](https://github.com/graphql/express-graphql) for more extensive documentation of the details of this method.
179 changes: 179 additions & 0 deletions docs/APIReference-GraphQL.md
@@ -0,0 +1,179 @@
---
title: graphql
layout: ../_core/GraphQLJSLayout
category: API Reference
permalink: /graphql-js/graphql/
sublinks: graphql
next: /graphql-js/error/
---

The `graphql` module exports a core subset of GraphQL functionality for creation
of GraphQL type systems and servers.

```js
import { graphql } from 'graphql'; // ES6
var { graphql } = require('graphql'); // CommonJS
```

## Overview

*Entry Point*

<ul class="apiIndex">
<li>
<a href="#graphql">
<pre>function graphql</pre>
Lexes, parses, validates, and executes a GraphQL request on a schema.
</a>
</li>
</ul>

*Schema*

<ul class="apiIndex">
<li>
<a href="../type/#graphqlschema">
<pre>class GraphQLSchema</pre>
A representation of the capabilities of a GraphQL Server.
</a>
</li>
</ul>

*Type Definitions*

<ul class="apiIndex">
<li>
<a href="../type/#graphqlscalartype">
<pre>class GraphQLScalarType</pre>
A scalar type within GraphQL.
</a>
</li>
<li>
<a href="../type/#graphqlobjecttype">
<pre>class GraphQLObjectType</pre>
An object type within GraphQL that contains fields.
</a>
</li>
<li>
<a href="../type/#graphqlinterfacetype">
<pre>class GraphQLInterfaceType</pre>
An interface type within GraphQL that defines fields implementations will contain.
</a>
</li>
<li>
<a href="../type/#graphqluniontype">
<pre>class GraphQLUnionType</pre>
A union type within GraphQL that defines a list of implementations.
</a>
</li>
<li>
<a href="../type/#graphqlenumtype">
<pre>class GraphQLEnumType</pre>
An enum type within GraphQL that defines a list of valid values.
</a>
</li>
<li>
<a href="../type/#graphqlinputobjecttype">
<pre>class GraphQLInputObjectType</pre>
An input object type within GraphQL that represents structured inputs.
</a>
</li>
<li>
<a href="../type/#graphqllist">
<pre>class GraphQLList</pre>
A type wrapper around other types that represents a list of those types.
</a>
</li>
<li>
<a href="../type/#graphqlnonnull">
<pre>class GraphQLNonNull</pre>
A type wrapper around other types that represents a non-null version of those types.
</a>
</li>
</ul>

*Scalars*

<ul class="apiIndex">
<li>
<a href="../type/#graphqlint">
<pre>var GraphQLInt</pre>
A scalar type representing integers.
</a>
</li>
<li>
<a href="../type/#graphqlfloat">
<pre>var GraphQLFloat</pre>
A scalar type representing floats.
</a>
</li>
<li>
<a href="../type/#graphqlstring">
<pre>var GraphQLString</pre>
A scalar type representing strings.
</a>
</li>
<li>
<a href="../type/#graphqlboolean">
<pre>var GraphQLBoolean</pre>
A scalar type representing booleans.
</a>
</li>
<li>
<a href="../type/#graphqlid">
<pre>var GraphQLID</pre>
A scalar type representing IDs.
</a>
</li>
</ul>

*Errors*

<ul class="apiIndex">
<li>
<a href="../error/#formaterror">
<pre>function formatError</pre>
Format an error according to the rules described by the Response Format.
</a>
</li>
</ul>

## Entry Point

### graphql

```js
graphql(
schema: GraphQLSchema,
requestString: string,
rootValue?: ?any,
contextValue?: ?any,
variableValues?: ?{[key: string]: any},
operationName?: ?string
): Promise<GraphQLResult>
```

The `graphql` function lexes, parses, validates and executes a GraphQL request.
It requires a `schema` and a `requestString`. Optional arguments include a
`rootValue`, which will get passed as the root value to the executor, a `contextValue`,
which will get passed to all resolve functions,
`variableValues`, which will get passed to the executor to provide values for
any variables in `requestString`, and `operationName`, which allows the caller
to specify which operation in `requestString` will be run, in cases where
`requestString` contains multiple top-level operations.

## Schema

See the [Type System API Reference](../type#schema).

## Type Definitions

See the [Type System API Reference](../type#definitions).

## Scalars

See the [Type System API Reference](../type#scalars).

## Errors

See the [Errors API Reference](../error)