跳转到主要内容

pg_graphql

PG内的GraphQL支持

pg_graphql · PG内的GraphQL支持

概览

ID扩展软件包版本类别许可证编程语言
2740pg_graphqlpg_graphql1.6.3FEATApache-2.0Rust
属性可执行文件动态库需要预加载需要建扩展可迁移可信
--s-d--否是否是否否
1.6.3 fixes quoted primary keys in nodeId.

软件包

类型仓库版本兼容的 PostgreSQL 大版本包名模式依赖
EXTPIGSTY1.6.319 18 17 16 15pg_graphql-
RPMPIGSTY1.6.319 18 17 16 15pg_graphql_$v-
DEBPIGSTY1.6.319 18 17 16 15postgresql-$v-pg-graphql-
Linux / PGPG19PG18PG17PG16PG15
el8.x86_64N/APIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3
el8.aarch64N/APIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3
el9.x86_64PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3
el9.aarch64PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3
el10.x86_64PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3
el10.aarch64PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3
d12.x86_64PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3
d12.aarch64PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3
d13.x86_64PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3
d13.aarch64PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3
u22.x86_64PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3
u22.aarch64PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3
u24.x86_64PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3
u24.aarch64PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3
u26.x86_64PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3
u26.aarch64PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3PIGSTY 1.6.3
软件包版本平台仓库大小下载
pg_graphql_191.6.3el9.x86_64pigsty894.4 KiBpg_graphql_19-1.6.3-2PGSTY.el9.x86_64.rpm
pg_graphql_191.6.3el9.aarch64pigsty853.9 KiBpg_graphql_19-1.6.3-2PGSTY.el9.aarch64.rpm
pg_graphql_191.6.3el10.x86_64pigsty895.2 KiBpg_graphql_19-1.6.3-2PGSTY.el10.x86_64.rpm
pg_graphql_191.6.3el10.aarch64pigsty854.0 KiBpg_graphql_19-1.6.3-2PGSTY.el10.aarch64.rpm
postgresql-19-pg-graphql1.6.3d12.x86_64pigsty659.9 KiBpostgresql-19-pg-graphql_1.6.3-2PGSTY~bookworm_amd64.deb
postgresql-19-pg-graphql1.6.3d12.aarch64pigsty566.5 KiBpostgresql-19-pg-graphql_1.6.3-2PGSTY~bookworm_arm64.deb
postgresql-19-pg-graphql1.6.3d13.x86_64pigsty660.1 KiBpostgresql-19-pg-graphql_1.6.3-2PGSTY~trixie_amd64.deb
postgresql-19-pg-graphql1.6.3d13.aarch64pigsty567.0 KiBpostgresql-19-pg-graphql_1.6.3-2PGSTY~trixie_arm64.deb
postgresql-19-pg-graphql1.6.3u22.x86_64pigsty715.3 KiBpostgresql-19-pg-graphql_1.6.3-2PGSTY~jammy_amd64.deb
postgresql-19-pg-graphql1.6.3u22.aarch64pigsty662.6 KiBpostgresql-19-pg-graphql_1.6.3-2PGSTY~jammy_arm64.deb
postgresql-19-pg-graphql1.6.3u24.x86_64pigsty710.2 KiBpostgresql-19-pg-graphql_1.6.3-2PGSTY~noble_amd64.deb
postgresql-19-pg-graphql1.6.3u24.aarch64pigsty656.9 KiBpostgresql-19-pg-graphql_1.6.3-2PGSTY~noble_arm64.deb
postgresql-19-pg-graphql1.6.3u26.x86_64pigsty709.2 KiBpostgresql-19-pg-graphql_1.6.3-2PGSTY~resolute_amd64.deb
postgresql-19-pg-graphql1.6.3u26.aarch64pigsty655.5 KiBpostgresql-19-pg-graphql_1.6.3-2PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_graphql_181.6.3el8.x86_64pigsty752.9 KiBpg_graphql_18-1.6.3-1PGSTY.el8.x86_64.rpm
pg_graphql_181.6.3el8.aarch64pigsty644.4 KiBpg_graphql_18-1.6.3-1PGSTY.el8.aarch64.rpm
pg_graphql_181.6.3el9.x86_64pigsty889.8 KiBpg_graphql_18-1.6.3-2PGSTY.el9.x86_64.rpm
pg_graphql_181.6.3el9.aarch64pigsty847.1 KiBpg_graphql_18-1.6.3-2PGSTY.el9.aarch64.rpm
pg_graphql_181.6.3el10.x86_64pigsty890.3 KiBpg_graphql_18-1.6.3-2PGSTY.el10.x86_64.rpm
pg_graphql_181.6.3el10.aarch64pigsty847.6 KiBpg_graphql_18-1.6.3-2PGSTY.el10.aarch64.rpm
postgresql-18-pg-graphql1.6.3d12.x86_64pigsty657.2 KiBpostgresql-18-pg-graphql_1.6.3-2PGSTY~bookworm_amd64.deb
postgresql-18-pg-graphql1.6.3d12.aarch64pigsty563.0 KiBpostgresql-18-pg-graphql_1.6.3-2PGSTY~bookworm_arm64.deb
postgresql-18-pg-graphql1.6.3d13.x86_64pigsty657.2 KiBpostgresql-18-pg-graphql_1.6.3-2PGSTY~trixie_amd64.deb
postgresql-18-pg-graphql1.6.3d13.aarch64pigsty563.3 KiBpostgresql-18-pg-graphql_1.6.3-2PGSTY~trixie_arm64.deb
postgresql-18-pg-graphql1.6.3u22.x86_64pigsty712.5 KiBpostgresql-18-pg-graphql_1.6.3-2PGSTY~jammy_amd64.deb
postgresql-18-pg-graphql1.6.3u22.aarch64pigsty660.3 KiBpostgresql-18-pg-graphql_1.6.3-2PGSTY~jammy_arm64.deb
postgresql-18-pg-graphql1.6.3u24.x86_64pigsty707.1 KiBpostgresql-18-pg-graphql_1.6.3-2PGSTY~noble_amd64.deb
postgresql-18-pg-graphql1.6.3u24.aarch64pigsty654.0 KiBpostgresql-18-pg-graphql_1.6.3-2PGSTY~noble_arm64.deb
postgresql-18-pg-graphql1.6.3u26.x86_64pigsty706.1 KiBpostgresql-18-pg-graphql_1.6.3-2PGSTY~resolute_amd64.deb
postgresql-18-pg-graphql1.6.3u26.aarch64pigsty653.1 KiBpostgresql-18-pg-graphql_1.6.3-2PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_graphql_171.6.3el8.x86_64pigsty752.9 KiBpg_graphql_17-1.6.3-1PGSTY.el8.x86_64.rpm
pg_graphql_171.6.3el8.aarch64pigsty644.1 KiBpg_graphql_17-1.6.3-1PGSTY.el8.aarch64.rpm
pg_graphql_171.6.3el9.x86_64pigsty886.1 KiBpg_graphql_17-1.6.3-2PGSTY.el9.x86_64.rpm
pg_graphql_171.6.3el9.aarch64pigsty843.6 KiBpg_graphql_17-1.6.3-2PGSTY.el9.aarch64.rpm
pg_graphql_171.6.3el10.x86_64pigsty886.5 KiBpg_graphql_17-1.6.3-2PGSTY.el10.x86_64.rpm
pg_graphql_171.6.3el10.aarch64pigsty843.8 KiBpg_graphql_17-1.6.3-2PGSTY.el10.aarch64.rpm
postgresql-17-pg-graphql1.6.3d12.x86_64pigsty654.6 KiBpostgresql-17-pg-graphql_1.6.3-2PGSTY~bookworm_amd64.deb
postgresql-17-pg-graphql1.6.3d12.aarch64pigsty561.3 KiBpostgresql-17-pg-graphql_1.6.3-2PGSTY~bookworm_arm64.deb
postgresql-17-pg-graphql1.6.3d13.x86_64pigsty655.0 KiBpostgresql-17-pg-graphql_1.6.3-2PGSTY~trixie_amd64.deb
postgresql-17-pg-graphql1.6.3d13.aarch64pigsty561.3 KiBpostgresql-17-pg-graphql_1.6.3-2PGSTY~trixie_arm64.deb
postgresql-17-pg-graphql1.6.3u22.x86_64pigsty709.3 KiBpostgresql-17-pg-graphql_1.6.3-2PGSTY~jammy_amd64.deb
postgresql-17-pg-graphql1.6.3u22.aarch64pigsty658.4 KiBpostgresql-17-pg-graphql_1.6.3-2PGSTY~jammy_arm64.deb
postgresql-17-pg-graphql1.6.3u24.x86_64pigsty704.6 KiBpostgresql-17-pg-graphql_1.6.3-2PGSTY~noble_amd64.deb
postgresql-17-pg-graphql1.6.3u24.aarch64pigsty651.7 KiBpostgresql-17-pg-graphql_1.6.3-2PGSTY~noble_arm64.deb
postgresql-17-pg-graphql1.6.3u26.x86_64pigsty703.8 KiBpostgresql-17-pg-graphql_1.6.3-2PGSTY~resolute_amd64.deb
postgresql-17-pg-graphql1.6.3u26.aarch64pigsty650.8 KiBpostgresql-17-pg-graphql_1.6.3-2PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_graphql_161.6.3el8.x86_64pigsty752.9 KiBpg_graphql_16-1.6.3-1PGSTY.el8.x86_64.rpm
pg_graphql_161.6.3el8.aarch64pigsty644.2 KiBpg_graphql_16-1.6.3-1PGSTY.el8.aarch64.rpm
pg_graphql_161.6.3el9.x86_64pigsty883.9 KiBpg_graphql_16-1.6.3-2PGSTY.el9.x86_64.rpm
pg_graphql_161.6.3el9.aarch64pigsty841.6 KiBpg_graphql_16-1.6.3-2PGSTY.el9.aarch64.rpm
pg_graphql_161.6.3el10.x86_64pigsty883.5 KiBpg_graphql_16-1.6.3-2PGSTY.el10.x86_64.rpm
pg_graphql_161.6.3el10.aarch64pigsty842.4 KiBpg_graphql_16-1.6.3-2PGSTY.el10.aarch64.rpm
postgresql-16-pg-graphql1.6.3d12.x86_64pigsty653.6 KiBpostgresql-16-pg-graphql_1.6.3-2PGSTY~bookworm_amd64.deb
postgresql-16-pg-graphql1.6.3d12.aarch64pigsty560.4 KiBpostgresql-16-pg-graphql_1.6.3-2PGSTY~bookworm_arm64.deb
postgresql-16-pg-graphql1.6.3d13.x86_64pigsty654.1 KiBpostgresql-16-pg-graphql_1.6.3-2PGSTY~trixie_amd64.deb
postgresql-16-pg-graphql1.6.3d13.aarch64pigsty560.7 KiBpostgresql-16-pg-graphql_1.6.3-2PGSTY~trixie_arm64.deb
postgresql-16-pg-graphql1.6.3u22.x86_64pigsty708.3 KiBpostgresql-16-pg-graphql_1.6.3-2PGSTY~jammy_amd64.deb
postgresql-16-pg-graphql1.6.3u22.aarch64pigsty656.7 KiBpostgresql-16-pg-graphql_1.6.3-2PGSTY~jammy_arm64.deb
postgresql-16-pg-graphql1.6.3u24.x86_64pigsty703.2 KiBpostgresql-16-pg-graphql_1.6.3-2PGSTY~noble_amd64.deb
postgresql-16-pg-graphql1.6.3u24.aarch64pigsty650.4 KiBpostgresql-16-pg-graphql_1.6.3-2PGSTY~noble_arm64.deb
postgresql-16-pg-graphql1.6.3u26.x86_64pigsty702.3 KiBpostgresql-16-pg-graphql_1.6.3-2PGSTY~resolute_amd64.deb
postgresql-16-pg-graphql1.6.3u26.aarch64pigsty649.8 KiBpostgresql-16-pg-graphql_1.6.3-2PGSTY~resolute_arm64.deb
软件包版本平台仓库大小下载
pg_graphql_151.6.3el8.x86_64pigsty752.9 KiBpg_graphql_15-1.6.3-1PGSTY.el8.x86_64.rpm
pg_graphql_151.6.3el8.aarch64pigsty644.2 KiBpg_graphql_15-1.6.3-1PGSTY.el8.aarch64.rpm
pg_graphql_151.6.3el9.x86_64pigsty878.7 KiBpg_graphql_15-1.6.3-2PGSTY.el9.x86_64.rpm
pg_graphql_151.6.3el9.aarch64pigsty830.4 KiBpg_graphql_15-1.6.3-2PGSTY.el9.aarch64.rpm
pg_graphql_151.6.3el10.x86_64pigsty878.6 KiBpg_graphql_15-1.6.3-2PGSTY.el10.x86_64.rpm
pg_graphql_151.6.3el10.aarch64pigsty831.5 KiBpg_graphql_15-1.6.3-2PGSTY.el10.aarch64.rpm
postgresql-15-pg-graphql1.6.3d12.x86_64pigsty650.8 KiBpostgresql-15-pg-graphql_1.6.3-2PGSTY~bookworm_amd64.deb
postgresql-15-pg-graphql1.6.3d12.aarch64pigsty557.8 KiBpostgresql-15-pg-graphql_1.6.3-2PGSTY~bookworm_arm64.deb
postgresql-15-pg-graphql1.6.3d13.x86_64pigsty650.8 KiBpostgresql-15-pg-graphql_1.6.3-2PGSTY~trixie_amd64.deb
postgresql-15-pg-graphql1.6.3d13.aarch64pigsty558.1 KiBpostgresql-15-pg-graphql_1.6.3-2PGSTY~trixie_arm64.deb
postgresql-15-pg-graphql1.6.3u22.x86_64pigsty704.7 KiBpostgresql-15-pg-graphql_1.6.3-2PGSTY~jammy_amd64.deb
postgresql-15-pg-graphql1.6.3u22.aarch64pigsty653.5 KiBpostgresql-15-pg-graphql_1.6.3-2PGSTY~jammy_arm64.deb
postgresql-15-pg-graphql1.6.3u24.x86_64pigsty699.2 KiBpostgresql-15-pg-graphql_1.6.3-2PGSTY~noble_amd64.deb
postgresql-15-pg-graphql1.6.3u24.aarch64pigsty647.3 KiBpostgresql-15-pg-graphql_1.6.3-2PGSTY~noble_arm64.deb
postgresql-15-pg-graphql1.6.3u26.x86_64pigsty698.7 KiBpostgresql-15-pg-graphql_1.6.3-2PGSTY~resolute_amd64.deb
postgresql-15-pg-graphql1.6.3u26.aarch64pigsty646.2 KiBpostgresql-15-pg-graphql_1.6.3-2PGSTY~resolute_arm64.deb

