Hasura offers instant GraphQL APIs for your data within minutes for free! We can run Hasura, locally or in the cloud, and connect it to your new or existing databases to instantly get a production-grade GraphQL API.
Hasura is compatible with all GraphQL tooling and works with PostgreSQL and MySQL Server.
Hasura’s built-in RLS style authorisation engine allows you to specify authorisation rules at a model level conveniently, and safely expose the GraphQL API to developers inside or outside your organization. 🔐
We can either use Hasura Core which is open-source, includes all core features and can be deployed anywhere with Docker or use Hasura Cloud which is fully managed.
This guide will show you how to deploy Hasura Core using their public Docker image on Northflank with a PostgreSQL database.
Create a new PostgreSQL addon on Northflank.
Under Networking, ensure to tick ‘Deploy with TLS’ and ‘Publicly accessible’.
- These two options will ensure your addon is exposed publicly to the internet and accessible to Hasura.
Create a new secret group of type ‘Runtime’ to share Environment variables across different services and addons.
Add the following key-value pair secrets:
Key Value HASURA_GRAPHQL_METADATA_DATABASE_URL
${PG_DATABASE_URL}
PG_DATABASE_URL
${POSTGRES_URI}
HASURA_GRAPHQL_DEV_MODE
true
HASURA_GRAPHQL_ENABLE_CONSOLE
true
Under Linked addons select
Configure
for the PostgreSQL addon we just created.Select
POSTGRES_URI
and add an aliasPOSTGRES_URI
.
Create a new deployment service in Northflank for Hasura Core GraphQL Engine using their public Docker image as below.
Set the image path as
hasura/graphql-engine:v2.6.1
(version can change depending upon Hasura's releases) You can refer to this docker-compose.yml for the latest version to use.Add an
8080
port in the networking and expose it using the internet if you want to access the Hasura Console or you can use Northflank’s CLI to port forward to your machine.We have successfully created the Hasura Core GraphQL Engine service.
Open the Hasura Console in your browser by going to the public domain for your Hasura GraphQL Engine service or port forward to your local machine. You should see something like this.
Switch to the
Data
tab to connect our PostgreSQL database. Fill in the details below for database connection. We can reuse the same environment variable here.After our database is connected, navigate to the PostgreSQL database from the left. We will try to apply a template from Template Gallery to get started. Click on the “Hello World” template.
Click on Install Template. It will create necessary Schema and Tables with some dummy data to play around with.
You can see dummy data created in the tables article and author.
We switch to the API tab and test GraphQL APIs.
a. Fetching Articles (Query)
query FetchArticles { helloworld_article { title, author { name } } }
b. Create a user (Mutation)
mutation MyMutation { insert__helloworld_article_one(object: {author_id: 10, rating: 10, title: "New Article"}) { id } }
There is a lot of stuff you can now do with the Hasura platform. You can learn a lot from this tutorial by Hasura. Fullstack GraphQL Tutorial Series | Learn GraphQL & Hasura
Hope you enjoyed and learned from this guide on how to deploy Hasura on Northflank. Till the next time cheers!
Northflank allows you to deploy your code and databases within minutes. Sign up for a Northflank account and create a free project to get started.
- Connect with your preferred VCS: GitHub, GitLab or Bitbucket
- Manage build arguments and environment variables using secret groups
- Scale vertically and horizontally with multiple replicas per service
- Deployment of Docker containers
- Observe & monitor with real-time metrics & logs
- Low latency and high performance
- Multiple read and write replicas
- Backup, restore and fork databases