Subscriptions

A GraphQL subscription is essentially a query where the client receives an event whenever the value of any field changes upstream. The Hasura GraphQL engine supports subscriptions for all kind of queries. All the concepts of queries hold true with subscriptions as well.

You can turn any query into a subscription by simply replacing query with subscription as the operation type.

Example:

subscription {
  article (
    order_by: published_on_desc,
    limit: 2
  ) {
    id
    title
    published_on
    author {
      name
    }
  }
}
subscription { article ( order_by: published_on_desc, limit: 2 ) { id title published_on author { name } } }
{ "data": { "article": [ { "id": 2, "title": "a nibh", "published_on": "2018-06-10", "author": { "name": "Beltran" } }, { "id": 13, "title": "vulputate elementum", "published_on": "2018-03-10", "author": { "name": "April" } } ] } }

Protocol

Hasura GraphQL engine uses the GraphQL over Websocket Protocol by the apollographql/subscriptions-transport-ws library for sending and receiving events.