源码

pig build pkg pg_graphql;		# build rpm/deb

安装

启用 PGDG 和 PIGSTY 仓库并更新缓存。

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

使用 pig 安装扩展。

pig install pg_graphql;		# install by package name

pig install pg_graphql -v 19;   # install for PG 19
pig install pg_graphql -v 18;   # install for PG 18
pig install pg_graphql -v 17;   # install for PG 17
pig install pg_graphql -v 16;   # install for PG 16
pig install pg_graphql -v 15;   # install for PG 15

在数据库中创建扩展。

CREATE EXTENSION pg_graphql;

用法

来源:README、documentation、v1.6.1 release

pg_graphql 从现有的 SQL 模式反射生成 GraphQL 模式,无需额外的服务器或中间件即可直接在 PostgreSQL 内部执行 GraphQL 查询。

模式反射

表、外键和枚举类型会自动映射为 GraphQL 类型:

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
);

此模式会自动生成 GraphQL 类型(Account、Blog、BlogPost),关系由外键推导而来。

命名转换

启用 snake_case 到 camelCase/PascalCase 的自动转换:

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

查询

通过 graphql.resolve 函数执行 GraphQL 查询:

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

功能特性

  • 表查询以可分页集合的形式出现在根 Query 类型上
  • 外键关系自动创建嵌套查询字段
  • 变更操作支持批量插入、更新和删除
  • 内置过滤、排序和分页功能
  • 遵守 PostgreSQL 行级安全(RLS)策略

版本说明

pg_graphql 1.6.1 修复 byPk argument types 中重复 NON_NULL wrapping 导致 GraphiQL introspection 失败的问题,修复 introspection/data 混合查询错误返回 partial results 的问题,并更新 introspection opt-in notice 相关文档。

表格阅读器