From 6e4cf80f0482adc7208d3a713a6a35947a6e714d Mon Sep 17 00:00:00 2001 From: Hesham Salman Date: Wed, 14 Feb 2024 17:08:44 -0500 Subject: [PATCH] one more init --- .../AsyncGraphQLQueryPager.swift | 32 +++++++++++++------ .../ApolloPagination/GraphQLQueryPager.swift | 30 +++++++++++------ 2 files changed, 44 insertions(+), 18 deletions(-) diff --git a/apollo-ios-pagination/Sources/ApolloPagination/AsyncGraphQLQueryPager.swift b/apollo-ios-pagination/Sources/ApolloPagination/AsyncGraphQLQueryPager.swift index 227e6c52b..87c1a74c0 100644 --- a/apollo-ios-pagination/Sources/ApolloPagination/AsyncGraphQLQueryPager.swift +++ b/apollo-ios-pagination/Sources/ApolloPagination/AsyncGraphQLQueryPager.swift @@ -80,15 +80,6 @@ public class AsyncGraphQLQueryPager: 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, @@ -136,6 +127,29 @@ public class AsyncGraphQLQueryPager: Publisher { } } + public convenience init< + P: PaginationInfo, + InitialQuery: GraphQLQuery, + PaginatedQuery: GraphQLQuery + >( + client: ApolloClientProtocol, + initialQuery: InitialQuery, + watcherDispatchQueue: DispatchQueue = .main, + extractPageInfo: @escaping (PageExtractionData) -> P, + pageResolver: ((P, PaginationDirection) -> PaginatedQuery?)? + ) async where Model == PaginationOutput { + 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, diff --git a/apollo-ios-pagination/Sources/ApolloPagination/GraphQLQueryPager.swift b/apollo-ios-pagination/Sources/ApolloPagination/GraphQLQueryPager.swift index cde5e8c0e..78a4afa57 100644 --- a/apollo-ios-pagination/Sources/ApolloPagination/GraphQLQueryPager.swift +++ b/apollo-ios-pagination/Sources/ApolloPagination/GraphQLQueryPager.swift @@ -71,15 +71,27 @@ public class GraphQLQueryPager: 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) -> P, + pageResolver: ((P, PaginationDirection) -> PaginatedQuery?)? + ) where Model == PaginationOutput { + let pager = GraphQLQueryPagerCoordinator( + client: client, + initialQuery: initialQuery, + watcherDispatchQueue: watcherDispatchQueue, + extractPageInfo: extractPageInfo, + pageResolver: pageResolver + ) + self.init(pager: pager) + } + public convenience init< P: PaginationInfo, InitialQuery: GraphQLQuery,