pg_graphql
pg_graphql copied to clipboard
Support filtering based on child table relationship
Describe the bug Support filtering based on child table relationship
Expected behavior
This issue is stale because it has been open for 30 days with no activity.
Would like to see this as well, this is really what makes graphql appealing imo.
How can I vote for this enhancement? 😅
you just did!
I agree this would be a great feature. We're currently focusing on some rough edges where we're not quite spec compliant + and improving type support (json/jsonb) arrays etc.
Once we have a good foundation for all the basics, this will be a feature we'll be interested in, but it isn't actively under development yet
+1 (Adding context from #296)
Hasura can do this for both child and parent relationships. AFAIK the REST API can do this currently only for child relationships (see "Filter Foreign Tables").
For example with Hasura, this selects authors containing a name with all their books, or authors and the specific books whose description contains the name. This is often desired in a search. Note how this filters both on child and parent relationships.
query {
authors(where: {_or: [{name: {_iregex: $name}}, {books: {description: {_iregex: $name}}}]}) {
name
books(where: {_or: [{author: {name: {_iregex: $name}}}, {description: {_iregex: $name}}]}) {
title
description
}
}
}
(Note, for the relationship names to be set like this in Hasura, the foreign key columns should not match the table name. For example, one can use a suffix like _id
, e.g. books_id
column in authors
table and author_id
column in books
table.)
Any update on this feature? It's currently my biggest blocker.
No movement yet but I'm aware that this is high interest feature
The only higher priority is user defined mutations via SQL functions
FYI: Everyone is currently finalizing deliverables for launch week 8. You should see the pace of development pick back up after that
I just wanted to add to the hype of this feature 🥳.
Keep up the good work pg_graphql is very promising!
I'm also looking for this feature!
Interested in this one. Is there any workaround now like database views or whatever?
Interested in this one. Is there any workaround now like database views or whatever?
unfortunately, there isn't currently a workaround for filtering parents based on children
Hey @olirice,
Any update on this ?
We're using pg_graphql
at Twenty when querying the database for the dynamic part of the GraphQL API, and really need this feature
Thanks a lot to Supabase for this awesome project !
none yet, but we've identified nested inserts (which requires upsert support to work well) as the next big project we're tackling in pg_graphql so you should start to see movement on it
none yet, but we've identified nested inserts (which requires upsert support to work well) as the next big project we're tackling in pg_graphql so you should start to see movement on it
is there any workaround to achieve the same effect right now?
You could
- write a function that performs the filter ahead of time
- use two requests / filter on the client
- use a computed field if you're always filtering the child in the same way (no parameters required)
but all have their drawbacks
I'm trying to filter data from table A based on a value in table B. Specifically, I want to filter records where B.something (some condition) specific value. I haven't been able to find an example of this query in the Supabase documentation. Could you please confirm if this type of filtering is supported in GraphQL on Supabase? If not, are there any workarounds or alternative approaches I could consider?
@Mihai-github have you tried one of the options mentioned by @olirice above? If these don't work for you can you share more details about your use case?
I'd love to tackle this problem, but I'm not sure how the GQL is translated into a PG query. Is the GQL just translated into a pgREST query?
Is the GQL just translated into a pgREST query?
No, GQL is converted into a SQL query which is executed by the QueryEntrypoint::execute
method for a query and MutationEntrypoint::execute
method for a mutation.
I'm not sure how the GQL is translated into a PG query
The QueryEntrypoint::execute
and MutationEntrypoint::execute
methods convert GQL into SQL by calling the self.to_sql_entrypoint
methods. The to_sql_entrypoint
methods are implemented by various builder objects that implement the QueryEntrypoint
or MutationEntrypoint
traits. E.g. FunctionCallBuilder
's impl just delegates to a call to its to_sql
method. These builder objects are created earlier by parsing GQL and looking at the SQL context.
Let me know if this is sufficient detail for you to take a stab at implementing a solution or you need more.