How to Install Hasura on macOS
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.
Prerequisites:
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-composeHasura CLI
You can install Hasura CLI by running the following command in the terminal:
brew install hasura-cli
Install Hasura
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-projectCreate a Docker Compose file.
Create a new file named
docker-compose.yamlin 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.yamlfile defines two services:postgresandgraphql-engine. Thepostgresservice provides a PostgreSQL database that Hasura will use, and thegraphql-engineservice provides the Hasura GraphQL engine.Note that the
HASURA_GRAPHQL_DATABASE_URLenvironment variable in thegraphql-engineservice is set to connect to thepostgresservice's database.Start the Hasura stack.
Run the following command in the terminal to start the Hasura stack:
docker-compose up -dThis 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 downThis 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.