且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

执行经过身份验证的 keystone.js/GraphQL API 查询

更新时间:2023-12-06 15:44:04

答案是首先提交下面的查询,验证您的用户并生成访问令牌:

The answer is to first submit the query below, to authenticate your user and generate an access token:

query: `mutation ($identity: String, $secret: String) {
  authenticate: authenticateUserWithPassword(email: $identity, password: $secret) {
    token
  }
}`

然后通过将提供的令牌添加到您的请求标头中来验证后续查询:

Subsequent queries are then authenticated by adding the provided token to your headers of your request with:

'Authorization: Bearer <token>'.

更多信息此处.

更一般地说,GraphQL 游乐场非常值得一看适合刚接触 keystonejs 和 GraphQL 的任何人.

More generally, the GraphQL playground is well worth a look for anyone getting into keystonejs and new to GraphQL.