DEV Community

Alex Spinov
Alex Spinov

Posted on

Hasura Has a Free API — Here's How to Get Instant GraphQL on Any Database

Why Hasura?

Hasura gives you an instant GraphQL API on top of your existing database. Point it at PostgreSQL, MySQL, SQL Server, or BigQuery — get a full GraphQL API with subscriptions, permissions, and remote joins in seconds.

Hasura Cloud free tier: 60 requests/minute, 1 GB data passthrough/month.

Getting Started

Option 1: Hasura Cloud (Free)

Sign up at hasura.io — launch a free project in 30 seconds.

Option 2: Docker

docker compose up -d
# docker-compose.yml:
# hasura/graphql-engine with HASURA_GRAPHQL_DATABASE_URL pointing to your PostgreSQL
Enter fullscreen mode Exit fullscreen mode

Connect Database & Get API

  1. Open Hasura Console (localhost:8080 or cloud URL)
  2. Connect your PostgreSQL
  3. Click "Track" on tables → instant GraphQL API!

Query Examples

GraphQL Queries

# Get all users with their orders
query {
  users(order_by: {created_at: desc}, limit: 10) {
    id
    name
    email
    orders(where: {status: {_eq: "paid"}}) {
      id
      total
      created_at
    }
  }
}

# Aggregate: total revenue per user
query {
  users {
    name
    orders_aggregate(where: {status: {_eq: "paid"}}) {
      aggregate {
        sum { total }
        count
      }
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Real-Time Subscriptions

# Live data — updates pushed automatically!
subscription {
  orders(where: {status: {_eq: "pending"}}, order_by: {created_at: desc}) {
    id
    total
    user {
      name
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

JavaScript Client

import { createClient } from "graphql-ws";
import { WebSocket } from "ws";

// REST-style query
const response = await fetch("https://your-project.hasura.app/v1/graphql", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "x-hasura-admin-secret": "YOUR_SECRET"
  },
  body: JSON.stringify({
    query: `{
      users(limit: 5) { id name email }
    }`
  })
});

const { data } = await response.json();
data.users.forEach(u => console.log(`${u.name} (${u.email})`));

// Real-time subscription
const wsClient = createClient({
  url: "wss://your-project.hasura.app/v1/graphql",
  webSocketImpl: WebSocket,
  connectionParams: { headers: { "x-hasura-admin-secret": "YOUR_SECRET" } }
});

const subscription = wsClient.iterate({
  query: `subscription { orders(where: {status: {_eq: "pending"}}) { id total } }`
});

for await (const event of subscription) {
  console.log("New order:", event.data.orders);
}
Enter fullscreen mode Exit fullscreen mode

Python Client

import requests

HASURA_URL = "https://your-project.hasura.app/v1/graphql"
HEADERS = {"x-hasura-admin-secret": "YOUR_SECRET", "Content-Type": "application/json"}

# Query
result = requests.post(HASURA_URL, json={
    "query": """
    {
      users(order_by: {created_at: desc}, limit: 10) {
        name
        email
        orders_aggregate {
          aggregate { sum { total } count }
        }
      }
    }
    """
}, headers=HEADERS)

for user in result.json()["data"]["users"]:
    agg = user["orders_aggregate"]["aggregate"]
    print(f"{user['name']}: {agg['count']} orders, ${agg['sum']['total'] or 0}")

# Mutation
result = requests.post(HASURA_URL, json={
    "query": """
    mutation($name: String!, $email: String!) {
      insert_users_one(object: {name: $name, email: $email}) { id name }
    }
    """,
    "variables": {"name": "Dave", "email": "dave@example.com"}
}, headers=HEADERS)
print(f"Created: {result.json()['data']['insert_users_one']}")
Enter fullscreen mode Exit fullscreen mode

Key Features

Feature Description
Instant API Track tables → get GraphQL
Subscriptions Real-time via WebSocket
Permissions Row-level security per role
Remote Joins Join across databases + REST APIs
Actions Custom business logic endpoints
Event Triggers Webhook on DB changes

Need data for your Hasura-powered app? I build production-ready scrapers. Check out my Apify actors or email spinov001@gmail.com for custom data pipelines.

Using Hasura? Share your setup below!

Top comments (0)