File tree 2 files changed +20
-2
lines changed
2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -85,8 +85,14 @@ open class HTTPRequest<Operation: GraphQLOperation>: Hashable {
85
85
/// - Throws: Any error in creating the request
86
86
/// - Returns: The URL request, ready to send to your server.
87
87
open func toURLRequest( ) throws -> URLRequest {
88
- var request = URLRequest ( url: self . graphQLEndpoint)
89
-
88
+ var request : URLRequest
89
+
90
+ if let configContext = context as? any RequestContextTimeoutConfigurable {
91
+ request = URLRequest ( url: self . graphQLEndpoint, timeoutInterval: configContext. requestTimeout)
92
+ } else {
93
+ request = URLRequest ( url: self . graphQLEndpoint)
94
+ }
95
+
90
96
for (fieldName, value) in additionalHeaders {
91
97
request. addValue ( value, forHTTPHeaderField: fieldName)
92
98
}
Original file line number Diff line number Diff line change @@ -10,3 +10,15 @@ import ApolloAPI
10
10
/// This allows the various interceptors to make modifications, or perform actions, with information
11
11
/// that they cannot get just from the existing operation. It can be anything that conforms to this protocol.
12
12
public protocol RequestContext { }
13
+
14
+ /// A request context specialization protocol that specifies options for configuring the timeout of a `URLRequest`.
15
+ ///
16
+ /// A `RequestContext` object can conform to this protocol to provide a custom `requestTimeout` for an individual request.
17
+ /// If the `RequestContext` for a request does not conform to this protocol, the default request timeout of `URLRequest` will be used.
18
+ public protocol RequestContextTimeoutConfigurable : RequestContext {
19
+ /// The timeout interval specifies the limit on the idle interval allotted to a request in the process of
20
+ /// loading. This timeout interval is measured in seconds.
21
+ ///
22
+ /// The value of this property will be set as the `timeoutInterval` on the `URLRequest` created for this GraphQL request.
23
+ var requestTimeout : TimeInterval { get }
24
+ }
You can’t perform that action at this time.
0 commit comments