Skip to content

ref(api): Migrate component and util mutations to apiFetch - #127700

Closed
ryan953 wants to merge 8 commits into
masterfrom
ref/api-fetch-mutations-components
Closed

ryan953 wants to merge 8 commits into
masterfrom
ref/api-fetch-mutations-components

Conversation

@ryan953

@ryan953 ryan953 commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Moves every fetchMutation call in static/app components, utils and action creators to apiFetch, part of the stack that removes fetchMutation (see #127699 for the motivation). Mutations here now resolve to ApiResponse ({json, headers, status}), the same shape the query cache stores, so status and headers are available to them.

Most of the diff is a mechanical rewrite of fetchMutation({method, url, data, options}) to apiFetch({queryKey: [url, {method, data, ...options}]}). The hand edits are the consumers of the result: onSuccess handlers, mutateAsync callers, cache writes, and explicit useMutation generics now read or declare .json. Helpers with a body-typed public contract unwrap .json themselves so their callers stay unchanged.

Places worth a closer look, because TypeScript would not have flagged them:

  • useDataExport used includeAllArgs to read the response status; it now reads response.status from ApiResponse.
  • usePipeline switches on the body's own status field, so it destructures json rather than reading response.status, which is now the numeric HTTP status.
  • createReleaseIntegrationModal passed the mutation result into an any-typed prop, so it would have silently received the wrapper.
  • The dashboard action creators, useBulkUpdateRepositorySettings and initializeRun keep returning the body, because other modules depend on those contracts.
  • The replay specs mocked fetchMutation on sentry/utils/queryClient; they now mock apiFetch. scmPlatformFeatures.spec.tsx lives under views but is in this PR, because it spies on the apiFetch call in linkProjectToRepository.

Depends on #127699. Independent of the other area PRs; the cleanup PR that deletes fetchMutation merges after all of them.

No feature flags. No intended UI changes, so no screenshots.

apiFetch now accepts just {queryKey} rather than a full
QueryFunctionContext, so mutations can call it directly and resolve to
the same ApiResponse ({json, headers, status}) shape the query cache
uses. queryFn usage is unchanged, since a full context still satisfies
the narrower parameter; usePinnedLogsQuery built a context literal with
extra fields and now passes only the queryKey.

The mock API client now awaits a promise body when includeAllArgs is
set. apiFetch always sets it, so specs that hold a mutation in flight
with a promise body would otherwise receive the pending promise as json.
One preprod spec passed only because of that leak and now mocks a
resolved size analysis instead.
…tations from fetchMutation to apiFetch

Mutations in static/app components, utils and action creators now call apiFetch({queryKey: [url, {method, data}]})
and resolve to ApiResponse, the same {json, headers, status} shape the
query cache stores. Consumers that read the response body (onSuccess,
mutateAsync callers, cache writes, explicit useMutation generics) read
.json; status and headers are now available to them as well.

Helpers with a body-typed public contract unwrap .json at the helper so
their callers stay unchanged.
@github-actions github-actions Bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Oct 15, 2026
Narrowing the parameter to just queryKey meant apiFetch could never use other context fields, even though a mutation could supply them itself (for example its own AbortSignal). Keep queryKey required and accept the rest optionally, so queries pass the full context as before and mutations pass what they have. usePinnedLogsQuery can again pass its full context literal.
Mutations have no query context to forward, and the other QueryFunctionContext fields (signal, client, meta) describe a running query that a mutation would have to invent. Accept just the queryKey that both callers can supply. usePinnedLogsQuery built a context literal with extra fields and now passes only the queryKey.
Match apiFetch: destructure the two context fields the function reads instead of accepting the whole query context.
linkProjectToRepository now calls apiFetch, so the spec that holds the link pending has to spy there. It moves into this PR with the code it exercises.
Base automatically changed from ref/api-fetch-mutations-base to master October 16, 2026 17:30
@ryan953 ryan953 closed this Oct 16, 2026

This branch was successfully deployed

1 active deployment
Preview — e7f36a7e Deployed Oct 16, 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