Company
Date Published
Author
Amanda Liu
Word count
1428
Language
English
Hacker News points
None

Summary

GraphQL Subscriptions in Apollo Client allow developers to introduce new levels of interactivity to their apps with near-realtime updates, enabling clients to keep updated on the latest changes between different users. The design leverages existing publish-subscribe systems and clients specify the data they want to subscribe to by sending a query with the subscription keyword to the server. On the server-side, subscriptions are implemented using a WebSocket connection and a simple publish-subscribe system, where the server subscribes to one or more pub/sub channels based on the subscription field name. The client specifies the name of the subscription and any relevant arguments, and the server runs the GraphQL query specified in the subscription when something is published to one of these channels. A long-lived connection is necessary for subscriptions, which can deliver more than one result, making them similar to mutations but with a different usage pattern. To demonstrate how to wire up subscriptions with Apollo Client and a JavaScript GraphQL server, an example app called GitHunt was created, showcasing the implementation of subscriptions in detail.