What if I told you there was an open source GraphQL backend that automatically learned the structure of your database and allowed you to instantly start querying it with GraphQL. No code or no configs it just works out of the box.
While this sounds unreal - it exists. GraphJin is an instant GraphQL to SQL compiler that converts your GraphQL query into an efficient and fast SQL query. GraphJin is written in Go and can be used as a standalone service or a library within your own app. It works with Postgres, Mysql and the Distributed Yugabyte and CockroackDB databases.
Install GraphJin
go get github.com/dosco/graphjin
You need Go installed on your system. The above command will download, compile and install GraphJin into your GOPATH
which is usually ~/go/bin
and should be added to your path.
Create a GraphJin App
graphjin new blog
INF created 'blog'
INF created 'blog/Dockerfile'
INF created 'blog/docker-compose.yml'
INF created 'blog/cloudbuild.yaml'
INF created 'blog/config'
INF created 'blog/config/dev.yml'
INF created 'blog/config/prod.yml'
INF created 'blog/config/seed.js'
INF created 'blog/config/migrations'
INF created 'blog/config/migrations/0_init.sql'
INF app 'blog' initialized
The newly created app will be in the blog
folder and will contain a docker environment, config files and database migration files.
Setup Your Database
docker-compose run api db:setup
We use Docker Compose which is a nice way to run your entire backend in Docker and not have to clutter your machine. This above command will use docker-compose
to start a Postgres
database and GraphJin
using the config/dev.yml
config file.
It will then run the db:setup
GraphJin command which will create the blog_development
database and create the tables defined in the config/migrations/0_init.sql
database migration script. It will then run seed.js
the seeding script to add fake data to your database to help you with development.
Start Your App
docker-compose up
The up
command will also run the database but this time it will run Graphjin with the serv
command which will start your GraphQL API backend.
Try some GraphQL
query {
users {
id
email
}
}
Open a browser and visit http://localhost:8080. You'll be presented with the GraphJin web ui. You can craft and test your GraphQL queries here.
Some more details
Security
In development mode all named queries query getUser { user { id } }
(queries with a name eg: getUser) are saved into an allow list file and in production mode only those queries are allowed to run. This makes GraphJin very fast and secure since no one can send different queries to your API and expect to get any data that you don't want to expose. Also in production mode queries are compiled to database prepared statements which makes then extremely fast.
Frontend development
GraphJin works fine with all GraphQL client libraries like Apollo
and URQL
. Just use named queries when building your app they are automatically saved (or updated) as your app evolves. So when deployed into production your allow list is packaged along.
Who uses GraphJin
GraphJin is fully open source Apache Licensed project. It has an active and growing community, great documentation and a clean codebase with great test coverage using integration tests.
GraphJin is being used by many startups saving them months of development time. For example the popular 42papers.com platform to discover top trending CS/ML and AI papers uses the standalone GraphJin service.
Save you time and money
Developing REST APIs to create, update, delete and fetch data from your database is a tedious job also as your UI evolves those APIs have to be maintained and updated. This all takes weeks to months of relatively boring work and can be a vector to introduce security holes in your app.
With GraphJin all this work goes away instantly. The SQL queries GraphJin generates are lighting fast and your web developers now has to power to create the query he needs while building the UI. It frees you up to focus on the interesting parts of your app. Also GraphJin starts up in milliseconds so it works great on severless scale to zero platforms like Google App Engine, Google CloudRun, AWS Fargate, Azure Container Service. It's tiny, fast and feature packed give it a try and I'm happy to help so feel free to reach out on th comments or my twitter @dosco
Top comments (2)
Its really a good idea. But in current era with the help of ai you can make it even in a shorter time. Give a read to this techai blog.
Just wanted to say thank you for all your hard work on GraphJin. All the best in your endeavors and my you and GraphJin flourish