GraphQL Dev Environment with Unraid, Hasura, and PostgreSQL

Nov 18, 2020

In this post I'll be covering setting up a dev server using a few tools including Unraid, Hasura, and PostgreSQL. This is part of an on going series that you can read about here.

Tools

The Following is a basic description of the tools I'll be using for this project.

Unraid OS

Unleash Your Hardware
Unraid OS allows sophisticated media aficionados, gamers, and other intensive data-users to have ultimate control over their data, media, applications, and desktops, using just about any combination of hardware.

I've been using it as the OS for my home server, it makes it easy to manage containers and VMs remotely. This is where I'll be hosting my dev environment.

Hasura

Hasura | Instant GraphQL APIs for your data | Join data across databases, GraphQL & REST services to build powerful modern applications
Hasura gives you instant GraphQL APIs on your data sources. Point Hasura to your preferred internal and external data sources, setup relationships and security rules on your data models across sources and get a managed unified GraphQL API to build modern applications, instantly.

I'll be using Hasura for this GraphQL endpoint. I've used it before and it's very easy to work with and includes all the features I'll need for this project.

PostgreSQL

PostgreSQL
The world’s most advanced open source database.

This is that database that integrates with Hasura, I've used it for previous projects and I've been very happy with it's performance and feature set.

Setup

With that out of the way here's the setup for the environment.

Hasura and Postgres can be setup at once using docker compose as is shown in the quickstart guide. In this case I'll be setting up the containers separately in Unraid.

Postgres 13

The setup here is very simple using unraid. It involves navigating to Docker -> Add Container. Then we select an image from dockerhub and specify all the required variables. From there the image is created and run.

The config for a new Postgres docker container

A command from the terminal would look something like this, though you would need to change some parameters including the password, user and database.

docker run -d --name='Postgres13' --net='bridge' -e TZ="America/Phoenix" -e HOST_OS="Unraid" -e 'POSTGRES_PASSWORD'='pass' -e 'POSTGRES_USER'='user' -e 'POSTGRES_DB'='database' -p '5432:5432/tcp' -v '/mnt/cache/appdata/postgres':'/var/lib/postgresql/data':'rw' 'postgres:13.1-alpine'

At that point we can check the logs and see the database up and running.

Hasura

The setup for Hasura is similar. Just double check that all the variables match those set in Postgres and select a port that isn't in use.

docker run -d -p 8080:8080 \
  -e HASURA_GRAPHQL_DATABASE_URL=postgres://user:[email protected]:port/dbname \
  -e HASURA_GRAPHQL_ENABLE_CONSOLE=true \
  hasura/graphql-engine:latest

At this point can open our browser to [Unraid IP address]:[Port] and see the the Hasura console!

This is a great starting point, and from here on we can start playing with Hasura's model and GraphQL endpoint.


In the next post I'll be covering securing the endpoint and exposing it to the internet.


I hope you've found this post useful. If you have any questions or comments, please feel free to reach out!

Get In Touch


or via telegram

Great! You've successfully subscribed.
Great! Next, complete checkout for full access.
Welcome back! You've successfully signed in.
Success! Your account is fully activated, you now have access to all content.