reym
Projections/Schema/Object

@webhook

Trigger a webhook that executes complex projection logic.

The @webhook directive is available for fields of a projection as well as for the projection itself. While the field definition can be found here, this page describes the directive for the projection.

Specified on a projection, the entire projection 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.

user.graphql
type User @upsertOn(...) @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 argumennts 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

ArgumentDescription
urlURL of the webhook, use placeholders for dynamic parts. A placeholder is identified by a : character following the key of the placeholder
pathReplace keys in the URL by their corresponding value calculated by an expression
querykey is the name of a query parameter that will be added along with the value calculated by an expression
headerkey is the name of a request header that will be added along with the value calculated by an expression
bodyThe key value map will be transformed to a JSON object where the fields are the keys and the values are calculated by an expression
methodMethod used to execute the webhook
conditionExpression
topicsonly apply the webhook for events of a specific set of topics
eventsonly 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.

response.json
{
    "value": {
        "field": "field-value"
    }
}