Skip to content

Commit

Permalink
one more init
Browse files Browse the repository at this point in the history
  • Loading branch information
Iron-Ham committed Feb 14, 2024
1 parent 06e5572 commit 6e4cf80
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,6 @@ public class AsyncGraphQLQueryPager<Model>: Publisher {
)
}

/// For most use-cases, it's recommended to use the static `make...` functions instead of this initializer.
/// - Parameters:
/// - client: The Apollo client
/// - initialQuery: The initial query to be performed.
/// - watcherDispatchQueue: The queue that the internal `GraphQLQueryWatcher`s dispatch their results to. Defaults to `main`.
/// - extractPageInfo: This transforming function extracts a `PaginationInfo` from either `InitialQuery.Data` or `PaginatedQuery.Data`, represented in the form of `PageExtractionData`.
/// - pageResolver: This transforming function initializes a new `PaginatedQuery` given a `PagiantionInfo` and `PaginationDirection`.
/// - initialTransform: Transforms the `InitialQuery.Data` to a `Model` type.
/// - pageTransform: Transforms the `PaginatedQuery.Data` to a `Model` type.
public convenience init<
P: PaginationInfo,
InitialQuery: GraphQLQuery,
Expand Down Expand Up @@ -136,6 +127,29 @@ public class AsyncGraphQLQueryPager<Model>: Publisher {
}
}

public convenience init<
P: PaginationInfo,
InitialQuery: GraphQLQuery,
PaginatedQuery: GraphQLQuery
>(
client: ApolloClientProtocol,
initialQuery: InitialQuery,
watcherDispatchQueue: DispatchQueue = .main,
extractPageInfo: @escaping (PageExtractionData<InitialQuery, PaginatedQuery, Model?>) -> P,
pageResolver: ((P, PaginationDirection) -> PaginatedQuery?)?
) async where Model == PaginationOutput<InitialQuery, PaginatedQuery> {
let pager = AsyncGraphQLQueryPagerCoordinator(
client: client,
initialQuery: initialQuery,
watcherDispatchQueue: watcherDispatchQueue,
extractPageInfo: extractPageInfo,
pageResolver: pageResolver
)
await self.init(
pager: pager
)
}

public convenience init<
P: PaginationInfo,
InitialQuery: GraphQLQuery,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,27 @@ public class GraphQLQueryPager<Model>: Publisher {
)
}

/// For most use-cases, it's recommended to use the static `make...` functions instead of this initializer.
/// - Parameters:
/// - client: The Apollo client
/// - initialQuery: The initial query to be performed.
/// - watcherDispatchQueue: The queue that the internal `GraphQLQueryWatcher`s dispatch their results to. Defaults to `main`.
/// - extractPageInfo: This transforming function extracts a `PaginationInfo` from either `InitialQuery.Data` or `PaginatedQuery.Data`, represented in the form of `PageExtractionData`.
/// - pageResolver: This transforming function initializes a new `PaginatedQuery` given a `PagiantionInfo` and `PaginationDirection`.
/// - initialTransform: Transforms the `InitialQuery.Data` to a `Model` type.
/// - pageTransform: Transforms the `PaginatedQuery.Data` to a `Model` type.
public convenience init<
P: PaginationInfo,
InitialQuery: GraphQLQuery,
PaginatedQuery: GraphQLQuery
>(
client: ApolloClientProtocol,
initialQuery: InitialQuery,
watcherDispatchQueue: DispatchQueue = .main,
extractPageInfo: @escaping (PageExtractionData<InitialQuery, PaginatedQuery, Model?>) -> P,
pageResolver: ((P, PaginationDirection) -> PaginatedQuery?)?
) where Model == PaginationOutput<InitialQuery, PaginatedQuery> {
let pager = GraphQLQueryPagerCoordinator(
client: client,
initialQuery: initialQuery,
watcherDispatchQueue: watcherDispatchQueue,
extractPageInfo: extractPageInfo,
pageResolver: pageResolver
)
self.init(pager: pager)
}

public convenience init<
P: PaginationInfo,
InitialQuery: GraphQLQuery,
Expand Down

0 comments on commit 6e4cf80

Please sign in to comment.