Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing database within Hasura Action Handler

I would like to be able to access data from the database within an Action Handler in Hasura. Is the best approach:

  • to make a GraphQL query to the API exposed by Hasura; or
  • use a client, like Prisma, to read from the db directly?
like image 628
oldo.nicho Avatar asked May 11 '26 03:05

oldo.nicho


1 Answers

I'm not sure there is a best approach. Personally, I use the API exposed by Hasura in action handlers. I've chosen to do this because:

  • I like the API exposed by Hasura.
  • I like the access controls that Hasura layers over top of the DB (although you could just use the admin account, too).
  • The API can be used to generate TypeScript types, which I use in the action handler. This means that I can confidently change the database schema or Hasura API and then see where my other code fails.

I have thought many times about your question though, because there is something a little odd about calling back into Hasura to handle a Hasura action. But the reasons mentioned above are substantial gains in my opinion, so I've stuck with this approach.

like image 66
Dmitry Minkovsky Avatar answered May 13 '26 03:05

Dmitry Minkovsky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!