hasura / hasura/graphql-engine
Previous mutations are not rolled back when one fails
- Dominant language
- TypeScript
- Stars
- 32.1k
- Forks
- 3k
- PR merge metrics
- PR metrics pending
Description
### Version Information
Server Version: 2.8.3
### What is the current behaviour?
When executing a mutation composed of several operations, and when one of them failed, previous ones are not rolled back.
### What is the expected behaviour?
https://hasura.io/docs/latest/graphql/core/databases/postgres/mutations/multiple-mutations/#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.
### How to reproduce the issue?
Given these three postgres tables:
```sql
CREATE TABLE "articles"
(
"identifier" UUID NOT NULL DEFAULT Uuid_generate_v4(),
"title" TEXT NOT NULL,
CONSTRAINT "PK_eccda5e33eeb028ae7adc9ce71e" PRIMARY KEY ("identifier")
)
CREATE TABLE "images"
(
"identifier" UUID NOT NULL DEFAULT Uuid_generate_v4(),
"url" TEXT NOT NULL,
CONSTRAINT "PK_5dd26d55bd7a786386b840469cc" PRIMARY KEY ("identifier")
)
CREATE TABLE "articles_images"
(
"identifier" UUID NOT NULL DEFAULT Uuid_generate_v4(),
"article_identifier" UUID NOT NULL,
"image_identifier" UUID NOT NULL,
CONSTRAINT "PK_7f24e82a97c6c961bef5d97213a" PRIMARY KEY ("identifier")
)
```
and this graphQL mutation:
```graphql
mutation updateOneArticleMutation(
$identifier: uuid!,
$fields: articles_set_input!,
$imagesToAdd: [articles_images_insert_input!]!,
$imagesToDelete: [uuid!]!
) {
insert_articles_images(objects: $imagesToAdd) {
affected_rows
}
delete_articles_images(
where: {
article_identifier: {_eq: $identifier},
image_identifier: {_in: $imagesToDelete}
}
) {
affected_rows
}
update_articles_by_pk(
pk_columns: {identifier: $identifier},
_set: $fields
) {
identifier
title
images {
image {
identifier
url
}
}
}
}
```
When the third operation fails, the two ones before are not rolled back.
What i've done to determine that:
- I've replaced the `identifier` value in `update_articles_by_pk` > `pk_columns` by an invalid UUID string
```json
{
"errors": [
{
"extensions": {
"path": "$",
"code": "data-exception"
},
"message": "invalid input syntax for type uuid: \"NOT_AN_UUID\""
}
]
}
```
- I've set a SQL constraint that causes the update query to crash at the database level, not graphql engine:
```json
{
"errors": [
{
"extensions": {
"path": "$",
"code": "constraint-violation"
},
"message": "Uniqueness violation. duplicate key value violates unique constraint \"articles_title_key\""
}
]
}
```
These two cases leads to the same result: `insert_articles_images` and `delete_articles_images` mutations were commited to the database.
Thanks
Contributor guide
Assessment
This issue has not been assessed yet.