hasura / hasura/graphql-engine

insert one on conflict returns nothing

Open
#9,224 0 comments 0 reactions 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.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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.