Experience Report for Feature Request
What you wanted to do
Get access to deleted or changed data BEFORE it is deleted or changed in order to run backend validation.
Let’s say I want to verify the incoming data in an update or delete mutation is in a certain format. An email address may have a regular expression, or I made need to do some complex regular expression etc.
If that validation fails, there is no way to revert back to the old data. This defeats the purpose of of a webhook in a lot of cases.
What you actually did
I can’t do anything to revert the data… the data has already been changed or deleted…
async function updateAuthorWebhook({event, dql, graphql, authHeader}) {
// event object has the add.input to do some validation
if (complex regex...) {
// event object has rootUIDs, but the data is already changed
// so no way to run a graphql mutation to revert back the data
...
}
Why that wasn’t great, with examples
There are no pre-hooks, but there is another way besides pre-hooks.
While I disagree because it is ultimately my cost, I certainly understand your point of view. However, here is what you could do to fix this:
Firebase Functions are ultimately post-hooks like Dgraph Webhooks. However, they give you access to the changed data so that you can revert back to it if you need to.
There are also cases where you don’t need the original data to revert back to anything, but you need the original data for something else, maybe to create new data. There are many problems here.
Any external references to support your case
Here you can see a before and an after change variable in firebase functions:
https://firebase.google.com/docs/reference/functions/cloud_functions_.change
There are also dozens of posts here referring to the pre-hook scenario…
J