You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Adds queryOptions 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. The exception is Vue, 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.
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
Release Notes
New Features
Added framework-agnostic queryOptions and mutationOptions helpers for enhanced type inference and reusable query/mutation configurations across all supported frameworks.
Adds framework-agnostic queryOptions and mutationOptions helper functions and their corresponding CoreQueryOptions/CoreMutationOptions types to @tanstack/query-core. Exports them from the package's public API, updates Vue Query's useBaseQuery/useQuery to accept options factories returning these core types, and validates cross-framework type inference in all adapter packages.
Changes
Framework-agnostic queryOptions and mutationOptions
Layer / File(s)
Summary
Core queryOptions and mutationOptions implementation packages/query-core/src/queryOptions.ts, packages/query-core/src/mutationOptions.ts, packages/query-core/src/index.ts, .changeset/quiet-cooks-sparkle.md
Introduces queryOptions.ts with three typed overloads (DefinedInitialDataOptions, UndefinedInitialDataOptions, UnusedSkipTokenOptions) merged into CoreQueryOptions, and mutationOptions.ts with CoreMutationOptions (omitting _defaulted) and three mutationKey-aware overloads. Both are no-op passthroughs at runtime. Re-exports all four public symbols from index.ts.
useBaseQuery parameter type is broadened to MaybeRefOrGetter<UseQueryOptionsGeneric> | (() => CoreQueryOptions) and internal options resolution is simplified to a conditional expression. useQuery overloads are rewritten to require an options factory () => CoreQueryOptions or () => DefinedCoreQueryOptions.
Type tests assert that useQuery infers data from a coreQueryOptions getter, that direct (non-getter) core options are rejected, and that queryKey[dataTagSymbol] carries the result type. A runtime test validates reactive ref updates through coreQueryOptions.
Framework adapter type tests packages/react-query/src/__tests__/..., packages/angular-query-experimental/src/__tests__/..., packages/solid-query/src/__tests__/..., packages/preact-query/src/__tests__/..., packages/svelte-query/tests/..., packages/lit-query/src/tests/...
Adds coreMutationOptions/coreQueryOptions import aliases and new type-inference test cases across all adapters, each verifying that passing core option objects into the framework-specific hooks infers correct data, variables, and mutate types.
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
TanStack/query#9914: Modifies useBaseQuery/useQuery in Vue Query to accept options as getter functions (options: () => ...), which directly overlaps with the Vue integration changes in this PR.
🐇 A hop and a skip, the options now core, queryOptions and mutationOptions — framework-free, what's more!
Each adapter gets tagged keys, typed to the brim,
No _defaulted sneaking in on a whim.
The bunny types safely, all inferences true,
🎉 One helper to share them — for me and for you!
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name
Status
Explanation
Resolution
Docstring Coverage
⚠️ Warning
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%.
Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name
Status
Explanation
Title check
✅ Passed
The title 'Query mutation options in core' accurately describes the main change—adding queryOptions and mutationOptions helpers to the core library.
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.
Description check
✅ Passed
The PR description follows the template with clear changes, completed checklist items, and release impact including a changeset.
✨ Finishing Touches🧪 Generate unit tests (beta)
Create PR with unit tests
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.
Comment @coderabbitai help to get the list of available commands.
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
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.
🎯 Changes
Adds
queryOptionsandmutationOptionsto 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. The exception is Vue, 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() => coreOptionsas 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:
CoreQueryOptionsandCoreMutationOptionsok names for the interface the newqueryOptionsandmutationOptionsrequires? The core library already hasQueryOptionsandMutationOptions. The newCoreQueryOptionsandCoreMutationOptionsare the equivalent ofQueryOptionsandMutationOptionsexported by each individual adapter. The new types can't replace the base options alredy defined in core.CoreQueryOptionsandCoreMutationOptionsbe excluded from the re-export from core? How? Each adapter exportsqueryOptionsandmutationOptions, so a consumer can't import the implementation defined in core if the consumer hasn't installed@tanstack/query-coredirectly, but they can consumeCoreQueryOptionsandCoreMutationOptions.useQueryinterface of Vue had to be extended, there is probably something that can be done there to simplify the types.✅ Checklist
pnpm run test:pr.🚀 Release Impact
Summary by CodeRabbit
Release Notes
queryOptionsandmutationOptionshelpers for enhanced type inference and reusable query/mutation configurations across all supported frameworks.