Wiki.js GraphQL: create page example

5.7k Views Asked by At

I'm totally new at GraphQL and I don't understand how to compose a PageMutation create call for Wiki.js. Their GraphQL playground is available on the public docs. The schema for creation is:

type PageMutation {
  create(
    content: String!
    description: String!
    editor: String!
    isPublished: Boolean!
    isPrivate: Boolean!
    locale: String!
    path: String!
    publishEndDate: Date
    publishStartDate: Date
    scriptCss: String
    scriptJs: String
    tags: [String]!
    title: String!
  ): PageResponse

In the GraphQL docs pages they say mutation parameters should be declared as input ones, but this one isn't. Also, I've seen no description for this kind of structure (object in object?), and I don't see how to use it.

Hints welcome. Thanks

1

There are 1 best solutions below

0
On BEST ANSWER

So here's the example for a page creation without variables, just the mutation itself:

mutation Page {
  pages {
    create (content:"contenuto", description:"descrizione", editor: "code", isPublished: true, isPrivate: false, locale: "it", path:"/", tags: ["tag1", "tag2"], title:"titolo") {
      responseResult {
        succeeded,
        errorCode,
        slug,
        message
      },
      page {
        id,
        path,
        title
      }
    }
  }
}

Details on GraphQL docs.

Here's an example with variables:

mutation Page ($content: String!, $descrizione: String!, $editor:String!, $isPublished:Boolean!, $isPrivate:Boolean!, $locale:String!, $path:String!,$tags:[String]!, $title:String!) {
  pages {
    create (content:$content, description:$descrizione, editor: $editor, isPublished: $isPublished, isPrivate: $isPrivate, locale: $locale, path:$path, tags: $tags, title:$title) {
      responseResult {
        succeeded,
        errorCode,
        slug,
        message
      },
      page {
        id,
        path,
        title
      }
    }
  }
}

Query variables:

{
  "content": "contenuto", 
  "descrizione":"descrizione", 
  "editor": "code", 
  "isPublished": true, 
  "isPrivate": false, 
  "locale": "it", 
  "path":"/pagina01", 
  "tags": ["tag1", "tag2"], 
  "title":"titolo"
}