Handle Webhooks with GraphQL Subscriptions
GraphQL Mesh can consume Webhooks as GraphQL Subscriptions in the unified schema by using built-in PubSub implementation
#
Add new Subscription fieldYou can use additionalTypeDefs
and additionalResolvers
to add subscription root fields to your unified schema.
We're able to use existing types from our unified schema, and this root field is subscribed to our specific topic
in our PubSub service.
#
Use JSON Schema Handler insteadYou can also use JSON Schema handler if you don't want to write an extra GraphQL type definitions. You can generate GraphQL type definitions from sample JSON response;
Just add the following to your existing JSON schema handler configuration in .meshrc.yml
file;
#
Handle Webhook HTTP RequestsAdd custom express handler to listen specific path for your HTTP Webhook on Mesh CLI Server. You can do it either in a programmatic or declarative way.
#
Using Declarative APILet's say you have running GraphQL Mesh server listening 4000
port, and you need to listen a specific route for upcoming HTTP requests as HTTP Webhook.
path
defines the path in our server that will receive HTTP requests as "Webhook" from our API then send it to pubsubTopic
.
#
Custom Handler in Codehandler
can get any kind of Express request handler. So you can extend Mesh Server however you want.
and in todo_added_handler.js
we have something like following;
You can check out our example