@@ -7,44 +7,43 @@ sublinks: formatError,GraphQLError,locatedError,syntaxError
7
7
next : /graphql-js/execution/
8
8
---
9
9
10
- The ` graphql/error ` module is responsible for creating and formatting
11
- GraphQL errors. You can import either from the ` graphql/error ` module, or from the root ` graphql ` module. For example:
10
+ ` graphql/error ` 模块负责创建和格式化 GraphQL 的错误信息。你可以直接从 ` graphql/error ` 模块导入,也可以从 ` graphql ` 这个根模块导入。举例来说就是这样:
12
11
13
12
``` js
14
13
import { GraphQLError } from ' graphql' ; // ES6
15
14
var { GraphQLError } = require (' graphql' ); // CommonJS
16
15
```
17
16
18
- ## Overview
17
+ ## 概述
19
18
20
19
<ul class =" apiIndex " >
21
20
<li >
22
21
<a href="#graphqlerror">
23
22
<pre>class GraphQLError</pre>
24
- A representation of an error that occurred within GraphQL.
23
+ GraphQLError 表示 GraphQL 产生的错误信息。
25
24
</a>
26
25
</li >
27
26
<li >
28
27
<a href="#syntaxerror">
29
28
<pre>function syntaxError</pre>
30
- Produces a GraphQLError representing a syntax error.
29
+ 产生一个表示语法错误的 GraphQLError。
31
30
</a>
32
31
</li >
33
32
<li >
34
33
<a href="#locatedError">
35
34
<pre>function locatedError</pre>
36
- Produces a new GraphQLError aware of the location responsible for the error.
35
+ 产生一个新的负责错误定位的 GraphQLError。
37
36
</a>
38
37
</li >
39
38
<li >
40
39
<a href="#formaterror">
41
40
<pre>function formatError</pre>
42
- Format an error according to the rules described by the Response Format.
41
+ 根据响应格式的规则描述来格式化一条错误信息。
43
42
</a>
44
43
</li >
45
44
</ul >
46
45
47
- ## Errors
46
+ ## 错误信息
48
47
49
48
### GraphQLError
50
49
@@ -60,9 +59,7 @@ class GraphQLError extends Error {
60
59
}
61
60
` ` `
62
61
63
- A representation of an error that occurred within GraphQL. Contains
64
- information about where in the query the error occurred for debugging. Most
65
- commonly constructed with ` locatedError` below.
62
+ GraphQLError 表示 GraphQL 产生的错误信息。它包含一些用于调试的信息,比如查询语句中错误发生的位置。最常见的错误信息就是下面的的 ` locatedError` 。
66
63
67
64
### syntaxError
68
65
@@ -74,18 +71,15 @@ function syntaxError(
74
71
): GraphQLError;
75
72
```
76
73
77
- Produces a GraphQLError representing a syntax error, containing useful
78
- descriptive information about the syntax error's position in the source.
74
+ 产生一个表示语法错误的 GraphQLError,它包含原始语句中语法错误具体定位的描述性信息。
79
75
80
76
### locatedError
81
77
82
78
```js
83
79
function locatedError(error: ?Error, nodes: Array<any>): GraphQLError {
84
80
` ` `
85
81
86
- Given an arbitrary Error, presumably thrown while attempting to execute a
87
- GraphQL operation, produce a new GraphQLError aware of the location in the
88
- document responsible for the original Error.
82
+ 当尝试执行 GraphQL 操作时抛出的任意一个错误,都会产生一个新的负责原始错误文档定位的 GraphQLError 。
89
83
90
84
### formatError
91
85
@@ -103,5 +97,4 @@ type GraphQLErrorLocation = {
103
97
};
104
98
` ` `
105
99
106
- Given a GraphQLError, format it according to the rules described by the
107
- Response Format, Errors section of the GraphQL Specification.
100
+ 给定一个 GraphQLError,根据 GraphQL 规范中的响应格式和错误分类的规则描述来格式化错误信息。
0 commit comments