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

Fix sort with pagination and composite fields #9150

Merged

Conversation

Weiko
Copy link
Member

@Weiko Weiko commented Dec 19, 2024

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 the orderBy parameter.
Refactored the code accordingly.

Copy link
Contributor

@greptile-apps greptile-apps bot left a 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 like fullName with nested properties
  • Introduced buildCompositeWhereCondition function in compute-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

Comment on lines +32 to +46
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;
};
Copy link
Contributor

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', () => {
Copy link
Contributor

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

@charlesBochet charlesBochet merged commit 3f58a41 into main Dec 19, 2024
22 checks passed
@charlesBochet charlesBochet deleted the c--fix-sort-by-with-pagination-and-composite-fields branch December 19, 2024 15:41
mdrazak2001 pushed a commit to mdrazak2001/twenty that referenced this pull request Dec 20, 2024
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.
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.

On People object, sorting by name.ascending prevents scrolling
3 participants