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

[ApolloPagination] Remove convenience functions, improved Offset-pagination support #268

Merged
merged 7 commits into from
Feb 16, 2024

Conversation

Iron-Ham
Copy link
Contributor

@Iron-Ham Iron-Ham commented Feb 14, 2024

Follow-up from #267


When writing docs in #262, I recognized that support for offset pagination could be better. Specifically:

  • We can support more paging types (reverse, bidirectional)
  • We can support multi-query paging.

As such, this pull request modifies the OffsetPagination class to be a namespace, just like CursorBasedPagination. We introduce three new structs to facilitate pagination:

  • OffsetPagination.Forward: Introduced OffsetPagination.Forward structure to represent a forward pagination state. This is identical to the previous contents of OffsetPagination.
  • OffsetPagination.Reverse: Introduced OffsetPagination.Reverse structure to represent a reverse pagination state.
  • OffsetPagination.Bidirectional: Introduced OffsetPagination.Bidirectional structure to represent a bidirectional pagination state.

Once introduced, I added tests to use an offset pagination scheme.
The tests made clear that offset-pagination needs the full set of existing data in order to properly determine whether the end of the list had been reached.

As a result, there were changes to the PageExtractionData type to include an additional value. Classes and tests were updated accordingly.

Finally, we generalized and deleted the many convenience functions present – we are working under the assumption that if a user is primarily only using one pagination type, that they can trivially create their own extension. In order to facilitate the user adding their own extensions, two new initializers were added to both GraphQLQueryPager and AsyncGraphQLQueryPager.


🤖🤖 Copilot Generated Summary 🤖🤖

This pull request includes changes to the ApolloPaginationTests in the Apollo iOS SDK. The changes focus on modifying the way the AsyncGraphQLQueryPager is created and how it handles pagination, as well as updating the extractPageInfo function in multiple test classes.

Here are the most important changes:

Changes to AsyncGraphQLQueryPager creation:

  • Tests/ApolloPaginationTests/AsyncGraphQLQueryPagerTests.swift: The AsyncGraphQLQueryPager is now created with makeQueryPager instead of makeForwardCursorQueryPager. The queryProvider has been replaced with an initialQuery and a closure that provides a new query based on the page and direction. This allows for the handling of both next and previous pages. The extractPageInfo function has also been updated to handle both initial and paginated data. [1] [2] [3] [4]

Changes to extractPageInfo function:

Addition of new test:

@Iron-Ham Iron-Ham requested a review from a team as a code owner February 14, 2024 22:00
Copy link

netlify bot commented Feb 14, 2024

👷 Deploy request for eclectic-pie-88a2ba pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit aaf0f82

Copy link
Contributor

@AnthonyMDev AnthonyMDev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@AnthonyMDev AnthonyMDev merged commit 2c54238 into apollographql:main Feb 16, 2024
14 checks passed
BobaFetters pushed a commit that referenced this pull request Feb 16, 2024
BobaFetters pushed a commit to apollographql/apollo-ios-pagination that referenced this pull request Feb 16, 2024
BobaFetters pushed a commit that referenced this pull request Feb 16, 2024
c762dcf0 [ApolloPagination] Remove convenience functions, improved Offset-pagination support (#268)

git-subtree-dir: apollo-ios-pagination
git-subtree-split: c762dcf0e62508e9b54163e854fbfb257f63feda
BobaFetters pushed a commit that referenced this pull request Feb 16, 2024
…nvenience functions, improved Offset-pagination support

git-subtree-dir: apollo-ios-pagination
git-subtree-mainline: 637a4ad
git-subtree-split: c762dcf0e62508e9b54163e854fbfb257f63feda
@hankqqu
Copy link

hankqqu commented Feb 19, 2024

Follow-up from #267


When writing docs in #262, I recognized that support for offset pagination could be better. Specifically:

  • We can support more paging types (reverse, bidirectional)

  • We can support multi-query paging.

As such, this pull request modifies the OffsetPagination class to be a namespace, just like CursorBasedPagination. We introduce three new structs to facilitate pagination:

  • OffsetPagination.Forward: Introduced OffsetPagination.Forward structure to represent a forward pagination state. This is identical to the previous contents of OffsetPagination.

  • OffsetPagination.Reverse: Introduced OffsetPagination.Reverse structure to represent a reverse pagination state.

  • OffsetPagination.Bidirectional: Introduced OffsetPagination.Bidirectional structure to represent a bidirectional pagination state.

Once introduced, I added tests to use an offset pagination scheme.

The tests made clear that offset-pagination needs the full set of existing data in order to properly determine whether the end of the list had been reached.

As a result, there were changes to the PageExtractionData type to include an additional value. Classes and tests were updated accordingly.

Finally, we generalized and deleted the many convenience functions present – we are working under the assumption that if a user is primarily only using one pagination type, that they can trivially create their own extension. In order to facilitate the user adding their own extensions, two new initializers were added to both GraphQLQueryPager and AsyncGraphQLQueryPager.


🤖🤖 Copilot Generated Summary 🤖🤖

This pull request includes changes to the ApolloPaginationTests in the Apollo iOS SDK. The changes focus on modifying the way the AsyncGraphQLQueryPager is created and how it handles pagination, as well as updating the extractPageInfo function in multiple test classes.

Here are the most important changes:

Changes to AsyncGraphQLQueryPager creation:

  • Tests/ApolloPaginationTests/AsyncGraphQLQueryPagerTests.swift: The AsyncGraphQLQueryPager is now created with makeQueryPager instead of makeForwardCursorQueryPager. The queryProvider has been replaced with an initialQuery and a closure that provides a new query based on the page and direction. This allows for the handling of both next and previous pages. The extractPageInfo function has also been updated to handle both initial and paginated data. [1] [2] [3] [4]

Changes to extractPageInfo function:

Addition of new test:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants