pg_graphql v1.0
pg_graphql, a PostgreSQL extension that compiles GraphQL requests into a single SQL query, reaches 1.0 with a SemVer backwards-compatibility guarantee. Running inside Postgres instead of as a separate server keeps its memory footprint negligible on 1 GB Free Plan instances. That design also gives it Postgres roles and RLS for security, an always-in-sync schema with no N+1 queries, and ACID rollback across multi-mutation requests. The original pure-SQL transpiler hit limits near 4,000 lines because SQL functions pass by value and the planner stops inlining deeply nested calls, so it was rewritten in Rust with pgx. After the rewrite, overhead is under 300µs per request, about 1,060 queries/sec per connection from SQL, and about 645 req/s through the full HTTP and auth stack on Free Plan hardware.
Related posts
- pg_graphql: A GraphQL extension for PostgreSQL
Supabase mediumAdeptpg_graphql is an open-source PostgreSQL extension, written in C and SQL, that reflects a GraphQL schema from existing tables and resolves queries entirely inside the database. Supabase built it because its 1 GB free-tier VMs had no memory left for a separate GraphQL process like Graphile or Hasura. Each GraphQL request is transpiled into a single SQL statement that aggregates results as JSON. This avoids N+1 queries, respects row level security, and gives multi-operation requests transactional semantics. Pagination follows the Relay connection spec using keyset pagination, the API is one SQL function (gql.resolve) exposed over HTTP via PostgREST, and a benchmark shows about 2,205 requests/second on a 4-core machine.
- How pg_graphql works
Supabase mediumAdeptpg_graphql is a Rust-based Postgres extension that reflects the SQL schema as a GraphQL schema and serves queries through a `graphql.resolve` SQL function, with no separate server. A request is tokenized and parsed into an AST with the graphql-parser crate, then validated against the GraphQL spec using a reflected schema built from system catalogs. That schema is memoized and reloaded only when the search path, role or schema version changes. Validated queries become builder objects that emit SQL, with quote_ident/quote_literal guarding against injection, and the SQL returns jsonb that is passed back to the client as JSON.
- GraphQL is now available in Supabase
Supabase mediumAdeptSupabase has made GraphQL generally available through pg_graphql, an open source PostgreSQL extension that reflects tables, columns and foreign keys into GraphQL types, fields and relations, queryable from SQL or over HTTP. Authorization is handled by Postgres itself: exposed types and introspection are filtered by the JWT's SQL role, and row level security applies automatically. Performance comes from transpiling every GraphQL query into exactly one SQL query, which avoids N+1 problems and duplicated join data, plus caching transpiled queries as prepared statements and making all operations bulk. On Free Plan hardware this yields about 377 requests/s via the API and 656 queries/s via SQL, and a HackerNews clone built with The Guild demonstrates the stack.
- pg_graphql: Postgres functions now supported
Supabase mediumAdeptpg_graphql 1.4+ reflects Postgres user-defined functions into the GraphQL schema, giving custom SQL logic a GraphQL entry point. Argument nullability follows from defaults, and function volatility decides placement: immutable and stable functions become Query fields, while volatile functions become Mutations. Functions returning setof a table type get Relay-style pagination, filtering, sorting and foreign-key relationships automatically. Overloaded, variadic, void-returning, nameless-argument, array-argument and tuple-argument functions are not yet supported.
- pg_graphql 1.5.7: pagination and multi-tenancy support
Supabase mediumAdeptpg_graphql 1.5.7 adds offset-based pagination alongside existing keyset pagination, per-role schema caching for schema-per-tenant multi-tenancy, and array filter operators. Offset pagination maps to SQL LIMIT/OFFSET and gets slower as offsets grow, so keyset pagination remains the recommended approach. Since 1.5.2 the schema cache, keyed by Postgres role and schema version, loads only schemas the role has USAGE on. Tenants no longer all rebuild their caches when one tenant changes its schema, and this setup now serves a project with over 2,200 tenants. Since 1.5.6, contains, containedBy and overlaps filters work on scalar array columns such as text[].