File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed
Expand file tree Collapse file tree 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 {
8585 /// - Throws: Any error in creating the request
8686 /// - Returns: The URL request, ready to send to your server.
8787 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+
9096 for (fieldName, value) in additionalHeaders {
9197 request. addValue ( value, forHTTPHeaderField: fieldName)
9298 }
Original file line number Diff line number Diff line change @@ -10,3 +10,15 @@ import ApolloAPI
1010/// This allows the various interceptors to make modifications, or perform actions, with information
1111/// that they cannot get just from the existing operation. It can be anything that conforms to this protocol.
1212public 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