Graphql-engine: Better support for event trigger creation

Created on 13 Jun 2019  路  4Comments  路  Source: hasura/graphql-engine

When we create an event trigger and selecting webhook url, we have option to use environment variables but we cannot use string template here (${MY_LAMBDA_DEPLOYMENT}/mytable-insert-hook, ...), do we suppose to have each env variable for each hook?

And when I try to pull out all the event triggers creation to a separate JSON file to have version control (and so I can use jq for templating) and update metadata through posting to /v1/query, the replace option of 'create_event_trigger' type cannot act as "replace if exist, insert otherwise" the error is from here, so we need to know which trigger already exists and which doesn't.
Another option is deleting all event trigger and bulk creating all again.

event-triggers server ideas

Most helpful comment

@trungtin Yes, that's right we do not have templating for Webhook URLs yet. We can add this to our queue of tasks.

Regarding the second problem you faced, yes replace only works if the event trigger exists. This means you cannot run just the last create_event_trigger API directly. You can either:

  1. Replace the entire metadata of the system by using any on these APIs: https://docs.hasura.io/1.0/graphql/manual/api-reference/schema-metadata-api/manage-metadata.html

  2. You can remove the replace: true key from the metdata API.

All 4 comments

@trungtin Yes, that's right we do not have templating for Webhook URLs yet. We can add this to our queue of tasks.

Regarding the second problem you faced, yes replace only works if the event trigger exists. This means you cannot run just the last create_event_trigger API directly. You can either:

  1. Replace the entire metadata of the system by using any on these APIs: https://docs.hasura.io/1.0/graphql/manual/api-reference/schema-metadata-api/manage-metadata.html

  2. You can remove the replace: true key from the metdata API.

Follow-up issue for templating of webhook URL: https://github.com/hasura/graphql-engine/issues/2483

@tirumaraiselvan I feel like this issue should remain open.

It seems to me like replacing the entire metadata of the system would be overkill if you just want to be able to manage your event triggers in a way that can be version controlled. Please correct me if I'm wrong though, and if it's considered 'normal' to be replacing the entire metadata of the system for this sort of purpose.

So if you don't use the metadata approach, and instead you try to have an event-triggers.json file like the one that exists in the 3factor-example project at https://github.com/hasura/3factor-example/blob/master/event-triggers.json, you can't just include "replace": true for each webhook because then you'll get an error when you are trying to add a new webhook (saying "event trigger X does not exist"), and you also can't leave this out (having it fall back to the default of "replace": false) because then you'll get an error when you are trying to update an existing webhook (saying the webhook with name X already exists).

It seems like it would be very useful if there was a way to maintain an event-triggers.json that always has the current up-to-date event triggers and works using an upsert type of mechanism so that existing webhooks are updated and new webhooks are inserted.

Let me gather my thoughts around having replace: true work as an upsert.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sachaarbonel picture sachaarbonel  路  3Comments

jjangga0214 picture jjangga0214  路  3Comments

codepunkt picture codepunkt  路  3Comments

macalinao picture macalinao  路  3Comments

coco98 picture coco98  路  3Comments