graphqlhasura

Count in Hasura subscription


I am new to GraphQL and Hasura. I have a table that has a "completed" field that is value can be true/false/null. I am trying to count the total number of rows and the number of rows that is false in the "completed" field

I tried the following:-

subscription MySubscription {
  total:  table_aggregate {
    aggregate {
      count
    }
  }
  incomplete: table_aggregate(where: {completed: {_eq: false}}) {
    aggregate {
      count(columns: completed)
    }
  }
}

but it dont work. Is it not possible in the case of subscription or what I am missing? Thanks in advance 🙏


Solution

  • Hasura doesn't allow multiple top-level fields in a single subscription query. You'll need to create two separate subscriptions:

    subscription TotalItems {
      table_aggregate {
        aggregate {
          count
        }
      }
    }
    

    and

    subscription IncompleteItems {
      table_aggregate(where: {completed: {_eq: false}}) {
        aggregate {
          count
        }
      }
    }