2

I'm trying out the GraphQL mutations and would like to issue an update of an Entry, triggered from a webhook.

However, documentation on mutations seems sparse, and I find GraphQL highly confusing. Most examples talk about creating new entries, not update current ones, and how you actually call graphQL relies on implementation, it's hard to figure out how to deal with this in Craft.

I found https://github.com/craftcms/cms/issues/4835, which shows an example of creating an entry. Documentation talks about creating drafts, and publishing drafts, but no examples are shown, just a bunch of words thrown around.

First it says:

To save a draft for an entry, use the entry type-specific mutation which will have the name in the form of save___Draft

But then followed by:

To create a draft use the createDraft mutation., which requires the id of the entry for which to create the draft as an argument and returns the resulting id of the draft as the result.

For publishing a draft, you should use the publishDraft mutation, which requires the id of the draft to publish as an argument and returns the id of the entry it belongs to as the result.

None of these things makes sense to me...

Anyone have any comprehensible examples they can give?

1 Answer 1

3

To edit an entry via a GraphQL mutation you will need to pass the id of the entry you want to edit (similar to front end entry form).

This example assumes a news Section, an article Entry Type and will update the entry title.

Mutation

mutation MyMutation($id: ID = "", $title: String = "") {
  save_news_article_Entry(id: $id, title: $title) {
    id
    title
  }
}

Query variables

{
  "id": "12345",
  "title": "My title update"
}
4
  • This should be runnable in the "Explore the GraphQL API" executor, right? Because it seems to do nothing, I'm passing in the id (605, from the url of that entry page) but I just get { "data": [] } in return.
    – jishi
    Dec 15, 2020 at 9:44
  • Did you change save_news_article_Entry to match your entry section and type? So save_yourSectionHandle_yourEntrytypeHandle_Entry.
    – Oli
    Dec 15, 2020 at 9:59
  • Yeah, I'm using save_lovstaStuteriStallions_hingstsida_Entry to match the handle of the section, and the handle of the entry type. Just realized that it works with the Full Schema, and I had forgotten to check the "save entries" under the mutation permission, only had the parent "edit entries" permission checked. Not sure about the purpose of the parent "Edit" checkbox if you still need one of the child permissions selected anyway... ?
    – jishi
    Dec 15, 2020 at 10:03
  • It's mostly for grouping purposes. Glad it's working for you though!
    – Oli
    Dec 15, 2020 at 10:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.