Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom ordering in pagination #34

Closed
gearnode opened this issue Mar 18, 2025 · 0 comments
Closed

Support custom ordering in pagination #34

gearnode opened this issue Mar 18, 2025 · 0 comments
Assignees
Labels
complexity: hard Complex changes, requires deep knowledge component:api Related to API functionality component:database Related to database operations priority:high High priority, should be addressed soon

Comments

@gearnode
Copy link
Contributor

gearnode commented Mar 18, 2025

Currently, pagination is restricted to ordering by created_at. We aim to enhance this functionality by supporting custom ordering fields such as name, updated_at, status, etc.

Proposed Changes

1. GraphQL Schema Update

We will extend the GraphQL schema to support custom ordering. Below is an example of the updated GraphQL definition:

   enum OrderDirection {
     ASC
     DESC
   }

   enum PeopleOrderField {
     CREATED_AT
     NAME
     UPDATED_AT
     STATUS
   }

   input OrganizationOrder {
     direction: OrderDirection!
     field: PeopleOrderField!
   }

   type User implements Node {
     organizations(first: Int, last: Int, before: CursorKey, after: CursorKey, orderBy: OrganizationOrder)
   }

   type Query {
     viewer: User!
   }

2. Page package and cursor key implementation

  • CursorKey:
    Transition from custom binary encoding to a JSON array. This change is necessary because the cursor key must now accommodate variable sizes, storing not only the ID and timestamp but also a custom value based on the chosen ordering field.

  • Cursor:
    The SQL fragment generated by the cursor should be dynamic. It must incorporate the field name and field value, replacing the hardcoded created_at.
    The SQL should consider the orderBy direction and position, rather than relying solely on position for determining the order.

@gearnode gearnode added complexity: hard Complex changes, requires deep knowledge component:api Related to API functionality component:database Related to database operations priority:high High priority, should be addressed soon status:in-progress Work is currently in progress labels Mar 18, 2025
@gearnode gearnode self-assigned this Mar 18, 2025
@gearnode gearnode removed the status:in-progress Work is currently in progress label Mar 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
complexity: hard Complex changes, requires deep knowledge component:api Related to API functionality component:database Related to database operations priority:high High priority, should be addressed soon
Projects
None yet
Development

No branches or pull requests

1 participant