Skip to content

Conversation

@0xlakshan
Copy link
Contributor

@0xlakshan 0xlakshan commented Sep 13, 2025

Description

Added a new select option to QueryCollectionConfig that lets developers extract item arrays from wrapped API responses (e.g., with pagination or metadata) while preserving the full response in the TanStack Query cache.

Changes

  • Added select field to QueryCollectionConfig interface
  • In addition to updating the core interface as the issue suggests, i've added two more function overloads, since the code structure was recently updated with use of overloads. to maintain the consistency & strong type inference (Refactoring of the types for collection configurations #530)
  • Updated internal sync logic to apply select before processing query results

Todo

  • Test that select properly extracts array from wrapped response
  • Test error handling when select returns non-array
  • Test that full response is cached in QueryClient
  • Test type inference with select option
  • Test that mutations still work correctly

Related Issue - #345

@changeset-bot
Copy link

changeset-bot bot commented Sep 13, 2025

🦋 Changeset detected

Latest commit: 9eb0135

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

This PR includes changesets to release 2 packages
Name Type
@tanstack/query-db-collection Patch
@tanstack/db-example-react-todo 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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Sep 13, 2025

More templates

@tanstack/angular-db

npm i https://pkg.pr.new/@tanstack/angular-db@551

@tanstack/db

npm i https://pkg.pr.new/@tanstack/db@551

@tanstack/db-ivm

npm i https://pkg.pr.new/@tanstack/db-ivm@551

@tanstack/electric-db-collection

npm i https://pkg.pr.new/@tanstack/electric-db-collection@551

@tanstack/query-db-collection

npm i https://pkg.pr.new/@tanstack/query-db-collection@551

@tanstack/react-db

npm i https://pkg.pr.new/@tanstack/react-db@551

@tanstack/rxdb-db-collection

npm i https://pkg.pr.new/@tanstack/rxdb-db-collection@551

@tanstack/solid-db

npm i https://pkg.pr.new/@tanstack/solid-db@551

@tanstack/svelte-db

npm i https://pkg.pr.new/@tanstack/svelte-db@551

@tanstack/trailbase-db-collection

npm i https://pkg.pr.new/@tanstack/trailbase-db-collection@551

@tanstack/vue-db

npm i https://pkg.pr.new/@tanstack/vue-db@551

commit: 9eb0135

@0xlakshan 0xlakshan marked this pull request as ready for review September 17, 2025 15:31
@0xlakshan
Copy link
Contributor Author

Hi @KyleAMathews @samwillis would you mind taking a quick look at my PR ? im open to any feedback you might have

Copy link
Collaborator

@samwillis samwillis left a comment

Choose a reason for hiding this comment

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

Thanks @0xlakshan, this is great and perfectly matches the proposed design from @KyleAMathews. A couple of other inline comments along with:

  • I don't suppose you could add the option to the docs in docs/collections/query-collection.md?

  • It also needs a changeset - run pnpm changeset repo root and follow the instructions. This would be a patch release at this point.

@0xlakshan
Copy link
Contributor Author

All done! @samwillis , thanks for the feedback

@0xlakshan 0xlakshan requested a review from samwillis September 28, 2025 11:58
KyleAMathews and others added 2 commits September 29, 2025 19:05
- Enhanced error messages to include package name, error type, received value type, and queryKey for easier debugging
- Added negative type test to verify TypeScript catches wrapped response data without select function
- Updated existing runtime tests to handle improved error messaging
- Fixed eslint warnings for unnecessary conditions

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Collaborator

@KyleAMathews KyleAMathews left a comment

Choose a reason for hiding this comment

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

Great work! Thanks for taking this on! Sorry for the delay getting it merged 🙏

@KyleAMathews KyleAMathews merged commit 271960d into TanStack:main Sep 30, 2025
6 checks passed
@github-actions github-actions bot mentioned this pull request Sep 29, 2025
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.

3 participants