Skip to content

Commit 01ee769

Browse files
jonirringslinhe0x0
authored andcommitted
Tutorial-BasicTypes.md (xitu#63)
1 parent e32298a commit 01ee769

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

site/graphql-js/Tutorial-BasicTypes.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
---
2-
title: Basic Types
2+
title: 基本类型
33
layout: ../_core/GraphQLJSLayout
4-
category: GraphQL.js Tutorial
4+
category: GraphQL.js 教程
55
permalink: /graphql-js/basic-types/
66
next: /graphql-js/passing-arguments/
77
---
88

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` 函数。
1010

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 中直接使用这些类型。
1212

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.
13+
默认情况下,每个类型都是可以为空的 —— 意味着所有的标量类型都可以返回 `null`。使用感叹号可以标记一个类型不可为空,如 `String!` 表示非空字符串。
1414

15-
To use a list type, surround the type in square brackets, so `[Int]` is a list of integers.
15+
如果是列表类型,使用方括号将对应类型包起来,如 `[Int]` 就表示一个整数列表。
1616

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:
17+
这些类型都直接映射 JavaScript,所以你可以直接返回原本包含这些类型的原生 JavaScript 对象。下面是一个展示如何使用这些基本类型的示例:
1818

1919
```javascript
2020
var express = require('express');
2121
var graphqlHTTP = require('express-graphql');
2222
var { buildSchema } = require('graphql');
2323

24-
// Construct a schema, using GraphQL schema language
24+
// 使用 GraphQL schema language 构建一个 schema
2525
var schema = buildSchema(`
2626
type Query {
2727
quoteOfTheDay: String
@@ -30,7 +30,7 @@ var schema = buildSchema(`
3030
}
3131
`);
3232

33-
// The root provides a resolver function for each API endpoint
33+
// root 将会提供每个 API 入口端点的解析函数
3434
var root = {
3535
quoteOfTheDay: () => {
3636
return Math.random() < 0.5 ? 'Take it easy' : 'Salvation lies within';
@@ -53,6 +53,6 @@ app.listen(4000);
5353
console.log('Running a GraphQL API server at localhost:4000/graphql');
5454
```
5555

56-
If you run this code with `node server.js` and browse to http://localhost:4000/graphql you can try out these APIs.
56+
如果你使用 `node server.js` 运行这个代码,浏览 http://localhost:4000/graphql 你就能尝试这些 API 了。
5757

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

Comments
 (0)