community/boilerplates/event-triggers/aws-lambda/go/mutation/README.md
This example trigger updates (executes a mutation) when an event occurs on another table, written in Golang.
Table name: note
Columns:
id Integer auto-increment
note Text
Primary key: id
Table name: note_revision
Columns:
id Integer auto-increment
note Text
note_id Integer
update_at Timestamp, default: now()
Primary key: id
Create a Lambda function in AWS. This will be our webhook.
i. Run the bash script provided
bash build.sh
ii. Upload mutation.zip in the lambda console.
9. In the Designer pane, add an environment variable HGE_ENDPOINT which is the Hasura GraphQL Engine endpoint.
10. Click the save button for the changes to take effect.
11. Create an API with a lambda proxy integration as specified in the AWS Documentation.
Goto Data tab on Hasura console, browse to note table and to the Browse rows
tab. Edit an existing note and check if the note_revision entry has been
created. Also, checkout the trigger request and response.
Trigger payload (request):
{
"event": {
"op": "UPDATE",
"data": {
"old": {
"note": "note1",
"id": 1
},
"new": {
"note": "note1 updated",
"id": 1
}
}
},
"created_at": "2018-10-02T06:38:22.67311Z",
"id": "f57a1c79-72ba-4c19-8791-37d1b9616bcf",
"trigger": {
"name": "note_revision_trigger",
"id": "5d85cbd1-c134-45ce-810c-7ecd3b4fc1ee"
},
"table": {
"schema": "public",
"name": "note"
}
}
Webhook response:
{
"data": {
"insert_note_revision": {
"affected_rows": 1,
"returning": [
{
"id": 2
}
]
}
}
}