Introducing the Grafbase Postgres Connector

Introducing the Grafbase Postgres Connector


Postgres is one of the most popular databases available and underpins several new database providers, such as Supabase, Neon, and Railway. Therefore, it has always been a must on our list of Grafbase connectors.

Today, we’re pleased to announce we’re releasing and open-sourcing our Grafbase Postgres connector. This connector will allow developers to seamlessly integrate their Postgres databases with Grafbase and instantly serve data at the edge to all their users.

Here are some of the features of the Grafbase Postgres connector we’re most excited about.

It’s not feasible to have terabytes of data globally replicated. But you don’t need to with edge-deployed serverless APIs. Once connected, Grafbase will maintain a connection pool to your database to dramatically speed up queries. Handshakes and authentication only have to happen the first time. Once the connection is created, it will be used across all queries coming into your database, reducing query times to under 100 milliseconds from anywhere globally.

For your most common or extensive queries, Grafbase employs edge caching to reduce response times even further, down to 15-20 milliseconds. With edge caching, your results really do live at the edge and are available to your users almost instantly.

This is all handled within Grafbase. You don’t need any extra services or costs. Just deploy a new Grafbase project, and then your data will be cached at the edge.

import { config, connector, graph } from '@grafbase/sdk' const g = graph.Standalone() const pg = connector.Postgres('pg', { url: g.env('DATABASE_URL'), }) g.datasource(pg) export default config({ graph: g, cache: { rules: [ { types: ['Query'], maxAge: 60, staleWhileRevalidate: 60, }, ], }, })

With our previous connectors, such as MongoDB, once Grafbase was connected developers still had to define their models in the schema from their collections.

With the Postgres connector, Grafbase introspects the schema for you from your models and automatically generates the correct queries and mutations. You connect the Grafbase Postgres connector and get schemas for free.

These are all fully customizable. You can extend queries how you need or transform mutations how you see fit. Or you can just keep the critical queries and mutations and delete the rest. But from connection, you have an instant GraphQL API ready to use with your data.

The Grafbase Postgres connector takes advantage of best practices within Postgres development, such as:

  • Optimized queries: Every query created by the Grafbase Postgres connector is highly optimized. We generate exactly one SQL query even for complex selections, and we do not waste time doing multiple round-trips when joining data from multiple tables.
  • Connection Pooling: The Grafbase Postgres connector provides connection pooling, bringing you super-fast response times at the edge. This allows you to have faster and more consistent connections, scale your connections, and reduce resource consumption on your backend. By efficiently managing the connections, the system can handle a higher volume of concurrent users, making it suitable for more extensive and demanding applications.
  • Branching. For Postgres providers that support branching, Grafbase has this built-in and integrates seamlessly via environment variables. This helps with development, isolation, testing, schema changes, and rollbacks. Incorporating database branching in the workflow streamlines the development process, enabling developers to work on multiple features or datasets simultaneously without conflicts.

You can use the Grafbase Postgres connector in your local developer environment and control the entire process via CLI. Connect to Postgres, then, when ready, you can push it to GitHub or deploy via the CLI to the edge.

No YAML files, no Docker image. It's just a 5MB native Rust binary with no dependencies. Just point it to Postgres, and it works.

Just as we open-sourced both the Grafbase Engine and our Pathfinder IDE, we’re also opening this connector to the community for improvements, fixes, and other functionality. We want developers to be able to use this connector, as well as our other Grafbase connectors, however they need and to build on top of them to support their workflows. We’re working internally to ensure the Grafbase Postgres connector supports all Postgres providers and cutting-edge functionality.

The next connector on our roadmap is the Grafbase MySQL connector. As the most popular database out there, it is essential we allow Grafbase users to connect MySQL to GraphQL APIs at the edge. If you are a MySQL developer, chat with us on our Discord about what you’d like to see with this connector.

But if you are using Postgres, get started with the Grafbase Postgres connector today.

Get Started

Build your API of the future now.