Multiple mutations in a request¶
Table of contents
Execution¶
If multiple mutations are part of the same request, they are executed sequentially in a single transaction. If any of the mutations fail, all the executed mutations will be rolled back.
Run multiple top level mutations in the same request¶
Example: Delete all article
objects written by an author and update the author
object:
GraphiQL
1
mutation reset_author {
2
delete_article (
3
where: {author_id: {_eq: 6}}
4
) {
5
affected_rows
6
}
7
update_author (
8
where: {id: {_eq: 6}}
9
_set: {name: "Cory"}
10
) {
11
returning {
12
id
13
name
14
articles {
15
id
16
title
17
}
18
}
19
}
20
}
Variables
x
1
xxxxxxxxxx
{
"data": {
"delete_article": {
"affected_rows": 2
},
"update_author": {
"returning": [
{
"id": 6,
"name": "Cory",
"articles": []
}
]
}
}
}
Insert an object and a nested object in the same mutation¶
If you are trying to insert multiple objects which have relationships between them, you can use nested inserts.
Example: Insert a new article
object with its author
and return the inserted article object with its author
in the response:
GraphiQL
25
1
mutation insert_article {
2
insert_article(
3
objects: [
4
{
5
title: "Article 1",
6
content: "Sample article content",
7
author: {
8
data: {
9
name: "Cory"
10
}
11
}
12
}
13
]
14
) {
15
affected_rows
16
returning {
17
id
18
title
19
author {
20
id
21
name
22
}
23
}
24
}
25
}
Variables
1
1
xxxxxxxxxx
{
"data": {
"insert_article": {
"affected_rows": 2,
"returning": [
{
"id": 21,
"title": "Article 1",
"author": {
"id": 11,
"name": "Cory"
}
}
]
}
}
}
Was this page helpful?
Thank you for your feedback!
Stay up to date with product & security news
See past editions