Using this logic, mutations and queries will use HTTP as normal, and subscriptions will use WebSocket. There is no limitation, and you can extend this configuration and create anything your like.
GraphQL is a great way to write customizable API’s and combine numerous services into one endpoint. Mainly, the idea has a single endpoint, but getting the different combinations of models is amazing, mostly for the organizations working with large-scale multi-platform applications with various developers and designers.
What is a Web-Socket? According to MDN, “[The WebSocket API] is an advanced technology that makes it possible to open a two-way interactive communication session between the user’s browser and a server. With this API, you can send messages to a server and receive event-driven responses without having to poll the server for a reply.”
In this tutorial, we are going to go through the process of adding GraphQL Subscriptions to our server.
We wanted to build something anyone can integrate into their servers and clients, without reinventing the common features any implementation would need. That way, as a community we can start building and sharing integrations for different backends, such as Redis, PostgreSQL triggers, Kafka, and more.
Subscriptions offer a clean and efficient way to get pushed updates in realtime. They act in parallel to mutations. Just like how mutations describe the set of actions you can take to change your data, subscriptions define the set of events that you can subscribe to when data changes.
GraphQL subscriptions allow developers to introduce new levels of interactivity to their apps with near-realtime updates.
Let's build a realtime chat app with React, Apollo, GraphQL Subscriptions, Websockets and Module Federation