Hi. I’m using Apollo and Apollo/WebSocket (v0.50) on iOS.
I’m running into issues where, on app startup (particularly from a deep link), the code path is calling client.fetch (or even client.perform), but its immediately failing because the connection to the server has not been made yet.
Is there something in your library that allows the network calls to be queued/saved until (or while) the client connection is being established/re-established?
Hi @joe, looking at the
write function in
WebSocketTransport there is a very basic implementation of a queue which then written/flushed when the connection is ack’d. Do you know which protocol the server you’re connecting to implements?
I don’t know, how do I find out which protocol the server uses? I asked the backend engineer but he says he doesn’t know what that means. Thanks @calvincestari
Maybe I’m confusing the question - I assumed you are using GraphQL over WebSocket because you mentioned using the Apollo/WebSocket module and your description of the problem was “immediately failing because the connection to the server has not been made yet”.
WebSocket is the only transport type that requires an active socket connection to make requests. GraphQL over WebSocket requires that the server implement a specific protocol too though - documentation. v0.50.0 only supports the graphql-ws library whereas v0.51.0 supports two different implementations. If you’re not using GraphQL over WebSocket though then none of this is applicable.
Traditional HTTP-based GraphQL requests don’t require an active connection though which means I might not understand your problem yet. Do you mind sharing a bit more about your apollo-ios configuration and the error please - thanks!
Yes, I took a look around the server code and found that it supports the subprotocol
On the iOS client I use
SplitNetworkTransport which uses
uploadingNetworkTransport and use
webSocketNetworkTransport. I then create an ApolloClient using the
splitTransport and a default
The web socket disconnects often and then auto re-connects, and I’ve noticed that in some instances if I make an API call (
client.perform(mutation:)) before it has established the connection again, the API call fails (which runs the failure block of the calls).
The web socket also disconnects when the app is backgrounded (appropriately, I would say), and then re-connects when the app comes to active from background. But, the problem is, sometimes the app is being launched because of a “deep link” and is requiring a network connection; it makes an API call, but he API calls automatically FAIL because the socket has not been connected.
Not sure what I’m doing wrong but its causing A LOT of errors in my iOS client.
I’m going to have to write an “API call queue” that waits for websocket connections and manage it myself. I thought ApolloGraphQL library would do this for me, but it doesn’t seem to be working.
Am I doing something wrong? Can you help? Thanks! @calvincestari
Looking into this further, I’m not sure if this is the issue I’m facing. I am facing an issue but not sure its related to this. Can probably table this, at least for now. Thanks.
You’re right that the websocket should disconnect when the app is backgrounded but I can’t think of a reason why it would constantly cycle the connection when active. Sorry I couldn’t be of more help @joe.