Skip to content

Commit 38a7c73

Browse files
gh-action-runnergh-action-runner
authored andcommitted
Squashed 'apollo-ios-pagination/' changes from ec5e1c0b..d8ddfdbc
d8ddfdbc [ApolloPagination] Add completion callbacks to fetch and refetch in GraphQLQueryPager for API Consistency (#292) git-subtree-dir: apollo-ios-pagination git-subtree-split: d8ddfdbc22d8cd1515a7e8288498e1056850d7f8
1 parent 98627e6 commit 38a7c73

File tree

2 files changed

+47
-13
lines changed

2 files changed

+47
-13
lines changed

Sources/ApolloPagination/GraphQLQueryPager.swift

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,14 +228,27 @@ public class GraphQLQueryPager<Model>: Publisher {
228228
}
229229

230230
/// Discards pagination state and fetches the first page from scratch.
231-
/// - Parameter cachePolicy: The apollo cache policy to trigger the first fetch with. Defaults to `fetchIgnoringCacheData`.
232-
public func refetch(cachePolicy: CachePolicy = .fetchIgnoringCacheData) {
233-
pager.refetch(cachePolicy: cachePolicy)
231+
/// - Parameters:
232+
/// - cachePolicy: The apollo cache policy to trigger the first fetch with. Defaults to `fetchIgnoringCacheData`.
233+
/// - callbackQueue: The `DispatchQueue` that the `completion` fires on. Defaults to `main`.
234+
/// - completion: A completion block that will always trigger after the execution of this operation.
235+
public func refetch(
236+
cachePolicy: CachePolicy = .fetchIgnoringCacheData,
237+
callbackQueue: DispatchQueue = .main,
238+
completion: (() -> Void)? = nil
239+
) {
240+
pager.refetch(cachePolicy: cachePolicy, callbackQueue: callbackQueue, completion: completion)
234241
}
235242

236243
/// Fetches the first page.
237-
public func fetch() {
238-
pager.fetch()
244+
/// - Parameters:
245+
/// - callbackQueue: The `DispatchQueue` that the `completion` fires on. Defaults to `main`.
246+
/// - completion: A completion block that will always trigger after the execution of this operation.
247+
public func fetch(
248+
callbackQueue: DispatchQueue = .main,
249+
completion: (() -> Void)? = nil
250+
) {
251+
pager.fetch(callbackQueue: callbackQueue, completion: completion)
239252
}
240253

241254
/// Resets pagination state and cancels in-flight updates from the pager.

Sources/ApolloPagination/GraphQLQueryPagerCoordinator.swift

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,15 @@ public protocol PagerType {
2525
callbackQueue: DispatchQueue,
2626
completion: ((PaginationError?) -> Void)?
2727
)
28-
func refetch(cachePolicy: CachePolicy)
29-
func fetch()
28+
func refetch(
29+
cachePolicy: CachePolicy,
30+
callbackQueue: DispatchQueue,
31+
completion: (() -> Void)?
32+
)
33+
func fetch(
34+
callbackQueue: DispatchQueue,
35+
completion: (() -> Void)?
36+
)
3037
}
3138

3239
/// Handles pagination in the queue by managing multiple query watchers.
@@ -151,9 +158,17 @@ class GraphQLQueryPagerCoordinator<InitialQuery: GraphQLQuery, PaginatedQuery: G
151158
}
152159

153160
/// Discards pagination state and fetches the first page from scratch.
154-
/// - Parameter cachePolicy: The apollo cache policy to trigger the first fetch with. Defaults to `fetchIgnoringCacheData`.
155-
func refetch(cachePolicy: CachePolicy = .fetchIgnoringCacheData) {
156-
Task {
161+
/// - Parameters:
162+
/// - cachePolicy: The apollo cache policy to trigger the first fetch with. Defaults to `fetchIgnoringCacheData`.
163+
/// - callbackQueue: The `DispatchQueue` that the `completion` fires on. Defaults to `main`.
164+
/// - completion: A completion block that will always trigger after the execution of this operation.
165+
func refetch(
166+
cachePolicy: CachePolicy = .fetchIgnoringCacheData,
167+
callbackQueue: DispatchQueue = .main,
168+
completion: (() -> Void)? = nil
169+
) {
170+
execute(callbackQueue: callbackQueue, completion: { _ in completion?() }) { [weak self] in
171+
guard let self else { return }
157172
for completion in await self.completionManager.completions {
158173
completion.execute(error: PaginationError.cancellation)
159174
}
@@ -162,9 +177,15 @@ class GraphQLQueryPagerCoordinator<InitialQuery: GraphQLQuery, PaginatedQuery: G
162177
}
163178

164179
/// Fetches the first page.
165-
func fetch() {
166-
Task {
167-
await pager.fetch()
180+
/// - Parameters:
181+
/// - callbackQueue: The `DispatchQueue` that the `completion` fires on. Defaults to `main`.
182+
/// - completion: A completion block that will always trigger after the execution of this operation.
183+
func fetch(
184+
callbackQueue: DispatchQueue = .main,
185+
completion: (() -> Void)? = nil
186+
) {
187+
execute(callbackQueue: callbackQueue, completion: { _ in completion?() }) { [weak self] in
188+
await self?.pager.fetch()
168189
}
169190
}
170191

0 commit comments

Comments
 (0)