Skip to Main ContentSkip to Footer

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

November 18, 2019

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[](https://cdn-images-1.medium.com/max/800/1*pEIKhNSiiFwkH_keAmFcJw.png) 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

  1. Add Star Wars SQL: Go to the DATA tab, and you’ll add the SQL from there.

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

1  1DJ8t8iS  gM17jrGvRzm1g

  1. 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.

1  Cqfz  0PTtZ8xI9V0wKPsCg 1  WknxLdMOvJ  iuvDv  GQVvg

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.

query planets {
  planet {
    name
    diameter
    climate
    people(limit: 5) {
      name
    }
  }
}

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.

0  bsFzre1ZsYDer3OO

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.

0  te7pfJLYYPUSCMHp

I Don’t Want to Use Hasura

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

Resources and References:


Subscribe to my email list!

If you enjoy my work, you should definitely join my newsletter"Giorat Mails". It’s one email a week with everything interesting I’ve read or found, plus new articles and fresh tutorials.

Sign up for our newsletter