Is it possible to query multiple aggregates with different where conditions for each (hasura)?

Is it possible to query multiple aggregates with different where conditions for each (hasura)?


0

Say I have two tables, clubs and posts. Each club can have many posts and my app stores a timestamp for when the user last viewed a post for each club (‘last_viewed’). What I want to do, is query for the number of all new posts (since that club was looked at) and display that value for each club.

Is that possible with Hasura, or will that query have to be broken up into n queries for n clubs?

The closest I could figure out is to query clubs where id is in an array of club ids, but I haven’t found a way to vary the timestamp input to the where clause of the post_aggregate.

query GetNewPostCounts($lastSeen: timestamp!, $clubIds: [uuid!]!) {
  clubs(where: {id: {_in: $clubIds}}) {
    id
    post_aggregate(where: {created_at: {_gt: $lastSeen}}) {
      aggregate {
        count
      }
    }
  }
}

Is there a way to query by passing in an array of object in this form below (or some other method), and run the query for each object in the array?

{
  clubId: some uuid,
  timestamp: some timestamp,
}

Share
Improve this question

New contributor

vh71886 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


Load 5 more related questions


Show fewer related questions

0

Reset to default



Leave a Reply

Your email address will not be published. Required fields are marked *