Connect Supabase to Hasura with this step-by-step guide. Learn to set up Supabase, retrieve credentials, install Hasura CLI, deploy via Docker, and verify your GraphQL connection.
Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
Step 1: Set Up Supabase
Supabase is a backend-as-a-service platform that employs PostgreSQL for its database management. Begin by visiting the Supabase website and creating an account. Once logged in, create a new project:
Once the project is set up, you will get access to your project’s API details. These will be essential when connecting to Hasura.
Step 2: Access Supabase Database Credentials
To connect Supabase to Hasura, you need the database credentials. You can find these credentials in the Supabase dashboard:
postgres://username:password@host:port/database
.Take note of the username, password, host, port, and database name as you will need these to connect Supabase with Hasura.
Step 3: Install Hasura CLI
Hasura can be integrated with Supabase through its GraphQL API. First, you need to set up Hasura. Begin by installing the Hasura CLI on your system:
npm install --global hasura-cli
After installation, verify the installation by checking the version:
hasura version
Ensure you get an output showing the current version of the installed Hasura CLI.
Step 4: Deploy Hasura using Docker
Setting up Hasura usually involves using Docker, as it provides a straightforward setup process:
docker-compose.yml
file to configure Hasura with PostgreSQL. Insert the following content, replacing placeholders with your Supabase database details:
version: '3.6'
services:
postgres:
image: 'postgis/postgis:13-3.1'
restart: always
environment:
POSTGRES\_PASSWORD: your-supabase-db-password
POSTGRES\_USER: your-supabase-db-username
POSTGRES\_DB: your-supabase-db-name
ports:
- '5432:5432'
graphql-engine:
image: hasura/graphql-engine:v2.0.0
ports:
- '8080:8080'
depends\_on:
- 'postgres'
restart: always
environment:
HASURA_GRAPHQL_DATABASE\_URL: 'postgres://your-supabase-db-username:your-supabase-db-password@your-supabase-db-host:your-supabase-db-port/your-supabase-db-name'
HASURA_GRAPHQL_ENABLE\_CONSOLE: 'true'
HASURA_GRAPHQL_ADMIN\_SECRET: your-hasura-secret-key
To deploy, run:
docker-compose up -d
This command will start Hasura and connect it to your Supabase PostgreSQL instance.
Step 5: Access the Hasura Console
Once the containers are running, access the Hasura console to explore data and manage your schema:
http://localhost:8080
your-hasura-secret-key
).The Hasura console will now be connected to your Supabase database, allowing you to interact with your data via GraphQL.
Step 6: Verify Connection and Manage Data
After setting up, it’s crucial to verify the connection with Supabase and explore Hasura’s features such as creating tables, managing permissions, and writing GraphQL queries:
To check if your tables have been successfully replicated:
Now you can manage your database schema, set permissions, and write complex GraphQL queries directly within the Hasura console.
This step-by-step process helps you seamlessly connect Supabase with Hasura, leveraging the power of GraphQL to manage and streamline your backend operations.
When it comes to serving you, we sweat the little things. That’s why our work makes a big impact.