-
-
Notifications
You must be signed in to change notification settings - Fork 567
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Natural vs opaque surrogate keys for defining associations #42
Comments
This doesn't sound like a bad idea. What I'd recommend is detecting if the primary key column has a type of uuid and then switch to using solely the A couple of constraints to keep in mind:
|
Automatic detection can produce inconsistency in query schema(some entities will work with ID/rowId, some will work with UUID). I am not sure if we should silently select identification scheme based only on schema. I would otherwise require specific switch to turn on auto-detection mode. So I would suggest to create special UUID mode with parameter, which will turn on autodetection you suggested. Also extra information will be printed in log(about table-scheme mode). |
Another question(probably related to topic) : why do we need Node(id:ID) query? Without it:
|
The Relay object identification specification requires it to retrieve nodes back. |
I'm not afraid of automatic detection because Another complexity is the current id format contains information about the table so that it can be reselected according to the Relay specification using the |
About automatic detection - ok, let's do it this way.
|
Why we need This interface used during refetching and partial fetching of extra props. I have better idea how to get rid of
So mutation :
where 1 - is
and
That approach should remove inconsistency between UUID question became not important in case of implementation of such scheme. |
@artem-barim yep, consistency between these two ID schemes is super important. The blocker that I've run into before is compound keys. We can't easily generate a name for that single ID field when a table has two keys (well A solution using the constraint name is plausible as is explored in #34. |
For me, main question here : what is the best way to define associations? If scheme design is based on surrogate keys, we can force user to use opaque In case of natural keys user probably wants to build associations using specific values(ex: country code, language code) and forcing him to use opaque identifier may break usage scenarios. So he should be able to use specific column values for building association. As for composite key naming - constraint name is good option. |
Yeah, I agree this is a tough decision. Maybe union types are a good space to explore? So for your example a GraphQL ID could be: |
Since this issue has evolved into a new conversation could you rename the title or open a more specific issue? |
To summarize:
(sorry: I can't imagine real world example with composite primary key, only table with many-to-many association, but in general algorithm can handle them) Sample pg schema:
Will produce following graphql schema:
Mutations will be following
Such scheme gives as ability to build associations with opaque ID's, still keeping natural keys available. |
I’m going to close this as its in the PostGraphQL 2.0 beta 🎉 Start playing with the pre-release, the final release should be out really soon. Tell me what you think! 👍 Specifically,
|
* Add uppercase enums to reproduce issue * Fix enum capitalisation issues * Prefix 0_CONSTANT with _ * Lint * Tweak README
For some applications have separate
ID
androwId
fields increase complexity a lot(I am portingng-admin
to usepostgraphql
generated endpoint).As I understand - main reason for using special ID type is to provide global unique object identifier across all entities/tables. This requirement also can be solved by usage of UUID as primary key for tables.
That's why I would like to see parameter(for example : --uuid-based-schema) that will remove
rowId
and will use ordinaryid
as key forgraphql
queries.I can work on this feature and would like to hear any thoughts/concerns before designing it.
The text was updated successfully, but these errors were encountered: