How to detect client connection state? #1832
-
I wondered if there is a way to detect and possibly subscribe to connection state changes. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
I'm not sure if you're referring to subscription transport libraries here, but if you mean, let's say, If you use WebSockets, then you'll have to note that they're built to try to retain "broken" connections for as long as possible, so they can recover on unstable internet connections. That means, depending on the network conditions, even if they drop ACK packets, as far as I know, they won't actually tell you that something's gone wrong. In the case of Graphcache, where we account for simple network errors, we actually only react to them if we do see a network error, so you may want to do something similar. That's because there is an event that the browser provides for connection changes, but it won't tell you whether you're actually online or offline. |
Beta Was this translation helpful? Give feedback.
I'm not sure if you're referring to subscription transport libraries here, but if you mean, let's say,
graphql-ws
, then you'll instantiate their client first, which means that it then is responsible for describing its connection state. Last time I checked I wasn't sure whether they implemented a ping system to detect the connection state, but in either way, it's actually a more complicated problem than it sounds.If you use WebSockets, then you'll have to note that they're built to try to retain "broken" connections for as long as possible, so they can recover on unstable internet connections. That means, depending on the network conditions, even if they drop ACK packets, as far as I know…