Setup Hasura
Make sure the Hasura CLI is installed
Download the Hasura Docker compose file to the project root
Modify the graphql-engine service to point to our own Dockerfile
graphql-engine:build:context: ./hasuradockerfile: ./Dockerfileports:- "8080:8080"depends_on:- "postgres"restart: alwaysenv_file:- ./hasura/.envRun the command
hasura init hasura --admin-secret <the string you created in .env>
Create
./hasura/Dockerfile
with the auto applying migrations imageFROM hasura/graphql-engine:v2.2.0.cli-migrations-v3COPY ./metadata /hasura-metadataCOPY ./migrations /hasura-migrationsCreate
./hasura/.env
HASURA_GRAPHQL_METADATA_DATABASE_URL="postgres://postgres:postgrespassword@postgres:5432/postgres"PG_DATABASE_URL="postgres://postgres:postgrespassword@postgres:5432/postgres"HASURA_GRAPHQL_ENABLE_CONSOLE=falseHASURA_GRAPHQL_DEV_MODE=trueHASURA_GRAPHQL_ENABLED_LOG_TYPES="startup, http-log, webhook-log, websocket-log, query-log"HASURA_GRAPHQL_ADMIN_SECRET="<Your admin secret you made in .env>"HASURA_GRAPHQL_JWT_SECRET=<Hasura JWT secret config>HASURA_GRAPHQL_UNAUTHORIZED_ROLE="anonymous"Startup Hasura
docker compose up -d --build
remember to rundocker compose down
when you want to stop it.Start the Hasura console
hasura console --project hasura --admin-secret <Your admin secret from .env>
Click the data tab and connect database. Name will be
default
and we connect via the environment variablePG_DATABASE_URL
- Build apps and APIs 10x faster
- Built-in authorization and caching
- 8x more performant than hand-rolled APIs