Skip to content

Move Bounty Filtering and Sorting to Server-Side (GraphQL) #126

@Benjtalkshow

Description

@Benjtalkshow

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

  • No client-side filtering or sorting logic remains
  • GraphQL query supports filter, sort, and pagination arguments
  • UI interactions correctly update query variables
  • Data returned from API reflects applied filters and sorting
  • Performance improves with large datasets
  • No regressions in bounty listing functionality

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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions