Lurker News

Comments (103) 27 threads

kilburn4 replies#
This is very impressive. Congratulations!

What I'm not seeing is how do you envision enforcement of complex business rules when using this API. Examples (silly, but you get the idea):
- The price is only visible for projects of type "whatever".
- The price may only be updated when it is not closed (closed_date is null)
- The project is only visible on mondays
The other point I don't see is how do you expect to trigger side-actions when changes are made. For instance:
- Send an e-mail when a project is created
- Call a webhook when a post is modified
Finally, and this may be from my lack of expertise with GraphQL, how do you deal with recursive data structures? For instance, how would you store and fetch a tree of categories?

marksomnian1 reply#
For the latter, GraphQL itself explicitly forbids recursivity [0], as it's impossible to guarantee that in all cases the data isn't infinitely recursive, especially with cyclic queries, which could lead to a denial-of-service. Postgres has its own support for recursive queries [1], however you'd need to strap a pagination layer on top in order to make it work with GraphQL.

[0]: https://github.com/facebook/graphql/issues/91#issuecomment-2...
[1]: https://www.postgresql.org/docs/9.1/static/queries-with.html

vsurabhi2 replies#
> What I'm not seeing is how do you ..

You can write fairly complex rules with the access control layer ! The first two conditions are possible (except for the project is only visible on Mondays).

  allow select on rows which satisfy this property:
  { "project_type" : { "_eq" : "whatever" } }

  allow update on rows which satisfy this property:
  { "closed_data" : { "_is_null" : true } }

The idea is simple, we provide a boolean expression based access control layer which can use variables from headers. When you can't specify it using the access control layer, you can write this in your own graphql layer and schema stitch with hasura. So you only have to write what is not possible with the access control layer.

> The other point I don't see is how do you ...
You can use the tooling around Postgres ! You can create an `ON INSERT` trigger on the table and listen to these events.
We're launching something very cool in the subscriptions/event-source to solve these kinds of problems. We also have 2 nice projects that work independent of the graphql-engine to help with change subscription on postgres (skor[1], pgdeltastream[2])
[1] https://github.com/hasura/skor [2] https://github.com/hasura/pgdeltastream

dustingetz#
For "access control layer" to work in the general case we need to be able to code it in a real programming language, no? Or are you going for something one-size-fits-many like Sharepoint?
kilburn1 reply#
> u can write fairly complex rules with the access control layer

Oh, I see. As a suggestion then, many business rules are not tied to roles. You may want to look into some "always enforced rules" or something like that, to avoid having to repeat these rules for each role (and the maintenance nightmare this entails).
> your own graphql layer and schema stitch with hasura
Again, I'm not versed in GraphQL in general, so this is from my ignorance. Maybe you could provide some example/tutorial on "stitching your own GraphQL apis with hasura" (your other examples, posts and tutorials are awesome btw!).
> You can use the tooling around Postgres
Fair enough. I've always found a bit hard to properly manage and test these native features (much harder than managing/testing pure code), but it is a sound solution nonetheless. Maybe you want to hint to these other projects somewhere in hasura's docs (I've checked them and couldn't find it, but maybe I'm just blind/didn't look hard enough).
Again, awesome project and good answers. I can't stop going through possible pet-projects to try this out soon! :)

praveenweb#
> Maybe you could provide some example/tutorial on "stitching your own GraphQL apis with hasura"

We have an example of schema stitching in this repo https://github.com/hasura/graphql-schema-stitching-demo
It stitches a weather API schema and a person schema. Hope it gives an idea.

eganist#
> The price is only visible for projects of type "whatever".

Tangentially, this one's shockingly common and not something I'd consider silly. Many manufacturers obligate their distribution partners to market only certain prices in order to keep pricing expectations for a certain product at a certain level.

evadne#
I suppose this can be done with row-based security if you are willing to mirror/maintain this in Postgres and/or fork the query engine to issue them under the right roles. There was a talk at PG Day UK 2018 about this but there are no performance benchmarking results available AFAIK.

