I have a social network kind of web app which includes graphql by react-apollo-client (my graphql server is a Hasura instance).
I have notifications feature in my app and I query the notifications details together with count aggregation to show the user how many notifications he has before displaying it.
Recently I added web sockets to my app and refactor my notifications query to be a subscribtion. It works just fine - when new notification was inserted to the DB the subscription gets called instantly.
My problem is the count aggregation.
When I run the following subscription:
const GET_NOTIFICATIONS = gql`
subscription($userId: Number!) {
notifications(where: { user_id: { _eq: $userId } }) {
creation_time
description
}
notifications_aggregations (where: { user_id: { _eq: $userId } }) {
aggregate {
count
}
}
`
I am getting the following error - {"type":"subscription_data","id":4,"payload":{"errors":[{"message":"Subscription \"A\" must select only one top level field.","locations":[{"line":7,"column":3}]}]}}
After quick research I still could not find any solution to my problem.
Is there a way for my to keep the count aggregation in my subscribtion? Or do I need to count the notifications number myself after the subscription called?
Thanks for every response.