DEV Community

Alex Spinov
Alex Spinov

Posted on

Grafbase Has a Free API You've Never Heard Of

Grafbase is a serverless GraphQL backend that deploys to the edge. Define your schema, get a globally distributed GraphQL API with auth, caching, and real-time subscriptions — all on a generous free tier.

What Makes Grafbase Special?

  • Edge deployment — GraphQL API at 300+ PoPs globally
  • Free tier — 1M requests/month free
  • Serverless resolvers — custom logic in TypeScript
  • Built-in auth — JWT, API keys, OIDC
  • Edge caching — automatic response caching

The Hidden API: Edge GraphQL

# grafbase/schema.graphql
type Product @model {
  name: String!
  price: Float!
  description: String
  category: Category @relation
  reviews: [Review] @relation
  inStock: Boolean! @default(value: true)
  createdAt: DateTime! @default(value: "now()")
}

type Category @model {
  name: String! @unique
  products: [Product] @relation
}

type Review @model {
  rating: Int! @range(min: 1, max: 5)
  content: String!
  product: Product! @relation
  author: String!
}
Enter fullscreen mode Exit fullscreen mode

This auto-generates:

query {
  productCollection(first: 10, filter: { inStock: { eq: true } }, orderBy: { price: ASC }) {
    edges {
      node {
        id name price
        category { name }
        reviews(first: 5) { edges { node { rating content } } }
      }
    }
  }
}

mutation {
  productCreate(input: {
    name: "Widget Pro"
    price: 29.99
    category: { link: "cat_id" }
  }) {
    product { id name }
  }
}
Enter fullscreen mode Exit fullscreen mode

Serverless Resolvers

// grafbase/resolvers/featured-products.ts
export default async function Resolver(_, { limit }) {
  const response = await fetch('https://api.analytics.com/top-products');
  const trending = await response.json();
  return trending.slice(0, limit);
}
Enter fullscreen mode Exit fullscreen mode

Auth Configuration

// grafbase.config.ts
import { config, graph, auth } from '@grafbase/sdk';

export default config({
  graph: graph.Standalone(),
  auth: {
    rules: (rules) => {
      rules.private().filter(({ context }) => ({
        owner: { eq: context.identity?.sub }
      }));
      rules.public().read();
    },
    providers: [
      auth.JWT({ issuer: 'https://auth.example.com', secret: 'JWT_SECRET' })
    ]
  },
  cache: {
    rules: [{ maxAge: 60, types: ['Product'] }]
  }
});
Enter fullscreen mode Exit fullscreen mode

Quick Start

npx grafbase init
npx grafbase dev
# GraphQL playground at localhost:4000
Enter fullscreen mode Exit fullscreen mode

Why Teams Choose Grafbase

A frontend developer shared: "We replaced our Node.js + Apollo + Prisma stack with Grafbase. Our API latency dropped from 200ms to 15ms because it runs at the edge. And we deleted 3,000 lines of resolver code."


Building GraphQL APIs? Email spinov001@gmail.com or check my toolkit.

Edge GraphQL or traditional servers? What's your preference?

Top comments (0)