hasura / hasura/graphql-engine

Can't do nested upsert if unique constraint

Open
#8,143 0 comments 1 reaction 0 assignees View on GitHub
k/bug
Dominant language
TypeScript
Stars
32.1k
Forks
3k
PR merge metrics
PR metrics pending

Description

### Version Information

Server Version: [v2.0.10-cloud.1](https://cloud.hasura.io/project/1ff3f003-6a5e-4907-a304-29bac3d0132a/console/)

### Environment

Cloud

### What is the expected behaviour?

I set up a tiny hasura cloud project to show the behaviour. The name is "fair-moccasin-95". Can you access it or can I transfer ownership to someone who can have a look?

![image](https://user-images.githubusercontent.com/10000865/152591697-9334f7be-0692-4b9c-a2fd-8e60cad75942.png)

![image](https://user-images.githubusercontent.com/10000865/152591775-edb4f6ab-0fe5-488c-a906-886e4cffe23a.png)

I would expect this mutation to work:

```graphql
mutation {
insert_apples(objects: [
{id: 1, apple_oranges: {
data: [{
orange_id: 2,
order: 1
},
{
orange_id: 1,
order: 2
},
],
on_conflict: {
constraint: apple_oranges_apple_id_order_key
}
}}
], on_conflict: {
constraint: apples_pkey
update_columns: [id]
}) {
affected_rows
}
}
```

but I am getting there error:
```
{
"errors": [
{
"extensions": {
"path": "$.selectionSet.insert_apples.args.objects[0].apple_oranges.data",
"code": "constraint-violation"
},
"message": "Uniqueness violation. duplicate key value violates unique constraint \"apple_oranges_pkey\""
}
]
}
```

I am expecting it to work because at the end of the mutation then the uniqueness is preserved.

Thanks a million,

Lydia

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.