Adding Subscriptions To Schema
Adding GraphQL subscriptions to your GraphQL schema is simple, since Subscription is just another GraphQL operation type like Query and Mutation.
You specify operation type, then the operation name and you can customize the publication data with a selection set and arguments.
You need to create a root schema definition and a root resolver for your
Subscription root, just like with Query and Mutation:
Create a resolver just like queries and mutations, but instead of function, pass an Object with
subscribe field and a subscription resolver method.
The subscription resolver method must return
AsyncIterator, which you can get from using
asyncIterator method of your
Then, later on your code, you can publish data to your topic by using
pubsub.publish with the topic name and the payload to want to publish:
subscribe field, it’s also possible to manipulate the event payload before running it throught the GraphQL execution engine.
resolve method near your
subscribe and change the payload as you wish: