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

[2/2] Update ApolloPagination usage docs for a 0.2.0 release #317

Merged
merged 5 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -228,14 +228,27 @@ public class GraphQLQueryPager<Model>: Publisher {
}

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

/// Fetches the first page.
public func fetch() {
pager.fetch()
/// - Parameters:
/// - callbackQueue: The `DispatchQueue` that the `completion` fires on. Defaults to `main`.
/// - completion: A completion block that will always trigger after the execution of this operation.
public func fetch(
callbackQueue: DispatchQueue = .main,
completion: (() -> Void)? = nil
) {
pager.fetch(callbackQueue: callbackQueue, completion: completion)
}

/// Resets pagination state and cancels in-flight updates from the pager.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,15 @@ public protocol PagerType {
callbackQueue: DispatchQueue,
completion: ((PaginationError?) -> Void)?
)
func refetch(cachePolicy: CachePolicy)
func fetch()
func refetch(
cachePolicy: CachePolicy,
callbackQueue: DispatchQueue,
completion: (() -> Void)?
)
func fetch(
callbackQueue: DispatchQueue,
completion: (() -> Void)?
)
}

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

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

/// Fetches the first page.
func fetch() {
Task {
await pager.fetch()
/// - Parameters:
/// - callbackQueue: The `DispatchQueue` that the `completion` fires on. Defaults to `main`.
/// - completion: A completion block that will always trigger after the execution of this operation.
func fetch(
callbackQueue: DispatchQueue = .main,
completion: (() -> Void)? = nil
) {
execute(callbackQueue: callbackQueue, completion: { _ in completion?() }) { [weak self] in
await self?.pager.fetch()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,12 @@
},
{
"identifiers" : [
"doc:\/\/ApolloPagination\/documentation\/ApolloPagination\/GraphQLQueryPager\/fetch()",
"doc:\/\/ApolloPagination\/documentation\/ApolloPagination\/GraphQLQueryPager\/fetch(callbackQueue:completion:)",
"doc:\/\/ApolloPagination\/documentation\/ApolloPagination\/GraphQLQueryPager\/loadAll(fetchFromInitialPage:callbackQueue:completion:)",
"doc:\/\/ApolloPagination\/documentation\/ApolloPagination\/GraphQLQueryPager\/loadNext(cachePolicy:callbackQueue:completion:)",
"doc:\/\/ApolloPagination\/documentation\/ApolloPagination\/GraphQLQueryPager\/loadPrevious(cachePolicy:callbackQueue:completion:)",
"doc:\/\/ApolloPagination\/documentation\/ApolloPagination\/GraphQLQueryPager\/receive(subscriber:)",
"doc:\/\/ApolloPagination\/documentation\/ApolloPagination\/GraphQLQueryPager\/refetch(cachePolicy:)",
"doc:\/\/ApolloPagination\/documentation\/ApolloPagination\/GraphQLQueryPager\/refetch(cachePolicy:callbackQueue:completion:)",
"doc:\/\/ApolloPagination\/documentation\/ApolloPagination\/GraphQLQueryPager\/reset()",
"doc:\/\/ApolloPagination\/documentation\/ApolloPagination\/GraphQLQueryPager\/subscribe(completion:)"
],
Expand Down Expand Up @@ -430,7 +430,7 @@
"type" : "topic",
"url" : "\/documentation\/apollopagination\/graphqlquerypager\/cancellables"
},
"doc://ApolloPagination/documentation/ApolloPagination/GraphQLQueryPager/fetch()": {
"doc://ApolloPagination/documentation/ApolloPagination/GraphQLQueryPager/fetch(callbackQueue:completion:)": {
"abstract" : [
{
"text" : "Fetches the first page.",
Expand All @@ -452,15 +452,49 @@
},
{
"kind" : "text",
"text" : "()"
"text" : "("
},
{
"kind" : "externalParam",
"text" : "callbackQueue"
},
{
"kind" : "text",
"text" : ": "
},
{
"kind" : "typeIdentifier",
"preciseIdentifier" : "c:objc(cs)OS_dispatch_queue",
"text" : "DispatchQueue"
},
{
"kind" : "text",
"text" : ", "
},
{
"kind" : "externalParam",
"text" : "completion"
},
{
"kind" : "text",
"text" : ": (() -> "
},
{
"kind" : "typeIdentifier",
"preciseIdentifier" : "s:s4Voida",
"text" : "Void"
},
{
"kind" : "text",
"text" : ")?)"
}
],
"identifier" : "doc:\/\/ApolloPagination\/documentation\/ApolloPagination\/GraphQLQueryPager\/fetch()",
"identifier" : "doc:\/\/ApolloPagination\/documentation\/ApolloPagination\/GraphQLQueryPager\/fetch(callbackQueue:completion:)",
"kind" : "symbol",
"role" : "symbol",
"title" : "fetch()",
"title" : "fetch(callbackQueue:completion:)",
"type" : "topic",
"url" : "\/documentation\/apollopagination\/graphqlquerypager\/fetch()"
"url" : "\/documentation\/apollopagination\/graphqlquerypager\/fetch(callbackqueue:completion:)"
},
"doc://ApolloPagination/documentation/ApolloPagination/GraphQLQueryPager/init(client:initialQuery:watcherDispatchQueue:extractInitialPageInfo:extractNextPageInfo:pageResolver:)": {
"abstract" : [
Expand Down Expand Up @@ -2981,7 +3015,7 @@
"type" : "topic",
"url" : "\/documentation\/apollopagination\/graphqlquerypager\/receive(subscriber:)"
},
"doc://ApolloPagination/documentation/ApolloPagination/GraphQLQueryPager/refetch(cachePolicy:)": {
"doc://ApolloPagination/documentation/ApolloPagination/GraphQLQueryPager/refetch(cachePolicy:callbackQueue:completion:)": {
"abstract" : [
{
"text" : "Discards pagination state and fetches the first page from scratch.",
Expand Down Expand Up @@ -3020,15 +3054,49 @@
},
{
"kind" : "text",
"text" : ")"
"text" : ", "
},
{
"kind" : "externalParam",
"text" : "callbackQueue"
},
{
"kind" : "text",
"text" : ": "
},
{
"kind" : "typeIdentifier",
"preciseIdentifier" : "c:objc(cs)OS_dispatch_queue",
"text" : "DispatchQueue"
},
{
"kind" : "text",
"text" : ", "
},
{
"kind" : "externalParam",
"text" : "completion"
},
{
"kind" : "text",
"text" : ": (() -> "
},
{
"kind" : "typeIdentifier",
"preciseIdentifier" : "s:s4Voida",
"text" : "Void"
},
{
"kind" : "text",
"text" : ")?)"
}
],
"identifier" : "doc:\/\/ApolloPagination\/documentation\/ApolloPagination\/GraphQLQueryPager\/refetch(cachePolicy:)",
"identifier" : "doc:\/\/ApolloPagination\/documentation\/ApolloPagination\/GraphQLQueryPager\/refetch(cachePolicy:callbackQueue:completion:)",
"kind" : "symbol",
"role" : "symbol",
"title" : "refetch(cachePolicy:)",
"title" : "refetch(cachePolicy:callbackQueue:completion:)",
"type" : "topic",
"url" : "\/documentation\/apollopagination\/graphqlquerypager\/refetch(cachepolicy:)"
"url" : "\/documentation\/apollopagination\/graphqlquerypager\/refetch(cachepolicy:callbackqueue:completion:)"
},
"doc://ApolloPagination/documentation/ApolloPagination/GraphQLQueryPager/reset()": {
"abstract" : [
Expand Down
Loading
Loading