Skip to content

fix(@tanstack/query-core): skip SSE endpoints in createMutationOptions#3470

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-sse-endpoint-mutation
Draft

fix(@tanstack/query-core): skip SSE endpoints in createMutationOptions#3470
Copilot wants to merge 2 commits intomainfrom
copilot/fix-sse-endpoint-mutation

Conversation

Copy link
Contributor

Copilot AI commented Feb 26, 2026

createMutationOptions was missing the hasOperationSse guard that createQueryOptions and createUseQuery already have, causing SSE POST endpoints to generate a broken mutationFn that destructures { data } from ServerSentEventsResult (which has stream, not data).

Changes

  • mutationOptions.ts: Add early-return guard if (hasOperationSse({ operation })) return — mirrors the existing pattern in queryOptions.ts and useQuery.ts
  • specs/3.1.x/sse-post.yaml: Minimal spec with a POST SSE endpoint + a GET JSON endpoint to drive the new test
  • 3.1.x.test.ts + snapshots: Test case confirming the SSE POST endpoint produces no entry in @tanstack/react-query.gen.ts while the GET endpoint still generates queryOptions normally
// Before — generated broken mutation for POST /events/subscribe (SSE):
export const subscribeToEventStreamMutation = (options?) => ({
  mutationFn: async (fnOptions) => {
    const { data } = await subscribeToEventStream({ ... }); // TS error: no 'data' on ServerSentEventsResult
    return data;
  },
});

// After — SSE endpoint is silently skipped, no mutation emitted

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • fonts.googleapis.com
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node /home/REDACTED/work/openapi-ts/openapi-ts/examples/openapi-ts-tanstack-angular-query-experimental/node_modules/.bin/../@angular/cli/bin/ng.js build bash --no�� esm (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>React Query generates broken mutation for SSE endpoints — missing hasOperationSse guard</issue_title>
<issue_description>## Description

The @tanstack/react-query plugin generates a mutation function for SSE endpoints that destructures { data } from the SDK call. However, SSE endpoints return ServerSentEventsResult which has a stream property, not data. This produces a TypeScript error.

Root Cause

In createMutationOptions, the generated mutation function assumes the SDK call returns { data }:

// Generated @tanstack/react-query.gen.ts
export const subscribeToEventStreamMutation = (options?) => ({
  mutationFn: async (localOptions) => {
    const { data } = await subscribeToEventStream({ ... }); // ← TS error: no 'data' on ServerSentEventsResult
    return data;
  },
});

But subscribeToEventStream returns ServerSentEventsResult which is:

type ServerSentEventsResult<TData = unknown> = {
  stream: AsyncGenerator<...>;  // not 'data'
};

The query-related handlers (createQueryOptions, createUseQuery) already skip SSE endpoints with:

if (hasOperationSse({ operation })) return;

But createMutationOptions is missing this guard.

Expected Behavior

createMutationOptions should skip SSE endpoints, consistent with the other handlers:

const createMutationOptions = ({ operation, plugin }) => {
  if (hasOperationSse({ operation })) return; // ← missing guard
  // ...
};

Versions

  • @hey-api/openapi-ts: 0.92.3
  • @tanstack/react-query plugin</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@bolt-new-by-stackblitz
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

@vercel
Copy link

vercel bot commented Feb 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
hey-api-docs Ready Ready Preview, Comment Feb 26, 2026 11:35pm

Request Review

@changeset-bot
Copy link

changeset-bot bot commented Feb 26, 2026

⚠️ No Changeset found

Latest commit: 894cdfd

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

…ndpoints

Co-authored-by: mrlubos <12529395+mrlubos@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix broken mutation for SSE endpoints in React Query fix(@tanstack/query-core): skip SSE endpoints in createMutationOptions Feb 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

React Query generates broken mutation for SSE endpoints — missing hasOperationSse guard

2 participants