3

I am using Wiki.js as docker container and came to know that it does supports Graphql to respond to API request (for eg: getting wiki pages content). When I try to query it for a page's title, I get a response message as "Forbidden".

Request:

query{
  pages {
    single(id: 2 ){
      title
    }
  }
}

Response:

{
  "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
    }
  }
} 

Could someone let me know what wrong I am doing to get page's title via Graphql APIs of wiki.js?

Thanks for the Help.

Rizwan
  • 61
  • 1
  • 6

1 Answers1

3

Assuming that we are firing querying from Graphql Playground

It took me some time to understand it but here is the how you can fire graphql queries which need authorized users permission.

You need ensure the server that request is coming from an authorized user, for this fire a login request and get a token (jwt) for that user

mutation { 
    authentication {
    login(
      username: "username@test.com",
      password: "yourpassword",
      strategy: "local"
    ) {
      jwt
    }
  }
}

then in HTTP Headers add the token you received from logging in request like

{
  "Authorization": "Bearer longStringOfYourJwtToken"
}

Hope that this helps other newbees like me in understanding Wiki.js and GraphQL

Rizwan
  • 61
  • 1
  • 6