Setup Hasura

githubdocker-compose.yml

Make sure the Hasura CLI is installed

  1. Download the Hasura Docker compose file to the project root

  2. Modify the graphql-engine service to point to our own Dockerfile

    graphql-engine:
    build:
    context: ./hasura
    dockerfile: ./Dockerfile
    ports:
    - "8080:8080"
    depends_on:
    - "postgres"
    restart: always
    env_file:
    - ./hasura/.env
  3. Run the command hasura init hasura --admin-secret <the string you created in .env>

githubDockerfile
  1. Create ./hasura/Dockerfile with the auto applying migrations image

    FROM hasura/graphql-engine:v2.2.0.cli-migrations-v3
    COPY ./metadata /hasura-metadata
    COPY ./migrations /hasura-migrations
  2. Create ./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=false
    HASURA_GRAPHQL_DEV_MODE=true
    HASURA_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"
  3. Startup Hasura docker compose up -d --build remember to run docker compose down when you want to stop it.

  4. Start the Hasura console hasura console --project hasura --admin-secret <Your admin secret from .env>

  5. Click the data tab and connect database. Name will be default and we connect via the environment variable PG_DATABASE_URL

Did you find this page helpful?
Start with GraphQL on Hasura for Free
  • ArrowBuild apps and APIs 10x faster
  • ArrowBuilt-in authorization and caching
  • Arrow8x more performant than hand-rolled APIs
Promo
footer illustration
Brand logo
© 2024 Hasura Inc. All rights reserved
Github
Titter
Discord
Facebook
Instagram
Youtube
Linkedin
graphql-handbook