Skip to content

Conversation

@Dprof-in-tech
Copy link
Contributor

@Dprof-in-tech Dprof-in-tech commented Jan 25, 2026

This pull request introduces a comprehensive query management system for bounties using React Query. The changes modularize query key generation, query option factories, and prefetch utilities, making it easier to fetch, cache, and prefetch bounty data throughout the application.

Query Key Management:

  • Added a hierarchical query key factory bountyKeys in query-keys.ts for granular cache control of bounty lists and details. Also exported a type helper for query keys.

Query Option Factories:

  • Implemented reusable query option functions in bounty-queries.ts for listing bounties (bountyListQueryOptions), fetching single bounty details (bountyDetailQueryOptions), and paginated/infinite queries (bountyInfiniteQueryOptions). Added a helper to flatten paginated results.

Prefetch Utilities:

  • Added functions in prefetch.ts to create a new QueryClient per request, and to prefetch bounty lists, details, and multiple bounties for server-side rendering or data hydration.

Centralized Exports:

  • Updated index.ts to re-export all query keys, query option factories, and prefetch utilities for easy import throughout the codebase.

closes #27

Summary by CodeRabbit

  • New Features
    • Added client-side query helpers for bounty lists, individual bounty details, infinite pagination, and a helper to flatten paginated results.
    • Introduced typed query-key utilities for consistent cache keys and smart invalidation.
    • Added server-friendly prefetch utilities and a routine to create a query client to prefetch single or multiple bounties for faster page loads.

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

…ery options, keys, and prefetching utilities.
@coderabbitai
Copy link

coderabbitai bot commented Jan 25, 2026

📝 Walkthrough

Walkthrough

Adds a React Query layer for bounties: a typed query-key factory, query option helpers for list/detail/infinite fetches (including a pages-flatten utility), and server-friendly prefetch utilities with a fresh QueryClient factory.

Changes

Cohort / File(s) Summary
Query Key Factory
lib/query/query-keys.ts
Adds bountyKeys with hierarchical keys (all, lists, list, infinite, details, detail) and exports BountyQueryKey type.
Query Option Helpers
lib/query/bounty-queries.ts
New React Query option creators: bountyListQueryOptions(params?), bountyDetailQueryOptions(id) (enabled when id non-empty), bountyInfiniteQueryOptions(params?) (infinite pagination, default limit 20), and flattenBountyPages(pages).
Prefetch Utilities
lib/query/prefetch.ts
New server-component friendly utilities: createQueryClient() (staleTime=60s), prefetchBountyList(), prefetchBounty(), and prefetchBounties() (parallel prefetch).
Public Exports
lib/query/index.ts
Re-exports bountyKeys, query option helpers, prefetch utilities, and related types for unified access.

Sequence Diagram(s)

sequenceDiagram
  participant Server as "Server Component"
  participant QC as "QueryClient"
  participant API as "bountiesApi"

  Server->>QC: createQueryClient()
  Server->>QC: prefetchQuery(bountyListQueryOptions(params))
  QC->>API: call bountiesApi.list(params page/limit)
  API-->>QC: PaginatedResponse<Bounty>
  QC-->>Server: cache populated
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐰 I hopped through keys and queries bright,
Prefetched bounties in the night,
Pages flattened, caches warmed anew,
QueryClient hummed — the data flew,
A joyful hop — this rabbit cheers for you!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: introducing TanStack Query integration with query options, keys, and prefetching utilities for bounties.
Linked Issues check ✅ Passed All coding objectives from issue #27 are met: hierarchical query key factory created, query option functions implemented, prefetch utilities added, and centralized exports configured.
Out of Scope Changes check ✅ Passed All changes directly support the bounty query management system objectives; no unrelated modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In `@lib/query/prefetch.ts`:
- Around line 32-37: prefetchBounty currently calls queryClient.prefetchQuery
with bountyDetailQueryOptions(id) even when id is empty (enabled flag is ignored
by prefetchQuery), so add a guard at the top of prefetchBounty to return early
when id is falsy/empty; keep the function signature and simply do if (!id)
return; before calling queryClient.prefetchQuery (reference prefetchBounty and
bountyDetailQueryOptions to locate the code).

In `@lib/query/query-keys.ts`:
- Around line 22-23: BountyQueryKey currently only includes ReturnType<typeof
bountyKeys.list | typeof bountyKeys.detail> but the codebase also uses
bountyKeys.infinite; update the union to include that variant (e.g.
ReturnType<typeof bountyKeys.list | typeof bountyKeys.detail | typeof
bountyKeys.infinite>) so the type covers all active bountyKeys variants used
(referencing bountyKeys and BountyQueryKey to locate the change).

@0xdevcollins 0xdevcollins merged commit ef3725f into boundlessfi:main Jan 25, 2026
2 checks passed
@coderabbitai coderabbitai bot mentioned this pull request Jan 26, 2026
5 tasks
DanielEmmanuel1 pushed a commit to DanielEmmanuel1/bounties that referenced this pull request Jan 26, 2026
…y-keys-and-query-functions

feat: introduce TanStack Query integration for bounties, including query options, keys, and prefetching utilities.
@coderabbitai coderabbitai bot mentioned this pull request Jan 31, 2026
21 tasks
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.

Implement Query Keys and Query Functions

2 participants