pg_graphql

Add in-database GraphQL support

Overview

PackageVersionCategoryLicenseLanguage
pg_graphql1.5.12FEATApache-2.0Rust
IDExtensionBinLibLoadCreateTrustRelocSchema
2750pg_graphqlNoYesNoYesNoNographql
Relatedage pg_jsonschema jsquery pg_net http pg_summarize pg_tiktoken wrappers

not an official release by Vonng

Version

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY1.5.121817161514pg_graphql-
RPMPIGSTY1.5.121817161514pg_graphql_$v-
DEBPIGSTY1.5.121817161514postgresql-$v-pg-graphql-
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
d12.x86_64
d12.aarch64
d13.x86_64
d13.aarch64
PIGSTY 1.5.12
PIGSTY 1.5.12
PIGSTY 1.5.12
PIGSTY 1.5.12
PIGSTY 1.5.12
u22.x86_64
PIGSTY 1.5.12
PIGSTY 1.5.12
PIGSTY 1.5.12
PIGSTY 1.5.12
PIGSTY 1.5.12
u22.aarch64
PIGSTY 1.5.12
PIGSTY 1.5.12
PIGSTY 1.5.12
PIGSTY 1.5.12
PIGSTY 1.5.12
u24.x86_64
PIGSTY 1.5.12
PIGSTY 1.5.12
PIGSTY 1.5.12
PIGSTY 1.5.12
PIGSTY 1.5.12
u24.aarch64
PIGSTY 1.5.12
PIGSTY 1.5.12
PIGSTY 1.5.12
PIGSTY 1.5.12
PIGSTY 1.5.12

Build

You can build the RPM / DEB packages for pg_graphql using pig build:

pig build pkg pg_graphql         # build RPM / DEB packages

Install

You can install pg_graphql directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:

pig repo add pgsql -u          # Add repo and update cache

Install the extension using pig or apt/yum/dnf:

pig install pg_graphql;          # Install for current active PG version
pig ext install -y pg_graphql -v 18  # PG 18
pig ext install -y pg_graphql -v 17  # PG 17
pig ext install -y pg_graphql -v 16  # PG 16
pig ext install -y pg_graphql -v 15  # PG 15
pig ext install -y pg_graphql -v 14  # PG 14
dnf install -y pg_graphql_18       # PG 18
dnf install -y pg_graphql_17       # PG 17
dnf install -y pg_graphql_16       # PG 16
dnf install -y pg_graphql_15       # PG 15
dnf install -y pg_graphql_14       # PG 14
apt install -y postgresql-18-pg-graphql   # PG 18
apt install -y postgresql-17-pg-graphql   # PG 17
apt install -y postgresql-16-pg-graphql   # PG 16
apt install -y postgresql-15-pg-graphql   # PG 15
apt install -y postgresql-14-pg-graphql   # PG 14

Create Extension:

CREATE EXTENSION pg_graphql;

Usage

pg_graphql: Add in-database GraphQL support

pg_graphql reflects a GraphQL schema from your existing SQL schema, enabling GraphQL queries directly inside PostgreSQL without additional servers or middleware.

Schema Reflection

Tables, foreign keys, and enums are automatically mapped to GraphQL types:

CREATE TABLE account (
    id serial PRIMARY KEY,
    email varchar(255) NOT NULL,
    created_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)
);

CREATE TYPE blog_post_status AS ENUM ('PENDING', 'RELEASED');

CREATE TABLE blog_post (
    id uuid NOT NULL DEFAULT gen_random_uuid() 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
);

This schema automatically generates GraphQL types (Account, Blog, BlogPost) with relationships derived from foreign keys.

Name Inflection

Enable automatic snake_case to camelCase/PascalCase conversion:

COMMENT ON SCHEMA public IS e'@graphql({"inflect_names": true})';

Querying

Execute a GraphQL query via the graphql.resolve function:

SELECT graphql.resolve($$
    {
      accountCollection(first: 1) {
        edges {
          node {
            id
            email
            blogCollection {
              edges {
                node {
                  name
                  blogPostCollection(filter: { status: { eq: RELEASED } }) {
                    edges {
                      node {
                        title
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }
$$);

Features

  • Table queries appear as pageable collections on the root Query type
  • Foreign key relationships create nested query fields automatically
  • Mutations support bulk insert, update, and delete
  • Filtering, ordering, and pagination are built in
  • PostgreSQL Row-Level Security (RLS) policies are respected

Last Modified 2026-03-12: add pg extension catalog (95749bf)