Refactor: Move Bounty Filtering & Sorting to Backend (GraphQL)
Overview
Currently, app/bounty/page.tsx performs filtering and sorting of bounties on the client using useMemo. While this works for small datasets, it will not scale efficiently as the number of bounties grows.
To improve performance and scalability, we should move filtering, sorting, and pagination logic to the backend by updating the GraphQL query to accept parameters.
Goals
- Eliminate client-side filtering and sorting
- Move filtering, sorting, and pagination to GraphQL
- Improve performance for large datasets
- Ensure consistent data handling across the app
Implementation Details
1. Update GraphQL Query
Modify: lib/graphql/operations/bounties.graphql
- Update the
bounties query to accept:
- Filter parameters (e.g., status, category, search)
- Sorting options (e.g., date, reward, popularity)
- Pagination arguments (e.g., limit, cursor/page)
- Ensure the backend resolver supports these parameters
2. Update Hook
Modify: hooks/use-bounties.ts
- Pass UI filter state into the GraphQL query variables
- Ensure query re-fetches when filters/sort/pagination change
- Use stable query keys for caching (if using TanStack Query or similar)
3. Refactor Page Logic
Modify: app/bounty/page.tsx
- Remove:
useMemo-based filtering and sorting logic
- Replace with:
- Direct consumption of filtered/sorted data from the API
- Ensure UI controls (filters, sort options) update query parameters correctly
Files Affected
Modified
lib/graphql/operations/bounties.graphql
hooks/use-bounties.ts
app/bounty/page.tsx
Acceptance Criteria
Testing Notes
- Test filtering (e.g., status, category, search)
- Test sorting (e.g., newest, highest reward)
- Validate pagination behavior (infinite scroll or page-based)
- Ensure correct data is fetched when filters change
- Confirm no UI lag with large datasets
Additional Notes
- Use debouncing for search inputs to avoid excessive queries
- Ensure backend indexing supports efficient filtering
- Consider cursor-based pagination for scalability
- Keep query variables structured and predictable for maintainability
Refactor: Move Bounty Filtering & Sorting to Backend (GraphQL)
Overview
Currently,
app/bounty/page.tsxperforms filtering and sorting of bounties on the client usinguseMemo. While this works for small datasets, it will not scale efficiently as the number of bounties grows.To improve performance and scalability, we should move filtering, sorting, and pagination logic to the backend by updating the GraphQL query to accept parameters.
Goals
Implementation Details
1. Update GraphQL Query
Modify:
lib/graphql/operations/bounties.graphqlbountiesquery to accept:2. Update Hook
Modify:
hooks/use-bounties.ts3. Refactor Page Logic
Modify:
app/bounty/page.tsxuseMemo-based filtering and sorting logicFiles Affected
Modified
lib/graphql/operations/bounties.graphqlhooks/use-bounties.tsapp/bounty/page.tsxAcceptance Criteria
Testing Notes
Additional Notes