0

I am new to Hasura, and I have questions about how to implement own business logic by utilising the hasura framework.

I am starting a e-commerce project and plan to use graphql. I want to minimise the code by applying some tools, and hasura is my first choice so far.

Hasura did a great job to convert models into running graphql endpoints, and those generated CRUD functions will save a lot of time.

However, how about the other non-CRUD logics, like sign in, place order, etc.

Per my knowledge, Hasura has two ways to implement own business logic:

  • Actions: it is very handy if the logic exists in some existing REST API
  • Remote Schema: stitching another schema into own

But, IMO, for these two ways, I cannot take any advantage from hasura.

What I mean is, e.g., sign in, given user name and password, I need to search in the user table, if success then I need to generate token and save in the session table.

It seems I have to query user table by myself using other framework and create record to session table by myself. Ideally, I hope I can take advantage of the hasura framework cos hasura actually is be able to.

I am not sure if I miss anything for hasura to support this common case.

Thank you, Ron

Ron
  • 6,037
  • 4
  • 33
  • 52
  • I have impression that you're trying to use hasura for things it was not created for. E.g. you ask about `sign in` and then about session tables: of course you can treat hasura as some kind of "ODBC of XXI century" but more typical is to use hasura in combination with `Auth0`, `keycloak`, etc.. For non-CRUD logic as `place order` I would recommend to look for hasura 2.0 functionality - it allows registering functions for mutations. Or go for remote schemas - consider yourself what's your situation. Overall: hasura is a great tool. just don't try to use it "for everything". – Alex Yu Sep 04 '21 at 07:05
  • Although if you have already existing `sign in` functionality in a REST API - you can reuse it in actions. Hasura allows that. – Alex Yu Sep 04 '21 at 07:25
  • @AlexYu Thanks for your comments. The examples I put might not good, and my point is that if a customised mutation contains some basic CRUD functions, there is no way we can get from hasura, we have to implement those CRUD logic by own. Wondering if hasura could expose those CRUD in another way. – Ron Sep 06 '21 at 11:59
  • I think you're underestimating hasura: it's good now, even exceptionally "no-nonsense good" - I don't remember a case when it hanged or returned something non-expected. And in hasura 2.0 with VOLATILE function support it's even better. "CRUD" is the simplest and least interesting case but hasura makes it not that stupid with ability to insert/update related objects and doing it correctly – Alex Yu Sep 07 '21 at 09:21

0 Answers0