Replies: 1 comment 1 reply
-
When you say: "Here I'm also not sure why step 2 does not set c ID for b automatically." With your schema, nothing is inherently linking nodes b and c. Say you were to make fields
This outputs for example (using auto-incrementing keys to have tested this some):
I suspect your data-modeling might be a bit mangled, is there a reason to split B and C into different entities? The closest I can get to something like a single transaction is to set the columns nullable as mentioned above and then run a mutation like this:
Which outputs:
Keep in mind the way you have your structure setup will mean that the following statements must hold. A can have B's and C's B has an A and a C C has an A and a B There are no rules that say that "If B and C are linked, they have to share the same A". If that is a rule, as you seem to want it to be from the way you are expecting step 2 to set C for B automatically, you should probably remodel your data. Does it make sense for B and C to be separate tables? Could you put all the properties from both B and C into a single table "BC" and simplify your schema so that the rules simply becomes: A can have BC's BC's have an A Technically, if Table B requires a non-null foreign key from table C and table C requires a non-null foreign key from table B, you have a complete deadlock situation, because you cannot insert into one table without already having the required reference from the other table. Hope this helps some! :) |
Beta Was this translation helpful? Give feedback.
-
I'm using Relay endpoints generated in Hasura, connected to a PostgreSQL database.
Suppose there are three objects
a
,b
, andc
.a
has one-to-many relationships withb
s andc
s.c
has a one-to-one relationship withb
. (Exactly oneb
for eachc
, but not the other way around.)This is the essence of the Relay GraphQL schema for these objects:
I want to insert an object
a
withb
andc
altogether:But if I try the followings:
neither works, emitting errors like
I'm currently resorting to
a
withb
object nested,c
withb
ID, andb
withc
ID.Here I'm also not sure why step 2 does not set
c
ID forb
automatically.This makes 3 GraphQL queries which really hurts the performance.
Ideally I would like to perform this operation in a single transaction to make it robust.
What is the recommended way to deal with this kind of mutation?
I've originally asked this here.
Beta Was this translation helpful? Give feedback.
All reactions