Skip to content

Query mutation options in core - #10973

Open
benjavicente wants to merge 3 commits into
TanStack:mainfrom
benjavicente:query-mutation-options-in-core
Open

benjavicente wants to merge 3 commits into
TanStack:mainfrom
benjavicente:query-mutation-options-in-core

Conversation

@benjavicente

@benjavicente benjavicente commented Jun 21, 2026 •

Copy link
Copy Markdown
Member

🎯 Changes

Adds queryOptions,infiniteQueryOptions and mutationOptions to the core library.

This was requested at #10735 and #9258 discussions. Having those function in core is useful for defining shared query options for a framework agnostic layer, or for server side usage. Specially for using query keys for type-safe interactions with the core imperative API.

Most of the frameworks accept the shared interface from core without changes, with Vue been the exception that require a small change in the interface since MaybeRefOrGetterwasn't compatible. I added runtime test for Vue to demonstrate that it works with the core query options, with the same shape of () => coreOptions as Solid/Angular/Lit/Svelte.

About docs: There is a lot of outdated docs, so I excluded the doc generation in the PR. I didn't add docs mentioning that core has this new functions.

Pending questions:

  • Is CoreQueryOptions and CoreMutationOptions ok names for the interface the new queryOptions and mutationOptions requires? The core library already has QueryOptions and MutationOptions. The new CoreQueryOptions and CoreMutationOptions are the equivalent of QueryOptions and MutationOptions exported by each individual adapter. The new types can't replace the base options alredy defined in core.
  • Should CoreQueryOptions and CoreMutationOptions be excluded from the re-export from core? How? Each adapter exports queryOptions and mutationOptions, so a consumer can't import the implementation defined in core if the consumer hasn't installed @tanstack/query-core directly, but they can consume CoreQueryOptions and CoreMutationOptions.
  • I'm not happy on how the useQuery interface of Vue had to be extended, there is probably something that can be done there to simplify the types.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • New Features

    • Added framework-agnostic queryOptions, infiniteQueryOptions, and mutationOptions helpers, along with shared types for describing their options.
    • Options created with these helpers retain type inference when used with query, infinite-query, and mutation APIs across supported frameworks.
  • Documentation

    • Added API reference pages for the shared option types and guidance on using the helpers in framework-agnostic code.

@coderabbitai

coderabbitai Bot commented Jun 21, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 9d64034 and 8275110.

Files selected for processing: 25
  • docs/config.json
  • docs/framework/angular/reference/index.md
  • docs/framework/lit/reference/index.md
  • docs/framework/preact/reference/index.md
  • docs/framework/react/reference/index.md
  • docs/framework/solid/reference/index.md
  • docs/framework/svelte/reference/index.md
  • packages/angular-query-experimental/src/__tests__/infinite-query-options.test-d.ts
  • packages/angular-query-experimental/src/__tests__/mutation-options.test-d.ts
  • packages/angular-query-experimental/src/__tests__/query-options.test-d.ts
  • packages/lit-query/src/__tests__/createQueryController.test-d.ts
  • packages/lit-query/src/__tests__/infiniteQueryOptions.test-d.ts
  • packages/preact-query/src/__tests__/infiniteQueryOptions.test-d.tsx
  • packages/preact-query/src/__tests__/mutationOptions.test-d.tsx
  • packages/preact-query/src/__tests__/queryOptions.test-d.tsx
  • packages/query-core/src/__tests__/options.test.ts
  • packages/react-query/src/__tests__/infiniteQueryOptions.test-d.tsx
  • packages/react-query/src/__tests__/mutationOptions.test-d.tsx
  • packages/react-query/src/__tests__/queryOptions.test-d.tsx
  • packages/solid-query/src/__tests__/infiniteQueryOptions.test-d.tsx
  • packages/solid-query/src/__tests__/mutationOptions.test-d.tsx
  • packages/solid-query/src/__tests__/queryOptions.test-d.tsx
  • packages/svelte-query/tests/createQuery/createQuery.test-d.ts
  • packages/svelte-query/tests/infiniteQueryOptions.test-d.ts
  • packages/svelte-query/tests/mutationOptions/mutationOptions.test-d.ts
Files skipped from review as they are similar to previous changes: 7
  • docs/framework/angular/reference/index.md
  • docs/framework/solid/reference/index.md
  • docs/framework/preact/reference/index.md
  • docs/framework/lit/reference/index.md
  • docs/framework/svelte/reference/index.md
  • docs/framework/react/reference/index.md
  • docs/config.json

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

query-core adds and exports framework-agnostic queryOptions, infiniteQueryOptions, and mutationOptions helpers with associated option types. Tests cover helper behavior and type inference in core and across six framework adapters. Reference documentation and a minor changeset entry are added.

Changes: Framework-agnostic query and mutation options

