@@ -7,112 +7,110 @@ sublinks: astFromValue,buildASTSchema,buildClientSchema,buildSchema,introspectio
7
7
next : /graphql-js/validation/
8
8
---
9
9
10
- The ` graphql/utilities ` module contains common useful computations to use with
11
- the GraphQL language and type objects. You can import either from the ` graphql/utilities ` module, or from the root ` graphql ` module. For example:
10
+ ` graphql/utilities ` 模块包含用于 GraphQL 语言和类型对象的常用计算。你可以从 ` graphql/utilities ` 模块或是 ` graphql ` 根模块引入。如下:
12
11
13
12
``` js
14
13
import { introspectionQuery } from ' graphql' ; // ES6
15
14
var { introspectionQuery } = require (' graphql' ); // CommonJS
16
15
```
17
16
18
- ## Overview
17
+ ## 概览
19
18
20
- * Introspection *
19
+ ** 内省 * *
21
20
22
21
<ul class =" apiIndex " >
23
22
<li >
24
23
<a href="#introspectionquery">
25
24
<pre>var introspectionQuery</pre>
26
- A GraphQL introspection query containing enough information to reproduce a type system.
25
+ GraphQL 内省查询,包含足够的信息以重现类型系统。
27
26
</a>
28
27
</li >
29
28
<li >
30
29
<a href="#buildclientschema">
31
30
<pre>function buildClientSchema</pre>
32
- Produces a client schema given the result of querying a schema with `introspectionQuery`.
31
+ 通过使用 `introspectionQuery` 查询 schema 的结果,生成客户端 schema。
33
32
</a>
34
33
</li >
35
34
</ul >
36
35
37
- * Schema Language*
36
+ ** Schema Language* *
38
37
39
38
<ul class =" apiIndex " >
40
39
<li >
41
40
<a href="#buildschema">
42
41
<pre>function buildSchema</pre>
43
- Builds a Schema object from GraphQL schema language.
42
+ 基于 GraphQL schema language 构建一个 Schema 对象。
44
43
</a>
45
44
</li >
46
45
<li >
47
46
<a href="#printschema">
48
47
<pre>function printSchema</pre>
49
- Prints the schema in a standard format.
48
+ 使用标准格式打印 schema。
50
49
</a>
51
50
</li >
52
51
<li >
53
52
<a href="#printintrospectionschema">
54
53
<pre>function printIntrospectionSchema</pre>
55
- Prints the introspections featurs of the schema in a standard format.
54
+ 使用标准格式打印 schema 的内省特性。
56
55
</a>
57
56
</li >
58
57
<li >
59
58
<a href="#buildastschema">
60
59
<pre>function buildASTSchema</pre>
61
- Builds a schema from a parsed AST Schema.
60
+ 基于分析后的 AST Schema 构建 schema。
62
61
</a>
63
62
</li >
64
63
<li >
65
64
<a href="#typefromast">
66
65
<pre>function typeFromAST</pre>
67
- Looks up a type referenced in an AST in the GraphQLSchema.
66
+ 在 GraphQLSchema 的 AST 中查找一个类型引用。
68
67
</a>
69
68
</li >
70
69
<li >
71
70
<a href="#astfromvalue">
72
71
<pre>function astFromValue</pre>
73
- Produces a GraphQL Input Value AST given a JavaScript value.
72
+ 基于一个 JavaScript 值生成一个 GraphQL Input Value AST。
74
73
</a>
75
74
</li >
76
75
</ul >
77
76
78
- * Visitors*
77
+ ** Visitors* *
79
78
80
79
<ul class =" apiIndex " >
81
80
<li >
82
81
<a href="#typeinfo">
83
82
<pre>class TypeInfo</pre>
84
- Tracks type and field definitions during a visitor AST traversal..
83
+ 在 visitor 遍历 AST 时追踪类型和字段定义。
85
84
</a>
86
85
</li >
87
86
</ul >
88
87
89
- * Value Validation *
88
+ ** 值验证 * *
90
89
91
90
<ul class =" apiIndex " >
92
91
<li >
93
92
<a href="#isvalidjsvalue">
94
93
<pre>function isValidJSValue</pre>
95
- Determins if a JavaScript value is valid for a GraphQL type.
94
+ 判断一个 JavaScript 值是否是有效的 GraphQL 类型的值。
96
95
</a>
97
96
</li >
98
97
<li >
99
98
<a href="#isvalidliteralvalue">
100
99
<pre>function isValidLiteralValue</pre>
101
- Determins if a literal value from an AST is valid for a GraphQL type.
100
+ 判断一个 AST 中的字面量值是否是有效的 GraphQL 类型的值。
102
101
</a>
103
102
</li >
104
103
</ul >
105
104
106
- ## Introspection
105
+ ## 内省
107
106
108
107
### introspectionQuery
109
108
110
109
``` js
111
110
var introspectionQuery: string
112
111
```
113
112
114
- A GraphQL query that queries a server's introspection system for enough
115
- information to reproduce that server's type system.
113
+ GraphQL 内省查询,用于查询服务器的内省系统,得到足够的信息以重现服务器类型系统。
116
114
117
115
### buildClientSchema
118
116
@@ -122,39 +120,35 @@ function buildClientSchema(
122
120
): GraphQLSchema
123
121
```
124
122
125
- Build a GraphQLSchema for use by client tools.
123
+ 构建客户端工具用的 GraphQLSchema。
126
124
127
- Given the result of a client running the introspection query, creates and
128
- returns a GraphQLSchema instance which can be then used with all GraphQL.js
129
- tools, but cannot be used to execute a query, as introspection does not
130
- represent the "resolver", "parse" or "serialize" functions or any other
131
- server-internal mechanisms.
125
+ 假设客户端有运行内省查询的结果,创建并返回了一个 GraphQLSchema 实例,这个实例可以用于所有的 GraphQL.js 工具,但不能用于执行查询,因为内省并不代表有“解析器”、“分析”或者“序列化”函数,或者其他服务器内部机制。
132
126
133
- ## Schema Representation
127
+ ## Schema 表示
134
128
135
129
### buildSchema
136
130
137
131
```js
138
132
function buildSchema(source: string | Source): GraphQLSchema {
139
133
` ` `
140
134
141
- Creates a GraphQLSchema object from GraphQL schema language. The schema will use default resolvers. For more detail on the GraphQL schema language, see the [schema language docs ](/learn/schema/) or this [schema language cheat sheet ](https://wehavefaces.net/graphql-shorthand-notation-cheatsheet-17cd715861b6#.9oztv0a7n).
135
+ 基于 GraphQL schema language 创建一个 GraphQLSchema 对象。 schema 将会使用默认解析器。关于 GraphQL schema language 的更多细节,请查看 [schema language 文档 ](/learn/schema/) 或者 [schema language 速查表 ](https://wehavefaces.net/graphql-shorthand-notation-cheatsheet-17cd715861b6#.9oztv0a7n)。
142
136
143
137
### printSchema
144
138
145
139
` ` ` js
146
140
function printSchema (schema : GraphQLSchema ): string {
147
141
` ` `
148
142
149
- Prints the provided schema in the Schema Language format.
143
+ 使用 Schema Language 格式打印给定的 schema。
150
144
151
145
### printIntrospectionSchema
152
146
153
147
` ` ` js
154
148
function printIntrospectionSchema (schema : GraphQLSchema ): string {
155
149
` ` `
156
150
157
- Prints the built-in introspection schema in the Schema Language format.
151
+ 使用 Schema Language 格式打印内建的内省 schema。
158
152
159
153
### buildASTSchema
160
154
@@ -166,11 +160,7 @@ function buildASTSchema(
166
160
): GraphQLSchema
167
161
` ` `
168
162
169
- This takes the ast of a schema document produced by ` parseSchemaIntoAST ` in
170
- ` graphql / language / schema ` and constructs a GraphQLSchema instance which can be
171
- then used with all GraphQL.js tools, but cannot be used to execute a query, as
172
- introspection does not represent the "resolver", "parse" or "serialize"
173
- functions or any other server-internal mechanisms.
163
+ 这个函数需要一个 schema 文档的 ast(可通过 ` graphql / language / schema ` 的 ` parseSchemaIntoAST ` 生成)构建一个 GraphQLSchema 实例,这个实例可以用于所有的 GraphQL.js 工具,但不能用于执行查询,因为内省并不代表有“解析器”、“分析”或者“序列化”函数,或者其他服务器内部机制。
174
164
175
165
### typeFromAST
176
166
@@ -181,8 +171,7 @@ function typeFromAST(
181
171
): ?GraphQLType
182
172
```
183
173
184
- Given the name of a Type as it appears in a GraphQL AST and a Schema, return the
185
- corresponding GraphQLType from that schema.
174
+ 给定一个出现在 GraphQL AST 和 Schema 中的类型名称,返回其在 schema 中对应的 GraphQLType。
186
175
187
176
### astFromValue
188
177
@@ -192,10 +181,10 @@ function astFromValue(
192
181
type?: ?GraphQLType
193
182
): ?Value
194
183
```
195
- Produces a GraphQL Input Value AST given a JavaScript value.
196
184
197
- Optionally, a GraphQL type may be provided, which will be used to
198
- disambiguate between value primitives.
185
+ 基于一个 JavaScript 值生成一个 GraphQL Input Value AST。
186
+
187
+ 可选参数,一个 GraphQL 类型,用于消除类型原生值之间的歧义。
199
188
200
189
## Visitors
201
190
@@ -213,21 +202,17 @@ class TypeInfo {
213
202
}
214
203
` ` `
215
204
216
- TypeInfo is a utility class which, given a GraphQL schema, can keep track
217
- of the current field and type definitions at any point in a GraphQL document
218
- AST during a recursive descent by calling ` enter (node)` and ` leave (node)` .
205
+ TypeInfo 是一个工具类,在 GraphQL 文档 AST 的递归分析中的任何位置上,调用 ` enter (node)` 和 ` leave (node)` 的时候,可以追踪指定 GraphQL schema 中当前字段和类型定义。
219
206
220
- ## Value Validation
207
+ ## 值验证
221
208
222
209
### isValidJSValue
223
210
224
211
` ` ` js
225
212
function isValidJSValue (value : any , type : GraphQLInputType ): string[]
226
213
```
227
214
228
- Given a JavaScript value and a GraphQL type, determine if the value will be
229
- accepted for that type. This is primarily useful for validating the
230
- runtime values of query variables.
215
+ 给定一个 JavaScript 值和 GraphQL 类型,判断这个值是否能被这个类型接受。这个功能在验证运行时查询参数值的时候特别有用。
231
216
232
217
### isValidLiteralValue
233
218
@@ -238,8 +223,6 @@ function isValidLiteralValue(
238
223
): string[]
239
224
```
240
225
241
- Utility for validators which determines if a value literal AST is valid given
242
- an input type.
226
+ 验证器的工具可以判断 AST 字面量值是否是一个给定输入类型的有效值。
243
227
244
- Note that this only validates literal values, variables are assumed to
245
- provide values of the correct type.
228
+ 注意,这个功能只验证字面量值,并假设变量值是正确的类型。
0 commit comments