Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,36 @@ becomes the release notes of the next tag.

## [Unreleased]

### Added

- `persisted_queries.max_bytes` (default 8 MiB) and
`persisted_queries.max_entry_bytes` (default 64 KiB) bound the APQ store
by memory (least recently used evicted first) instead of a count of 1024
documents of any size.

### Changed

- **Breaking:** a list returned by a set-returning function (a `SETOF` root
function or computed column) holds at most `limits.max_page_size` items
and the cost estimate charges it that many rows; it was unbounded and
costed as 10 rows, so `limits.max_cost` did not bound its work
([upgrading](docs/upgrading.md#set-returning-function-lists-hold-at-most-a-page)).
- **Breaking:** `server.request_timeout` must be at least `1s`; `0` silently
disabled the timeout.
- **Breaking:** `/schema.graphql` requires the credentials `/graphql`
requires: without an anonymous role, a request without valid credentials
is answered `401`, as an introspection query is.
- **Breaking:** an EWKT filter operand or `near:` reference whose SRID
differs from the column's typmod SRID is rejected as `invalid_argument`
instead of failing in PostGIS with `pg:XX000`.
- APQ documents are registered only after the request authenticated and the
document parsed, passed the document limits and validated; unauthenticated
clients can no longer fill the store.
- Under a transaction (role switching, claims, `transactions.per_request`),
a database error in one query root field no longer fails the later fields
with `pg:25P02` or adds a pathless `internal` error logged at `ERROR`: the
query runs again with each root field in its own savepoint.

## [0.30.0] - 2026-11-24

### Added
Expand Down
2 changes: 2 additions & 0 deletions cmd/pdbq/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ func configFlags(cmd *cobra.Command) {
fs.Bool("persisted_queries.apq", false, "enable Apollo automatic persisted queries")
fs.String("persisted_queries.path", "", "JSON file of persisted queries (sha256 hex hash to document)")
fs.Bool("persisted_queries.only", false, "reject requests that do not reference a persisted query")
fs.Int("persisted_queries.max_bytes", 8<<20, "memory the APQ-registered documents may hold")
fs.Int("persisted_queries.max_entry_bytes", 64<<10, "size above which a document is not registered for APQ")
fs.Bool("incremental.enabled", false, "serve the defer and stream directives (multipart/mixed over HTTP, next messages over WebSocket)")
fs.Duration("incremental.write_timeout", 10*time.Second, "longest one incremental payload write may block before the response is aborted")
fs.Int("incremental.max_responses", 5, "incremental responses holding a transaction at once (below database.max_conns)")
Expand Down
10 changes: 6 additions & 4 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ same names: `limits.*` (`max_body_bytes`, `max_depth`, `max_cost`,
| `database.statement_timeout` | `25s` | per-statement timeout on every request (`0` disables); kept below `server.request_timeout` so a slow statement fails with SQLSTATE `57014` (code `pg:57014`) before the request is cut off |
| `server.addr` | `:8080` | |
| `server.graphiql` | `false` | GraphiQL playground at `/` (enable for dev) |
| `server.introspection` | `true` | answer `__schema`/`__type` queries, serve the SDL at `/schema.graphql` and add "Did you mean …" suggestions to validation errors; `false` hides the schema shape so guessed names don't reveal real ones (`__typename` keeps working). On by default like pdbr's `openapi.enabled`; turn it off in production |
| `server.introspection` | `true` | answer `__schema`/`__type` queries, serve the SDL at `/schema.graphql` (with the authentication `/graphql` requires: without credentials only when `roles.anonymous` is set, else `401`) and add "Did you mean …" suggestions to validation errors; `false` hides the schema shape so guessed names don't reveal real ones (`__typename` keeps working). On by default like pdbr's `openapi.enabled`; turn it off in production |
| `server.readyz_timeout` | `2s` | deadline of the pool ping behind `GET /readyz`; must be `> 0` |
| `server.request_timeout` | `30s` | overall HTTP request timeout; an expired request is answered `504` with code `timeout` ([errors.md](errors.md)) |
| `server.request_timeout` | `30s` | overall HTTP request timeout; an expired request is answered `504` with code `timeout` ([errors.md](errors.md)); must be `>= 1s` (there is no way to disable it) |
| `limits.max_body_bytes` | 1048576 | maximum request body size (1 MiB); a larger body is answered `413` with code `body_too_large` |
| `limits.max_depth` | 15 | maximum selection depth per operation |
| `limits.max_cost` | 100000 | estimated cost per operation: each field costs 1, a list multiplies its selections, a connection its `nodes`/`edges`, by `first`/`last`, or by `max_page_size` when neither is given (the page it fetches); `totalCount`, `pageInfo` and aggregates count once; recursive relations can tune the estimate with `@costMultiplier` (see [smart comments](smart-comments.md#cost-estimation-for-recursive-relations)) |
| `limits.max_page_size` | 100 | largest accepted `first`/`last` (a larger value errors); also the default page size when neither is given |
| `limits.max_cost` | 100000 | estimated cost per operation: each field costs 1, a list multiplies its selections, a connection its `nodes`/`edges`, by `first`/`last`, or by `max_page_size` when neither is given (the page it fetches); a list returned by a set-returning function (a `SETOF` root function or computed column) multiplies by `max_page_size`, the rows it fetches; `totalCount`, `pageInfo` and aggregates count once; recursive relations can tune the estimate with `@costMultiplier` (see [smart comments](smart-comments.md#cost-estimation-for-recursive-relations)) |
| `limits.max_page_size` | 100 | largest accepted `first`/`last` (a larger value errors); also the default page size when neither is given, and the most items a list returned by a set-returning function (`SETOF` root function or computed column) holds: later rows are cut off (paginate inside the function, e.g. with `limit`/`offset` parameters) |
| `limits.max_headline_document` | 65536 | characters of the document a full-text headline reads (`left(doc, n)`); each headline costs 10 per started 8192 characters of it, per row (see [contrib](contrib.md#full-text-headlines)) |
| `limits.max_query_tokens` | 15000 | lexical tokens per GraphQL document (names, punctuation, values, comments); parsing stops at the first one beyond it, bounding the parse and validation work of one request |
| `limits.max_input_depth` | 32 | nesting of input values: list and input object literals, and variables of list or input object types (`not`/`and`/`or` filter chains, nested mutation inputs); JSON scalar values are not counted |
Expand All @@ -71,6 +71,8 @@ same names: `limits.*` (`max_body_bytes`, `max_depth`, `max_cost`,
| `persisted_queries.apq` | `false` | Apollo automatic persisted queries (in-memory, register-on-miss) |
| `persisted_queries.path` | — | JSON file of sha256 → document, preloaded as persisted queries |
| `persisted_queries.only` | `false` | reject requests that don't reference a persisted query (requires `apq` or `path`) |
| `persisted_queries.max_bytes` | 8388608 | memory the APQ-registered documents may hold (query text, hash and bookkeeping, 8 MiB); least recently used registrations are evicted beyond it; documents from `path` do not count. A document is registered only after its request authenticated and the document parsed, passed the document limits and validated |
| `persisted_queries.max_entry_bytes` | 65536 | size above which a document sent for registration is executed but not registered (64 KiB); the client keeps sending it in full |
| `server.read_only` | `false` | reject every mutation (maintenance, demos, defense in depth) |
| `incremental.enabled` | `false` | serve `@defer` and `@stream`: declared in the schema, queries delivered as `multipart/mixed` over HTTP (`Accept: multipart/mixed`) and as several `next` messages over WebSocket, every payload read from one repeatable read snapshot; off leaves the SDL without directives, rejects `@stream` and delivers `@defer` inline — see [Incremental delivery](incremental.md) |
| `incremental.max_deferred` | 16 | `@defer` fragments plus `@stream` fields one operation may apply; each runs its own statements |
Expand Down
11 changes: 10 additions & 1 deletion docs/errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ WebSocket close codes, not GraphQL errors (`4400`, `4401`, `4403`, `4406`,
| `partial_mutations_disabled` | 200 | `extensions.partialMutations` while `transactions.partial.enabled` is off |
| `operation_not_supported` | 200 | a subscription sent over HTTP; a subscription or live query while that feature is off; a subscription selecting more than one root field or one that is not `listen` |
| `operation_rejected` | 200 | a `RequestHook`'s `BeforeOperation` refused the operation with an error that carries no code of its own (the hook's message is the message) |
| `invalid_argument` | 200 | an argument value the compiler rejects: a negative `first` / `offset`, `first` with `last`, an empty patch or bulk-create list, an upsert input without its key field, a malformed `nodeId`, a filter of the wrong shape, an unknown operator, an invalid geometry, interval or vector value, a distance or similarity orderBy value or score field without its `near:` reference (`orderBy LOCATION_DISTANCE_ASC requires near: {location: …}`), a nested-mutation input that is not allowed, more than `plugins.settings.nested_mutations.max_operations` nested operations, a subscription topic that is invalid or not allowed, ... |
| `invalid_argument` | 200 | an argument value the compiler rejects: a negative `first` / `offset`, `first` with `last`, an empty patch or bulk-create list, an upsert input without its key field, a malformed `nodeId`, a filter of the wrong shape, an unknown operator, an invalid geometry, interval or vector value, an EWKT geometry whose SRID differs from the column's typmod SRID (filters and `near:`), a distance or similarity orderBy value or score field without its `near:` reference (`orderBy LOCATION_DISTANCE_ASC requires near: {location: …}`), a nested-mutation input that is not allowed, more than `plugins.settings.nested_mutations.max_operations` nested operations, a subscription topic that is invalid or not allowed, ... |
| `invalid_cursor` | 200 | an `after` / `before` cursor that cannot be decoded, has the wrong number of key values or belongs to another type |
| `not_found` | 200; 404 for a path | a keyed update or delete matched no row (`no row matched "<alias>"`), or a nested `connectBy…` / `updateBy…` / `deleteBy…` (or the key of an update with nested fields) matched no row (`nested_mutations: <path> matched 0 rows`; the whole mutation is rolled back); an HTTP path pdbq does not serve |
| `auth_required` | 401 | no credentials and `roles.anonymous` is empty; `WWW-Authenticate: Bearer` |
Expand Down Expand Up @@ -107,6 +107,15 @@ after `transactions.max_retries`), `pg:57014` (`database.statement_timeout`),
`pg:P0001` (`RAISE EXCEPTION`). A function can pick the code with
`RAISE … USING ERRCODE = '<state>'`.

A query whose root fields run in one transaction (role switching, claims,
`transactions.per_request`) keeps its fields independent: when one field's
statement fails, the operation runs again with each root field in its own
savepoint, so only that field reports its error. `pg:25P02` (current
transaction is aborted) is left for the fields that could not run after a
failure that was not a field's own database error, such as a dropped
connection or an expired `server.request_timeout`, and for serialization
failures that exhausted `transactions.max_retries`.

There is one exception: the `22P02` that the nested-mutation guard raises
when a keyed nested operation matches no row is reported as `not_found`
with the message `nested_mutations: <path> matched 0 rows`.
Expand Down
5 changes: 3 additions & 2 deletions docs/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ These shipped features are outside the 1.0 compatibility promise: they may chang
- [x] Scalar returns (via `to_jsonb`)
- [x] `SETOF <table>` returns → list of the table's object type with full selection support
- [x] `SETOF <scalar>` returns → scalar lists
- [x] Set-returning function lists (root and computed) cut at `limits.max_page_size` items and costed as that many rows
- [x] Single-row table returns with selection support
- [x] Composite returns → the composite's object type (except `auth.mint_type`, minted into a token string)
- [x] Rows nested in other values (`<table>[]` results and columns, composite attributes, `RETURNS TABLE` columns and columns of a row type) → `<Type>Row`, the columns the table's type exposes (no `@omit read` or contract-hidden column, no raster), built with `json_build_object`; values of an omitted or contract-hidden table's row type have no field
Expand Down Expand Up @@ -178,7 +179,7 @@ These shipped features are outside the 1.0 compatibility promise: they may chang
- [x] One transaction per operation; mutations abort remaining root fields on error
- [x] Queries transaction-free unless RLS context requires one
- [x] Plugins can force a transaction (`op.ForceTx`)
- [x] Transactions sent as one pipelined batch (identity, root field statements, commit): one round trip for queries, two for single-statement mutations; multi-statement mutations (and custom mutations whose payload is read by a second statement) run statement by statement
- [x] Transactions sent as one pipelined batch (identity, root field statements, commit): one round trip for queries, two for single-statement mutations; a query field's database error re-runs the query with a savepoint per root field, so the other fields keep their values; multi-statement mutations (and custom mutations whose payload is read by a second statement) run statement by statement
- [x] Isolation level config (read_committed / repeatable_read / serializable)
- [x] Statement timeout per connection (`database.statement_timeout`)
- [x] PG error → GraphQL error mapping with `errors.detail: dev|prod` (constraint violations pass through in prod, internals sanitized)
Expand All @@ -199,7 +200,7 @@ These shipped features are outside the 1.0 compatibility promise: they may chang
- [x] Machine-readable `extensions.code` on every error (HTTP bodies, GraphQL errors, WebSocket), one closed vocabulary shared with pdbr, `pg:<SQLSTATE>` for database errors — see [Errors](errors.md)
- [x] Atomic schema hot-swap (in-flight requests finish on the old schema)
- [x] `/metrics` (Prometheus) endpoint (opt-in `metrics.enabled`, optional separate `metrics.addr`; see [metrics.md](metrics.md))
- [x] Persisted queries / APQ (`persisted_queries.apq` Apollo protocol, `persisted_queries.path` allowlist file, `persisted_queries.only` lockdown)
- [x] Persisted queries / APQ (`persisted_queries.apq` Apollo protocol, `persisted_queries.path` allowlist file, `persisted_queries.only` lockdown); APQ registration only after authentication and document validation, bounded by `persisted_queries.max_bytes` / `max_entry_bytes`
- [x] `@defer` / `@stream` incremental delivery (opt-in `incremental.enabled`): `multipart/mixed` over HTTP (`incrementalSpec=v0.2` and `deferSpec=20220824` shapes), `next` messages over WebSocket; deferred fragments and stream batches run as their own statements in one repeatable read snapshot under the request's RLS identity — see [Incremental delivery](incremental.md)
- [x] Schema contracts — named schema variants that hide tagged tables, columns, functions and relations per audience (e.g. `public`/`partner`/`internal`), each with its own SDL export (`schema print --contract`) and served endpoint; builds on the `@omit` machinery in `smart_comments` ([contracts.md](contracts.md))
- [x] CORS configuration (`server.cors_origins`: exact-match allowlist or `*`)
Expand Down
2 changes: 1 addition & 1 deletion docs/postgis.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ geometry) follows it:
| input | on `geometry(..., 3857)` |
|---|---|
| bare WKT `POINT(1 2)` | bound as `SRID=3857;POINT(1 2)` |
| EWKT `SRID=4326;POINT(1 2)` | keeps 4326; PostgreSQL rejects the mismatch |
| EWKT `SRID=4326;POINT(1 2)` | rejected as `invalid_argument` in filters and `near:` (send it in 3857, or as GeoJSON to have it reprojected); in a mutation input PostgreSQL rejects the mismatch |
| GeoJSON (4326, or its `crs`) | reprojected by the `ST_Transform(..., 3857)` branch (a no-op when already 3857) |
| bounding box without `srid` | built in 3857 |

Expand Down
28 changes: 28 additions & 0 deletions docs/upgrading.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,34 @@ connection's `totalCount`, `pageInfo`, `aggregates` and `groupedAggregates`
are no longer multiplied by its page size: they are computed once per
connection, so only `nodes` and `edges` repeat per row.

### Set-returning function lists hold at most a page

A list returned by a set-returning function, a `SETOF` root function
(`searchPosts(term:)`) or a `SETOF` computed column (`User.recentPosts`),
had no `LIMIT` but was costed as 10 rows, so a function over a growing
table could return any number of rows, each with its nested selections,
within `limits.max_cost`. Such a list now holds at most
`limits.max_page_size` items (100 by default), the rows after them are cut
off, and the cost estimate charges it that many rows, like a connection
without `first`. A list that needs more rows pages inside the function (for
example `limit`/`offset` parameters), or is exposed through a table or view
connection instead.

| Before | After |
|---|---|
| `searchPosts(term: "")` returns every matching row | at most `limits.max_page_size` rows |
| `{ searchPosts { … postsByAuthorId { nodes { … } } } }` costs 10 × its selection | `max_page_size` × its selection, so a nested connection below it may now exceed `limits.max_cost` |

### Smaller behaviour changes

| Before | After |
|---|---|
| `server.request_timeout: 0` silently disabled the request timeout | rejected at startup: `server.request_timeout must be >= 1s` |
| `/schema.graphql` was served without credentials even when `roles.anonymous` was empty (and `__schema` on `/graphql` answered `401`) | it requires the same credentials as `/graphql`: `401 auth_required` / `invalid_token` without valid ones unless `roles.anonymous` is set |
| an EWKT filter operand or `near:` reference in another SRID than a `geometry(…, n)` column: `pg:XX000` `invalid geometry` (or an empty result) | `invalid_argument`, `spatial value has SRID m, but the column's SRID is n` |
| under a transaction (role switching, claims, `transactions.per_request`), a query field's database error failed every later root field with `pg:25P02` and added a pathless `internal` error (logged at `ERROR`) | the query runs again with a savepoint per root field: only the failing field reports its error, the others keep their values |
| APQ registered a document before authentication and the document limits, up to 1024 documents of any size | registration only after the request authenticated and the document validated; the store is bounded by `persisted_queries.max_bytes` (8 MiB) and `persisted_queries.max_entry_bytes` (64 KiB), least recently used first |

### Default naming

pdbq's default names are now PostGraphile v4's, and `simple_names` is an
Expand Down
Loading
Loading