Layer / File(s) Summary
Core helper contracts and exports
packages/query-core/src/queryOptions.ts, packages/query-core/src/infiniteQueryOptions.ts, packages/query-core/src/mutationOptions.ts, packages/query-core/src/index.ts, .changeset/quiet-cooks-sparkle.md
Adds three typed helpers that return their supplied options unchanged, exports the helpers and core option types, and records a minor changeset for @tanstack/query-core.
Core helper runtime and type tests
packages/query-core/src/__tests__/options.test.ts, packages/query-core/src/__tests__/queryOptions.test-d.tsx, packages/query-core/src/__tests__/infiniteQueryOptions.test-d.tsx, packages/query-core/src/__tests__/mutationOptions.test-d.tsx
Tests helper passthrough and behavior. Type tests cover query-key data tags, initial-data variants, skipToken, infinite-page types, mutation keys, and rejection of _defaulted.
Framework adapter type compatibility
packages/{angular-query-experimental,lit-query,preact-query,react-query,solid-query,svelte-query}/...
Adds type tests passing core query, infinite-query, and mutation options to the corresponding adapter APIs.
Framework reference documentation
docs/framework/{angular,lit,preact,react,solid,svelte}/reference/..., docs/framework/react/guides/query-options.md, docs/config.json
Adds reference pages and navigation links for the core option types. The React guide describes the core and adapter helpers.

Priority: Normal

Estimated code review effort: 3 (Moderate) | ~25 minutes

Change: Feature

Suggested labels: package: svelte-query

Suggested reviewers: sukvvon

Merge Risk: Minimal · up to 82751

The supplied evidence identifies no issue that needs resolution before merging.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title "Query mutation options in core" names a real part of the changeset: adding the mutationOptions helper to @tanstack/query-core. However, the change also adds queryOptions and infiniteQueryOp…
Description check Passed The description follows the repository template. It has the Changes section, which explains the motivation and cites the linked discussions. It has the Checklist, with the contributing guide, local te…
Docstring Coverage Passed Docstring coverage is inconclusive: files from earlier reviews still need to be rechecked within the check's analysis limits. Not blocking.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "Query mutation options in core" names a real part of the changeset: adding the mutationOptions helper to @tanstack/query-core. However, the change also adds queryOptions and infiniteQueryOptions, and the title mentions only mutation options. That makes the title partially related: it covers a real aspect of the change but not the main point, which is the addition of all three framework-agnostic options helpers to core. The title is short, specific, and free of noise.

Full details: Description check

Explanation

The description follows the repository template. It has the Changes section, which explains the motivation and cites the linked discussions. It has the Checklist, with the contributing guide, local test, and AI policy items. It has the Release Impact section, with the changeset item checked. The AI policy checkbox is missing from the author's checklist, and the Changes section does not say how the helpers are used. The description also contains struck-through notes and open questions that the author has not resolved. These gaps are minor, so the description is mostly complete.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

export { queryOptions } from './queryOptions'
export type { CoreQueryOptions } from './queryOptions'
export { mutationOptions } from './mutationOptions'
export type { CoreMutationOptions } from './mutationOptions'

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

since adapters re-export the core and then export their own things, they won’t have access to the queryOptions from the core, right? is that on purpose?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes. I don't think someone wanting to define shared query options for multiple frameworks would import from a framework specific package.

Comment on lines +58 to +61
const { data } = useQuery(options)
expectTypeOf(data).toEqualTypeOf<
{ id: string; title: string } | undefined
>()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

with this, what’s the difference between useQuery(queryOptions) and useQuery(coreQueryOption) ?

in other words, if they are compatible, why would e.g. the react adapter need a separate queryOptions and not just re-export and let users use the one from the core?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

queryOptions from each library could extend the coreQueryOption, like with deferStream in Solid or RefOrGetter pattern in Vue.

@benjavicente

Copy link
Copy Markdown
Member Author

I avoided changing the types of the adapters to reuse the new types in core to keep the changes of this PR small (only test changes for most adapters). The code query options could be something that adapters completely reuse.

@TkDodo

TkDodo commented Aug 22, 2026

Copy link
Copy Markdown
Collaborator

The code query options could be something that adapters completely reuse.

I guess you mean re-use on type-level, because at runtime, they all don’t do anything?

@benjavicente

Copy link
Copy Markdown
Member Author

The code query options could be something that adapters completely reuse.

I guess you mean re-use on type-level, because at runtime, they all don’t do anything?

Yes

@TkDodo

TkDodo commented Aug 22, 2026

Copy link
Copy Markdown
Collaborator

okay, let’s do it 🔥 . can you fix the conflicts ?

@benjavicente
benjavicente force-pushed the query-mutation-options-in-core branch from ff39c7b to 51a48d8 Compare August 22, 2026 14:30
@coderabbitai

coderabbitai Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@benjavicente
benjavicente requested a review from TkDodo August 22, 2026 15:54
@benjavicente
benjavicente force-pushed the query-mutation-options-in-core branch from 51a48d8 to fc5ffde Compare October 13, 2026 02:20
@changeset-bot

