Interactie met de GraphQL APIUitvoeren van bulk mutations
Uitvoeren van bulk mutations
Gato GraphQL biedt "bulk" mutation-velden voor alle mutations in het schema, waarmee je meerdere resources tegelijk kunt muteren.
Zo maakt de mutation createPosts (de mutation voor een enkele resource is createPost) meerdere posts aan:
mutation CreatePosts {
createPosts(inputs: [
{
title: "First post"
contentAs: {
html: "This is the content for the first post"
}
},
{
title: "Second post"
contentAs: {
html: "Here is another content, for another post"
}
excerpt: "The cup is within reach"
},
{
title: "Third post"
contentAs: {
html: "This is yet another piece of content"
},
authorBy: {
id: 1
},
status: draft
}
]) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
post {
id
title
content
excerpt
author {
name
}
status
}
}
}Argumenten
Alle bulk mutations accepteren twee argumenten:
inputs(verplicht): De array van invoeronderdelen, waarbij elk onderdeel de gegevens bevat om één resource te muterenstopExecutingMutationItemsOnFirstError(standaardfalse): Geeft aan of, als een van de invoeronderdelen een fout oplevert, de uitvoering van de mutation op de volgende onderdelen gestopt moet worden.
Alle mutations worden uitgevoerd in dezelfde volgorde als opgegeven in het argument inputs.
Gebruiksscenario's
Bulk mutations bieden nieuwe mogelijkheden voor het beheren van je WordPress-site.
De volgende GraphQL query gebruikt bijvoorbeeld createPosts om posts te dupliceren:
query ExportPostData
{
postsToDuplicate: posts {
rawTitle
rawContent
rawExcerpt
postInput: _echo(value: {
title: $__rawTitle
contentAs: {
html: $__rawContent
},
excerpt: $__rawExcerpt
})
@export(as: "postInputs", type: LIST)
@remove
}
}
mutation CreatePosts
@depends(on: "ExportPostData")
{
createPosts(inputs: $postInputs) {
status
errors {
__typename
...on ErrorPayload {
message
}
}
post {
id
title
content
excerpt
}
}
}