
Show HN: Json2graphql – From a JSON file to Postgres-backed realtime GraphQL - wawhal
https://github.com/hasura/graphql-engine/tree/master/community/tools/json2graphql
======
michelpp
I've tried Hasura and really liked it, but there were a few quirks that led me
to another tool, but in general, the whole idea that tools like Hasura,
PostgREST, pREST and PostGraphile are trying to solve are the future.

Server side frameworks are obsolete. ORMs are decrepit meta-models and log
hewing busywork. Mapping an already powerful model onto one that is less
powerful, eating gigabytes of ram to run JVM/Python stacks, countless rolling
and restarting of processes. So many hand-rolled loops of code that could just
be joins. Multiple queries to smash together two datum that could just be
views all in so many thousands of lines of pointless code.

Postgres is already object-oriented, and has been for decades. It already
speaks JSON and has for almost 10 years now. It can speak a number of
languages, including Python and Javascript, right in the database. Postgres
not only stores your data, it _knows_ your data, the statistical distribution
and selectivity of queries. No ORM system maintains this kind of optimization
state when they generate SQL.

The real power of tools like Hasura is that they get out of the way. They
encourage the use of views, functions, extensions, all the powerful stuff
that's native to Postgres.

Who cares if it runs on MySQL? The idea is so simple that MySQL can have its
own version that gets out of the way and leverages the core power of MySQL.
The idea is not to have more frameworks, but to have fewer.

~~~
ruslan_talpa
Can you share what tool was the final choice and what were the quirks that
influenced your decision?

------
cpursley
Hasura is a boon to productivity and keeps gaining very useful features. I
really wish they had a hosted version (like netlify); I don't want to manage
servers.

~~~
cpursley
This looks setup pretty compelling, but it would still be nice to have an easy
to use abstraction on top of it:

[https://dev.to/lineup-ninja/deploying-hasura-on-aws-with-
far...](https://dev.to/lineup-ninja/deploying-hasura-on-aws-with-fargate-rds-
and-terraform-4gk7)

------
jacques_chester
I was excited to see graphql-engine, but unfortunately the AGPL is a bit hard
to pitch to folks in an enterprise software context.

~~~
tango12
Hey, I'm from Hasura.

Out of curiosity, did you face trouble trying to get something like Mongo
running in the same enterprise context? Especially back when they were AGPL?

We've put up an explanation reg. our AGPL licens here:
[https://github.com/hasura/graphql-engine/wiki/License-
Explai...](https://github.com/hasura/graphql-engine/wiki/License-Explained)

~~~
yodon
AGPL is pretty much a non-starter for us. It's simply viewed as too risky a
license. Thanks to jacues_chester for pointing out the license. The project
sounds super cool but there is simply no point in my looking into it on
account of that licensing decision. You're shaking my confidence in your
decision making, Hasura.

~~~
quietbritishjim
(I am not from Hasura.)

AGPL only makes a difference if you link that program and your own code
together into one executable (including through dynamic linking). If you're
calling from another executable over an API then it makes no practical
difference whether it's AGPL, regular GPL or even BSD-style. This is, by
definition, a remote API so you'd really have to make an effort to infect your
code with the licence.

Just saying "it's too risky" sounds like ignorance. Like if I refused to
compile my code with GCC because I heard GCC has a GPL licence. There's not
much that vendors can do to counter an attitude like that.

~~~
ensignavenger
Are you a lawyer? A great deal many lawyers have reviewed the AGPL and labeled
it too risky for their companies. While I tend to agree with your
interpretation of it, I still am extra cautious and avoid AGPL software when I
can for infrastructure products like this. I am cautious because of the
lawyers opinions on it, and I am also cautious because many companies that
adopt an AGPL license turn out to be not very good open source stewards, and
they put up roadblocks to community contributions that weaken the project and
make having a real open source community behind the projects nearly
impossible. There are some exceptions, but they are rare, so I exercise
extreme caution around AGPL licensed products.

------
maratd
Is there some way to make data available to specific users, but unavailable to
others? Basically enforcing an ACL or similar?

~~~
tango12
Yep! Hasura allows you to configure access control rules which are namespaced
by "roles" that you can attach to your tables.

Each permission rule can reference a session variable that comes in from your
authentication system (whatever it is).

Docs:
[https://docs.hasura.io/1.0/graphql/manual/auth/index.html](https://docs.hasura.io/1.0/graphql/manual/auth/index.html)

Examples: [https://docs.hasura.io/1.0/graphql/manual/auth/common-
roles-...](https://docs.hasura.io/1.0/graphql/manual/auth/common-roles-auth-
examples.html)

------
priansh
This is awesome but how do you deal with circular references?

~~~
wawhal
It works with circular references. For example, this works:

    
    
      {
        "user": [
              { "id": 456, "name": "Sita K", "user_id": 123 },
              { "id": 123, "name": "John Doe", "user_id": 123  }
        ]
      }
    

Do you have anything else in mind?

PS: Co-author here

~~~
chrisseaton
But then to go from user 456 to user 123 via the field user_id do I have to do
a linear search of all users to check their IDs?

~~~
wawhal
No. The tool also creates relationships based on foreign key references using
Hasura. So to query all the users with the child users, you would make a
GraphQL query like:

    
    
      query {
        user {
          id
          name
          childUser: userByUserId {
            id
            name
          }
        }
      }
    

The response would be:

    
    
      {
        "data": {
          "user": [
            {
              "id": 123,
              "name": "John Doe",
              "childUser": {
                "id": 123,
                "name": "John Doe"
              }
            },
            {
              "id": 456,
              "name": "Sita K",
              "childUser": {
                "id": 123,
                "name": "John Doe"
              }
            }
          ]
        }
      }
    

Did I answer your question?

~~~
chrisseaton
Those child users don't then have their own child users (because it's cyclic)
so do you have to choose one option of the two, both with a drawback?

I was thinking you could replace or supplement the real user IDs with their
indices in the array of returned users.

~~~
wawhal
I am sorry, but if possible, could you elaborate @chrisseaton? (preferably
with a bit more punctuation :D)

~~~
chrisseaton
With more punctuation? What's that supposed to mean? I've written two short
sentences. It's not some wall of text.

------
marknadal
For other related automatic GraphQL tools that create realtime subscriptions
to queries, check out [https://github.com/brysgo/graphql-
gun](https://github.com/brysgo/graphql-gun)

I'm curious though, with Postgres, how does the realtime aspect work?

------
dksidana
Is your code heavily dependent on Postgres or it works with any SQL store ?

~~~
tango12
(I'm from Hasura)

Well, today it is fairly dependent on postgres, but we can add more SQL
backends eventually. We also leverage some neat Postgres performance tricks
which would have to change depending on the database.

Do you have a database in mind?

Hasura is structured as a compiler that takes GraphQL queries, adds access
control rules configured by the user and then generates a SQL query. Adding
more SQL backends is supporting more SQL dialects.

~~~
billbrown
I'm exploring GraphQL for a legacy MySQL database right now and the only
option I can see is based on Sequelize, which we don't use.

I'd love MySQL support!

~~~
tango12
Noted!

Not sure if this will help, but one of our users mentioned using symmetricds
[1] to sync data from sql-server to postgres and then using Hasura.

[1] [https://www.symmetricds.org/](https://www.symmetricds.org/)

