I'm trying to use Hasura REST endpoints as webhooks to Azure Event Grid subscriptions. However, the webhook validation payload look like this:
[
{
"id": "2d1781af-3a4c-4d7c-bd0c-xxxxxxxxxxx",
"topic": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"subject": "",
"data": {
"validationCode": "512d38b6-c7b8-40c8-89fe-xxxxxxxxxxx",
"validationUrl": "https://rp-eastus2.eventgrid.azure.net:553/eventsubscriptions/myeventsub/validate?id=0000000000-0000-0000-0000-00000000000000&t=2022-10-28T04:23:35.1981776Z&apiVersion=2018-05-01-preview&token=1A1A1A1A"
},
"eventType": "Microsoft.EventGrid.SubscriptionValidationEvent",
"eventTime": "2022-10-28T04:23:35.1981776Z",
"metadataVersion": "1",
"dataVersion": "1"
}
]
If you notice the structure, it does not have a root key and it's an array object.
When I go to define a mutation in Hasura (to be wrapped in a REST endpoint later), this is what I'm able to write this as a bare minimum:
mutation ProcessEvent($events: [EventInput]!) {
storage_event_handshake(event: $events) {
validationResponse
}
}
This very much expectedly throws:
{
"code": "validation-failed",
"error": "expecting a value for non-nullable variable: \"events\"",
"path": "$"
}
If I wrap the Azure handshake JSON object with events at the root of the JSON object, I can get it to work (in Postman), such as:
{
"events": [
{
"id": "2d1781af-3a4c-4d7c-bd0c-xxxxxxxxxxx",
"topic": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"subject": "",
"data": {
"validationCode": "512d38b6-c7b8-40c8-89fe-xxxxxxxxxxx",
"validationUrl": "https://rp-eastus2.eventgrid.azure.net:553/eventsubscriptions/myeventsub/validate?id=0000000000-0000-0000-0000-00000000000000&t=2022-10-28T04:23:35.1981776Z&apiVersion=2018-05-01-preview&token=1A1A1A1A"
},
"eventType": "Microsoft.EventGrid.SubscriptionValidationEvent",
"eventTime": "2022-10-28T04:23:35.1981776Z",
"metadataVersion": "1",
"dataVersion": "1"
}
]
}
However, fact of the matter is that we don't have control over the validation payload or the event notification payload that is sent from Azure. How do I get such JSON objects in my Hasura mutation?
Please note I'm not only trying to get the validation working. I will also be using same method to receive actual event notifications which are of the same JSON structure.
After speaking with Microsoft, I can confirm that there is no support for GraphQL webhooks out of the box at this point in time.
In the spirit of RESTifying things, we tried "Cloud Events Schema 1.0", which is a more suitable JSON structure for Hasura. However, when using this schema, Azure Event grid sends an
OPTIONSrequest before sending thePOSTrequest as a part of abuse protection. Unfortunately Hasura doesn't support OPTIONS call at this stage. It only suport POST, GET, PATCH and few others. Therefore, this didn't turn out to be the solution for us.We ditched the "Webhooks" altogether and instead chose "Storage Queue" for the events to land in. From there, we have a K8s pod that reads from that queue and process the messages.