Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tutorial-PassingArguments.md #51

Merged

Conversation

Joursion
Copy link

@Joursion Joursion commented Jul 29, 2017

完成翻译,求校对
close #29

var schema = buildSchema(`
type Query {
rollDice(numDice: Int!, numSides: Int): [Int]
}
`);

// The root provides a resolver function for each API endpoint
// root 为每个 端点入口 API 提供一个解析器
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

中间多了一个空格


```javascript
type Query {
rollThreeDice: [Int]
}
```

Instead of hardcoding “three”, we might want a more general function that rolls `numDice` dice, each of which have `numSides` sides. We can add arguments to the GraphQL schema language like this:
我们可能想要一个更通用的函数来实现投掷点数 `numDice` ,而不是硬性地设为 "3",并且有一个参数 `numSide` 来表示骰子的面数,我们可以这样在 GraphQL schema language 实现:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的 numDice 应该不是投掷点数,而是投掷的骰子个数

@@ -89,19 +89,19 @@ app.listen(4000);
console.log('Running a GraphQL API server at localhost:4000/graphql');
```

When you call this API, you have to pass each argument by name. So for the server above, you could issue this GraphQL query to roll three six-sided dice:
当你调用这个 API 时,你需要按名称传入每个参数,对于上面的服务器代码,你可以通过发起这样的 GraphQL 查询,来投掷一个 6 面的,点数为 3 的骰子。
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上,这里应该是投掷 3 个六面的骰子


```javascript
{
rollDice(numDice: 3, numSides: 6)
}
```

If you run this code with `node server.js` and browse to http://localhost:4000/graphql you can try out this API.
如果你使用 `node server.js` 运行这段代码,你可以浏览 http://localhost:4000/graphql 来尝试这个 API
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

链接前边多了一个空格

@@ -123,6 +123,6 @@ xhr.send(JSON.stringify({
}));
```

Using `$dice` and `$sides` as variables in GraphQL means we don't have to worry about escaping on the client side.
使用 `$dice` `$sides` 作为 GraphQL 中的变量,我们可以不用担心在客户端转义。
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

后半句表意不太清楚,可以改成“我们无需在客户端对它们进行转义”


With basic types and argument passing, you can implement anything you can implement in a REST API. But GraphQL supports even more powerful queries. You can replace multiple API calls with a single API call if you learn how to [define your own object types](/graphql-js/object-types/).
通过基础类型和参数传递,你可以定义任意你在 REST API 中定义的内容。但 GraphQL 支持更强大的查询。如果你学习了 [定义你自己的对象类型](/graphql-js/object-types/),你可以用单个 API 调用来代替多个 API 调用。
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

你可以定义任意你“能够”在 REST API 中定义的内容

@@ -6,25 +6,25 @@ permalink: /graphql-js/passing-arguments/
next: /graphql-js/object-types/
---

Just like a REST API, it's common to pass arguments to an endpoint in a GraphQL API. By defining the arguments in the schema language, typechecking happens automatically. Each argument must be named and have a type. For example, in the [Basic Types documentation](/graphql-js/basic-types/) we had an endpoint called `rollThreeDice`:
就像 REST API 一样,在 GraphQL API 中,通常向入口端点传入参数,在 schema language 中定义参数,并自动进行类型检查。每一个参数必须有名字和数据类型。举个例子,在 [基础类型文档](/graphql-js/basic-types/) 中,我们定义了一个名为 `rollThreeDice` 的入口端点:
Copy link
Collaborator

@jonirrings jonirrings Aug 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

title,sidebarTitle和category也麻烦翻一下:+1:

@jonirrings jonirrings changed the title 完成翻译 Tutorial-PassingArguments Tutorial-PassingArguments.md Aug 4, 2017
@jonirrings
Copy link
Collaborator

暂时没问题了,我先merge了

@jonirrings jonirrings merged commit 868de27 into xitu:zh-Hans Aug 6, 2017
Copy link
Collaborator

@ydfzgyj ydfzgyj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

还有一个小问题麻烦再修改一下


With basic types and argument passing, you can implement anything you can implement in a REST API. But GraphQL supports even more powerful queries. You can replace multiple API calls with a single API call if you learn how to [define your own object types](/graphql-js/object-types/).
通过基础类型和参数传递,你可以定义任意你"能够"在 REST API 中定义的内容。但 GraphQL 支持更强大的查询。如果你学习了 [定义你自己的对象类型](/graphql-js/object-types/),你可以用单个 API 调用来代替多个 API 调用。
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

“能够”两边的引号不需要的……我加引号的目的是表示这两个字漏了需要补上……我下次换成用加粗好了……虽然已经合并了,麻烦再修改一下

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😂有劳修改了,再PR一下

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我是要重新提交一个PR 吗?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嗯,直接新发pr吧,revert会导致一堆PR失效,比较麻烦。或者@sqrthree 看看怎么弄

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

直接提交新 PR 即可。

jonirrings added a commit that referenced this pull request Aug 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tutorial-PassingArguments.md
4 participants