ragool
Like queries, subscriptions enable you to fetch data. Unlike queries, subscriptions are long-lasting operations that can change their result over time. They can maintain an active connection to your GraphQL server (most commonly via WebSocket), enabling the server to push updates to the subscription's result.
Subscriptions are useful for notifying your client in real time about changes to back-end data, such as the creation of a new object or updates to an important field.
In the majority of cases, your client should not use subscriptions to stay up to date with your backend. Instead, you should with queries, or when a user performs a relevant action (such as clicking a button).
You should use subscriptions for the following:
The GraphQL spec does not define a specific protocol for sending subscription requests. The first popular JavaScript library to implement subscriptions over WebSocket is called subscriptions-transport-ws. This library is no longer actively maintained. Its successor is a library called graphql-ws. The two libraries do not use the same WebSocket subprotocol, so you need to make sure that your server and clients all use the same library.
Apollo Client supports both graphql-ws and subscriptions-transport-ws. We recommend you use the newer library graphql-ws, and this page shows how to use it. If you need to use subscriptions-transport-ws because your server still uses that protocol.
Web Developer.