Apollo-ios: How to subclass URLSessionClient to have a custom URLSession

Created on 12 May 2020  路  4Comments  路  Source: apollographql/apollo-ios

Hey, on the recently update was introduced a new type called URLSessionClient that has the URLSession used to fetch data as a private(set) attribute.

I use on my project a custom instance of URLSession to be able to switch between real and fake data.
I use Vinyl to be able to replay recorded https sessions on my functional tests.

Thank you!

networking-stack

Most helpful comment

@designatednerd thx for the answer, yah that makes sense, going to give it a try using the initializer.

Nevertheless, congrats and thank you for all the effort on this library, one of the best documented and well implements libs I've used, so easy to extend. 馃憦馃憦馃憦

All 4 comments

Unfortunately, because you can only set a URLSession's delegate in the initializer, we have to initialize the URLSession within the URLSessionClient. There's no way to pass a URLSession into URLSessionClient and still have it fundamentally work.

However, the URLSession is available as a property - could you use the Turntable initializer which takes a URLSession and pass in the session from URLSessionClient?

@designatednerd thx for the answer, yah that makes sense, going to give it a try using the initializer.

Nevertheless, congrats and thank you for all the effort on this library, one of the best documented and well implements libs I've used, so easy to extend. 馃憦馃憦馃憦

Thanks! Big props to @martijnwalraven for getting it all up and running.

Do you mind if we close out this issue?

I'm gonna go ahead and close this one out - @dchohfi please feel free to reopen if you're still running into problems. If someone else has got a similar problem, please open a new issue. Thank you!

Was this page helpful?
0 / 5 - 0 ratings