Skip to content

Commit 56a913c

Browse files
jonirringslinhe0x0
authored andcommitted
APIReference-Validation.md (xitu#68)
1 parent 83a264f commit 56a913c

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed
Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,36 @@
11
---
22
title: graphql/validation
33
layout: ../_core/GraphQLJSLayout
4-
category: API Reference
4+
category: API 参考
55
permalink: /graphql-js/validation/
66
sublinks: specifiedRules,validate
77
---
88

9-
The `graphql/validation` module fulfills the Validation phase of fulfilling a
10-
GraphQL result. You can import either from the `graphql/validation` module, or from the root `graphql` module. For example:
9+
`graphql/validation` 模块负责完成一个 GraphQL 请求的验证阶段。你可以从 `graphql/validation` 模块导入,或者从根 `graphql` 模块导入,如下:
1110

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

17-
## Overview
16+
## 概览
1817

1918
<ul class="apiIndex">
2019
<li>
2120
<a href="#validate">
2221
<pre>function validate</pre>
23-
Validates an AST against a provided Schema.
22+
根据给定 Schema 验证一个 AST(抽象语法树)。
2423
</a>
2524
</li>
2625
<li>
2726
<a href="#specifiedrules">
2827
<pre>var specifiedRules</pre>
29-
A list of standard validation rules described in the GraphQL specification.
28+
GraphQL 规范中描述的一系列标准验证规则。
3029
</a>
3130
</li>
3231
</ul>
3332

34-
## Validation
33+
## 验证
3534

3635
### validate
3736

@@ -43,26 +42,20 @@ function validate(
4342
): Array<GraphQLError>
4443
```
4544

46-
Implements the "Validation" section of the spec.
45+
实现规范的“验证”章节。
4746

48-
Validation runs synchronously, returning an array of encountered errors, or
49-
an empty array if no errors were encountered and the document is valid.
47+
验证过程会同步执行,如果发生错误则返回错误数组,如果文档有效没有发生错误,则返回空数组。
5048

51-
A list of specific validation rules may be provided. If not provided, the
52-
default list of rules defined by the GraphQL specification will be used.
49+
如果未提供特定的验证规则,则执行 GraphQL 规范的默认验证规则。
5350

54-
Each validation rules is a function which returns a visitor
55-
(see the language/visitor API). Visitor methods are expected to return
56-
GraphQLErrors, or Arrays of GraphQLErrors when invalid.
51+
每个验证规则都是一个函数,返回一个 visitor(查看 language/visitor API)。visitor 方法应当在文档无效时返回 GraphQLErrors,或者 GraphQLError 数组。
5752

58-
Visitors can also supply `visitSpreadFragments: true` which will alter the
59-
behavior of the visitor to skip over top level defined fragments, and instead
60-
visit those fragments at every point a spread is encountered.
53+
visitor 应该支持 `visitSpreadFragments: true`,这将改变 visitor 的行为:跳过顶层定义的片段,并访问这些片段的所有展开点。
6154

6255
### specifiedRules
6356

6457
```js
6558
var specifiedRules: Array<(context: ValidationContext): any>
6659
```
6760

68-
This set includes all validation rules defined by the GraphQL spec
61+
这个集合包含了所有 GraphQL 规范定义的验证规则。

0 commit comments

Comments
 (0)