首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >对Wiki.js的Graphql的响应是“禁止的”

对Wiki.js的Graphql的响应是“禁止的”
EN

Stack Overflow用户
提问于 2019-12-05 10:39:57
回答 1查看 2.8K关注 0票数 3

我使用Wiki.js作为停靠容器,并且知道它确实支持Graphql响应API请求(例如:获取wiki页面内容)。当我试图查询一个页面的标题时,我会收到一条响应消息,称为“禁止的”。

请求:

代码语言:javascript
复制
query{
  pages {
    single(id: 2 ){
      title
    }
  }
}

响应:

代码语言:javascript
复制
{
  "errors": [
    {
      "message": "Forbidden",
      "locations": [
        {
          "line": 3,
          "column": 5
        }
      ],
      "path": [
        "pages",
        "single"
      ],
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "exception": {
          "stacktrace": [
            "Error: Forbidden",
            "    at field.resolve (/wiki/server/graph/directives/auth.js:47:17)",
            "    at field.resolve (/wiki/node_modules/graphql-extensions/dist/index.js:133:26)",
            "    at resolveFieldValueOrError (/wiki/node_modules/graphql/execution/execute.js:467:18)",
            "    at resolveField (/wiki/node_modules/graphql/execution/execute.js:434:16)",
            "    at executeFields (/wiki/node_modules/graphql/execution/execute.js:275:18)",
            "    at collectAndExecuteSubfields (/wiki/node_modules/graphql/execution/execute.js:713:10)",
            "    at completeObjectValue (/wiki/node_modules/graphql/execution/execute.js:703:10)",
            "    at completeValue (/wiki/node_modules/graphql/execution/execute.js:591:12)",
            "    at /wiki/node_modules/graphql/execution/execute.js:492:16",
            "    at process._tickCallback (internal/process/next_tick.js:68:7)"
          ]
        }
      }
    }
  ],
  "data": {
    "pages": {
      "single": null
    }
  }
} 

有人能让我知道我做错了什么来通过wiki.js的Graphql获得页面的标题吗?

谢谢你的帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-12-18 12:26:10

假设我们正在从Graphql游乐场进行查询

我花了一些时间来理解它,但这里是如何启动graphql查询,这需要授权用户的权限。

您需要确保请求来自授权用户的服务器,为此触发登录请求,并为该用户获取令牌(jwt)。

代码语言:javascript
复制
mutation { 
    authentication {
    login(
      username: "username@test.com",
      password: "yourpassword",
      strategy: "local"
    ) {
      jwt
    }
  }
}

然后在Headers中添加从登录请求中收到的令牌,如

代码语言:javascript
复制
{
  "Authorization": "Bearer longStringOfYourJwtToken"
}

希望这能帮助其他像我这样的记者理解Wiki.js和GraphQL。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59193315

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档