golevelup / nestjs

A collection of badass modules and utilities to help you level up your NestJS applications 🚀
MIT License
2.24k stars 259 forks source link

Integrate Support for Hasura Actions #156

Closed WonderPanda closed 9 months ago

WonderPanda commented 4 years ago

Actions enable custom business logic for Hasura applications. We should find a way to support them in an idiomatic way with NestJS.

It would be worth looking into a Custom Codegen integration that could help people write action handlers in NestJS\/

WonderPanda commented 4 years ago

@n3n The Events plugin exposes a single HTTP endpoint for the user and then allows for automatic routing to the correct handler internally using Decorators with the Trigger Name.

This is an option for Actions as well, however I'm curious if you think that people would prefer to write individual API endpoints for Actions as opposed to having them all flow through one.

Or perhaps we should offer both approaches and let people choose what makes the most sense for their application

n3n commented 4 years ago

@WonderPanda I would say that just decorator with the Action Name, it's enough.

For the people who prefer to write individual API endpoints, we can provide them Guard, Interface.

jgoux commented 4 years ago

Hey @WonderPanda , I saw that you made a prerelease including the support for Hasura action 🎆 . Is anything missing?

WonderPanda commented 4 years ago

Hey @jgoux thanks for your interest in the project! The prerelease includes some glue for being able to easily route Actions to specific Service handlers similar to the current Events integration.

However, in working on this I've found a number of limitations in terms of boilerplate on the Hasura side for how Actions and especially the related Custom Types are defined. I'm currently working on a much more in depth integration that I'm hoping will be ready for a prerelease in the coming weeks which will provide a significantly improved developer experience. I'm aiming to have things wrapped up to hopefully present the new and improved integration in the August Hasura Community call

I'd love to know more about your experiences with NestJS and Hasura so far if you're willing to chat about it here or in email or something as I think there is a huge opportunity for the two communities

linus1412 commented 3 years ago

Did the actions work ever progress? Seems a perfect fit.

WonderPanda commented 3 years ago

@linus1412 To be honest this has fallen onto the backburner a bit lately. For my own projects I've been opting to go with using NestJS GraphQL capability and using the Remote Schema option to write custom business logic instead. It feels a bit more idiomatic and there is much less stuff that needs to be specially code generated.

If you and others are still interested in this though I could consider tackling it again to try to get something published

linus1412 commented 3 years ago

Thanks @WonderPanda,

TBH I'm looking for best practice here and maybe what you described above it is. My particular requirement is this:

I want my front end JavaScript app to be able to update multiple tables in one go and fire some business logic. It seemed a good idea to get the web app to call a Hasura action that gets mapped through to Nestjs. Inside Nest I would perform business logic, write to the database and then fire an event (somehow) for another microservice to pick up.

Could I do that with your approach? I've not actually used Hasura and Nest yet, but my research had led me in this direction and I was intending to use them for my next project as a Firebase replacement.

WonderPanda commented 3 years ago

Yes this type of thing works really well with the Remote Schema functionality provided by Hasura. You would implement your custom business logic in NestJS and expose it over its own GraphQL server which can then be stitched together with Hasura's. Inside NestJS you can touch as many tables as you like using an ORM of your choice or even just using Hasura on the backend to execute your custom logic.

It's on my radar to put together a demo app that showcases the best ways to integrate Hasura and NestJS, currently tracked in https://github.com/golevelup/nestjs/issues/215

linus1412 commented 3 years ago

Thanks for the walk through, I look forward to your demo when you find the time.

joelbqz commented 3 years ago

Yes this type of thing works really well with the Remote Schema functionality provided by Hasura. You would implement your custom business logic in NestJS and expose it over its own GraphQL server which can then be stitched together with Hasura's. Inside NestJS you can touch as many tables as you like using an ORM of your choice or even just using Hasura on the backend to execute your custom logic.

It's on my radar to put together a demo app that showcases the best ways to integrate Hasura and NestJS, currently tracked in #215

@WonderPanda this approach seems good, I was thinking to do the same, especially now with Hasura 2.0 that supports RBAC for Remote Schema

WonderPanda commented 3 years ago

@joelbqz Yes I agree completely. With the addition of permissions for remote schemas in 2.0 the best way to integrate Nest and Hasura together is using this feature.

I don't think that there is any point in spending time trying to pursue auto generating Hasura Actions handlers with regular HTTP and Controllers compared to going the GraphQL approach. I'll put up a sample repo of how I currently structure things also to help with #215.

I think that the Community could benefit from a good Reference Architecture style example app.

Out of curiosity, what kind of repo organization pattern do you use? Are you doing any work with NX Monorepos by chance?

LeulAria commented 1 year ago

any work done here...

WonderPanda commented 9 months ago

With the recent news about Hasura v3 Actions are effectively deprecated. I'll be reviewing the possibility of building out a dedicated Data Source plugin for the new engine

LeulAria commented 9 months ago

would be awesome