Hi, I have a question regarding how graphcool woul...
# prisma-whats-new
j
Hi, I have a question regarding how graphcool would handle two entities such as the following:
Copy code
type TwoWayLeft {
  id: ID!
  one: TwoWayRight!  // ! (required) and [] (list) thrown in for extra complication
  two: [TwoWayRight] // although even plain (modifier-free) fields would seem problematic.
}

type TwoWayRight {
  id: ID!
  three: TwoWayLeft
  four: TwoWayLeft
}
[or any number of similar problematic (from a data modeling perspective) cases]. How would graphcool know which fields on each side correspond to fields on the other side in order to setup the foreign keys/relationships in the underlying physical database schema (Postgres/SQL or NoSQL or what have you)?
n
@jleonard did you try to set a project up with that data model? By analysing the query we can distinguish between
one
and
two
, or between
three
and
four
j
@nilan which query? How do you know the correspondences between the tables for foreign key relations (which must be done from the data model only-- no queries exist or are involved at that point).
n
so first of all, the DB we use is AWS Aurora, which is a highly-scalable MySQL variant.
We're taking the data model that you define and build a database that keeps model and relation tables. Then a relation field on a model will have a FK on the relation table.
j
Yes, but when there are 2 or more fields between two tables, how do you know which links to which? In my example,
three
or
four
could correspond to
one
or
two
.
and
two
itself could actually be an independent list with no reverse link back from
TwoWayRight
.
make sense?
and, based on this: https://www.graph.cool/docs/reference/platform/relations-goh5uthoc1/ it seems that this is forbidden
"Note: Two nodes can only be connected once for each relation between the according two models."
n
it's not forbidden
for each relation
meaning that for a given relation, two nodes can either be connected, or not connected. They can not be connected twice for the same relation.
They can be connect with two separate relations though.
j
how would "twice for the same relation" even look in practice? can you give an example data model that would violate this rule?
that's kind of like saying: "the number one cannot be the number two"
well, yes, because the number one is the number one. it is not the number two. a tautology.
n
I cannot give you a data model violating this rule, but I can give you a data state that violates this rule. Because this is a rule about the data state and not the data model.
j
ok, what state is that?
n
Let's say you're subscribing to products
maybe you wanted to subscribe to the same product twice in your app
why not
j
so, on
User
I have a
[Product]
yea?
n
yea
j
so you're saying that lists with repeating items are universally forbidden?
that seems a bit draconian
n
that's what I'm saying. If you need to model this, you can use an intermediate model
j
ok cool. thx
but you still haven't answered my original question re: the correspondences between the two models' fields
n
may I ask why you're so interested in that question?
and you haven't answered my question if you have tried this in the UI 🙂
j
because i have such a model 🙂
i haven't tried it but it seemed like a problematic case just reasoning through it and i wondered how you guys were handling it
n
well I tried to answer your question by saying we are treating relations as their own entity
we save meta information for a relation, such as its name, the multiplicity for both sides, the models it connects and what the field names are
j
so.. a "linking table" for all cardinalities?
yes, but you wouldn't know all of that just from the model i gave above
n
now when we need to resolve a relation field, we look up this meta data and know what relation this field maps to
ah I see
j
the choice of "relation" between one:three, one:four, two:three, two:four particularly
n
note the @relation(name: "Tweets")
j
ahh, i see. so you've extended the GQL language?
n
well you usually define the relations using the UI
but yea, we did that for the schema files
j
right, but if down the road I want to take my schema to a different BaaS provider, it wouldn't work with those extensions in place
[at least not without some extra work/care]
n
hopefully that different BaaS provider has a similar, straightforward syntax so you can write a script that migrates the IDL syntax we propose to the other option
j
ok, fair enough. thx for your help!
n
we're open to and actively pushing for a general consensus regarding the IDL syntax for matters like this
cheers!
j
cheers!