Create a GraphQL API in 60 Seconds — With No Code — Using Hasura

Get a nearly instant GraphQL engine without writing any code

Riccardo Giorato
Nov 18 · 4 min read

What Is Hasura?

Hasura is an open-source project that connects your databases and microservices and instantly gives you a production-ready GraphQL API.

Reduce your time to go live by giving your team a powerful real-time GraphQL API in seconds from your PostgreSQL database.


Why Hasura?

The project is completely open source on GitHub, with new improvements coming out every week.

You can get more than 1,000 queries/sec with 50MB RAM — just with a container on a free Heroku dyno.

You can integrate and interact with microservices, connecting them by webhooks based on database events or merging multiple GraphQL external end points.

You get a full feature JWT or webhook-user-management system connectable to other authentication providers like Firebase or Auth0.

You get fully compatible subscriptions, which means you can get instant updates of the data from your back end to your front end thanks to WebSocket without having to handle anything except for writing the GraphQL query to get the data.

You can get all of that ready in less than one minute — or 60 seconds.


Let’s Get Started!

https://heroku.com/deploy?template=https://github.com/hasura/graphql-engine-heroku

Just press “Deploy to Heroku.” This will automatically add a new app to your account and will also configure a free PostgreSQL database for you.

If you don’t have an account on Heroku, you need to sign up for one. You won’t need a credit card, and once you sign up, you’ll be redirected to your Heroku-app creation page automatically.

All these steps on Heroku will require around 30 seconds, so we still have 30 seconds to prepare Hasura.


Let’s Add Some Info to Your Database

Remember: Tick the “Track this” checkbox to automatically add these tables to the ones handled by Hasura without having to manually add them.

2. Relationships: After having added the tables, you’ll have to do one last thing: adding the relationships to each table so you’ll be able to query the tables nesting together with the data based on foreign keys.

3. Let’s make a query: Go on the GraphQL page, insert this query, and press the play button to show the results of these two tables merged together.


Let’s Make a GraphQL Query From Your Front End

Let’s show this data from your front end. I’ll use a modified version of a simple React app with Apollo Client from this tutorial.

Remember to replace the URL of the GraphQL server with the URL of your Heroku application URL, in my case starwars-hasura.herokuapp.com.

https://codesandbox.io/s/star-wars-hasura-x7bt9

Complete code sanbox with data from Hasura:

https://codesandbox.io/s/star-wars-hasura-x7bt9


And now?

Secure your Hasura end point like the warning message on the top right of Hasura reminds you to do it.

You can add a user authentication. I suggest you use Firebase because they don’t have any hard limit on the number of users you can have in your app.

Then, you could also try to add an external end point to your Hasura instance by going to the Remote Schemas tab.

After that, you could link every update to a row of your table with an invocation of the microservice to check if the user input contains spam or phishing words.


I Don’t Want to Use Hasura

Sure you’ll be able to do similar things with other packages like:


Better Programming

Advice for programmers.

Riccardo Giorato

Written by

XR Developer and Photogrammetry Artist https://riccardogiorato.com/

Better Programming

Advice for programmers.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade