惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

J
Java Code Geeks
博客园 - 司徒正美
博客园 - 【当耐特】
爱范儿
爱范儿
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
IT之家
IT之家
人人都是产品经理
人人都是产品经理
雷峰网
雷峰网
酷 壳 – CoolShell
酷 壳 – CoolShell
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
大猫的无限游戏
大猫的无限游戏
月光博客
月光博客
宝玉的分享
宝玉的分享
V
V2EX
S
SegmentFault 最新的问题
V
Visual Studio Blog
阮一峰的网络日志
阮一峰的网络日志
Martin Fowler
Martin Fowler
Jina AI
Jina AI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园_首页
L
LangChain Blog
D
Docker
腾讯CDC

Supabase Blog

AI Agents Know About Supabase. They Don't Always Use It Right. Custom OIDC Providers for Supabase Auth 100,000 GitHub stars Supabase docs over SSH Navigating Regional Network Blocks Supabase Joins the Stripe Projects Developer Preview Log Drains: Now available on Pro Supabase Storage: major performance, security, and reliability updates Supabase incident on February 12, 2026 Hydra joins Supabase X / Twitter OAuth 2.0 is now available for Supabase Auth BKND joins Supabase Supabase is now an official Claude connector Supabase PrivateLink is now available Introducing: Postgres Best Practices When to use Read Replicas vs. bigger compute Introducing TRAE SOLO integration with Supabase Supabase Security Retro: 2025 Sync Stripe Data to Your Supabase Database in One Click Building ChatGPT Apps with Supabase Edge Functions and mcp-use Own Your Observability: Supabase Metrics API Introducing iceberg-js: A JavaScript Client for Apache Iceberg Introducing Supabase for Platforms Adding Async Streaming to Postgres Foreign Data Wrappers Build "Sign in with Your App" using Supabase Auth Introducing Seven New Email Templates for Supabase Auth The new Supabase power for Kiro Introducing Supabase ETL Introducing Analytics Buckets Introducing Vector Buckets
pg_graphql 1.5.7: pagination and multi-tenancy support
Oliver Rice · 2024-08-15 · via Supabase Blog

pg_graphql 1.5.7: pagination and multi-tenancy support

Since our last check-in on pg_graphql there have been a few quality of life improvements worth calling out. A quick roundup of the key differences includes:

  • Pagination via First/Offset
  • Schema based multi-tenancy
  • Filtering on array typed columns with contains, containedBy and overlaps

Since the earliest days of pg_graphql, keyset pagination has been supported. Keyset pagination allows for paging forwards and backwards through a collection by specifying a number of records and the unique id of a record within the collection. For example:


_10

{

_10

blogCollection(

_10

first: 2,

_10

after: "Y3Vyc29yMQ=="

_10

) {

_10

...

_10

}


to retrieve the first 2 records after the record with unique id Y3Vyc29yMQ== .

Starting in version 1.5.0 there is support for offset based pagination, which is based on skipping offset number of records before returning the results.


_10

{

_10

blogCollection(

_10

first: 2,

_10

offset: 5

_10

) {

_10

...

_10

}


That is roughly equivalent to the SQL


_10

select

_10

*

_10

from

_10

blog

_10

limit

_10

2

_10

offset

_10

5


In general as offset values increase, the performance of the query will decrease. For that reason its important to use keyset pagination where possible.

pg_graphql caches the database schema on first query and rebuilds that cache any time the schema changes. The cache key is a combination of the postgres role and the database schema's version number. Initially, the structure of all schemas was loaded for all roles, and table/column visibility was filtered down within pg_graphql.

In multi-tenant environments with 1 schema per tenant, that meant every time a tenant updated their schema, all tenants had to rebuild the cache. When the number of tenants gets large, that burdens the database if its under heavy load.

Following version 1.5.2 each tenant's cache only loads the schemas that they have usage permission for, which greatly reduces the query time in multi-tenant environments and the size of the schema cache. At time of writing this solution powers a project with >2200 tenants.

From 1.5.6 pg_graphql has added contains, containedBy, overlaps filter operators for scalar array fields like text[] or int[].

For example, given a table


_10

create table blog (

_10

id int primary key,

_10

name text not null,

_10

tags text[] not null,

_10

created_at timestamp not null

_10

);


the tags column with type text[] can be filtered on.


_12

{

_12

blogCollection(filter: { tags: { contains: ["tech", "innovation"] } }) {

_12

edges {

_12

cursor

_12

node {

_12

name

_12

tags

_12

createdAt

_12

}

_12

}

_12

}

_12

}


In this case, the result set is filtered to records where the tags column contains both tech and innovation.

The headline features we aim to launch in coming releases of pg_graphql include support for:

  • Insert on conflict / Upsert
  • Nested inserts

If you want to get started with GraphQL today, check out the Docs or the source code.