hasura / hasura/graphql-engine
insert one on conflict returns nothing
- Dominant language
- TypeScript
- Stars
- 32.1k
- Forks
- 3k
- PR merge metrics
- PR metrics pending
Description
### Version Information
Server Version: v2.15.0
### Environment
local docker dev env
### What is the current behaviour?
I've got a query like this. It's a simple users table with an autogenerated id and a default role.
```graphql
mutation insertIfNewUser($email: String!) {
insertMseagFinanceUsersOne(
object: {email: $email},
onConflict: {
constraint: users_email_key
}
) {id role}
}
```
when I run this mutation it will insert a new user and it returns a response. But I don't get any response at all when the user already exists. Also it seems that the sequence is getting incremented even if a user is not created
### What is the expected behavior?
I would like the above query to return results in case of a conflict. I would also like the sequence to not increment if there's no record inserted.
### How to reproduce the issue?
1. run the above query with a unique constraint on email
2. get a result
3. run it again, nothing is returned
### Any possible solutions/workarounds you're aware of?
my workaround is to just query first and then don't run the insert if the user already exists.
Contributor guide
Research direction
The report provides no source file or test entry point. Start by reproducing the mutation with a unique email and the users_email_key constraint, then trace how the insert and conflict response are handled. Done means a conflict returns the requested id and role, with the expected sequence behavior verified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- postgres
- Domain
- api, database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100