Search code examples
prismaredwoodjs

where and how to write pre/post query action in redwoodJS?


I'm in my first days on learning redwoodJS. I'm just jump in from Django.

All I know, redwood web app flow like this : web-client will call the API (apollo graphQL), API side is a Prisma-Client.

In Django, we can write a 'signal' that will be called pre/post query. I.e : pre-delete, post-delete, pre-add, post-add,etc etc. Signal is 'attached' in models.py

My question : is there any doc that elaborate on how and where to write that 'signal' in RedwoodJS?

Looks like Prisma have 'middleware' approach for this, but i don't know where and how to do it in redwoodJS.

Sincerely

-bino-


Solution

  • A Redwood API directory includes Services, used by your GraphQL API or any other place in your backend code. A Service function typically imports the db object, which is the Prisma Client. From there, you can use Prisma Middleware. Here are a couple of related links.

    Redwood Services: https://redwoodjs.com/docs/services

    Prisma Middleware: https://www.prisma.io/docs/concepts/components/prisma-client/middleware