Skip to content

Commit

Permalink
Inlinables
Browse files Browse the repository at this point in the history
  • Loading branch information
Iron-Ham committed May 31, 2023
1 parent 1492973 commit ec9ab16
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 25 deletions.
6 changes: 3 additions & 3 deletions Sources/Apollo/CustomDataTransformer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,18 @@ import ApolloAPI
/// Can be used to output a custom type, or can be used for fine grain control over how a `Query.Data` is merged.
public struct CustomDataTransformer<Query: GraphQLQuery, Output: Hashable>: DataTransformer {

private let _transform: (Query.Data) -> Output?
@usableFromInline let _transform: (Query.Data) -> Output?

/// Designated intializer
/// - Parameter transform: A user provided function which can transform a given network response into any `Hashable` output.
public init(transform: @escaping (Query.Data) -> Output?) {
@inlinable public init(transform: @escaping (Query.Data) -> Output?) {
self._transform = transform
}

/// The function by which we transform a `Query.Data` into an output
/// - Parameter data: Network response
/// - Returns: `Output`
public func transform(data: Query.Data) -> Output? {
@inlinable public func transform(data: Query.Data) -> Output? {
_transform(data)
}
}
6 changes: 3 additions & 3 deletions Sources/Apollo/CustomNextPageStrategy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import ApolloAPI

/// The strategy by which we create the next query in a series of paginated queries. Gives full custom control over mapping a `Page` into a `Query`.
public struct CustomNextPageStrategy<Page: Hashable, Query: GraphQLQuery>: NextPageStrategy {
private let _transform: (Page) -> Query
@usableFromInline let _transform: (Page) -> Query

public init(transform: @escaping (Page) -> Query) {
@inlinable public init(transform: @escaping (Page) -> Query) {
self._transform = transform
}

public func createNextPageQuery(page: Page) -> Query {
@inlinable public func createNextPageQuery(page: Page) -> Query {
_transform(page)
}
}
6 changes: 3 additions & 3 deletions Sources/Apollo/CustomPaginationMergeStrategy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ import ApolloAPI
/// A `PaginationMergeStrategy` which gives the caller fine-grain control over how to merge data together.
public class CustomPaginationMergeStrategy<Query: GraphQLQuery, Output: Hashable>: PaginationMergeStrategy {

let _transform: (PaginationDataResponse<Query, Output>) -> Output
@usableFromInline let _transform: (PaginationDataResponse<Query, Output>) -> Output

/// Designated initializer
/// - Parameter transform: a user-defined function which can transform a `PaginationDataResponse` into an `Output`.
public init(transform: @escaping (PaginationDataResponse<Query, Output>) -> Output) {
@inlinable public init(transform: @escaping (PaginationDataResponse<Query, Output>) -> Output) {
self._transform = transform
}

/// The function by which we merge several responses, in the form of a `PaginationDataResponse` into one `Output`.
/// - Parameter paginationResponse: A data type which contains the most recent response, the source of that response, and all other responses.
/// - Returns: `Output`
public func mergePageResults(paginationResponse: PaginationDataResponse<Query, Output>) -> Output {
@inlinable public func mergePageResults(paginationResponse: PaginationDataResponse<Query, Output>) -> Output {
_transform(paginationResponse)
}
}
10 changes: 5 additions & 5 deletions Sources/Apollo/GraphQLPaginatedQueryWatcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ public final class GraphQLPaginatedQueryWatcher<Strategy: PaginationStrategy> {
public typealias Page = Strategy.NextPageConstructor.Page
private typealias ResultHandler = (Result<GraphQLResult<Strategy.Query.Data>, Error>) -> Void

private let client: any ApolloClientProtocol
private var watchers: [GraphQLQueryWatcher<Strategy.Query>] = []
private var callbackQueue: DispatchQueue
let strategy: Strategy
@usableFromInline let client: any ApolloClientProtocol
@usableFromInline var watchers: [GraphQLQueryWatcher<Strategy.Query>] = []
@usableFromInline var callbackQueue: DispatchQueue
@usableFromInline let strategy: Strategy

/// Designated initalizer
/// - Parameters:
/// - client: the Apollo client
/// - callbackQueue: The `DispatchQueue` that results are returned on.
/// - strategy: The `PaginationStrategy` that this watcher employs.
/// - initialQuery: The `Query` that is being watched.
public init(
@inlinable public init(
client: ApolloClientProtocol,
callbackQueue: DispatchQueue = .main,
strategy: Strategy,
Expand Down
2 changes: 1 addition & 1 deletion Sources/Apollo/PaginationDataResponse.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public struct PaginationDataResponse<Query: GraphQLQuery, T> {
/// - allResponses: All responses, in page-order
/// - mostRecent: The response which triggered the watcher to update
/// - source: The source of that most recent trigger
public init(allResponses: [T], mostRecent: T, source: GraphQLResult<Query.Data>.Source) {
@inlinable public init(allResponses: [T], mostRecent: T, source: GraphQLResult<Query.Data>.Source) {
self.allResponses = allResponses
self.mostRecent = mostRecent
self.source = source
Expand Down
4 changes: 2 additions & 2 deletions Sources/Apollo/PassthroughDataTransformer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import ApolloAPI

/// A data transformer which allows the `Query.Data` to pass through unaltered.
public struct PassthroughDataTransformer<Query: GraphQLQuery>: DataTransformer {
public init() { }
@inlinable public init() { }

public func transform(data: Query.Data) -> Query.Data? {
@inlinable public func transform(data: Query.Data) -> Query.Data? {
data
}
}
8 changes: 4 additions & 4 deletions Sources/Apollo/RelayPageExtractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ public struct RelayPageExtractor<Query: GraphQLQuery>: PageExtractionStrategy {
}
}

private let _transform: (Query.Data) -> Page
@usableFromInline let _transform: (Query.Data) -> Page

/// Designated initializer
/// - Parameter transform: A user provided function which can extract a `Page` from a `Query.Data`
public init(transform: @escaping (Query.Data) -> Page) {
@inlinable public init(transform: @escaping (Query.Data) -> Page) {
self._transform = transform
}

/// Convenience initializer
/// - 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(
@inlinable public init(
hasNextPagePath: KeyPath<Query.Data, Bool>?,
endCursorPath: KeyPath<Query.Data, String?>?
) {
Expand All @@ -49,7 +49,7 @@ public struct RelayPageExtractor<Query: GraphQLQuery>: PageExtractionStrategy {
/// Transforms the `Query.Data` into a `Page` by utilizing the user-provided functions or key paths.
/// - Parameter input: A query response data.
/// - Returns: A `Page`.
public func transform(input: Query.Data) -> Page {
@inlinable public func transform(input: Query.Data) -> Page {
_transform(input)
}
}
2 changes: 1 addition & 1 deletion Sources/Apollo/RelayPaginationStrategy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ where MergeStrategy.Output == OutputTransformer.Output,
private var modelMap: [Page?: Output] = [:]
private var mostRecentModel: Output?

public init(
@inlinable public init(
pageExtractionStrategy: RelayPageExtractor<Query>,
outputTransformer: OutputTransformer,
nextPageStrategy: CustomNextPageStrategy<RelayPageExtractor<Query>.Page, Query>,
Expand Down
2 changes: 1 addition & 1 deletion Sources/Apollo/SimplePaginationMergeStrategy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import ApolloAPI
public class SimplePaginationMergeStrategy<Query: GraphQLQuery>: PaginationMergeStrategy {

/// Designated initializer
public init() { }
@inlinable public init() { }

/// The function by which we merge several responses, in the form of a `PaginationDataResponse` into one `Output`.
/// - Parameter paginationResponse: A data type which contains the most recent response, the source of that response, and all other responses.
Expand Down
4 changes: 2 additions & 2 deletions Sources/Apollo/TargetedPaginationStrategy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import ApolloAPI

/// A `PaginationMergeStrategy` which merges a specific list together in a response, outputting a `Query.Data`.
public class TargetedPaginationMergeStrategy<Query: GraphQLQuery>: PaginationMergeStrategy {
let keyPath: AnyKeyPath
@usableFromInline let keyPath: AnyKeyPath

/// Designated initializer
/// - Parameter targetedKeyPath: `KeyPath` that leads to the list of results to be concatenated.
public init(
@inlinable public init(
targetedKeyPath: KeyPath<Query.Data, [some SelectionSet]>
) {
self.keyPath = targetedKeyPath
Expand Down

0 comments on commit ec9ab16

Please sign in to comment.