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-Authentication.md #60

Merged
merged 5 commits into from
Aug 10, 2017

Conversation

jonirrings
Copy link
Collaborator

@jonirrings jonirrings commented Aug 4, 2017

close #22

Signed-off-by: Jonir Rings <peterpuyi@live.cn>
@jonirrings jonirrings changed the title Tutorial Authentication translation done Tutorial-Authentication.md Aug 4, 2017
@@ -46,8 +46,8 @@ app.listen(4000);
console.log('Running a GraphQL API server at localhost:4000/graphql');
```

In a REST API, authentication is often handled with a header, that contains an auth token which proves what user is making this request. Express middleware processes these headers and puts authentication data on the Express `request` object. Some middleware modules that handle authentication like this are [Passport](http://passportjs.org/), [express-jwt](https://github.com/auth0/express-jwt), and [express-session](https://github.com/expressjs/session). Each of these modules works with `express-graphql`.
REST API 中,认证通常是借由 header 处理的,其中包含一个 auth token 用于识别发出请求的用户。Express 中间件会处理这些 header,并将认证数据放进 Express `request` 对象。如此处理认证的中间件模块有 [Passport](http://passportjs.org/), [express-jwt](https://github.com/auth0/express-jwt),和 [express-session](https://github.com/expressjs/session)。这些模块每一个能配合 `express-graphql` 使用。
Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. 可以换成顿号
  2. 每一个“都”能配合


To use middleware with a GraphQL resolver, just use the middleware like you would with a normal Express app. The `request` object is then available as the second argument in any resolver.
你可以就像普通 Express 应用使用中间件一样把中间件和 GraphQL 解析器一起使用。然后 `request` 对象就会作为解析函数的第二参数传入。(译者案:[v0.5.0](https://github.com/graphql/graphql-js/releases/tag/v0.5.0) 之后,作为第三参数)
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 Author

Choose a reason for hiding this comment

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

我们得看看这个md的工具支持脚注不……

Copy link
Collaborator

Choose a reason for hiding this comment

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

我开个 issue 讨论一下


For example, let's say we wanted our server to log the IP address of every request, and we also want to write an API that returns the IP address of the caller. We can do the former with middleware, and the latter by accessing the `request` object in a resolver. Here's server code that implements this:
举个例子,假设我们想要服务器记录每个请求的 IP 地址,并编写一个返回调用者 IP 地址的 API。前者我们通过中间件完成,后者则通过在解析器中取 `request` 对象即可。下面是实现这个功能的服务端代码:
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 Author

Choose a reason for hiding this comment

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

嗯嗯,当时是有点觉得不对劲

Signed-off-by: Jonir Rings <peterpuyi@live.cn>
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.

除了译者注需再讨论外,没有问题了

@jonirrings
Copy link
Collaborator Author

jonirrings commented Aug 5, 2017

@ydfzgyj 那就开个issue吧,想想怎么组织issue内容……

Signed-off-by: Jonir Rings <peterpuyi@live.cn>
Signed-off-by: Jonir Rings <peterpuyi@live.cn>
@@ -46,8 +46,8 @@ app.listen(4000);
console.log('Running a GraphQL API server at localhost:4000/graphql');
```

In a REST API, authentication is often handled with a header, that contains an auth token which proves what user is making this request. Express middleware processes these headers and puts authentication data on the Express `request` object. Some middleware modules that handle authentication like this are [Passport](http://passportjs.org/), [express-jwt](https://github.com/auth0/express-jwt), and [express-session](https://github.com/expressjs/session). Each of these modules works with `express-graphql`.
REST API 中,认证通常是借由 header 处理的,其中包含一个 auth token 用于识别发出请求的用户。Express 中间件会处理这些 header,并将认证数据放进 Express `request` 对象。如此处理认证的中间件模块有 [Passport](http://passportjs.org/) [express-jwt](https://github.com/auth0/express-jwt) [express-session](https://github.com/expressjs/session)。这些模块每一个都能配合 `express-graphql` 使用。
Copy link
Member

Choose a reason for hiding this comment

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

『如此处理认证的中间件模块』要不改成『如果此处理认证的中间件模块』或『如该处理认证的中间件模块』,避免造成断句上的困扰?

Copy link
Collaborator Author

@jonirrings jonirrings Aug 7, 2017

Choose a reason for hiding this comment

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

好的。已更正,有劳再次审校。

Signed-off-by: Jonir Rings <peterpuyi@live.cn>
@linhe0x0 linhe0x0 merged commit 818f49e into xitu:zh-Hans Aug 10, 2017
@jonirrings jonirrings deleted the Tutorial-Authentication branch May 23, 2021 11:54
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-Authentication.md
3 participants