hasura / hasura/graphql-engine
Many to Many relationship - Foreign key violation. insert or update on table
- Dominant language
- TypeScript
- Stars
- 32.1k
- Forks
- 3k
- PR merge metrics
- PR metrics pending
Description
### Version Information
Server Version:
CLI Version (for CLI related issue): v2.30.1
### Environment
### What is the current behaviour?
My mutation does not work after upgraded Hasura version.
```
mutation insertSaasCompany(
$company: companies_insert_input!
$isOnboarding: Boolean!
$group: groups_insert_input!
) {
insertedGroup: insert_groups_one(object: $group) @include(if: $isOnboarding) {
group_id
name
type
}
insertedCompany: insert_companies_one(object: $company) {
companyId: company_id
groupId: group_id
}
}
```
My variables
```
{
"company": {
"company_id": "8b4ac3fb-bbc1-4893-afde-bde40e042584",
...
"company_employees": {
"data": [
{
"employee_id": "cdca39a3-e7fc-49d5-ae7b-1510ece54551",
...
}
]
},
...
"expense_policies": {
"data": [
{
...,
"expense_policies_employees": {
"data": [
{
"employee_id": "cdca39a3-e7fc-49d5-ae7b-1510ece54551"
}
]
}
}
]
},
...
},
"isOnboarding": true,
...
}
```
It worked on version 2.27 and older. But I got error after upgraded version to 2.28 - 2.30.1
### Please provide any traces or logs that could help here.
```
{
"errors": [
{
"message": "Foreign key violation. insert or update on table \"expense_policies_employees\" violates foreign key constraint \"expense_policies_employees_employee_id_fkey\"",
"extensions": {
"path": "$.selectionSet.insert_companies_one.args.object[0].expense_policies.data[0].expense_policies_employees.data",
"code": "constraint-violation"
}
}
]
}
```
### Any possible solutions/workarounds you're aware of?
I think it related to this issue https://github.com/hasura/graphql-engine/issues/8522
employee_id is predefined with uuid v4()
Contributor guide
Research direction
Start by reproducing the mutation with the nested company, expense policy, and employee data on version 2.27 and versions 2.28–2.30.1, then compare the nested-insert behavior and foreign-key ordering. Done means the mutation succeeds without the expense_policies_employees_employee_id_fkey violation, or the regression is isolated to a specific change.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, postgresql
- Domain
- api, backend, databases
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100