docs: mssql event trigger docs

PR-URL: https://github.com/hasura/graphql-engine-mono/pull/4321
Co-authored-by: Abhijeet Khangarot <26903230+abhi40308@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Rob Dominguez <24390149+robertjdominguez@users.noreply.github.com>
GitOrigin-RevId: 9cba9e90465e95bf587469554f508f272391cb0f
This commit is contained in:
Naveen Naidu 2022-11-07 22:51:43 +05:30 committed by hasura-bot
parent 3da905c851
commit 0961e4fd74
6 changed files with 149 additions and 32 deletions

View File

@ -12,18 +12,20 @@ keywords:
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import Thumbnail from '@site/src/components/Thumbnail';
import TOCInline from '@theme/TOCInline';
# Creating an event trigger
## Introduction
Event triggers can be created using the Hasura console, CLI or metadata APIs.
Event triggers can be created using the Hasura Console, Hasura CLI, or Metadata APIs. Currently, support for event
triggers exists for Postgres and MSSQL databases.
## Creating triggers
<Tabs className="api-tabs">
<TabItem value="console" label="Console">
Open the Hasura console, head to the `Events` tab and click on the `Create` button to open the page below:
Open the Hasura Console, head to the `Events` tab and click on the `Create` button to open the page below:
<Thumbnail src='/img/event-triggers/create-event-trigger.png' alt='Create an event trigger' />
@ -57,8 +59,14 @@ hasura metadata apply
</TabItem>
<TabItem value="api" label="API">
Add an event trigger by using the
[pg_create_event_trigger](/api-reference/metadata-api/event-triggers.mdx#metadata-pg-create-event-trigger) metadata API.
You can create event triggers by using the appropriate Metadata API, either:
[pg_create_event_trigger](/api-reference/metadata-api/event-triggers.mdx#metadata-pg-create-event-trigger) or
[mssql_create_event_trigger](/api-reference/metadata-api/event-triggers.mdx#metadata-mssql-create-event-trigger).
To create an event trigger via the the Metadata API, replace `<db_type_create_event_trigger>` with the following:
- **Postgres**: `pg_create_event_trigger`
- **MSSQL**: `mssql_create_event_trigger`
```http
POST /v1/metadata HTTP/1.1
@ -66,7 +74,7 @@ Content-Type: application/json
X-Hasura-Role: admin
{
"type" : "pg_create_event_trigger",
"type" : "<db_type_create_event_trigger>",
"args" : {
"name": "author_trigger",
"source": "<db_name>",
@ -88,7 +96,13 @@ X-Hasura-Role: admin
</TabItem>
</Tabs>
## Parameters
:::info Note
UPDATE event trigger for MSSQL will only work on tables that have a primary key.
:::
### Parameters
**Trigger Name**
@ -117,8 +131,6 @@ If you are running Hasura using Docker, ensure that the Hasura Docker container
## Advanced Settings
<TOCInline toc={toc} filterTOC={'advanced-settings'} />
### Listen columns for update
Update operations are special because you may want to trigger a webhook only if specific columns have changed in a row.
@ -129,7 +141,7 @@ If a column is not selected here, then an update to that column will not trigger
<Tabs className="api-tabs">
<TabItem value="console" label="Console">
Expand the `Advanced Settings` section on the Hasura console to define advanced settings for an event trigger:
Expand the `Advanced Settings` section on the Hasura Console to define advanced settings for an event trigger:
<Thumbnail
src='/img/event-triggers/create-event-trigger-listen-columns.png'
@ -167,8 +179,14 @@ hasura metadata apply
</TabItem>
<TabItem value="api" label="API">
You can configure advanced settings via the
[pg_create_event_trigger](/api-reference/metadata-api/event-triggers.mdx#metadata-pg-create-event-trigger) metadata API.
You can configure advanced settings via the appropriate Metadata API using either
[pg_create_event_trigger](/api-reference/metadata-api/event-triggers.mdx#metadata-pg-create-event-trigger) or
[mssql_create_event_trigger](/api-reference/metadata-api/event-triggers.mdx#metadata-mssql-create-event-trigger).
Replace `<db_type_create_event_trigger>` with the following:
- **Postgres**: `pg_create_event_trigger`
- **MSSQL**: `mssql_create_event_trigger`
```http {18-20}
POST /v1/metadata HTTP/1.1
@ -176,7 +194,7 @@ Content-Type: application/json
X-Hasura-Role: admin
{
"type": "pg_create_event_trigger",
"type" : "<db_type_create_event_trigger>",
"args": {
"name": "author_trigger",
"source": "<db_name>",
@ -225,7 +243,7 @@ Retry configuration is available in the "Advanced settings" when you create a tr
<Tabs className="api-tabs">
<TabItem value="console" label="Console">
Expand the `Advanced Settings` section on the Hasura console to define advanced settings for an event trigger:
Expand the `Advanced Settings` section on the Hasura Console to define advanced settings for an event trigger:
<Thumbnail
src="/img/event-triggers/create-event-trigger-retry.png"
@ -269,8 +287,14 @@ hasura metadata apply
</TabItem>
<TabItem value="api" label="API">
You can configure advanced settings via the
[pg_create_event_trigger](/api-reference/metadata-api/event-triggers.mdx#metadata-pg-create-event-trigger) metadata API.
Again, you can configure advanced settings via the appropriate Metadata API, either:
[pg_create_event_trigger](/api-reference/metadata-api/event-triggers.mdx#metadata-pg-create-event-trigger) or
[mssql_create_event_trigger](/api-reference/metadata-api/event-triggers.mdx#metadata-mssql-create-event-trigger).
Replace `<db_type_create_event_trigger>` with the following:
- **Postgres**: `pg_create_event_trigger`
- **MSSQL**: `mssql_create_event_trigger`
```http {21-25}
POST /v1/metadata HTTP/1.1
@ -278,7 +302,7 @@ Content-Type: application/json
X-Hasura-Role: admin
{
"type": "pg_create_event_trigger",
"type": "<db_type_create_event_trigger>",
"args": {
"name": "author_trigger",
"source": "<db_name>",
@ -313,6 +337,16 @@ X-Hasura-Role: admin
}
```
:::info Note
Event triggers are supported for Postgres and MSSQL databases. To create an event trigger via the the Metadata API,
replace `<db_type>` with the following:
- **Postgres**: `pg`
- **MSSQL**: `mssql`
:::
</TabItem>
</Tabs>
@ -331,7 +365,7 @@ Each header has 3 parameters:
<Tabs className="api-tabs">
<TabItem value="console" label="Console">
Expand the `Advanced Settings` section on the Hasura console to define advanced settings for an event trigger:
Expand the `Advanced Settings` section on the Hasura Console to define advanced settings for an event trigger:
<Thumbnail
src="/img/event-triggers/create-event-trigger-headers.png"
@ -375,8 +409,14 @@ hasura metadata apply
</TabItem>
<TabItem value="api" label="API">
You can configure advanced settings via the
[pg_create_event_trigger](/api-reference/metadata-api/event-triggers.mdx#metadata-pg-create-event-trigger) metadata API.
You can configure advanced settings via the appropriate Metadata API, either:
[pg_create_event_trigger](/api-reference/metadata-api/event-triggers.mdx#metadata-pg-create-event-trigger) or
[mssql_create_event_trigger](/api-reference/metadata-api/event-triggers.mdx#metadata-mssql-create-event-trigger).
Replace `<db_type_create_event_trigger>` with the following:
- **Postgres**: `pg_create_event_trigger`
- **MSSQL**: `mssql_create_event_trigger`
```http {26-35}
POST /v1/metadata HTTP/1.1
@ -384,7 +424,7 @@ Content-Type: application/json
X-Hasura-Role: admin
{
"type": "pg_create_event_trigger",
"type": "<db_type_create_event_trigger>",
"args": {
"name": "author_trigger",
"source": "<db_name>",

View File

@ -8,6 +8,8 @@ keywords:
- event trigger
- payload
---
import Tabs from "@theme/Tabs";
import TabItem from "@theme/TabItem";
# Event trigger payload
@ -47,16 +49,20 @@ Content-Type: application/json
}
```
| Key | Type | Description |
| ----------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
| session-variables | [Object](#object) or NULL | Key-value pairs of session variables (i.e. "x-hasura-\*" variables) and their values (NULL if no session variables found) |
| op-name | [OpName](#opname) | Name of the operation. Can only be "INSERT", "UPDATE", "DELETE", "MANUAL" |
| column-values | [Object](#object) | Key-value pairs of column name and their values of the table |
| timestamp | String | Timestamp at which event was created |
| uuid | String | UUID identifier for the event |
| name-of-trigger | String | Name of the trigger |
| schema-name | String | Name of the schema for the table |
| table-name | String | Name of the table |
| Key | Type | Description |
| ----------------- | ------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| session-variables | [Object](#object) or NULL | Key-value pairs of session variables (i.e. "x-hasura-\*" variables) and their values (NULL if no session variables found) (**Only available for Postgres**) |
| op-name | [OpName](#opname) | Name of the operation. Can only be "INSERT", "UPDATE", "DELETE", "MANUAL" |
| column-values | [Object](#object) | Key-value pairs of column name and their values of the table |
| timestamp | String | Timestamp at which event was created |
| uuid | String | UUID identifier for the event |
| name-of-trigger | String | Name of the trigger |
| schema-name | String | Name of the schema for the table |
| table-name | String | Name of the table |
<Tabs className="json-payloads">
<TabItem value="postgres" label="Postgres">
**In case of**:
@ -71,7 +77,8 @@ Content-Type: application/json
- `event.data.new` will be `null`
- MANUAL
- `event.data.old` will be `null`
- `event.data.new` will contain the current row
- `event.data.new` will contain the current row
:::info Note
@ -114,6 +121,76 @@ Content-Type: application/json
}
```
</TabItem>
<TabItem value="mssql" label="MSSQL">
**In case of**:
- INSERT
- `event.data.old` will be `null`
- `event.data.new` will contain the insert row
- UPDATE
- If a row is updated and the primary key is also updated
- `event.data.old` will be `null`
- `event.data.new` will contain the values after the update
- If a row is updated and the primary key is unchanged
- `event.data.old` will be values before the update
- `event.data.new` will contain the values after the update
- DELETE
- `event.data.old` will contain the row that is deleted
- `event.data.new` will be `null`
- MANUAL
- `event.data.old` will be `null`
- `event.data.new` will contain the current row
:::info Note
- In case of `UPDATE`, the events are delivered only if new data is
distinct from old data. We use the primary keys to join the temporary tables `inserted`
and `deleted` tables to correlate the old and new data.
- `UPDATE` event triggers will only work on tables which have primary keys.
- Since we use the primary key to co-relate DELETED and INSERTED table, if the
primary key is updated then it is not possible to correlate the `old` and `new` data. Hence, only `new` data is sent in this case.
:::
**For example**:
```json
{
"id": "85558393-c75d-4d2f-9c15-e80591b83894",
"created_at": "2018-09-05T07:14:21.601701Z",
"trigger": {
"name": "insert_user_trigger"
},
"table": {
"schema": "public",
"name": "users"
},
"event": {
"session_variables": {
"x-hasura-role": "admin",
"x-hasura-allowed-roles": "['user', 'boo', 'admin']",
"x-hasura-user-id": "1"
},
"op": "INSERT",
"data": {
"old": null,
"new": {
"id": "42",
"name": "john doe"
}
}
}
}
```
</TabItem>
</Tabs>
## Syntax definitions
### Object

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 35 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB