Live activity feeds
Deliver newly created reviews, messages, or comments as they happen.
GraphQL · Function
GraphQL subscriptions are long-lived operations that deliver selected data when relevant events occur. They use a schema’s Subscription root type and an implementation-selected transport.
A GraphQL subscription is a long-lived operation that receives selected data whenever relevant server-side events occur. The client sends a subscription operation, while the server commonly connects its resolver to a pub/sub system and chooses a transport such as WebSockets or server-sent events.
subscription OperationName {
rootField {
selectedField
}
}A stream of selected GraphQL results corresponding to successive events.
Subscription root operation type.subscription NewReviewCreated {
reviewCreated {
rating
commentary
}
}This operation asks the server to deliver selected review fields as matching events occur.
Deliver newly created reviews, messages, or comments as they happen.
Push state changes to dashboards without repeated polling.
Notify connected clients when shared application data changes.
A subscription is a long-lived GraphQL operation for receiving updates in response to events. Its result is delivered over time rather than as one finite response.
Follow-up: How are subscription events commonly produced? A separate pub/sub system publishes events, and subscription resolvers consume them.
The client declares the subscription operation type and selects the fields it wants from the subscription root field. The server then delivers matching event data according to that selection.
Follow-up: What constraint applies to the root selection? Each individual subscription operation must have exactly one root field.
GraphQL leaves transport selection to the server. WebSockets and server-sent events are common implementations, and clients must support the selected protocol.
Follow-up: Does GraphQL itself require WebSockets? No; the protocol is outside the GraphQL specification and can be chosen by the implementation.
querymutationSubscriptionWebSocketsserver-sent eventspub/sub