Skip to content

Commit e559e6a

Browse files
authored
APIReference-Utilities.md (xitu#70)
* APIReference-Utilities translation done Signed-off-by: Jonir Rings <[email protected]> * 修正用词,添加几个标题的翻译 Signed-off-by: Jonir Rings <[email protected]> * 统一“根模块”这个用词 Signed-off-by: Jonir Rings <[email protected]>
1 parent 7db7a85 commit e559e6a

File tree

1 file changed

+35
-52
lines changed

1 file changed

+35
-52
lines changed

site/graphql-js/APIReference-Utilities.md

Lines changed: 35 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -7,112 +7,110 @@ sublinks: astFromValue,buildASTSchema,buildClientSchema,buildSchema,introspectio
77
next: /graphql-js/validation/
88
---
99

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` 根模块引入。如下:
1211

1312
```js
1413
import { introspectionQuery } from 'graphql'; // ES6
1514
var { introspectionQuery } = require('graphql'); // CommonJS
1615
```
1716

18-
## Overview
17+
## 概览
1918

20-
*Introspection*
19+
**内省**
2120

2221
<ul class="apiIndex">
2322
<li>
2423
<a href="#introspectionquery">
2524
<pre>var introspectionQuery</pre>
26-
A GraphQL introspection query containing enough information to reproduce a type system.
25+
GraphQL 内省查询,包含足够的信息以重现类型系统。
2726
</a>
2827
</li>
2928
<li>
3029
<a href="#buildclientschema">
3130
<pre>function buildClientSchema</pre>
32-
Produces a client schema given the result of querying a schema with `introspectionQuery`.
31+
通过使用 `introspectionQuery` 查询 schema 的结果,生成客户端 schema
3332
</a>
3433
</li>
3534
</ul>
3635

37-
*Schema Language*
36+
**Schema Language**
3837

3938
<ul class="apiIndex">
4039
<li>
4140
<a href="#buildschema">
4241
<pre>function buildSchema</pre>
43-
Builds a Schema object from GraphQL schema language.
42+
基于 GraphQL schema language 构建一个 Schema 对象。
4443
</a>
4544
</li>
4645
<li>
4746
<a href="#printschema">
4847
<pre>function printSchema</pre>
49-
Prints the schema in a standard format.
48+
使用标准格式打印 schema
5049
</a>
5150
</li>
5251
<li>
5352
<a href="#printintrospectionschema">
5453
<pre>function printIntrospectionSchema</pre>
55-
Prints the introspections featurs of the schema in a standard format.
54+
使用标准格式打印 schema 的内省特性。
5655
</a>
5756
</li>
5857
<li>
5958
<a href="#buildastschema">
6059
<pre>function buildASTSchema</pre>
61-
Builds a schema from a parsed AST Schema.
60+
基于分析后的 AST Schema 构建 schema。
6261
</a>
6362
</li>
6463
<li>
6564
<a href="#typefromast">
6665
<pre>function typeFromAST</pre>
67-
Looks up a type referenced in an AST in the GraphQLSchema.
66+
在 GraphQLSchema 的 AST 中查找一个类型引用。
6867
</a>
6968
</li>
7069
<li>
7170
<a href="#astfromvalue">
7271
<pre>function astFromValue</pre>
73-
Produces a GraphQL Input Value AST given a JavaScript value.
72+
基于一个 JavaScript 值生成一个 GraphQL Input Value AST
7473
</a>
7574
</li>
7675
</ul>
7776

78-
*Visitors*
77+
**Visitors**
7978

8079
<ul class="apiIndex">
8180
<li>
8281
<a href="#typeinfo">
8382
<pre>class TypeInfo</pre>
84-
Tracks type and field definitions during a visitor AST traversal..
83+
visitor 遍历 AST 时追踪类型和字段定义。
8584
</a>
8685
</li>
8786
</ul>
8887

89-
*Value Validation*
88+
**值验证**
9089

9190
<ul class="apiIndex">
9291
<li>
9392
<a href="#isvalidjsvalue">
9493
<pre>function isValidJSValue</pre>
95-
Determins if a JavaScript value is valid for a GraphQL type.
94+
判断一个 JavaScript 值是否是有效的 GraphQL 类型的值。
9695
</a>
9796
</li>
9897
<li>
9998
<a href="#isvalidliteralvalue">
10099
<pre>function isValidLiteralValue</pre>
101-
Determins if a literal value from an AST is valid for a GraphQL type.
100+
判断一个 AST 中的字面量值是否是有效的 GraphQL 类型的值。
102101
</a>
103102
</li>
104103
</ul>
105104

106-
## Introspection
105+
## 内省
107106

108107
### introspectionQuery
109108

110109
```js
111110
var introspectionQuery: string
112111
```
113112

114-
A GraphQL query that queries a server's introspection system for enough
115-
information to reproduce that server's type system.
113+
GraphQL 内省查询,用于查询服务器的内省系统,得到足够的信息以重现服务器类型系统。
116114

117115
### buildClientSchema
118116

@@ -122,39 +120,35 @@ function buildClientSchema(
122120
): GraphQLSchema
123121
```
124122

125-
Build a GraphQLSchema for use by client tools.
123+
构建客户端工具用的 GraphQLSchema
126124

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 工具,但不能用于执行查询,因为内省并不代表有“解析器”、“分析”或者“序列化”函数,或者其他服务器内部机制。
132126

133-
## Schema Representation
127+
## Schema 表示
134128

135129
### buildSchema
136130

137131
```js
138132
function buildSchema(source: string | Source): GraphQLSchema {
139133
```
140134
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)
142136
143137
### printSchema
144138
145139
```js
146140
function printSchema(schema: GraphQLSchema): string {
147141
```
148142
149-
Prints the provided schema in the Schema Language format.
143+
使用 Schema Language 格式打印给定的 schema。
150144
151145
### printIntrospectionSchema
152146
153147
```js
154148
function printIntrospectionSchema(schema: GraphQLSchema): string {
155149
```
156150
157-
Prints the built-in introspection schema in the Schema Language format.
151+
使用 Schema Language 格式打印内建的内省 schema。
158152
159153
### buildASTSchema
160154
@@ -166,11 +160,7 @@ function buildASTSchema(
166160
): GraphQLSchema
167161
```
168162
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 工具,但不能用于执行查询,因为内省并不代表有“解析器”、“分析”或者“序列化”函数,或者其他服务器内部机制。
174164
175165
### typeFromAST
176166
@@ -181,8 +171,7 @@ function typeFromAST(
181171
): ?GraphQLType
182172
```
183173

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。
186175

