GraphQL subscriptions and real-time data.
GraphQL subscriptions:
useSubscription hook from Apollo ClientUse useSubscription for real-time data updates:
Combine initial query with subscription for updates:
Update Apollo cache when subscription receives data:
Subscribe only when needed:
Show the user that live updates stopped, and don't report the error yourself. The shell's Apollo client reports a socket that closed for good once per subscription, and the backend has already reported an error it sent (Who reports an error).
Handle connection drops gracefully:
For more detailed technical guidance, see these reference files: