hasura / graphql-engine

Blazing fast, instant realtime GraphQL APIs on your DB with fine grained access control, also trigger webhooks on database events.
https://hasura.io
Apache License 2.0
31.06k stars 2.76k forks source link

Add computed fields to Hasura Events payload #4978

Open seifip opened 4 years ago

seifip commented 4 years ago

Problem

Hasura computed fields are not sent to Hasura Events webhooks.

Example

I have a total_price computed field in the orders table, which is sum(price) of all items in that order.

orders
----------------
...
total_price: computed field: SELECT sum(price) FROM items WHERE order_id = id

I'm now writing a Hasura Event on order INSERT that creates an invoice with amount set to total_price of the inserted order.

The issue: req.body.event.data.new.total_price is not available to the webhook.

Workaround

My work around is to query total_price from Hasura using GraphQL before creating the invoice, but that requires a whole extra query and a dozen lines of code just to get that one missing field.

Solution

Computed fields should be part of the Hasura Events trigger payload under req.body.event.data.old and req.body.event.data.new.

josephtkach-bb commented 4 years ago

Is anyone actively working on this?

FabienGreard commented 3 years ago

We are definitely looking for this! I could take some times next week to work on it if needed !

flocosnier commented 3 years ago

+1 it would be very useful !

WickedBrat commented 2 years ago

+1 I have this use case as well and have felt the need of it at multiple occasions

rustyzone commented 2 years ago

+1 also have a use case for this, would be handy to avoid an extra query

vxm5091 commented 2 years ago

+1 either computed fields or views would be super helpful to incorporate

Remy-T commented 2 years ago

👍 Would love this feature.

WGTW commented 2 years ago

+2 Would be a great feature for my specific use case, it's been over 2 years since the issue has been opened. Can someone from the Hasura team look into this? Thanks!

warent commented 1 year ago

+1 on this. It is extremely useful for payload body transformations. For example, I need to convert a timestamp string into an epoch integer for a REST endpoint. I created the computed column and am now seeing it cannot be used in an event payload :(

rayhantr commented 1 year ago

image

rahulagarwal13 commented 1 year ago

Thank you everyone for the request and comments for this feature. We would like to inform you that this is on our roadmap but we do not have a timeline at present. Please continue to follow this Github issue. We plan to publish on this issue a detailed RFC that covers all use cases and limitations of the feature. We welcome more detailed feedback from you once we provide those details.