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

Follow-up from https://github.com/apollographql/apollo-ios-dev/pull/267 #2308

Open
hankqqu opened this issue Feb 19, 2024 · 0 comments
Open

Comments

@hankqqu
Copy link

hankqqu commented Feb 19, 2024

Follow-up from apollographql/apollo-ios-dev#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:

  • Tests/ApolloPaginationTests/AsyncGraphQLQueryPagerCoordinatorTests.swift: The extractPageInfo function in AsyncGraphQLQueryPagerCoordinatorTests has been updated to handle both initial and paginated data. [1] [2]
  • Tests/ApolloPaginationTests/GraphQLQueryPagerTests.swift: The extractPageInfo function in GraphQLQueryPagerTests has been updated to handle both initial and paginated data. [1] [2]
  • Tests/ApolloPaginationTests/GraphQLQueryPagerTestsCoordinator.swift: The extractPageInfo function in GraphQLQueryPagerTestsCoordinator has been updated to handle both initial and paginated data.
  • Tests/ApolloPaginationTests/ReversePaginationTests.swift: The extractPageInfo function in ReversePaginationTests has been updated to handle both initial and paginated data.

Addition of new test:

  • Tests/ApolloPaginationTests/OffsetTests.swift: A new test file OffsetTests.swift was added to test the handling of offset pagination.

Originally posted by @Iron-Ham in apollographql/apollo-ios-dev#268

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

No branches or pull requests

1 participant