Hasura query that works similar to a SQL inner join

Viewed 587

So let's say I have the following graph query that gets users and their posts:

query MyQuery {
  users{
    id
    posts {
      id
    }
  }
}

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.

1 Answers

I found out just a little later from an answer I received on Hasura's github discussions that I could just have done this:

query MyQuery {
  users (where:  { posts: {} }){
    id
    posts {
      id
    }
  }
}
Related