chore: replace fetchPersistedQuery with Yoga plugin - #7622
MounirDhahri wants to merge 1 commit into
Conversation
@graphql-yoga/plugin-persisted-operations plays inside Yoga's pipeline instead of running as a pre-parser express middleware, which plays nicely with the parser/validation cache and keeps the pipeline in one place. Behavior change: a missing persisted operation previously returned an HTTP 404 from the express middleware. The plugin instead returns a GraphQL error (HTTP 200 with `errors`). Clients that branch on HTTP status for persisted-query misses would need to check the body. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
d28bffc to
9cd1a22
Compare
Code ReviewSummaryThis PR replaces the hand-rolled Moving to the maintained plugin is a good direction and removes bespoke code. There is one behavioral regression worth addressing before merge. Issues Found🔴 Blocking / 🟡 Important —
|
| const persistedOperationsPlugin = usePersistedOperations({ | ||
| allowArbitraryOperations: true, | ||
| extractPersistedOperationId: (params) => | ||
| (params as { documentID?: string }).documentID ?? null, | ||
| getPersistedOperation: (key) => { | ||
| const query = (persistedQueryMap as Record<string, string>)[key] | ||
| if (query) { | ||
| info(`Serving persisted query with ID ${key}`) | ||
| return query | ||
| } | ||
| return null | ||
| }, | ||
| }) |
There was a problem hiding this comment.
This plugin resolves the persisted query into Yoga's internal params.query, but (unlike the old fetchPersistedQuery middleware) it does not write back to Express req.body.query.
The context factory below still derives the mutation flag from the raw body:
isMutation: !!req.body?.query?.includes("mutation"), // src/index.ts:312For a persisted request the client sends only { documentID } with no query, so req.body?.query is now undefined → isMutation is false for every persisted query, including the many persisted mutations in complete.queryMap.json. That flips skipCache off for GET loaders invoked during a mutation (see loader_without_authentication_factory.ts:117), allowing stale cache reads mid-mutation.
Suggest deriving it from the resolved params (already available as the params arg / _params):
isMutation: !!(params?.query ?? req.body?.query)?.includes("mutation"),
Summary
fetchPersistedQuerymiddleware with@graphql-yoga/plugin-persisted-operations. Persisted queries still come fromsrc/data/complete.queryMap.json; arbitrary (non-persisted) queries are still allowed, same as today.An unknown
documentIDused to return HTTP 404 with a plain-text body. Now it returns HTTP 200 with a GraphQLerrorsarray. Clients that check HTTP status for a persisted-query miss would need to check the response body instead.Test plan
yarn type-checkyarn testdocumentIDruns the query, unknowndocumentIDreturns a GraphQL error, requests with nodocumentIDstill work🤖 Generated with Claude Code