changeset-bot Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8275110

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 24 packages
Name Type
@tanstack/query-core Minor
@tanstack/angular-query-experimental Minor
@tanstack/lit-query Patch
@tanstack/preact-query Minor
@tanstack/query-async-storage-persister Minor
@tanstack/query-broadcast-client-experimental Minor
@tanstack/query-devtools Minor
@tanstack/query-persist-client-core Minor
@tanstack/query-sync-storage-persister Minor
@tanstack/react-query Minor
@tanstack/solid-query Minor
@tanstack/svelte-query Patch
@tanstack/vue-query Minor
@tanstack/preact-query-devtools Minor
@tanstack/preact-query-persist-client Minor
@tanstack/react-query-devtools Minor
@tanstack/solid-query-devtools Minor
@tanstack/svelte-query-devtools Patch
@tanstack/vue-query-devtools Patch
@tanstack/react-query-persist-client Minor
@tanstack/solid-query-persist-client Minor
@tanstack/svelte-query-persist-client Patch
@tanstack/react-query-next-experimental Minor
@tanstack/eslint-plugin-query Minor

Not sure what this means? Click here to learn what changesets are.

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

@nx-cloud

nx-cloud Bot commented Oct 13, 2026 •

Copy link
Copy Markdown

🤖 Nx Cloud AI Fix Eligible

An automatically generated fix could have helped fix failing tasks for this run, but Self-healing CI is disabled for this workspace. Visit workspace settings to enable it and get automatic fixes in future runs.

To disable these notifications, a workspace admin can disable them in workspace settings.


View your CI Pipeline Execution ↗ for commit 8275110

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ❌ Failed 6m View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 36s View ↗

☁️ Nx Cloud last updated this comment at 2026-10-28 22:52:53 UTC

@pkg-pr-new

pkg-pr-new Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
More templates

@tanstack/angular-query-experimental

npm i https://pkg.pr.new/@tanstack/angular-query-experimental@10973

@tanstack/eslint-plugin-query

npm i https://pkg.pr.new/@tanstack/eslint-plugin-query@10973

@tanstack/lit-query

npm i https://pkg.pr.new/@tanstack/lit-query@10973

@tanstack/preact-query

npm i https://pkg.pr.new/@tanstack/preact-query@10973

@tanstack/preact-query-devtools

npm i https://pkg.pr.new/@tanstack/preact-query-devtools@10973

@tanstack/preact-query-persist-client

npm i https://pkg.pr.new/@tanstack/preact-query-persist-client@10973

@tanstack/query-async-storage-persister

npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@10973

@tanstack/query-broadcast-client-experimental

npm i https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@10973

@tanstack/query-core

npm i https://pkg.pr.new/@tanstack/query-core@10973

@tanstack/query-devtools

npm i https://pkg.pr.new/@tanstack/query-devtools@10973

@tanstack/query-persist-client-core

npm i https://pkg.pr.new/@tanstack/query-persist-client-core@10973

@tanstack/query-sync-storage-persister

npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@10973

@tanstack/react-query

npm i https://pkg.pr.new/@tanstack/react-query@10973

@tanstack/react-query-devtools

npm i https://pkg.pr.new/@tanstack/react-query-devtools@10973

@tanstack/react-query-next-experimental

npm i https://pkg.pr.new/@tanstack/react-query-next-experimental@10973

@tanstack/react-query-persist-client

npm i https://pkg.pr.new/@tanstack/react-query-persist-client@10973

@tanstack/solid-query

npm i https://pkg.pr.new/@tanstack/solid-query@10973

@tanstack/solid-query-devtools

npm i https://pkg.pr.new/@tanstack/solid-query-devtools@10973

@tanstack/solid-query-persist-client

npm i https://pkg.pr.new/@tanstack/solid-query-persist-client@10973

@tanstack/svelte-query

npm i https://pkg.pr.new/@tanstack/svelte-query@10973

@tanstack/svelte-query-devtools

npm i https://pkg.pr.new/@tanstack/svelte-query-devtools@10973

@tanstack/svelte-query-persist-client

npm i https://pkg.pr.new/@tanstack/svelte-query-persist-client@10973

@tanstack/vue-query

npm i https://pkg.pr.new/@tanstack/vue-query@10973

@tanstack/vue-query-devtools

npm i https://pkg.pr.new/@tanstack/vue-query-devtools@10973

commit: 8275110

@benjavicente
benjavicente force-pushed the query-mutation-options-in-core branch from a05d8c3 to 9d64034 Compare October 13, 2026 03:19
@benjavicente

benjavicente commented Oct 13, 2026 •

Copy link
Copy Markdown
Member Author

Did a rebase on latest main and found a couple of issues with Vue that would make the PR too big, so I removed the Vue changes to support it 😞

Vue has a different main options shape for supporting reactive refs, and the enabled callback doesn't have the query parameter (query) => bool shape like other adapters. So it isn't as straightforward to cover those cases, and to avoid any issues on the types it is preferable to scope it out.

This would remain compatible with query core (queryClient.query and queryClient.infiniteQuery from QueryClient) + the 6 other adapters.

@benjavicente
benjavicente force-pushed the query-mutation-options-in-core branch from 9d64034 to 27885d1 Compare October 28, 2026 22:42
@benjavicente
benjavicente force-pushed the query-mutation-options-in-core branch from 27885d1 to 8275110 Compare October 28, 2026 22:45

This branch has not been deployed

No deployments
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.

2 participants