[ApolloPagination] Support queued operations #320
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is an experimental change which aims to add support for queued operations.
I'm testing this branch in a sample application here.
This change attempts to address the need for secondary triggers in SwiftUI projects, relevant to my comment here: #317 (comment)
For more information, read the README of my sample under the
Secondary Triggers
known issue.This pull request adds support for queued operations. Each queued operation is setup such that only one queued operation per set of current data can be executed. If, for example, I call
loadNext
rapidly three times while nothing is actively loading, the first call will trigger a pagination load, as before. The second call will queue to be executed after the completion of the first call, but will throw aloadInProgress
error (as before). The third call will behave as it did before: by only throwing the error. Once the first call is complete, the second pagination fetch will execute.I am using the current data state to disambiguate these fetches. That does mean that 3 calls to loadNext and 3 calls to loadPrevious will queue both a loadPrevious and a loadNext.
🤖 Copilot Generated 🤖
This pull request primarily focuses on improving the functionality of the
AsyncGraphQLQueryPagerCoordinator
in theapollo-ios-pagination
package. The changes include the introduction of anOperation
enum and aqueuedOperations
property to handle and queue operations, and modifications to theloadNext
,loadPrevious
, andreset
methods to execute these queued operations. Additionally, thepaginationFetch
method has been updated to handle pagination errors and queue operations accordingly.Here are the most important changes:
apollo-ios-pagination/Sources/ApolloPagination/AsyncGraphQLQueryPagerCoordinator.swift
: AnOperation
enum has been introduced within theAsyncGraphQLQueryPagerCoordinator
actor that includes two cases:loadNext
andloadPrevious
. Each case can hold aCachePolicy
and aPaginatedQuery
.apollo-ios-pagination/Sources/ApolloPagination/AsyncGraphQLQueryPagerCoordinator.swift
: A new propertyqueuedOperations
of typeOrderedSet<Operation>
has been added to store the operations to be executed.apollo-ios-pagination/Sources/ApolloPagination/AsyncGraphQLQueryPagerCoordinator.swift
: TheloadPrevious
andloadNext
methods now include a call toexecuteQueuedOperations
after thepaginationFetch
call. This ensures that any queued operations are executed after a page load operation. [1] [2]apollo-ios-pagination/Sources/ApolloPagination/AsyncGraphQLQueryPagerCoordinator.swift
: Thereset
method now clears all queued operations.apollo-ios-pagination/Sources/ApolloPagination/AsyncGraphQLQueryPagerCoordinator.swift
: ThepaginationFetch
method has been updated to queue operations in case of aloadInProgress
ormissingInitialPage
error. A new private method_paginationFetch
has been introduced to handle the actual fetch operation.apollo-ios-pagination/Sources/ApolloPagination/AsyncGraphQLQueryPagerCoordinator.swift
: A new methodexecuteQueuedOperations
has been introduced to execute all operations in the queue sequentially and then clear the queue.