GraphQL API와의 상호작용벌크 mutation 실행
벌크 mutation 실행
Gato GraphQL은 스키마 내의 모든 mutation에 대해 「벌크」 mutation 필드를 제공하여, 여러 리소스를 한 번에 mutate할 수 있습니다.
예를 들어, mutation createPosts(단일 리소스 mutation은 createPost)는 여러 게시물을 생성합니다:
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
}
}
}인수
모든 벌크 mutation은 두 가지 인수를 받습니다:
inputs(필수): 입력 항목의 배열로, 각 항목에는 하나의 리소스를 mutate하기 위한 데이터가 포함됩니다stopExecutingMutationItemsOnFirstError(기본값:false): 입력 중 하나가 오류를 발생시킨 경우, 이후 입력에 대한 mutation 실행을 중단할지 여부를 지정합니다.
모든 mutation은 inputs 인수에 지정된 순서대로 실행됩니다.
사용 사례
벌크 mutation을 사용하면 WordPress 사이트 관리에서 다양한 가능성이 열립니다.
예를 들어, 다음 GraphQL 쿼리는 createPosts를 사용하여 게시물을 복제합니다:
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
}
}
}Prev
Next