-
-
Notifications
You must be signed in to change notification settings - Fork 104
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
Naming reverse related fields #502
Comments
dupe of #345 the explanation of how to resolve is here: #345 (comment) Previously we decided that the current behavior is expected but this has come up enough times we might need to revisit. Do you have any suggestions for what behavior you'd find more intuitive? |
for example we could do
a challenge there would be that if the foreign key under |
Thanks for the quick response! I'm inclined towards the first option of making every relationship accessible and encouraging users to rename them. Is it feasible to display the actual column name in this process? Additionally, I've scoured the documentation, searched online, reached out to the Supabase community, and even consulted GPT, but unfortunately, I couldn't find any information on this topic. |
The solution is in docs here https://supabase.github.io/pg_graphql/configuration/#relationships-field but you're right that we should explicitly call out this issue as something it can address if we don't resolve it with the |
I'm running into the same issue, but with unique partial indices, and I'm unable to resolve it using comment directives (if I'm misunderstanding and this is better posted as a separate issue, let me know and I'm happy to move it!) I have a table that looks something like this:
When I look at userspaceWorks in the GraphiQL docs, I see:
So far so good. But now I want to add a unique partial index to ensure data integrity:
When I do that, and go back to userspaceWorks in the GraphiQL docs, This is exactly the same behavior I see when I run into name conflict issues with foreign key references (table1.foo references FIELD, and table1.bar also references FIELD), so I think this is caused by having both the (user_id, work_id) compound foreign key and the (user_id, work_id) as part of a unique partial index ...but I think the unique partial indices don't actually create an fkey, and comments on the indices seem to be ignored, so I'm actually unable to resolve this I'm currently using triggers to ensure data integrity, but would of course prefer to use a much cleaner unique partial index. |
Also: I would've preferred customer, customer1 instead of simply colliding the names This is also a great fit for another linter rule, I think When I ran into this in the wild, it was a headache to chase down I had a table like this:
Then we decided to make it so lists could contain other lists, so we changed it to something like:
All of a sudden, lists broke Took a while to chase down, but it was the same issue as above:
because they reference the same field, they collided in the GraphQL docs, and the "list_id" reference was silently overwritten by "other_list_id" reference I had to add this so the two relationships were considered separate by pg_graphql:
Similarly, I had to do the same for the compound fkey: I definitely would've preferred that the two relationships were considered separate by in pg_graphql And this also feels like something that would be a good warning in a linter, "hey you have two fkeys in the same table pointing to the same field, consider adding a comment directive to distinguish them" (or to rename them) |
@pawarren this sounds like, at minimum, we may be handling partial unique indexes as fully unique indexes. Could you please try to create a minimal reproducible example and open a separate issue for it. You covered a lot of ground in the explanation there. The more narrowly focused the issue is the easier it'll be for us to track down |
Done! |
Summary
I have a table
customers
that contains two foreign keys (coach
,partner
), which reference its own table. Using GraphQL, I aim to design a query that would allow me to retrievecustomers
along with their associatedcoach
andpartner
, both of which are alsocustomers
. However, the current GraphQL schema only provides a singlecustomers
field oncustomersEdge
, which does not differentiate betweencoach
andpartner
.Instead, my query looks like this, combining both foreign keys under a single
customers
field without a clear way to distinguish between the two roles:Is there a method or workaround to achieve the desired query structure?
Rationale
Creating distinct fields for
coach
andpartner
within thecustomers
query is essential for clarity and to accurately represent the relationships within our data model. This would allow consumers of the GraphQL API to specifically request the data they need and understand the relationships between differentcustomers
.Design
I do not have any known solutions.
Alternatives
Unresolved Questions
The text was updated successfully, but these errors were encountered: