Apollo-ios: Respsone timeout

Created on 5 Jun 2020  路  4Comments  路  Source: apollographql/apollo-ios

How to set response timeout for ApolloClient.

networking-stack question

Most helpful comment

Fixed.
let url = URL(string: baseURL)!
let configuration = URLSessionConfiguration.default
configuration.timeoutIntervalForResource = 10
let client = URLSessionClient(sessionConfiguration: configuration)
let transport = HTTPNetworkTransport(url: url,
client: client)
return ApolloClient(networkTransport: transport)

All 4 comments

We use whatever is on the URLSessionConfiguration you pass in - the property to set this is called timeoutIntervalForRequest. Per the docs:

The default value is 60.

But I am not able to pass URLSessionConfiguration during ApolloClient object creation.
HTTPNetworkTransport only accepts URL as a init parameter.

Screenshot 2020-06-06 at 1 56 38 AM

Fixed.
let url = URL(string: baseURL)!
let configuration = URLSessionConfiguration.default
configuration.timeoutIntervalForResource = 10
let client = URLSessionClient(sessionConfiguration: configuration)
let transport = HTTPNetworkTransport(url: url,
client: client)
return ApolloClient(networkTransport: transport)

Yep, right on. Thanks for posting the solution for future folks!

Was this page helpful?
0 / 5 - 0 ratings