When we had initially set up Apollo, we used Apollo Boost to install the required dependencies. But subscriptions is an advanced use case which Apollo Boost does not support. So we have to install more dependencies to set up subscriptions.

+ $ npm install apollo-link-ws subscriptions-transport-ws --save

Now we need to update our ApolloClient instance to point to the subscription server.

Open src/ and update the link as follows:

+let connectionParams = Json.Encode.object_([("headers", headers)]);
-let link = ApolloLinks.createHttpLink(
- ~uri="",
- ~headers=headers,
- ()
+let link = ApolloLinks.webSocketLink(
+ ~uri="wss://",
+ ~reconnect=true,
+ ~connectionParams=connectionParams,
+ ()

Note that we are replacing HttpLink with WebSocketLink and hence all GraphQL queries go through a single websocket connection. Look at how we are passing the headers. While initializing websocket link, we need to pass headers in the headers key in the connectionParams accepted by ApolloLinks.webSocketLink.