Skip to content

Commit b4063ff

Browse files
Added HTTPNetworkTransport.init to take URLSession instance to allow caller to handle exceptional cases by way of URLSessionDelegate
1 parent 759b6df commit b4063ff

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

Sources/Apollo/HTTPNetworkTransport.swift

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,20 @@ public class HTTPNetworkTransport: NetworkTransport {
5353
/// - url: The URL of a GraphQL server to connect to.
5454
/// - configuration: A session configuration used to configure the session. Defaults to `URLSessionConfiguration.default`.
5555
/// - sendOperationIdentifiers: Whether to send operation identifiers rather than full operation text, for use with servers that support query persistence. Defaults to false.
56-
public init(url: URL, configuration: URLSessionConfiguration = URLSessionConfiguration.default, sendOperationIdentifiers: Bool = false) {
56+
public convenience init(url: URL, configuration: URLSessionConfiguration = URLSessionConfiguration.default, sendOperationIdentifiers: Bool = false) {
57+
self.init(url: url, session: URLSession(configuration: configuration),
58+
sendOperationIdentifiers: sendOperationIdentifiers)
59+
}
60+
61+
/// Creates a network transport with the specified server URL and session.
62+
///
63+
/// - Parameters:
64+
/// - url: The URL of a GraphQL server to connect to.
65+
/// - session: An URLSession instance to be used for ensuing operations.
66+
/// - sendOperationIdentifiers: Whether to send operation identifiers rather than full operation text, for use with servers that support query persistence. Defaults to false.
67+
public init(url: URL, session: URLSession, sendOperationIdentifiers: Bool = false) {
5768
self.url = url
58-
self.session = URLSession(configuration: configuration)
69+
self.session = session
5970
self.sendOperationIdentifiers = sendOperationIdentifiers
6071
}
6172

0 commit comments

Comments
 (0)