Is it possible, with prisma 2 or `@nexus/schema`, ...
# orm-help
m
Is it possible, with prisma 2 or
@nexus/schema
, to "intercept" every time an update is done to the database? I'm looking at how to implement algolia, and looks like I have to call an sdk to push to them. Is there a way of "listening" when changes are done to the database by prisma+nexus? Or adding a callback for every prisma or nexus call? Something to "hook" that?
r
Hey @Matheus Assis 👋 Currently Prisma 2 doesn't support hooks for DB changes, so as a workaround for now you would have to add a callback for call you make via Nexus. There's a feature request for the same that you could follow here.
🦜 1
m
Thank you @Ryan ! Do you know what those callbacks are called in "nexus terms"?
r
It would be simple callbacks or something like a PubSub module that will fire after you update the DB. For e.g.
Copy code
resolve(_parent, args, ctx) {
  await prisma.somethings.update();
  // fire an event here and you can watch for that event someplace else.
}

anotherFn() {
  // this function listens for the event and captures that
  // and add the business logic required here
}
This would personally be my approach to do this 🙂
m
Oh I see, thanks!, that makes sense! But I'm using nexus so it's leveraging all the resolver work to nexus-prisma plugin and I'm not even implementing them. For now what I did was a nexus plugin to intercept resolver calls
💯 1