Repository navigation
feat(graphql): expose response headers and X-GraphQL-Keys parser - #176
Merged
Merged
Conversation
Every executor (createApqExecutor, createTrustedDocumentExecutor,
createPassthroughExecutor, createWpGraphql().executeGraphqlRequest) now also
exposes `.withMeta(document, variables?, options?)`, resolving to
`{ data, headers, transport, durationMs }` for the final response (after an
APQ miss that is the register/fallback POST, never the GET that missed). The
plain call is unchanged and still resolves to data only.
`GraphqlRequestPlugin.onResponse` now receives `headers` and `transport` next
to `data` / `error` / `durationMs`; headers are also recovered from a thrown
graphql-request ClientError. POST paths go through `client.rawRequest` so they
carry headers too.
New `@perimetre/graphql/keys` subpath (re-exported from the root):
`parseGraphqlKeys(headers | string)` splits WPGraphQL's X-GraphQL-Keys header
into `{ nodeIds, lists, skipped, operation?, queryId?, root? }` for tagging
`'use cache: remote'` reads. Executor internals (`createExecutor`,
`postViaClient`, transport types) are exported for custom transports.
Adds bun unit tests under src/__tests__ (run on `test` and before `build`),
and casts the fetch wrappers in middlewares.ts to `typeof fetch` so the test
tsconfig (bun-types, which adds `preconnect`) typechecks clean.
Docs: CLAUDE.md, AGENTS.md and README.md pointed at the deleted LLMs/ guides;
they now point at the ai-toolkit `perimetre-apps` plugin (app-code-review
references, app-caching, seo).
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
@perimetre/graphqlminor (changeset included).createApqExecutor,createTrustedDocumentExecutor,createPassthroughExecutor, andcreateWpGraphql().executeGraphqlRequest) now also exposes.withMeta(document, variables?, options?), resolving to{ data, headers, transport, durationMs }.headersare the raw fetchResponse.headersof the response that produceddata— after an APQ miss that is the register POST's (or the fallback POST's), never the GET's that missed. The plain call is unchanged and still resolves todataonly. NewGraphqlExecutortype;ExecuteGraphqlRequestis untouched so custom executors keep compiling.GraphqlRequestPlugin.onResponsenow receivesheadersandtransportnext todata/error/durationMs(GraphqlResponseOutcome). Headers are also recovered from a thrown graphql-requestClientError;undefinedonly when no response arrived.client.rawRequestso they carry headers too. Same middlewares anderrorPolicyasclient.request.@perimetre/graphql/keyssubpath (also re-exported from the root):parseGraphqlKeys(headers | string)→{ nodeIds, lists, skipped, operation?, queryId?, root? }. Pure, dependency-free, never throws.lists/skippedstay in wire form (list:post,skipped:post) since those are the keys WPGraphQL Smart Cache purges by.createExecutor,postViaClient,GraphqlTransport*,GraphqlResponseMeta,GraphqlExecuteResult,ExecuteGraphqlRequestWithMeta.packages/graphql/src/__tests__(31 tests), wired aspnpm --filter @perimetre/graphql testand run beforetsdownonbuild.Also in this PR
middlewares.ts: the two fetch wrappers are castas typeof fetch— bun-types'typeof fetchrequirespreconnect, which a plain wrapper never implements. No behaviour change;tsc -p src/__tests__/tsconfig.jsonis now clean.CLAUDE.md,AGENTS.md,README.mdstill pointed at theLLMs/*.mdguides deleted in 48f6c3e. They now point at the ai-toolkitperimetre-appsplugin (app-code-review/references/*.md,app-caching,seo).Usage
Test plan
pnpm turbo run lint typecheck build --filter=@perimetre/graphql --force— 4/4 tasks successfulpnpm --filter @perimetre/graphql test—31 pass, 0 fail, 113 expect() calls, 4 filestsc -p packages/graphql/src/__tests__/tsconfig.json— exit 0 (previously 2preconnecterrors)pnpm install --frozen-lockfile— lockfile in sync🤖 Generated with Claude Code