Wiki.js 对 Graphql API 的响应是 "Forbidden"
Response to Graphql API of Wiki.js is "Forbidden"
我正在使用 Wiki.js 作为 docker 容器,并且了解到它确实支持 Graphql 来响应 API 请求(例如:获取 wiki 页面内容)。
当我尝试向它查询页面标题时,我收到一条响应消息 "Forbidden"。
要求:
query{
pages {
single(id: 2 ){
title
}
}
}
响应:
{
"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 API 获取页面标题时做错了什么吗?
感谢您的帮助。
假设我们从 Graphql Playground 触发查询
我花了一些时间来理解它,但这里是如何触发需要授权用户许可的 graphql 查询。
您需要确保请求来自授权用户的服务器,为此会触发登录请求并为该用户获取令牌 (jwt)
mutation {
authentication {
login(
username: "username@test.com",
password: "yourpassword",
strategy: "local"
) {
jwt
}
}
}
然后在 HTTP Headers 中添加您从登录请求中收到的令牌,例如
{
"Authorization": "Bearer longStringOfYourJwtToken"
}
希望这有助于像我这样的其他新手理解 Wiki.js 和 GraphQL
我正在使用 Wiki.js 作为 docker 容器,并且了解到它确实支持 Graphql 来响应 API 请求(例如:获取 wiki 页面内容)。 当我尝试向它查询页面标题时,我收到一条响应消息 "Forbidden"。
要求:
query{
pages {
single(id: 2 ){
title
}
}
}
响应:
{
"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 API 获取页面标题时做错了什么吗?
感谢您的帮助。
假设我们从 Graphql Playground 触发查询
我花了一些时间来理解它,但这里是如何触发需要授权用户许可的 graphql 查询。
您需要确保请求来自授权用户的服务器,为此会触发登录请求并为该用户获取令牌 (jwt)
mutation {
authentication {
login(
username: "username@test.com",
password: "yourpassword",
strategy: "local"
) {
jwt
}
}
}
然后在 HTTP Headers 中添加您从登录请求中收到的令牌,例如
{
"Authorization": "Bearer longStringOfYourJwtToken"
}
希望这有助于像我这样的其他新手理解 Wiki.js 和 GraphQL