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

APIReference-GraphQL.md #59

Merged
merged 2 commits into from
Aug 9, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 32 additions & 41 deletions site/graphql-js/APIReference-GraphQL.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,139 +6,137 @@ 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.
`graphql` 模块导出了 GraphQL 的一个核心子集,其主要功能是创建 GraphQL 的类型系统和服务。

```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.
根据 schema 对一个 GraphQL 请求进行词法分析、解析、验证及执行。
</a>
</li>
</ul>

*Schema*
**Schema**

<ul class="apiIndex">
<li>
<a href="../type/#graphqlschema">
<pre>class GraphQLSchema</pre>
A representation of the capabilities of a GraphQL Server.
一个 GraphQL 服务的功能配置描述
</a>
</li>
</ul>

*Type Definitions*
**类型定义**

<ul class="apiIndex">
<li>
<a href="../type/#graphqlscalartype">
<pre>class GraphQLScalarType</pre>
A scalar type within GraphQL.
GraphQL 里的标量类型。
</a>
</li>
<li>
<a href="../type/#graphqlobjecttype">
<pre>class GraphQLObjectType</pre>
An object type within GraphQL that contains fields.
GraphQL 里的自定义对象类型,包含一个 fields 字段。
</a>
</li>
<li>
<a href="../type/#graphqlinterfacetype">
<pre>class GraphQLInterfaceType</pre>
An interface type within GraphQL that defines fields implementations will contain.
GraphQL 里的接口类型,定义多个类型中通用的字段。
</a>
</li>
<li>
<a href="../type/#graphqluniontype">
<pre>class GraphQLUnionType</pre>
A union type within GraphQL that defines a list of implementations.
GraphQL 里的联合类型,定义了(某个字段能支持的所有返回类型的)一个实现列表。
</a>
</li>
<li>
<a href="../type/#graphqlenumtype">
<pre>class GraphQLEnumType</pre>
An enum type within GraphQL that defines a list of valid values.
GraphQL 里的枚举类型,定义了一个有效(可枚举)数据类型的列表。
</a>
</li>
<li>
<a href="../type/#graphqlinputobjecttype">
<pre>class GraphQLInputObjectType</pre>
An input object type within GraphQL that represents structured inputs.
GraphQL 里的输入对象类型,表示一些结构化的输入。
</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.
表示 ID 值的标量类型。
</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

Expand All @@ -153,27 +151,20 @@ graphql(
): 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.
`graphql` 方法可以对一个 GraphQL 请求进行词法分析、解析、验证和执行。必要的参数是 `schema` 和 `requestString`,可选的参数则包括 `rootValue`(将作为根值传入执行器方法)、`contextValue`(将传入所有的解析函数)、`variableValues`(将传入执行器方法,为 `requestString` 中的任意类型变量赋值)以及 `operationName`(在 `requestString` 包含多个顶级操作的情况下,这个参数允许调用函数指定 `requestString` 运行哪个操作)。
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议这一行上面加一个空行,和上面的代码段区分开。


## Schema

See the [Type System API Reference](../type#schema).
详细介绍请看 [类型系统 API 参考](../type#schema)

## Type Definitions
## 类型定义

See the [Type System API Reference](../type#definitions).
详细介绍请看 [类型系统 API 参考](../type#definitions)

## Scalars
## 标量类型

See the [Type System API Reference](../type#scalars).
详细介绍请看 [类型系统 API 参考](../type#scalars)

## Errors
## 错误信息

See the [Errors API Reference](../error)
详细介绍请看 [错误信息 API 参考](../error)