GraphQL API ile EtkileşimToplu mutations çalıştırma
Toplu mutations çalıştırma
Gato GraphQL, şemadaki tüm mutations için "toplu" mutation alanları sağlar ve birden fazla kaynağı aynı anda mutate etmemize olanak tanır.
Örneğin, createPosts mutation (tek kaynak mutation: createPost) birden fazla gönderi oluşturur:
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
}
}
}Argümanlar
Tüm toplu mutations iki argüman kabul eder:
inputs(zorunlu): Her öğenin bir kaynağı mutate etmek için gerekli verileri içerdiği girdi öğeleri dizisistopExecutingMutationItemsOnFirstError(varsayılanfalse): Herhangi bir girdi hata üretirse, sonraki girdilerde mutation çalıştırmanın durdurulup durdurulmayacağını belirtir.
Tüm mutations, inputs argümanında belirtilen sırayla çalıştırılır.
Kullanım senaryoları
Toplu mutations, WordPress sitemizi yönetmek için yeni olanaklar sunar.
Örneğin, aşağıdaki GraphQL queries createPosts kullanarak gönderileri çoğaltır:
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
}
}
}