Skip to content

feat(api): Make the query-string@7 serializer the default - #131247

Merged
BYK merged 5 commits into
masterfrom
feat/api-query-string-serializer
Nov 17, 2026
Merged

BYK merged 5 commits into
masterfrom
feat/api-query-string-serializer

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Part of #131203

@sentry/api now writes query strings the way query-string@7's stringify does with its default options, for createSentryClient and every generated operation. The Sentry frontend builds its URLs with query-string, so making this the default means the SDK and the frontend produce the same URLs and cache keys for the same query, without every consumer opting in. The previous serializer is removed.

  • Keys are sorted by UTF-16 code unit.
  • null becomes a bare key (?query); "" stays query=.
  • undefined is omitted, and so is an empty array.
  • Arrays repeat the key (field=id&field=title), with the same rules per item.
  • Keys and values are percent-encoded, including !'()*.
  • Objects keep deepObject encoding (filter[status]=open, inner keys sorted), because query-string can't encode them. Dates are still written as ISO strings, and nested arrays or objects still throw.

A build step (scripts/replace-query-serializer.mjs) swaps hey-api's serializer for lib/query-serializer.ts in the generated client, using AST-located edits.

API changes

  • The opt-in queryStringSerializer export from earlier in this PR is gone. It's the default now, so a separate name would only duplicate it; the function is internal (serializeQuery).
  • querySerializer now only takes a function (query) => string. hey-api's options form ({ array, object, parameters, ... }) configured the old serializer and is removed along with it.

Breaking change

  • Keys are now sorted instead of kept in insertion order.
  • null now becomes a bare key instead of being dropped. On a URL that already has a query, null still removes the existing values for that key, but then adds a bare key back. For example, prepareRequest({ url: "/items/?cursor=abc", query: { cursor: null } }) used to produce /items/ and now produces /items/?cursor. Sentry's paginator reads an empty cursor as the first page.
  • undefined is still dropped.
  • Arrays are still repeated keys.
  • Passing an options object as querySerializer no longer typechecks. Pass a function instead.

What changes for the toolkit CLI and MCP (getsentry/toolkit uses the default client)

  • Every request built through generated operations or prepareRequest sends sorted keys. That changes URLs, response-cache keys and pagination context keys, and toolkit tests that pin exact URLs may need new expectations.
  • sentry api pagination (packages/cli/src/commands/api.ts) passes cursor: null to drop the cursor from the endpoint. It will now send a bare cursor, which the server treats as the first page. Passing undefined won't remove an existing cursor, so it may be cleaner to strip cursor from the endpoint string before calling prepareRawApiRequest.
  • No custom querySerializer or options form is used there.

via @BYK.

--

View Session [Sentry]

Consumers could already pass querySerializer to createSentryClient, but
code whose URLs, cache keys or snapshots depend on query-string@7 had no
matching serializer. queryStringSerializer gives stringify's default
output: sorted keys, null as a bare key, undefined omitted, repeated
arrays, strict percent-encoding. The client's default serializer is
unchanged.

Co-Authored-By: BYK <[email protected]>
@sentry-junior
sentry-junior Bot requested review from a team as code owners November 16, 2026 14:05
@sentry-junior
sentry-junior Bot requested a review from BYK November 16, 2026 14:05
@github-actions github-actions Bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Nov 16, 2026
…ng-serializer

Co-Authored-By: BYK <[email protected]>

# Conflicts:
#	static/packages/api/build.mjs
Comment thread static/packages/api/README.md Resolved
sentry-junior Bot and others added 2 commits November 17, 2026 14:54
The client and every generated operation now sort query keys, write null
as a bare key, omit undefined and repeat arrays, as query-string@7's
stringify does. Objects stay in deepObject style. The previous serializer,
its options form and the opt-in queryStringSerializer export are gone;
querySerializer now only takes a function.

Co-Authored-By: BYK <[email protected]>
@sentry-junior sentry-junior Bot changed the title feat(api): Add a query-string-compatible query serializer feat(api): Make the query-string@7 serializer the default Nov 17, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 649f876. Configure here.

];
});

rewrite("core/types.gen.ts", file => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No way to override this at build time??

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only partly. The one generation-time hook in @hey-api/openapi-ts 0.98 is the client plugin's runtimeConfigPath: a module that exports createClientConfig(), which the generated client.gen.ts calls to set the initial config of the default client. There's no option to plug in a query serializer module; the client runtime (client/utils.gen.ts, core/*) is copied verbatim.

With runtimeConfigPath alone:

  • the default client would get serializeQuery;
  • createSentryClient(config) calls createClient(config), which merges with createConfig() and still defaults to defaultQuerySerializer. We'd fix that in our own sentry-client.gen.ts generator by passing querySerializer: serializeQuery;
  • buildUrl would still fall back to hey-api's createQuerySerializer whenever querySerializer isn't a function;
  • the old serializer and the QuerySerializerOptions types would stay in the output.

Since the goal was to drop the old serializer completely, a post-generation step would still be needed for the last two points. So this script does all of it in one place, with AST-located edits that fail the build if hey-api's output changes shape. If you'd rather choose the default through runtimeConfigPath plus the createSentryClient generator and keep only a smaller removal step, that's doable, but it splits the change across two mechanisms.

@BYK
BYK merged commit 49694e8 into master Nov 17, 2026
72 checks passed
@BYK
BYK deleted the feat/api-query-string-serializer branch November 17, 2026 15:23

This branch was successfully deployed

1 active deployment
Preview — 649f8761 Deployed Nov 17, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant