Digging deeper into Apollo subscriptions
With the earlier versions of Apollo Client, it was required that you install further packages to support WebSockets. Now, the only requirement is one further package that implements the WebSocket support on the server side.
Note
You can find an excellent overview and more details about Apollo subscriptions in the official documentation at https://www.apollographql.com/docs/react/data/subscriptions/.
The first step is to install all the required packages to get GraphQL subscriptions working. Install them using npm
, as follows:
npm install --save subscriptions-transport-ws graphql-subscriptions
The following two packages provide the necessary modules for a subscription system:
- The
graphql-subscriptions
package provides the ability to connect our GraphQL backend with a publish-subscribe (PubSub) system. It gives the client the option to subscribe to specific channels and lets the backend publish new data to the client. It...