pg_graphql
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_graphql | 1.5.12 | FEAT | Apache-2.0 | Rust |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 2750 | pg_graphql | No | Yes | No | Yes | No | No | graphql |
| Related | age pg_jsonschema jsquery pg_net http pg_summarize pg_tiktoken wrappers |
|---|
not an official release by Vonng
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 1.5.12 | 1817161514 | pg_graphql | - |
| RPM | PIGSTY | 1.5.12 | 1817161514 | pg_graphql_$v | - |
| DEB | PIGSTY | 1.5.12 | 1817161514 | postgresql-$v-pg-graphql | - |
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 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
Querytype - 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
Feedback
Was this page helpful?
Thanks for the feedback! Please let us know how we can improve.
Sorry to hear that. Please let us know how we can improve.