Use Apollo's Multipart HTTP protocol for GraphQL subscriptions with Hive Router, for both client-to-router and router-to-subgraph communication.
Subgraphs
Subgraphs don’t require any special configuration to use multipart HTTP. When the router connects to a subgraph for a subscription, it will automatically negotiate multipart HTTP if the subgraph supports it, as it’s the preferred protocol.
Clients
To use Multipart HTTP, send requests with the following Accept header:
The router sends a heartbeat chunk every 10 seconds to keep the connection alive.
If an error occurs, the router emits an error event and completes the stream. If the requested subscription transport is not supported, the router returns 406 Not Acceptable.
Try It
curl 'http://localhost:4000/graphql' \ -H 'accept: multipart/mixed;subscriptionSpec=1.0' \ --json '{ "query": "subscription { reviewAdded { body rating product { name } author { name } } }" }'
This command creates an HTTP multipart request and keeps an open connection that receives new subscription data in response “chunks”:
--graphqlcontent-type: application/json{}--graphqlcontent-type: application/json{"payload":{"data":{"reviewAdded":{"body":"Great product!","rating":5,"product":{"name":"Croissant"},"author":{"name":"Alice"}}}}}--graphqlcontent-type: application/json{"payload":{"data":{"reviewAdded":{"body":"Could be better","rating":3,"product":{"name":"Baguette"},"author":{"name":"Bob"}}}}}--graphqlcontent-type: application/json{"payload":{"data":{"reviewAdded":{"body":"Excellent quality","rating":5,"product":{"name":"Croissant"},"author":{"name":"Charlie"}}}}}--graphql--
This example subscription emits three events and then closes the connection. Notice how the product and author fields are automatically resolved from their respective subgraphs.