187176
### astFromValue
188177

@@ -192,10 +181,10 @@ function astFromValue(
192181
type?: ?GraphQLType
193182
): ?Value
194183
```
195-
Produces a GraphQL Input Value AST given a JavaScript value.
196184

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 类型,用于消除类型原生值之间的歧义。
199188

200189
## Visitors
201190

@@ -213,21 +202,17 @@ class TypeInfo {
213202
}
214203
```
215204
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 中当前字段和类型定义。
219206
220-
## Value Validation
207+
## 值验证
221208
222209
### isValidJSValue
223210
224211
```js
225212
function isValidJSValue(value: any, type: GraphQLInputType): string[]
226213
```
227214

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 类型,判断这个值是否能被这个类型接受。这个功能在验证运行时查询参数值的时候特别有用。
231216

232217
### isValidLiteralValue
233218

@@ -238,8 +223,6 @@ function isValidLiteralValue(
238223
): string[]
239224
```
240225

241-
Utility for validators which determines if a value literal AST is valid given
242-
an input type.
226+
验证器的工具可以判断 AST 字面量值是否是一个给定输入类型的有效值。
243227

244-
Note that this only validates literal values, variables are assumed to
245-
provide values of the correct type.
228+
注意,这个功能只验证字面量值,并假设变量值是正确的类型。

0 commit comments

Comments
 (0)