Craft CMS Asked on July 17, 2021
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?
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"
}
Correct answer by Oli on July 17, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP