这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions docs/graphql/manual/event-triggers/payload.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ JSON payload

{
"event": {
"session_variables": <session-variables>,
"op": "<op-name>",
"data": {
"old": <column-values>,
"new": <column-values>
"old": <column-values>,
"new": <column-values>
}
},
"created_at": "<timestamp>",
Expand All @@ -48,6 +49,9 @@ JSON payload
* - Key
- Type
- Description
* - session-variables
- 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_
- Name of the operation. Can only be "INSERT", "UPDATE" or "DELETE"
Expand Down Expand Up @@ -104,6 +108,11 @@ JSON payload
"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,
Expand Down
12 changes: 6 additions & 6 deletions server/src-lib/Hasura/Events/Lib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,13 @@ instance ToJSON Event where

$(deriveFromJSON (aesonDrop 1 snakeCase){omitNothingFields=True} ''Event)

data Request
= Request
data WebhookRequest
= WebhookRequest
{ _rqPayload :: Value
, _rqHeaders :: Maybe [HeaderConf]
, _rqVersion :: T.Text
}
$(deriveToJSON (aesonDrop 3 snakeCase){omitNothingFields=True} ''Request)
$(deriveToJSON (aesonDrop 3 snakeCase){omitNothingFields=True} ''WebhookRequest)

data WebhookResponse
= WebhookResponse
Expand All @@ -117,7 +117,7 @@ data Invocation
= Invocation
{ iEventId :: EventId
, iStatus :: Int
, iRequest :: Request
, iRequest :: WebhookRequest
, iResponse :: Response
}

Expand Down Expand Up @@ -338,8 +338,8 @@ tryWebhook logenv pool e = do
where
decodeBS = TE.decodeUtf8With TE.lenientDecode

mkWebhookReq :: Value -> [HeaderConf] -> Request
mkWebhookReq payload headers = Request payload (mkMaybe headers) invocationVersion
mkWebhookReq :: Value -> [HeaderConf] -> WebhookRequest
mkWebhookReq payload headers = WebhookRequest payload (mkMaybe headers) invocationVersion

mkResp :: Int -> TBS.TByteString -> [HeaderConf] -> Response
mkResp status payload headers =
Expand Down
15 changes: 14 additions & 1 deletion server/src-rsr/trigger.sql.j2
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,20 @@ CREATE OR REPLACE function hdb_views.{{QUALIFIED_TRIGGER_NAME}}() RETURNS trigge
_new record;
_data json;
payload json;
session_variables json;
server_version_num int;
BEGIN
id := gen_random_uuid();
server_version_num := current_setting('server_version_num');
IF server_version_num >= 90600 THEN
session_variables := current_setting('hasura.user', 't');
ELSE
BEGIN
session_variables := current_setting('hasura.user');
EXCEPTION WHEN OTHERS THEN
session_variables := NULL;
END;
END IF;
IF TG_OP = 'UPDATE' THEN
_old := {{OLD_ROW}};
_new := {{NEW_ROW}};
Expand All @@ -23,7 +35,8 @@ CREATE OR REPLACE function hdb_views.{{QUALIFIED_TRIGGER_NAME}}() RETURNS trigge
);
payload := json_build_object(
'op', TG_OP,
'data', _data
'data', _data,
'session_variables', session_variables
)::text;
IF (TG_OP <> 'UPDATE') OR (_old <> _new) THEN
INSERT INTO
Expand Down
4 changes: 2 additions & 2 deletions server/tests-py/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ def anyq(self, u, q, h):
)
return resp.status_code, resp.json()

def v1q(self, q):
h = dict()
def v1q(self, q, headers = {}):
h = headers.copy()
if self.hge_key is not None:
h['X-Hasura-Access-Key'] = self.hge_key
resp = self.http.post(
Expand Down
Loading