Create an ORM schema and queries automatically from graphQL schema

Now that they are catching the graphical interface, some libraries have come out to facilitate working with the graphQL and database abstraction levels, for example (sequelize and bookshelf.js).

All of them seem to be focused on making ORM models work seamlessly with graphics.

I was wondering, why not go the other way around? It would be possible, in general, to generate ORM schemes using a graph.

Since I am not very good at graphics, I can’t see the restrictions on being sure, or not, is this possible? However, in my brain it should be possible to simply define a graphQL schema and then convert it into something that works for your database.

+5
source share
1 answer

I found a recent project that does just that. He called Gestalt . It only works with Postgres right now, but it looks pretty promising. Checkout Getting Started is quite simple to set up.

As long as you have PostgreSQL installed and running, you can run the following to start the project:

npm install --global gestalt-cli createdb blogs gestalt init blogs cd blogs read -r -d '' VARIABLE << EOM type Session implements Node { id: ID! } type User implements Node { id: ID! email: String! @unique passwordHash: String! @hidden } type Post implements Node { id: ID! text: String! createdAt: Date! } EOM echo "$VARIABLE" > schema.graphql gestalt migrate npm start 

Hooray! it works now, you can open GraphiQL in your browser:

 open http://localhost:3000/graphql 

Now, at any time, you can modify schema.graphql and then run gestalt migrate to update PostgreSQL and GraphQL.

+1
source

Source: https://habr.com/ru/post/1242472/


All Articles