As to triggers, you can totally do this with event sourcing in triggers, so when something is modified you write a row to the audit table, and you use another process to read from it and do the right thing, etc.

tango124 replies#
Hi HN! Super happy to announce the first open-source release of the Hasura GraphQL engine.

This is a standalone service that gives you GraphQL on Postgres. It comes with fine-grained access control that can integrate with any auth provider. It can also work with any existing postgres database as is, and allows you to expose select tables/views across your postgres schemas over GraphQL.
Looking forward to your feedback!

minxomat2 replies#
How does this project relate to prisma?
tirumaraiselvan1 reply#
Prisma doesn't work with existing postgres or access-controls.

Continue this thread — 1 reply

vsurabhi1 reply#
Hi, I'm one of the core contributors to the project.

Hasura and Prisma have very different approaches and end-goals at the moment.
TL;DR: Very simply put, Hasura is postgres first and adds an access-control layer to make it possible to query from the front end directly.
The longer version:
Prisma is intended to be a GraphQL ORM to Postgres (and several other databases with a common API) whereas Hasura is more database first and intended to let you leverage Postgres features over GraphQL.
Hasura comes with and lets you use any postgres migration system and then gives you GraphQL on top of it. This is what allows Hasura to give you GraphQL over any existing Postgres database and application even.
Hasura also comes with an optional access-control layer that makes it feasible to be used by frontend clients directly. This access control is inspired from postgres's RLS but does not depend on or use postgres RLS and can be coupled with application logic/auth.

filleokus2 replies#
> Prisma is intended to be a GraphQL ORM to Postgres

Sorry to be hijacking this thread, but how would you say Prisma compares to something like Graphene (with an appropriate ORM adapter). I've only used Graphene with Python and the SQLAlchemy adapter, but it sounds pretty similar? Is Prisma typically used as the only ORM in project, or is it used in conjunction with some other ORM?

Continue this thread — 2 replies

bsaul1 reply#
Thanks for releasing such a project. Your website is really well done, it immediately made me want to dig in the tech, congrats !

PS: as a sidenote and since i'm sure you'll get the question a lot : when i saw it was coded in haskell i was a bit nervous, but at the same time a bit more confident this wasn't another junior-level spaghetti code base.

tango12#
Haha, yes we do this get this a lot!

We're also planning to release a lot of cool GraphQL OSS stuff for the haskell community because of our work over the last year.

vetinari1 reply#
Any comparison with PostGraphile?
vsurabhi2 replies#
Very similar projects ! The emphasis of Hasura is to make it seamless to work with existing databases.

The primary difference is how authorization is handled. In Postgraphile, you map your application roles to Postgres users and define policies using Postgres's RLS. With Hasura, you define rules on roles (similar to Postgres's RLS) but it integrates into your existing auth system using webhooks.

Continue this thread — 1 reply

rogerrohrbach2 replies#
Another salient difference (and, for me, a deal-breaker): PostGraphile exposes user-defined functions in the GraphQL API, making it possible to define application logic and build a complete service without recourse to any other server-side technology.

Continue this thread — 2 replies

ASTP001#
This looks great! Is there any interface for extracting encrypted columns through this? For example, decrypting fernet encrypted values, given the key?
rcdmd#
Nice work. There are several competitors in the automagic Postgres REST/GraphQL space, and you're nailing documentation and ergonomics here. Your site and the Hansura Console sets your project apart from the rest.
sheeshkebab#
GraphQL is interesting although it doesn’t appear to be answer to designing better APIs (poor modularaization, monitoring, and tooling come to mind). “Mutations” look to be an afterthought, and schema/ui are not impressive either.

Above plus companies tripping hard to monetize tooling around something that you get completely for free with REST...
Even as UI engineer I don’t get the appeal of it - state, caching and all the “performance” tuning make it too complicated.

Load more comments