-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Description
Version Information
Server Version: 2.19.0
CLI Version (for CLI related issue): 2.18.0
Environment
OSS
What is the current behaviour?
When a 3-layer nested insert is executed and the middle layer its primary key column is also the foreign key to the top layer, an error occurs, preventing the insert mutation.
What is the expected behaviour?
When a 3-layer nested insert is executed and the middle layer its primary key is also the foreign key to the top layer, the insert succeeds and all three tables each have a new record added.
How to reproduce the issue?
- Create a table
A0_TABLEwith a single columnA0_PK, type uuid, not nullable, default value gen_random_uuid(), primary key - Create a table
A1_TABLEwith a single columnA1_PK, type uuid, not nullable, no default value, primary key, foreign key toA0_PK(RESTRICT,RESTRICT) - Create a table
A2_TABLEwith a single columnA2_PK, type uuid, not nullable, no default value, primary key, foreign key toA1_PK(RESTRICT,RESTRICT) - Add a relationship
A0_REL_TO_A1inA0_TABLE, type array, to remote tableA1_TABLE, fromA0_PKoA1_PK - Add a relationship
A1_REL_TO_A2inA1_TABLE, type object, to remote tableA2_TABLE, fromA1_PKtoA2_PK - Execute the following insert mutation:
mutation MyMutation {
insert_A0_TABLE(objects: {A0_REL_TO_A1: {data: {A1_REL_TO_A2: {data: {}}}}}) {
affected_rows
}
}
- The following error occurs:
{
"errors": [
{
"extensions": {
"code": "validation-failed",
"path": "$.selectionSet.insert_A0_TABLE.args.objects[0].A0_REL_TO_A1.data[0].A1_REL_TO_A2"
},
"message": "cannot insert object relationship \"A1_REL_TO_A2\" as \"A1_PK\" column values are already determined"
}
]
}
Screenshots or Screencast
Please provide any traces or logs that could help here.
Server error log when executing the insert mutation
2023-02-21 14:42:50 {"detail":{"generated_sql":null,"kind":"database","query":{"operationName":"MyMutation","query":"mutation MyMutation {\n insert_A0_TABLE(objects: {A0_REL_TO_A1: {data: {A1_REL_TO_A2: {data: {}}}}}) {\n affected_rows\n }\n}\n"},"request_id":"0635b3d0-43c0-4899-addf-68656358f8e1"},"level":"info","timestamp":"2023-02-21T13:42:50.064+0000","type":"query-log"}
2023-02-21 14:42:51 {"detail":{"http_info":{"content_encoding":null,"http_version":"HTTP/1.1","ip":"172.19.0.1","method":"POST","status":200,"url":"/v1/graphql"},"operation":{"error":{"code":"validation-failed","error":"cannot insert object relationship \"A1_REL_TO_A2\" as \"A1_PK\" column values are already determined","path":"$.selectionSet.insert_A0_TABLE.args.objects[0].A0_REL_TO_A1.data[0].A1_REL_TO_A2"},"query":{"operationName":"MyMutation","query":"mutation MyMutation {\n insert_A0_TABLE(objects: {A0_REL_TO_A1: {data: {A1_REL_TO_A2: {data: {}}}}}) {\n affected_rows\n }\n}\n","variables":null},"request_id":"0635b3d0-43c0-4899-addf-68656358f8e1","request_mode":"error","response_size":229,"uncompressed_response_size":229,"user_vars":{"x-hasura-role":"admin"}},"request_id":"0635b3d0-43c0-4899-addf-68656358f8e1"},"level":"error","timestamp":"2023-02-21T13:42:50.064+0000","type":"http-log"}
Any possible solutions/workarounds you're aware of?
It's not possible to fix this by changing the generated metadata files of public_A0-TABLE.yaml and/or public_A1-TABLE.yaml such that the insertion order setting would somehow cause Hasura to allow the insert.
As far as we can tell, it does not matter whether the Hasura GraphQL relationship between A0 and A1 defined above are of type array or object, the result is the same. It also makes no difference what value the database connection setting Isolation Level is set to.
We have a complex setup where in our case that's like this scenario, though with obviously more columns in each table but nothing that complicates the scenario (i.e. no other keys or relationships). In our case, there are several tables at the A2 layer that all have a foreign key to A1, but for the sake of submitting this bug we've reduced the scenario as much as possible, to this simple set of steps that causes the error.
We need this setup of tables and keys this way, to make proper use of the the code generation tool that creates TypeScript types based on the database structure and defined GraphQL relationships.
Keywords
nested, insert, column, values, already, determined, primary, foreign, key, cannot, insert, object, relationship,