Hasura is an open-source engine that provides instant GraphQL APIs to your existing databases, making it a popular choice for developers. Here is a step-by-step guide on installing Hasura on macOS.
Before installing Hasura, you must have the following prerequisites installed on your macOS:
Docker
You can install Docker from the official website: https://docs.docker.com/docker-for-mac/install/
Docker Compose
Docker Compose should come pre-installed with Docker on macOS. However, if it is not installed or outdated, you can install it using Homebrew by running the following command:
brew install docker-compose
Hasura CLI
You can install Hasura CLI by running the following command in the terminal:
brew install hasura-cli
Now that you have met all the prerequisites, let's proceed with installing Hasura.
Start the Docker daemon.
Ensure that the Docker daemon is running on your macOS by clicking the Docker icon in the menu bar and selecting "Open Docker Desktop."
Create a new directory for Hasura.
Create a new directory with a name of your choice for your Hasura project. For example:
mkdir my-hasura-project
cd my-hasura-project
Create a Docker Compose file.
Create a new file named docker-compose.yaml
in the directory you created in the previous step:
version: '3.6'
services:
postgres:
image: postgres
restart: always
environment:
POSTGRES_PASSWORD: postgres
graphql-engine:
image: hasura/graphql-engine:v2.0.12
ports:
- 8080:8080
depends_on:
- postgres
environment:
HASURA_GRAPHQL_DATABASE_URL: postgres://postgres:postgres@postgres:5432/postgres
HASURA_GRAPHQL_ENABLE_CONSOLE: "true"
This docker-compose.yaml
file defines two services: postgres
and graphql-engine
. The postgres
service provides a PostgreSQL database that Hasura will use, and the graphql-engine
service provides the Hasura GraphQL engine.
Note that the HASURA_GRAPHQL_DATABASE_URL
environment variable in the graphql-engine
service is set to connect to the postgres
service's database.
Start the Hasura stack.
Run the following command in the terminal to start the Hasura stack:
docker-compose up -d
This command will start the PostgreSQL database and the Hasura GraphQL engine inside Docker.
Open Hasura console.
After Hasura starts, you can access the Hasura console to create and manage your GraphQL API.
Open a web browser and go to http://localhost:8080/console
- this should open the Hasura console.
You will be prompted to log in with a Hasura administrator account. You can create an account by clicking on the "Create an account" button on the login page.
Once you log in, you can start creating your GraphQL API by adding tables and permissions to the Hasura engine.
Stop the Hasura stack.
To stop the Hasura stack, run the following command:
docker-compose down
This command will stop the PostgreSQL database and the Hasura GraphQL engine.
Congratulations! You have successfully installed and set up a Hasura server on your macOS.
If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!
Alternatively, for the best virtual desktop, try Shells!