Now that graphQL is catching on some libraries have popped up to make working with graphQL and database abstraction layers like (sequelize and bookshelf.js) easier.
They all seem to focus on making the ORM models work easily with the graphQL schema.
I was wondering however, why not go the other way around? Would it be possible in general to generate ORM schemata of off a graphQL one.
Since I do not know graphQL very good, I'm not able to see it's limitations as to wether or not this is possible? Yet in my brain it should be possible to just define a graphQL schema and then transform it to something that works for you database.
I found a recent project that does just that. It's called Gestalt. It only works with Postgres right now, but it looks pretty promising. Checkout out the Getting Started it's pretty simple to setup.
As long as you have PostgreSQL installed and running you can run the following to get a project started:
npm install --global gestalt-cli
createdb blogs
gestalt init blogs
cd blogs
cat > schema.graphql << 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
gestalt migrate
npm start
Hooray! it's running now you can open GraphiQL in your browser:
open http://localhost:3000/graphql
Now anytime you want you can change schema.graphql
and then run gestalt migrate
to update PostgreSQL and GraphQL.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With