How to set a trigger function when and entity is updated?

I am using apollo express server along with typeorm and type-graphql. I want to run a trigger function whenever there is a any mutation on a entity/db table. I cannot figure out a way to set this up. Can anyone guide me on how to achieve desired effect?

There are probably a few options, but here are two (if applicable).

You could use a middleware: maticzav/graphql-middleware: Split up your GraphQL resolvers in middleware functions (github.com)

Which can be run before or after a resolver executes.

If you are using MongoDB, you could use: Change Streams — MongoDB Manual

One important note about change streams. If you scale your application to run on multiple instances, the change stream will be executed for each instance.