hasura / graphql-engine

Blazing fast, instant realtime GraphQL APIs on your DB with fine grained access control, also trigger webhooks on database events.
https://hasura.io
Apache License 2.0
31.16k stars 2.76k forks source link

Middleware Pattern w/ Actions (Re-Use Types, Less Boilerplate) #7824

Open zlanich opened 2 years ago

zlanich commented 2 years ago

Is your proposal related to a problem?

Preface: I'm aware of ALL of documented Hasura features as of time of writing.

One of the main concerns I hear about with Hasura is how unwieldy the Actions/Types, etc will get once the API matures and there has to be TONS of exceptions for intermediary logic between the initial GraphQL request & the response. Obvious examples are:

  1. Advanced validation that can't be accomplished with Check Constraints, etc
  2. Custom authorization

Currently, every exception requires an Action w/ Derived types that needs to be maintained from there on, etc, and this is going to be rough once the API matures. If the boilerplate was simpler, and the types for these actions could be automatically derived from the original request, this would make maintenance simpler by using introspection & codegen for TS types in code, etc.

Describe the solution you'd like

I quite honestly don't know what this solution looks like yet, consider Hasura is written in Haskell. I would like to start a conversation about how this could improve.

Describe alternatives you've considered

Simple examples of other setups being more usable would be Node Express + custom resolvers, Prisma, etc, though I realize that Hausra has serious performance and initial time-to-launch advantages over these. Every middleware option in Node JS could be considered if you were using these other options.

If the feature is approved, would you be willing to submit a PR?

I have no idea how to write in Haskell, but I would be willing to contribute in JS/Node/TS environments and in any specification/planning manner.

Other Notes

Similar issues have been mentioned in the past, namely: https://github.com/hasura/graphql-engine/issues/5001

If anyone has any questions, please let me know! I'm almost 100% dead set on using Hasura for my company's go-to web/app API stack in the near future, and I want to iron out all possible foreseen issues in near/mid-term scale before I commit. Thank you!

soorajshankar commented 1 year ago

Partially related to https://github.com/hasura/graphql-engine/issues/5001

rahulagarwal13 commented 1 year ago

@zlanich Thanks for the detailed comment here!

We're working on a set of enhancements on Actions:

Would love to get on a quick chat with you if you're open to it to: a) discuss your current Authz and API system you've built around Hasura and help review it b) review what we're planning and see how that might be of immediate help to you

My email is rahul.agarwal@hasura.io - please do reach out!

manasag commented 6 months ago

Hi, I want to update that we are launching Hasura V3 (DDN) this month. V3 introduces a new code driven architecture for the enahnced and ever evolving business logic usecases. To start with, you can write your actions entirely in typescript, using our typescript connector (with support of auto introspection of your functions so that you dont have to maintain the Graphql types for your actions). Would like to hear if this new approach in V3 helps address your concerns here.

I would highly suggest to join us to see the full power of Hasura DDN at the Hasura Dev Day on April 16 🎉. Sign up here: https://hasura.io/dev-day. Can't make it? Sign up anyway and we'll send you the recording.