query icon indicating copy to clipboard operation
query copied to clipboard

init query rename and delegation

Open DogPawHat opened this issue 2 months ago • 9 comments

🎯 Changes

Implements #9135

  • renames fetchQuery and fetchInfiniteQuery to query and infiniteQuery
  • make new fetch* aliases for the renamed methods
  • delegates the prefetch* methods with query instead of fetchQuery
  • delegates ensureQueryData methods to query with staletime: 'static'
  • updates tests for QueryClient (straight copy of the fetch tests)
  • added new methods to vue-query QueryClient subclass.

TODO when this is merged (I have stacked branchs for these)

  • add new docs
  • refactor all the other tests to use the new methods (can be split up by package)
  • add deprecation tags to old methods

✅ Checklist

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

🚀 Release Impact

  • [x] 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 new imperative query methods (including infinite queries), exported InfiniteQueryExecuteOptions, and a public noop helper.
    • select is supported on the new imperative query paths; fetchQuery/fetchInfiniteQuery continue to ignore select.
  • Chores

    • Package bumps and renamed imperative surface with compatibility wrappers preserved.
  • Tests

    • Expanded coverage for staleTime, infinite paging, prefetching, select interactions, edge cases and typings.

✏️ Tip: You can customize this high-level summary in your review settings.

DogPawHat avatar Nov 01 '25 20:11 DogPawHat

🦋 Changeset detected

Latest commit: bf15113b2ec503d67a659909187148a16afd5af9

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

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

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

changeset-bot[bot] avatar Nov 01 '25 20:11 changeset-bot[bot]

Walkthrough

Adds new imperative execute methods query and infiniteQuery, exports QueryExecuteOptions / InfiniteQueryExecuteOptions, renames FetchInfiniteQueryPagesInfiniteQueryPages, updates typings/tests for select and staleTime, and wires infinite flows through the new execute surface.

Changes

Cohort / File(s) Change Summary
Core Client Implementation
packages/query-core/src/queryClient.ts
Added query and infiniteQuery methods with overloads using QueryExecuteOptions / InfiniteQueryExecuteOptions; infinite flow routed via the new execute surface; updated fetchInfiniteQuery overloads/wrappers.
Public Types & Typings
packages/query-core/src/types.ts
Added QueryExecuteOptions, exported InfiniteQueryExecuteOptions, introduced/renamed InfiniteQueryPages (was FetchInfiniteQueryPages), and updated related FetchInfiniteQueryOptions and type references.
Core Tests & Public Helpers
packages/query-core/src/__tests__/queryClient.test.tsx, packages/query-core/src/__tests__/queryClient.test-d.tsx
Tests updated/expanded for static staleTime, infinite-query scenarios, select behavior, and fully-typed usage; type tests updated to reference InfiniteQueryExecuteOptions; added test import usage of exported noop.
React Type Tests
packages/react-query/src/__tests__/infiniteQueryOptions.test-d.tsx, packages/react-query/src/__tests__/queryOptions.test-d.tsx
Added/updated type assertions validating select behavior across useInfiniteQuery, useSuspenseInfiniteQuery, infiniteQuery, and fetchInfiniteQuery/fetchQuery (select ignored for fetch variants).
Vue Integration
packages/vue-query/src/queryClient.ts
Added query and infiniteQuery overloads (plain and MaybeRefDeep variants) delegating to super with cloneDeepUnref; type signatures updated to match core execute-option types.
Changeset
.changeset/famous-owls-battle.md
Package bumps for @tanstack/react-query, @tanstack/query-core, @tanstack/vue-query; note about renamed imperative methods.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Caller as Caller
    participant QClient as QueryClient
    participant Executor as Execute Core
    participant Cache as Cache / Network
    participant Selector as Select (optional)

    Caller->>QClient: query(opts) / infiniteQuery(opts)
    QClient->>Executor: delegate(QueryExecuteOptions / InfiniteQueryExecuteOptions)
    Executor->>Cache: fetch raw TQueryData or pages
    Cache-->>Executor: raw TQueryData or pages
    alt select provided
        Executor->>Selector: apply select(raw data/pages)
        Selector-->>Executor: transformed TData or pages
    end
    Executor-->>QClient: Promise<TData or InfiniteData>
    QClient-->>Caller: resolved data

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

  • Pay special attention to:
    • packages/query-core/src/types.ts — new generics and renamed pagination types.
    • packages/query-core/src/queryClient.ts — overloads, routing, staleTime/select semantics.
    • packages/query-core/src/__tests__/queryClient.test.tsx and .test-d.tsx — expanded runtime and type coverage.
    • Cross-package typings in packages/vue-query and react type tests.

Suggested reviewers

  • TkDodo

Poem

