-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Fix sort with pagination and composite fields #9150
Fix sort with pagination and composite fields #9150
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
Implemented cursor-based pagination improvements for composite fields in the GraphQL API, focusing on proper handling of nested sorting structures and pagination direction.
- Added support for nested sorting in
ObjectRecordOrderBy
type to handle composite fields likefullName
with nested properties - Introduced
buildCompositeWhereCondition
function incompute-cursor-arg-filter.ts
for proper handling of composite field pagination - Added validation logic in
validateAndGetOrderBy
to ensure proper orderBy parameters for cursor-based queries - Added comprehensive test suite in
compute-cursor-arg-filter.spec.ts
covering composite field pagination scenarios - Fixed ascending/descending order determination for nested properties in composite fields
3 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings | Greptile
const validateAndGetOrderBy = ( | ||
key: string, | ||
orderBy: ObjectRecordOrderBy, | ||
): Record<string, any> => { | ||
const keyOrderBy = orderBy.find((order) => key in order); | ||
|
||
if (!keyOrderBy) { | ||
throw new GraphqlQueryRunnerException( | ||
'Invalid cursor', | ||
GraphqlQueryRunnerExceptionCode.INVALID_CURSOR, | ||
); | ||
} | ||
|
||
return keyOrderBy; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Consider caching the orderBy lookup result to avoid repeated array searches in a loop
}); | ||
}); | ||
|
||
describe('composite field handling', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
logic: Missing test case for backward pagination with composite fields - current test only verifies forward pagination
Fixes twentyhq#8863 ## Description This PR fixes an issue with cursor-based pagination when dealing with composite fields (like `fullName`). Previously, the pagination direction was incorrectly determined for composite fields because the code wasn't properly handling nested object structures in the `orderBy` parameter. Refactored the code accordingly.
Fixes #8863
Description
This PR fixes an issue with cursor-based pagination when dealing with composite fields (like
fullName
). Previously, the pagination direction was incorrectly determined for composite fields because the code wasn't properly handling nested object structures in theorderBy
parameter.Refactored the code accordingly.