Skip to content

pg_graphql

PostgreSQL version License Tests


Documentation: https://supabase.github.io/pg_graphql

Source Code: https://github.com/supabase/pg_graphql


Query your existing PostgreSQL database with GraphQL

pg_graphql inspects your PostgreSQL schema and reflects a GraphQL schema with resolvers.

  • Performant: +2k requests/second
  • Always up-to-date: Reflected from the SQL schema
  • Pagination: Relay compliant
  • Serverless: Runs in your database with no additional server required
  • Open Source: Apache License 2.0

Warning

pg_graphql is pre-alpha software under active development

Motivation

pg_graphql provides an SQL schema -> GraphQL schema reflection engine and an associated GraphQL query -> SQL query transpiler.

The extension keeps schema generation, query parsing, and resolvers all neatly contained on your database. This enables any programming language that can connect to PostgreSQL to query the database via GraphQL with no additional servers, processes, or libraries.

TL;DR

The SQL schema

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
create table account(
    id serial primary key,
    email varchar(255) not null,
    encrypted_password varchar(255) not null,
    created_at timestamp not null,
    updated_at timestamp not null
);

create table blog(
    id serial primary key,
    owner_id integer not null references account(id),
    name varchar(255) not null,
    description varchar(255),
    created_at timestamp not null,
    updated_at timestamp not null
);

create type blog_post_status as enum ('PENDING', 'RELEASED');

create table blog_post(
    id uuid not null default uuid_generate_v4() primary key,
    blog_id integer not null references blog(id),
    title varchar(255) not null,
    body varchar(10000),
    status blog_post_status not null,
    created_at timestamp not null,
    updated_at timestamp not null
);
Translates into a GraphQL schema exposing each table as a pageable collection with relationships defined by the foreign keys. GraphiQL