🐰 I tunneled through types and hopped in delight,
added two paths that now run just right.
Pages bound forward, selects take their cue,
noop waved softly — tests nodded too.
🥕

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Title check ❓ Inconclusive The title 'init query rename and delegation' is vague and generic, using non-descriptive terms that don't clearly convey the main changes (renaming fetchQuery/fetchInfiniteQuery to query/infiniteQuery or the delegation strategy). Use a more specific title like 'Rename fetchQuery/fetchInfiniteQuery to query/infiniteQuery' or 'Implement simplified imperative query methods' to clearly communicate the primary change.
✅ Passed checks (2 passed)
Check name Status Explanation
Description check ✅ Passed The PR description is comprehensive and follows the template structure with filled-out Changes and Checklist sections, clearly documenting the implementation and confirming testing and changeset generation.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • [ ] 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

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 and usage tips.

coderabbitai[bot] avatar Nov 01 '25 20:11 coderabbitai[bot]

View your CI Pipeline Execution ↗ for commit bf15113b2ec503d67a659909187148a16afd5af9

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

☁️ Nx Cloud last updated this comment at 2025-11-27 21:02:53 UTC

nx-cloud[bot] avatar Nov 01 '25 20:11 nx-cloud[bot]

More templates

@tanstack/angular-query-experimental

npm i https://pkg.pr.new/@tanstack/angular-query-experimental@9835
@tanstack/eslint-plugin-query

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

npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@9835
@tanstack/query-broadcast-client-experimental

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

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

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

npm i https://pkg.pr.new/@tanstack/query-persist-client-core@9835
@tanstack/query-sync-storage-persister

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

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

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

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

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

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

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

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

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

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

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

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

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

commit: bf15113

pkg-pr-new[bot] avatar Nov 01 '25 20:11 pkg-pr-new[bot]

renames fetchQuery and fetchInfiniteQuery to query and infiniteQuery

sorry the idea was not to rename those, but to add new methods and deprecate the old ones. Otherwise, this would be a breaking change.

TkDodo avatar Nov 01 '25 20:11 TkDodo

Codecov Report

:x: Patch coverage is 75.00000% with 5 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 59.97%. Comparing base (aba3260) to head (bf15113).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #9835       +/-   ##
===========================================
+ Coverage   45.89%   59.97%   +14.07%     
===========================================
  Files         200      129       -71     
  Lines        8437     5671     -2766     
  Branches     1940     1544      -396     
===========================================
- Hits         3872     3401      -471     
+ Misses       4116     1964     -2152     
+ Partials      449      306      -143     
Components Coverage Δ
@tanstack/angular-query-experimental 93.85% <ø> (ø)
@tanstack/eslint-plugin-query ∅ <ø> (∅)
@tanstack/query-async-storage-persister 43.85% <ø> (ø)
@tanstack/query-broadcast-client-experimental 24.39% <ø> (ø)
@tanstack/query-codemods ∅ <ø> (∅)
@tanstack/query-core 97.35% <93.75%> (-0.04%) :arrow_down:
@tanstack/query-devtools 3.48% <ø> (ø)
@tanstack/query-persist-client-core 80.00% <ø> (ø)
@tanstack/query-sync-storage-persister 84.61% <ø> (ø)
@tanstack/query-test-utils ∅ <ø> (∅)
@tanstack/react-query 96.01% <ø> (ø)
@tanstack/react-query-devtools 9.25% <ø> (ø)
@tanstack/react-query-next-experimental ∅ <ø> (∅)
@tanstack/react-query-persist-client 100.00% <ø> (ø)
@tanstack/solid-query 77.81% <ø> (ø)
@tanstack/solid-query-devtools 64.17% <ø> (ø)
@tanstack/solid-query-persist-client 100.00% <ø> (ø)
@tanstack/svelte-query ∅ <ø> (∅)
@tanstack/svelte-query-devtools ∅ <ø> (∅)
@tanstack/svelte-query-persist-client ∅ <ø> (∅)
@tanstack/vue-query 71.34% <0.00%> (-0.58%) :arrow_down:
@tanstack/vue-query-devtools ∅ <ø> (∅)
:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Nov 01 '25 20:11 codecov[bot]

From #9135:

Per default, this should behave like queryClient.fetchQuery does today:

  • it respects staleTime (like any good query should)
  • it returns a Promise you can await.

fetchQuery is still there, it's just a straight passthough for query now

DogPawHat avatar Nov 01 '25 21:11 DogPawHat

@coderabbitai full review

DogPawHat avatar Nov 27 '25 21:11 DogPawHat

✅ Actions performed

Full review triggered.

coderabbitai[bot] avatar Nov 27 '25 21:11 coderabbitai[bot]