Skip to content

Commit 6172015

Browse files
moar docs!
1 parent e246d86 commit 6172015

3 files changed

Lines changed: 55 additions & 3 deletions

File tree

Sources/Apollo/HTTPRequest.swift

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

3+
/// Encapsulation of all information about a request before it hits the network
34
open class HTTPRequest<Operation: GraphQLOperation> {
45

56
public enum HTTPRequestError: Error {
67
case noRequestConstructed
78
}
89

10+
/// The endpoint to make a GraphQL request to
911
open var graphQLEndpoint: URL
12+
13+
/// The GraphQL Operation to execute
1014
open var operation: Operation
15+
16+
/// The `Content-Type` header's value
1117
open var contentType: String
18+
19+
/// Any additional headers you wish to add by default to this request
1220
open var additionalHeaders: [String: String]
21+
22+
/// [optional] The name of the current client, defaults to nil
1323
open var clientName: String? = nil
24+
25+
/// [optional] The version of the current client, defaults to nil
1426
open var clientVersion: String? = nil
27+
28+
/// How many times this request has been retried. Must be incremented manually. Defaults to zero.
1529
open var retryCount: Int = 0
30+
31+
/// The `CachePolicy` to use for this request.
1632
public let cachePolicy: CachePolicy
17-
1833

34+
/// Designated Initializer
35+
///
36+
/// - Parameters:
37+
/// - graphQLEndpoint: The endpoint to make a GraphQL request to
38+
/// - operation: The GraphQL Operation to execute
39+
/// - contentType: The `Content-Type` header's value. Should usually be set for you by a subclass.
40+
/// - additionalHeaders: Any additional headers you wish to add by default to this request.
41+
/// - cachePolicy: The `CachePolicy` to use for this request. Defaults to the `.default` policy
1942
public init(graphQLEndpoint: URL,
2043
operation: Operation,
2144
contentType: String,
@@ -61,6 +84,10 @@ open class HTTPRequest<Operation: GraphQLOperation> {
6184
self.additionalHeaders[name] = value
6285
}
6386

87+
/// Converts this object to a fully fleshed-out `URLRequest`
88+
///
89+
/// - Throws: Any error in creating the request
90+
/// - Returns: The URL request, ready to send to your server.
6491
open func toURLRequest() throws -> URLRequest {
6592
var request = URLRequest(url: self.graphQLEndpoint)
6693

@@ -80,3 +107,15 @@ open class HTTPRequest<Operation: GraphQLOperation> {
80107
}
81108
}
82109

110+
extension HTTPRequest: Equatable {
111+
112+
public static func == (lhs: HTTPRequest<Operation>, rhs: HTTPRequest<Operation>) -> Bool {
113+
lhs.graphQLEndpoint == rhs.graphQLEndpoint
114+
&& lhs.additionalHeaders == rhs.additionalHeaders
115+
&& lhs.cachePolicy == rhs.cachePolicy
116+
&& lhs.contentType == rhs.contentType
117+
&& lhs.operation.queryDocument == rhs.operation.queryDocument
118+
&& lhs.clientName == rhs.clientName
119+
&& lhs.clientVersion == rhs.clientVersion
120+
}
121+
}

Sources/Apollo/JSONRequest.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,18 @@ public class JSONRequest<Operation: GraphQLOperation>: HTTPRequest<Operation> {
1111
public var isPersistedQueryRetry = false
1212

1313
public let serializationFormat = JSONSerializationFormat.self
14-
14+
15+
/// Designated initializer
16+
///
17+
/// - Parameters:
18+
/// - operation: The GraphQL Operation to execute
19+
/// - graphQLEndpoint: The endpoint to make a GraphQL request to
20+
/// - additionalHeaders: Any additional headers you wish to add by default to this request
21+
/// - cachePolicy: The `CachePolicy` to use for this request.
22+
/// - autoPersistQueries: `true` if Auto-Persisted Queries should be used. Defaults to `false`.
23+
/// - useGETForQueries: `true` if Queries should use `GET` instead of `POST` for HTTP requests. Defaults to `false`.
24+
/// - useGETForPersistedQueryRetry: `true` if when an Auto-Persisted query is retried, it should use `GET` instead of `POST` to send the query. Defaults to `false`.
25+
/// - requestCreator: An object conforming to the `RequestCreator` protocol to assist with creating the request body. Defaults to the provided `ApolloRequestCreator` implementation.
1526
public init(operation: Operation,
1627
graphQLEndpoint: URL,
1728
additionalHeaders: [String: String] = [:],

Tests/ApolloTests/RequestChainTests.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ class RequestChainTests: XCTestCase {
1616
let url = URL(string: "http://localhost:8080/graphql")!
1717

1818
let store = ApolloStore(cache: InMemoryNormalizedCache())
19-
let transport = RequestChainNetworkTransport(interceptorProvider: LegacyInterceptorProvider(store: store), endpointURL: url)
19+
let provider = LegacyInterceptorProvider(store: store)
20+
let transport = RequestChainNetworkTransport(interceptorProvider: provider,
21+
endpointURL: url)
2022

2123
return ApolloClient(networkTransport: transport)
2224
}()

0 commit comments

Comments
 (0)