-
Notifications
You must be signed in to change notification settings - Fork 743
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple ApolloClients per URLSessionClient instances ? #3213
Comments
Hi @petarbelokonski 👋🏻 - it sounds like you simply want to know how to deal with the interceptor provider, is that correct? If so then you can reuse the let url = URL(string: "http://localhost:4000/")!
let sharedStore = ApolloStore() // will give you an InMemoryNormalizedCache
let sessionClient = URLSessionClie nt() // can pass in the session configuration if needed
let interceptorProvider = DefaultInterceptorProvider(client: sessionClient,store: sharedStore) // standard provider list
let networkTransport = RequestChainNetworkTransport(interceptorProvider: interceptorProvider, endpointURL: url)
let apolloClient = ApolloClient(networkTransport: networkTransport, store: sharedStore) Does that answer your question or did I misunderstand? |
@calvincestari Thanks for your reply. I know how to work with the interceptor provider - my question is a structural one: I need to be able to use multiple URLSessionClient instances (with different operation queues) for my requests. However I have 1 InterceptorProvider instance per 1 ApolloClient instance. The flow goes as follows:
I need to be able to use multiple URLSessionClients (so that I can use multiple OperationQueues, and the way I currently see this fit is to have an ApolloClient instance tied up to a concrete URLSessionClient and concrete OperationQueue - do you think this approach is fine or else would you be able suggest an alternative ? |
I'm still not sure I 100% understand the issue but all the networking classes we've mentioned so far are pretty much linked 1:1. So the only way you would be able to use multiple I don't see anything particularly wrong with that other than the burden of maintaining multiple clients but what I am far less certain of is whether a store instance should be shared between them. I suspect that is not advisable and could lead to some difficult to debug caching issues. |
@calvincestari That's exactly the idea - I need to use multiple URLSessionClient instances. My thought process brought me to the idea of having a URLSessionClient instance per AplloClient instance hence multiple ApolloClient instances. However I haven't considered what you said about the store which is a valid concern. My goal is to be able to determine which URLSessionClient to use per concrete fetch method invocation. However, I must be able to use any URLSessionClient for any GraphQLOperation. I could potentially use the |
Question
I need to be able to issue operation requests on multiple OperationQueues (say 2). That said I need to keep a reference of multiple URLSessionClient instances. What I think will work best is to keep multiple separate instances of ApoIloClient each tied up to a specific URLSessionClient. Is there a preferred/suggested way of doing that given the InterceptorProvider protocol and that we need to initialize ApolloClient with a given InterceptorProvider before making the request ?
The text was updated successfully, but these errors were encountered: