Skip to content
GraphQL

Subscriptions

Receive pushed updates over a stream.

By EZ4Code Team
subscriptionrealtime

Code

subscription BookAdded {
  bookAdded {
    id
    title
    author {
      name
    }
  }
}

subscription MessageReceived($roomId: ID!) {
  messageReceived(roomId: $roomId) {
    id
    text
    createdAt
  }
}

Explanation

Subscriptions keep a long-lived connection open so the server can push events to the client when data changes. They use the same selection-set syntax as queries but are typically transported over WebSocket. Subscriptions suit real-time dashboards and chat, where polling would add latency and load.

More GraphQL Snippets