2

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

Maxxer
  • 1,038
  • 1
  • 18
  • 37
  • play with playground, it hints possible code lines ... create hardcoded mutation then parametrize it using query variables ... not much different than normal, simple, flat graphql schema – xadm Oct 14 '20 at 22:26

1 Answers1

4

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"
}
Maxxer
  • 1,038
  • 1
  • 18
  • 37