hasura / hasura/graphql-engine

RFC: Triggers at Business Logic Layer

Open
#4,540 3 comments 10 reactions 1 assignee Claimed by @tirumaraiselvan View on GitHub
a/eventing/data-triggers k/ideas
Dominant language
TypeScript
Stars
32.1k
Forks
3k
PR merge metrics
PR metrics pending

Description

The idea is to have triggers that run at business logic layer before or after data is inserted, updated or deleted into a table. This will allow for custom business logic without changes to schema. This logic will apply whether data is inserted directly into the table or via nested mutation.

[Salesforce Triggers](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_triggers.htm) is a similar concept which is very powerful. Salesforce Triggers also support [Transactions](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_transaction.htm) at the business logic layer. Notably, in Salesforce triggers, data is processed in batches of usually 200 records.

e.g. Consider a Customer table with an array relationship to Address table, and there is a custom logic for validating addresses. Use cases are that Address validation should run when inserting directly into Address, and when doing a nested insert into Account as well as Address. A business logic trigger that runs before Insert and before Update will work well. With Actions, two custom Actions will need to be created, adding to the schema as well as creating duplicate code.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.