PubSub is a class that exposes a simple
It sits between you application’s logic and the GraphQL subscriptions engine - it receives a publish command from your app logic and pushing it to your GraphQL execution engine.
graphql-subscriptions exposes a default
PubSub class you can use for a simple usage of data publication.
Check out how to change the
PubSubmechanism to an external one here
To get started, install
PubSub instance for publishing new data over your subscriptions transport, for example:
At this point, nothing works yet because there is nothing to publish into
SubscriptionManager will intercept the published data from the PubSub and execute this data over the GraphQL engine with the selection set from the clients.
Create a new
SubscriptionManager and pass it the schema and the PubSub instance:
SubscriptionsServer will manage the WebSocket connection between the
SubscriptionManager and the clients.
We will use the server provided by the
subscriptions-transport-ws transport package.
First install the
SubscriptionManager instance and a http server:
Somtimes a client will want filter out specific events based on context and arguments.
You can filter subscription’s publications per client using
setupFunctions which is a part of
Let’s see an example - for the following server-side subscription, the client want to subscribe only to comments added to a specific repo:
Here is the following definition of
setupFunctions that will filter out all of the
commentAdded events that are not the requested repository: