Skip to content

Commit

Permalink
Make KeyPaths optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Iron-Ham committed May 26, 2023
1 parent c76914d commit 1492973
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions Sources/Apollo/RelayPageExtractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ public struct RelayPageExtractor<Query: GraphQLQuery>: PageExtractionStrategy {
/// - Parameters:
/// - hasNextPagePath: A `KeyPath` over a `Query.Data` which identifies the `hasNextPage` key within the `Query.Data`.
/// - endCursorPath: A `KeyPath` over a `Query.Data` which identifies the `endCursor` key within the `Query.Data`.
public init(hasNextPagePath: KeyPath<Query.Data, Bool>, endCursorPath: KeyPath<Query.Data, String?>) {
public init(
hasNextPagePath: KeyPath<Query.Data, Bool>?,
endCursorPath: KeyPath<Query.Data, String?>?
) {
_transform = { data in
Page(
hasNextPage: data[keyPath: hasNextPagePath],
endCursor: data[keyPath: endCursorPath]
hasNextPage: hasNextPagePath.flatMap { data[keyPath: $0] } ?? false,
endCursor: endCursorPath.flatMap { data[keyPath: $0] }
)
}
}
Expand Down

0 comments on commit 1492973

Please sign in to comment.