@@ -6,139 +6,137 @@ permalink: /graphql-js/graphql/
6
6
sublinks : graphql
7
7
next : /graphql-js/error/
8
8
---
9
-
10
- The ` graphql ` module exports a core subset of GraphQL functionality for creation
11
- of GraphQL type systems and servers.
9
+ ` graphql ` 模块导出了 GraphQL 的一个核心子集,其主要功能是创建 GraphQL 的类型系统和服务。
12
10
13
11
``` js
14
12
import { graphql } from ' graphql' ; // ES6
15
13
var { graphql } = require (' graphql' ); // CommonJS
16
14
```
17
15
18
- ## Overview
16
+ ## 概述
19
17
20
- * Entry Point *
18
+ ** 入口点 * *
21
19
22
20
<ul class =" apiIndex " >
23
21
<li >
24
22
<a href="#graphql">
25
23
<pre>function graphql</pre>
26
- Lexes, parses, validates, and executes a GraphQL request on a schema.
24
+ 根据 schema 对一个 GraphQL 请求进行词法分析、解析、验证及执行。
27
25
</a>
28
26
</li >
29
27
</ul >
30
28
31
- * Schema*
29
+ ** Schema* *
32
30
33
31
<ul class =" apiIndex " >
34
32
<li >
35
33
<a href="../type/#graphqlschema">
36
34
<pre>class GraphQLSchema</pre>
37
- A representation of the capabilities of a GraphQL Server.
35
+ 一个 GraphQL 服务的功能配置描述
38
36
</a>
39
37
</li >
40
38
</ul >
41
39
42
- * Type Definitions *
40
+ ** 类型定义 * *
43
41
44
42
<ul class =" apiIndex " >
45
43
<li >
46
44
<a href="../type/#graphqlscalartype">
47
45
<pre>class GraphQLScalarType</pre>
48
- A scalar type within GraphQL.
46
+ GraphQL 里的标量类型。
49
47
</a>
50
48
</li >
51
49
<li >
52
50
<a href="../type/#graphqlobjecttype">
53
51
<pre>class GraphQLObjectType</pre>
54
- An object type within GraphQL that contains fields.
52
+ GraphQL 里的自定义对象类型,包含一个 fields 字段。
55
53
</a>
56
54
</li >
57
55
<li >
58
56
<a href="../type/#graphqlinterfacetype">
59
57
<pre>class GraphQLInterfaceType</pre>
60
- An interface type within GraphQL that defines fields implementations will contain.
58
+ GraphQL 里的接口类型,定义多个类型中通用的字段。
61
59
</a>
62
60
</li >
63
61
<li >
64
62
<a href="../type/#graphqluniontype">
65
63
<pre>class GraphQLUnionType</pre>
66
- A union type within GraphQL that defines a list of implementations.
64
+ GraphQL 里的联合类型,定义了(某个字段能支持的所有返回类型的)一个实现列表。
67
65
</a>
68
66
</li >
69
67
<li >
70
68
<a href="../type/#graphqlenumtype">
71
69
<pre>class GraphQLEnumType</pre>
72
- An enum type within GraphQL that defines a list of valid values.
70
+ GraphQL 里的枚举类型,定义了一个有效(可枚举)数据类型的列表。
73
71
</a>
74
72
</li >
75
73
<li >
76
74
<a href="../type/#graphqlinputobjecttype">
77
75
<pre>class GraphQLInputObjectType</pre>
78
- An input object type within GraphQL that represents structured inputs.
76
+ GraphQL 里的输入对象类型,表示一些结构化的输入。
79
77
</a>
80
78
</li >
81
79
<li >
82
80
<a href="../type/#graphqllist">
83
81
<pre>class GraphQLList</pre>
84
- A type wrapper around other types that represents a list of those types.
82
+ 这是对其他类型进行封装的类型,表示一个包含那些类型的列表。
85
83
</a>
86
84
</li >
87
85
<li >
88
86
<a href="../type/#graphqlnonnull">
89
87
<pre>class GraphQLNonNull</pre>
90
- A type wrapper around other types that represents a non-null version of those types.
88
+ 这也是对其他类型进行封装的类型,并强制要求类型值不能为空。
91
89
</a>
92
90
</li >
93
91
</ul >
94
92
95
- * Scalars *
93
+ ** 标量类型 * *
96
94
97
95
<ul class =" apiIndex " >
98
96
<li >
99
97
<a href="../type/#graphqlint">
100
98
<pre>var GraphQLInt</pre>
101
- A scalar type representing integers.
99
+ 表示整数的标量类型。
102
100
</a>
103
101
</li >
104
102
<li >
105
103
<a href="../type/#graphqlfloat">
106
104
<pre>var GraphQLFloat</pre>
107
- A scalar type representing floats.
105
+ 表示浮点数的标量类型。
108
106
</a>
109
107
</li >
110
108
<li >
111
109
<a href="../type/#graphqlstring">
112
110
<pre>var GraphQLString</pre>
113
- A scalar type representing strings.
111
+ 表示字符串的标量类型。
114
112
</a>
115
113
</li >
116
114
<li >
117
115
<a href="../type/#graphqlboolean">
118
116
<pre>var GraphQLBoolean</pre>
119
- A scalar type representing booleans.
117
+ 表示布尔值的标量类型。
120
118
</a>
121
119
</li >
122
120
<li >
123
121
<a href="../type/#graphqlid">
124
122
<pre>var GraphQLID</pre>
125
- A scalar type representing IDs.
123
+ 表示 ID 值的标量类型。
126
124
</a>
127
125
</li >
128
126
</ul >
129
127
130
- * Errors *
128
+ ** 错误信息 * *
131
129
132
130
<ul class =" apiIndex " >
133
131
<li >
134
132
<a href="../error/#formaterror">
135
133
<pre>function formatError</pre>
136
- Format an error according to the rules described by the Response Format.
134
+ 根据返回格式描述的规则格式化一个错误。
137
135
</a>
138
136
</li >
139
137
</ul >
140
138
141
- ## Entry Point
139
+ ## 入口点
142
140
143
141
### graphql
144
142
@@ -153,27 +151,20 @@ graphql(
153
151
): Promise < GraphQLResult>
154
152
` ` `
155
153
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.
154
+ ` graphql` 方法可以对一个 GraphQL 请求进行词法分析、解析、验证和执行。必要的参数是 ` schema` 和 ` requestString` ,可选的参数则包括 ` rootValue` (将作为根值传入执行器方法)、` contextValue` (将传入所有的解析函数)、` variableValues` (将传入执行器方法,为 ` requestString` 中的任意类型变量赋值)以及 ` operationName` (在 ` requestString` 包含多个顶级操作的情况下,这个参数允许调用函数指定 ` requestString` 运行哪个操作)。
164
155
165
156
## Schema
166
157
167
- See the [Type System API Reference ](../type#schema).
158
+ 详细介绍请看 [类型系统 API 参考 ](../type#schema)。
168
159
169
- ## Type Definitions
160
+ ## 类型定义
170
161
171
- See the [Type System API Reference ](../type#definitions).
162
+ 详细介绍请看 [类型系统 API 参考 ](../type#definitions)。
172
163
173
- ## Scalars
164
+ ## 标量类型
174
165
175
- See the [Type System API Reference ](../type#scalars).
166
+ 详细介绍请看 [类型系统 API 参考 ](../type#scalars)。
176
167
177
- ## Errors
168
+ ## 错误信息
178
169
179
- See the [Errors API Reference ](../error)
170
+ 详细介绍请看 [错误信息 API 参考 ](../error)
0 commit comments