Skip to content

Commit e0e0664

Browse files
update a ton of documentation
1 parent 89119c0 commit e0e0664

11 files changed

Lines changed: 52 additions & 4 deletions

Sources/Apollo/ApolloErrorInterceptor.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Foundation
22

3+
/// An error interceptor called to allow further examination of error data when an error occurs in the chain.
34
public protocol ApolloErrorInterceptor {
45

56
/// Asynchronously handles the receipt of an error at any point in the chain.

Sources/Apollo/ApolloInterceptor.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1+
/// A protocol to set up a chainable unit of networking work.
12
public protocol ApolloInterceptor: class {
23

4+
/// Called when this interceptor should do its work.
5+
///
6+
/// - Parameters:
7+
/// - chain: The chain the interceptor is a part of.
8+
/// - request: The request, as far as it has been constructed
9+
/// - response: The response, as far as it has been constructed
10+
/// - completion: The completion block to fire when data needs to be returned to the UI.
311
func interceptAsync<ParsedValue: Parseable, Operation: GraphQLOperation>(
412
chain: RequestChain,
513
request: HTTPRequest<Operation>,

Sources/Apollo/FinalizingInterceptor.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Foundation
22

3+
/// The last interceptor in a normal chain, which checks that parsing has been completed and returns information to the UI.
34
public class FinalizingInterceptor: ApolloInterceptor {
45

56
enum FinalizationError: Error {

Sources/Apollo/HTTPResponse.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
import Foundation
22

3+
/// Data about a response received by an HTTP request.
34
public class HTTPResponse<ParsedValue: Parseable> {
45
public var httpResponse: HTTPURLResponse?
56
public var rawData: Data?
67
public var parsedResponse: ParsedValue?
78

9+
/// Designated initializer
10+
///
11+
/// - Parameters:
12+
/// - response: [optional] The `HTTPURLResponse` received from the server. Will be nil if not yet received or if the response received was not an `HTTPURLResponse`.
13+
/// - rawData: [optional] The raw, unparsed data received from the server. Will be nil if not yet received or if data received from the server was nil.
14+
/// - parsedResponse: [optional] The response parsed into the `ParsedValue` type. Will be nil if not yet received, not yet parsed, or if parsing failed.
815
public init(response: HTTPURLResponse?,
916
rawData: Data?,
1017
parsedResponse: ParsedValue?) {

Sources/Apollo/InterceptorProvider.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Foundation
22

33
// MARK: - Basic protocol
44

5+
/// A protocol to allow easy creation of an array of interceptors for a given operation.
56
public protocol InterceptorProvider {
67

78
/// Creates a new array of interceptors when called
@@ -12,14 +13,17 @@ public protocol InterceptorProvider {
1213

1314
// MARK: - Default implementation for typescript codegen
1415

16+
/// The default interceptor provider for typescript-generated code
1517
public class LegacyInterceptorProvider: InterceptorProvider {
1618

1719
private let client: URLSessionClient
1820
private let store: ApolloStore
1921

2022
/// Designated initializer
2123
///
22-
/// - Parameter client: The URLSession client to use. Defaults to the default setup.
24+
/// - Parameters:
25+
/// - client: The `URLSessionClient` to use. Defaults to the default setup.
26+
/// - store: The `ApolloStore` to use when reading from or writing to the cache.
2327
public init(client: URLSessionClient = URLSessionClient(),
2428
store: ApolloStore) {
2529
self.client = client
@@ -40,6 +44,8 @@ public class LegacyInterceptorProvider: InterceptorProvider {
4044

4145
// MARK: - Default implementation for swift codegen
4246

47+
48+
/// The default interceptor proider for code generated with Swift Codegen™
4349
public class CodableInterceptorProvider<FlexDecoder: FlexibleDecoder>: InterceptorProvider {
4450

4551
private let client: URLSessionClient

Sources/Apollo/JSONRequest.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Foundation
22

3+
/// A request which sends JSON related to a GraphQL operation.
34
public class JSONRequest<Operation: GraphQLOperation>: HTTPRequest<Operation> {
45

56
public let requestCreator: RequestCreator

Sources/Apollo/LegacyCacheReadInterceptor.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Foundation
22

3+
/// An interceptor that reads data from the legacy cache for queries, following the `HTTPRequest`'s `cachePolicy`.
34
public class LegacyCacheReadInterceptor: ApolloInterceptor {
45

56
public enum CacheReadError: Error {
@@ -8,6 +9,9 @@ public class LegacyCacheReadInterceptor: ApolloInterceptor {
89

910
private let store: ApolloStore
1011

12+
/// Designated initializer
13+
///
14+
/// - Parameter store: The store to use when reading from the cache.
1115
public init(store: ApolloStore) {
1216
self.store = store
1317
}
@@ -55,7 +59,7 @@ public class LegacyCacheReadInterceptor: ApolloInterceptor {
5559
self.fetchFromCache(for: request, chain: chain) { cacheFetchResult in
5660
switch cacheFetchResult {
5761
case .failure:
58-
// Cache miss, proceed to network without calling completion
62+
// Cache miss, proceed to network without returning error
5963
chain.proceedAsync(request: request,
6064
response: response,
6165
completion: completion)

Sources/Apollo/LegacyCacheWriteInterceptor.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
import Foundation
22

3+
/// An interceptor which writes data to the legacy cache, following the `HTTPRequest`'s `cachePolicy`.
34
public class LegacyCacheWriteInterceptor: ApolloInterceptor {
45

56
public let store: ApolloStore
67

8+
/// Designated initializer
9+
///
10+
/// - Parameter store: The store to use when writing to the cache.
711
public init(store: ApolloStore) {
812
self.store = store
913
}

Sources/Apollo/LegacyParsingInterceptor.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import Foundation
22

3+
/// An interceptor which parses code using the legacy parsing system.
34
public class LegacyParsingInterceptor: ApolloInterceptor {
45

56
public func interceptAsync<ParsedValue: Parseable, Operation: GraphQLOperation>(

Sources/Apollo/NetworkFetchInterceptor.swift

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import Foundation
22

3-
public class NetworkFetchInterceptor: ApolloInterceptor {
3+
/// An interceptor which actually fetches data from the network.
4+
public class NetworkFetchInterceptor: ApolloInterceptor, Cancellable {
45
let client: URLSessionClient
56
private var currentTask: URLSessionTask?
67

7-
init(client: URLSessionClient) {
8+
/// Designated initializer.
9+
///
10+
/// - Parameter client: The `URLSessionClient` to use to fetch data
11+
public init(client: URLSessionClient) {
812
self.client = client
913
}
1014

@@ -46,4 +50,8 @@ public class NetworkFetchInterceptor: ApolloInterceptor {
4650
}
4751
}
4852
}
53+
54+
public func cancel() {
55+
self.currentTask?.cancel()
56+
}
4957
}

0 commit comments

Comments
 (0)