You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: site/graphql-js/Tutorial-BasicTypes.md
+11-11Lines changed: 11 additions & 11 deletions
Original file line number
Diff line number
Diff line change
@@ -1,27 +1,27 @@
1
1
---
2
-
title: Basic Types
2
+
title: 基本类型
3
3
layout: ../_core/GraphQLJSLayout
4
-
category: GraphQL.js Tutorial
4
+
category: GraphQL.js 教程
5
5
permalink: /graphql-js/basic-types/
6
6
next: /graphql-js/passing-arguments/
7
7
---
8
8
9
-
In most situations, all you need to do is to specify the types for your API using the GraphQL schema language, taken as an argument to the `buildSchema`function.
9
+
大多数情况下,你所需要做的只是使用 GraphQL schema language 指定你的 API 需要的类型,然后作为参数传给 `buildSchema`函数。
10
10
11
-
The GraphQL schema language supports the scalar types of `String`, `Int`, `Float`, `Boolean`, and`ID`, so you can use these directly in the schema you pass to `buildSchema`.
11
+
GraphQL schema language 支持的标量类型有 `String`、`Int`、`Float`、`Boolean` 和`ID`,因此你可以在传给 `buildSchema` 的 schema 中直接使用这些类型。
12
12
13
-
By default, every type is nullable - it's legitimate to return `null` as any of the scalar types. Use an exclamation point to indicate a type cannot be nullable, so `String!`is a non-nullable string.
To use a list type, surround the type in square brackets, so `[Int]`is a list of integers.
15
+
如果是列表类型,使用方括号将对应类型包起来,如 `[Int]`就表示一个整数列表。
16
16
17
-
Each of these types maps straightforwardly to JavaScript, so you can just return plain old JavaScript objects in APIs that return these types. Here's an example that shows how to use some of these basic types:
//Construct a schema, using GraphQL schema language
24
+
//使用 GraphQL schema language 构建一个 schema
25
25
var schema =buildSchema(`
26
26
type Query {
27
27
quoteOfTheDay: String
@@ -30,7 +30,7 @@ var schema = buildSchema(`
30
30
}
31
31
`);
32
32
33
-
//The root provides a resolver function for each API endpoint
33
+
// root 将会提供每个 API 入口端点的解析函数
34
34
var root = {
35
35
quoteOfTheDay: () => {
36
36
returnMath.random() <0.5?'Take it easy':'Salvation lies within';
@@ -53,6 +53,6 @@ app.listen(4000);
53
53
console.log('Running a GraphQL API server at localhost:4000/graphql');
54
54
```
55
55
56
-
If you run this code with `node server.js`and browse to http://localhost:4000/graphqlyou can try out these APIs.
56
+
如果你使用 `node server.js`运行这个代码,浏览 http://localhost:4000/graphql你就能尝试这些 API 了。
57
57
58
-
These examples show you how to call APIs that return different types. To send different types of data into an API, you will also need to learn about [passing arguments to a GraphQL API](/graphql-js/passing-arguments/).
58
+
这些案例展示了如何调用 API 以返回不同类型。如果要向 API 发送不同类型的数据,你还需要学习 [如何向 GraphQL API 传参](/graphql-js/passing-arguments/)。
0 commit comments