While queries and mutations follow the classic request-response cycle, real-time enterprise features (such as live trading monitors, collaborative chat, and real-time document notifications) require bidirectional push communication. GraphQL Subscriptions maintain a persistent WebSocket connection between client and server, streaming events to React components using useSubscription.
Modern Apollo Client architectures use a split-link configuration:
httpLink): Handles standard Queries and Mutations over HTTP/HTTPS.wsLink): Handles persistent Subscriptions using the standard graphql-ws library.graphql-wsuseSubscriptionAvoid using subscriptions for data that changes infrequently. For standard status checks (e.g. tracking a background export progress), simple query polling (pollInterval: 5000) avoids the overhead of managing long-lived WebSocket connections and socket reconnections.
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| GraphQL Mutations and Optimistic UI Updates | WebSockets Architecture with Socket.io in React |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.
Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.