Replies: 1 comment 1 reply
-
query MyQuery {
users (where: { posts: {} }){
id
posts {
id
}
}
} |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
Adron
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
So let's say I have the following graph query that gets users and their posts:
Say I have a user A that doesn't have any posts. The above query gives me a result that's similar to an outer join in SQL where I'd get the user A but with an empty posts array because it has no users.
What would I do if I want to get only those users who have atleast one post, similar to what an inner join in SQL would have done for me?
I did some digging and I found some results which said that I could use a '@cascade' in my query to do something like this in graphql. Unfortunately, it doesn't work for me in Hasura.
How do I go about achieving this in Hasura? I can sort the parent ('users') based on the aggregate of posts but there is no option for filter on a array relationship's aggregate or else I'd have filtered users based on post count > 0.
In case someone is interested in the use case, I'm building an app with a feed where I show a list of users and a snapshot of a few posts created by each user, so I need to have users as my top parent and also it would be weird if I also show users that don't have any posts at all.
Beta Was this translation helpful? Give feedback.
All reactions