@webhook
Trigger a webhook that executes complex projection logic.
The entire projection field data will be replaced by the value
field of the returned JSON data.
This directive can be specified multiple times.
Example
In this example, we define a webhook that is triggered when a user is created.
type User @upsertOn(...) {
status: String! @webhook(
url: "https://example.com/:path"
path: [{ key: "path", value: "payload.name" }]
query: [{ key: "query", value: "payload.name" }]
header: [{ key: "header", value: "payload.name" }]
body: [{ key: "body", value: "payload.name" }]
method: "GET"
condition: "payload.name == ''"
topics: ["users"]
events: ["createUser"]
)
}
Most of the arguments concern the configuration of the webhook itself.
The condition
argument is an expression that must evaluate to true
for the webhook to be triggered.
The topics
and events
arguments are used to filter the events that trigger the webhook.
Arguments
These are the arguments that can be used with the @webhook
directive.
Argument | Description |
---|---|
url | URL of the webhook, use placeholders for dynamic parts. A placeholder is identified by a : character following the key of the placeholder |
path | Replace keys in the URL by their corresponding value calculated by an expression |
query | key is the name of a query parameter that will be added along with the value calculated by an expression |
header | key is the name of a request header that will be added along with the value calculated by an expression |
body | The key value map will be transformed to a JSON object where the fields are the keys and the values are calculated by an expression |
method | Method used to execute the webhook |
condition | Expression |
topics | only apply the webhook for events of a specific set of topics |
events | only apply the webhook for events of a specific set of event types |
Response
The response of the webhook must return a JSON object containing a value
field. The value of that field will be the new data of the projected entry field.
{
"value": {
"field": "field-value"
}
}