First glance reaction: Awesome, just the thing I need.
Then I saw the fine print: AGPL. Haskell. The thing might be awesome, but the combination of the legal risk from AGPL (very little legal precedent for AGPL, especially outside the US, so the real legal implications of the license are very murky) and maintenance risk from Haskell (finding good Haskell developers is hard, and the learning curve is brutal), makes it a lot harder to choose.
Hm...Haskell was an important initial choice for us because of our team's comfort with the language and also because it's neat to implement parsers and compilers. The Hasura engine is essentially a GraphQL to SQL compiler :)
I'm not sure I understand your point about AGPL? Do you have the same issue with the MongoDB license and would hesitate to use Mongo because of their AGPL? Why is this different? Just curious, would love to understand where you're coming from!
I’m sure Haskell is great, just saying its a bit of a risk to add to your stack if you don’t already have Haskell developers in house.
That, and the AGPL issue are both more important in this case (compared to MongoDB), because of the position in the stack that Hasura GraphQL Engine (HGE) would have. In the MongoDB case, we would almost always have an application server between Mongo and the GraphQL client, where custom business logic could be implemented, so Mongo can be treated as an external system whose source code we do not need to modify (like PostgreSQL in the case of HGE). In case of HGE, the GraphQL client would talk directly to HGE, and thus any customisation would most likely need to happen inside HGE, whether by plugins or patches or whatnot, making it tricky to avoid having to open source your custom business logic (as well as probably having to write it in Haskell).
We didn't intend for Hasura to be something like a boilerplate that you would modify. Mostly because it's harder to work with upstream changes when you work with OSS software like that unless it's an explicit library type dependency. What OSS service type component do you use (know of?) that is used in this way? Currently, we encourage users to use GraphQL schema stitching to customise their GraphQL schema/resolvers treating HGE almost as an external GraphQL service.
> The Hasura engine is essentially a GraphQL to SQL compiler
How much of the code base (and complexity) is doing that vs the auto-schema mapping and whatnot? I would just "read the source, Luke" but haskell isn't one of those languages I can idly read.
I have a bit of a dumb question: where does GraphQL fit in a stack? I've seen in used primarily as a means of aggregating a bunch of disparate microservices, but then I see things like this that put it in the role of app server, almost. What advantages does this give over, for example, a Rails API (also on Postgres)? If it is supposed to fill the role of app server, how do you handle things more involved than simple CRUD operations? Like, if I sign up a user, how -- in a GraphQL world -- would I send a welcome email, typically?
I see GraphQL as a protocol replacement for REST. With REST you have the following problems:
* Responses either contain more data than you need, or not enough data (e.g. you need data for related entities as well). * With REST, if you need data for related entities then you need to perform additional REST calls, resulting in more network roundtrips. With GraphQL you can specify exactly what you want, and the server responds with just that, in a single call.
We’re experimenting with it on a new product at my company, and this is how we use it. Specifically, we use it as an API gateway in front of a bunch of restful services.
Another benefit is a more robust type system than you get with JSON. GraphQL supports union types, interfaces, etc., allows you to provide more strongly typed contracts between the backend and frontend. One downside though - while the responses can become smaller, with fewer round trips, the requests get A LOT bigger (than with REST), as you have to specify every field, subfield, etc. This is especially true if you make heavy use of union types - then you have to specify all the fields, sub fields, etc. of all the various concrete members you might get back. Like requests with payloads over 1KB is not uncommon. If you’re polling, and the result of the polling is generally an empty response, you may end up sending significantly MORE data over the wire, not less.
I believe it's intended as an API gateway, a means of creating a single front-facing web API for one or (usually) more back-end services. That way, clients can pick and mix apis and the data they want from it (e.g. streaming posts for mobile, or 20 posts at a time for desktop), without a developer having to create a REST / Rails API endpoint for each possible use case / client.
Just like there are frameworks for these protocols, this is one that automatically creates a service for a postgres database. postgrest[0] would probably be it's REST equivalent. https://github.com/PostgREST/postgrest
In practice it is like exposing a very limited interpreter directly to the public internet. Instead of working with resources and limited verbs and hypermedia or SOAP (which is literally just documents) you allow clients to submit what are essentially programs with are then evaluated. In other words its mobile code all over again. [1] [1] https://en.wikipedia.org/wiki/Code_mobility
well yeah, there is a reason why graphql gets called 'sql for web services' after all.
but I wasn't trying to draw a parallel between implementations...
while you're obviously right that the implementation and the way you actually interface with GraphQL is very different from REST, just like that differed from SOAP, its nonetheless the same use-case. They're all communication protocols between different software components.
There could be 2 ways to solve that specific problem of sending a welcome email:
1) Write a GraphQL schema stitching gateway, that can write a custom mutation that delegates to another API (or GraphQL API) to write to the database, or writes to the database directly. This is becoming popular as more backend services expose their functionalities via GraphQL. 2) React asynchronously after the database write is done. Put the database event in a queue, for example, that runs the email send async-ly.
The most prevalent use case for GraphQL right now is to act as a thin API layer over a bunch of microservices (which is what Facebook originally developed it for) -- but that is not the only use case.
GraphQL is actually much less than a replacement for a REST API. Its really just a type system with an execution engine that can map queries against that type system to resolvers (functions). That's it. This means that you can actually use it all over the place: - Because it provides a strongly typed interface, you could use GraphQL as the basis of an RPC protocol (infact, GraphQL doesn't specify a transport mechanism, since its only job is to map queries to functions, so you could send GraphQL queries over RabbitMQ if you wanted to.. or encode them with protobuf and send them via HTTP/2). - You could use a GraphQL schema to define the internal object model of an application and use GraphQL internally as a data access layer. You don't even have to expose it outside your codebase. - You can use the tooling that comes with GraphQL (at least in the Node.js implementation) to parse incoming queries into their abstract syntax trees and to all kinds of fun stuff with them (automagically stitch multiple GraphQL schema's together into a combined API). - I'm actually working on a proxy layer that can actually sit on top of an existing GraphQL API and apply additional logic to the incoming request and outgoing responses (it would actually be a good fit as a business logic layer for a Hasura based GraphQL api) I think that in the future we'll see lots of very interesting uses of GraphQL that go beyond is current status as "REST API replacement" *To answer your question "if I sign up a user, how -- in a GraphQL world -- would I send a welcome email, typically?" -- Define a mutation (update method) in your GraphQL schema to create a new user. Inside the resolver (function that is executed) for that mutation, write code to create a user (API call? Database update?) and send an email (drop a message in a queue to your email sending serivce?). It works just like it would for any other application codebase, you just initiate process with a GraphQL query, instead of, say an HTTP Post to a REST API.
I always thought it was in the name- a web API standard inspired by SQL over a graph data structure. This way, rather than having to predefine API endpoints that are super customized, you define fewer that follow the standard and act as a standard interface. Like if HTTP client = ODBC and GraphQL = SQL.
I am very hesitant to couple the business logic of any application to the transport layer (GraphQL) or the persistence layer (Postgres) for that matter.
Your reply suggests you either couple everything or nothing. It’s more nuanced than that. Everything is a trade off. With that said,
it looks like this library will position itself in the center of your architecture — and I would be very hesitant
to do that.
Of course anyone should be hesitant to over-model the business domain in any part of the application including the database, but the entire reason of existence of the RDBMS is to maintain consistency with something, and if that something isn't the business domain, then what good does it do?
Databases aren't simply persistence layers, they also encompass querying which implicitly couples your application to them. The simplest query model is the key value store, which itself is a form of coupling, but it's quite limited in the operations it can support with high performance.
GraphQL is similarly not a transport layer. The transport layer for GraphQL is HTTP. GraphQL is a query language. To use it with a particular database you need to transpile GraphQL to the query language supported by your database. Usually this is done in an unprincipled manner with ad-hoc code. In other cases it's done more globally and formally, as I assume Hasura is trying to do.
Broadly 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. Also, peripherally, we have quite a bit of tooling with an admin UI and a rails-like migration system to make the dev workflows easier :)
> The emphasis of Hasura is to make it seamless to work with existing databases.
Yet, I spent 15 minutes searching for example of using Hasura with an existing schema. Your "Getting Started" page has two examples: Deploy on Heroku and Run with Docker - in both cases, using a fresh database, not an existing one.
Comments (103) 27 threads
Earlier commentsThen I saw the fine print: AGPL. Haskell.
The thing might be awesome, but the combination of the legal risk from AGPL (very little legal precedent for AGPL, especially outside the US, so the real legal implications of the license are very murky) and maintenance risk from Haskell (finding good Haskell developers is hard, and the learning curve is brutal), makes it a lot harder to choose.
I'm not sure I understand your point about AGPL? Do you have the same issue with the MongoDB license and would hesitate to use Mongo because of their AGPL? Why is this different? Just curious, would love to understand where you're coming from!
That, and the AGPL issue are both more important in this case (compared to MongoDB), because of the position in the stack that Hasura GraphQL Engine (HGE) would have. In the MongoDB case, we would almost always have an application server between Mongo and the GraphQL client, where custom business logic could be implemented, so Mongo can be treated as an external system whose source code we do not need to modify (like PostgreSQL in the case of HGE).
In case of HGE, the GraphQL client would talk directly to HGE, and thus any customisation would most likely need to happen inside HGE, whether by plugins or patches or whatnot, making it tricky to avoid having to open source your custom business logic (as well as probably having to write it in Haskell).
We didn't intend for Hasura to be something like a boilerplate that you would modify. Mostly because it's harder to work with upstream changes when you work with OSS software like that unless it's an explicit library type dependency. What OSS service type component do you use (know of?) that is used in this way?
Currently, we encourage users to use GraphQL schema stitching to customise their GraphQL schema/resolvers treating HGE almost as an external GraphQL service.
Continue this thread — 1 reply
How much of the code base (and complexity) is doing that vs the auto-schema mapping and whatnot?
I would just "read the source, Luke" but haskell isn't one of those languages I can idly read.
* Responses either contain more data than you need, or not enough data (e.g. you need data for related entities as well).
* With REST, if you need data for related entities then you need to perform additional REST calls, resulting in more network roundtrips.
With GraphQL you can specify exactly what you want, and the server responds with just that, in a single call.
Another benefit is a more robust type system than you get with JSON. GraphQL supports union types, interfaces, etc., allows you to provide more strongly typed contracts between the backend and frontend.
One downside though - while the responses can become smaller, with fewer round trips, the requests get A LOT bigger (than with REST), as you have to specify every field, subfield, etc. This is especially true if you make heavy use of union types - then you have to specify all the fields, sub fields, etc. of all the various concrete members you might get back. Like requests with payloads over 1KB is not uncommon. If you’re polling, and the result of the polling is generally an empty response, you may end up sending significantly MORE data over the wire, not less.
Just like there are frameworks for these protocols, this is one that automatically creates a service for a postgres database.
postgrest[0] would probably be it's REST equivalent.
https://github.com/PostgREST/postgrest
In practice it is like exposing a very limited interpreter directly to the public internet. Instead of working with resources and limited verbs and hypermedia or SOAP (which is literally just documents) you allow clients to submit what are essentially programs with are then evaluated. In other words its mobile code all over again. [1]
[1] https://en.wikipedia.org/wiki/Code_mobility
but I wasn't trying to draw a parallel between implementations... while you're obviously right that the implementation and the way you actually interface with GraphQL is very different from REST, just like that differed from SOAP, its nonetheless the same use-case.
They're all communication protocols between different software components.
1) Write a GraphQL schema stitching gateway, that can write a custom mutation that delegates to another API (or GraphQL API) to write to the database, or writes to the database directly. This is becoming popular as more backend services expose their functionalities via GraphQL.
2) React asynchronously after the database write is done. Put the database event in a queue, for example, that runs the email send async-ly.
GraphQL is actually much less than a replacement for a REST API. Its really just a type system with an execution engine that can map queries against that type system to resolvers (functions). That's it. This means that you can actually use it all over the place:
- Because it provides a strongly typed interface, you could use GraphQL as the basis of an RPC protocol (infact, GraphQL doesn't specify a transport mechanism, since its only job is to map queries to functions, so you could send GraphQL queries over RabbitMQ if you wanted to.. or encode them with protobuf and send them via HTTP/2).
- You could use a GraphQL schema to define the internal object model of an application and use GraphQL internally as a data access layer. You don't even have to expose it outside your codebase.
- You can use the tooling that comes with GraphQL (at least in the Node.js implementation) to parse incoming queries into their abstract syntax trees and to all kinds of fun stuff with them (automagically stitch multiple GraphQL schema's together into a combined API).
- I'm actually working on a proxy layer that can actually sit on top of an existing GraphQL API and apply additional logic to the incoming request and outgoing responses (it would actually be a good fit as a business logic layer for a Hasura based GraphQL api)
I think that in the future we'll see lots of very interesting uses of GraphQL that go beyond is current status as "REST API replacement"
*To answer your question "if I sign up a user, how -- in a GraphQL world -- would I send a welcome email, typically?" -- Define a mutation (update method) in your GraphQL schema to create a new user. Inside the resolver (function that is executed) for that mutation, write code to create a user (API call? Database update?) and send an email (drop a message in a queue to your email sending serivce?). It works just like it would for any other application codebase, you just initiate process with a GraphQL query, instead of, say an HTTP Post to a REST API.
Continue this thread — 1 reply
GraphQL is similarly not a transport layer. The transport layer for GraphQL is HTTP. GraphQL is a query language. To use it with a particular database you need to transpile GraphQL to the query language supported by your database. Usually this is done in an unprincipled manner with ad-hoc code. In other cases it's done more globally and formally, as I assume Hasura is trying to do.
Unless – of course – you simply want something working quickly that does not need to be maintained or kept alive for a long time.
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.
Also, peripherally, we have quite a bit of tooling with an admin UI and a rails-like migration system to make the dev workflows easier :)
Yet, I spent 15 minutes searching for example of using Hasura with an existing schema. Your "Getting Started" page has two examples: Deploy on Heroku and Run with Docker - in both cases, using a fresh database, not an existing one.
EDIT: Docs updated, we'll keep improving it too :)
Continue this thread — 2 replies
All comments shown.
Couldn't load more comments. Check your connection and try again.