client.stop() should call close on websocket link
See original GitHub issueIntended outcome:
As per the documentation of the function Client.stop
, it should be ready to recycle the client once it is called. Meaning the websocket connection should be closed.
Actual outcome:
Currently, the websocket connection is NOT closed. This is problematic since a very common use case if to recycle the client when the authorization token changes. If a user is not careful, he will end up creating a lot of websocket connections to the backend.
How to reproduce the issue:
- Create a client with the WebsocketLink
- Call stop on the client
- Observe the network tab, the connection is not closed
Issue Analytics
- State:
- Created 3 years ago
- Reactions:11
- Comments:7 (1 by maintainers)
Top Results From Across the Web
How to terminate a WebSocket connection? - Stack Overflow
According to the ws documentation, you need to call websocket.close() to terminate a connection. let server = new WebSocketServer(options); ...
Read more >WebSocket.close() - Web APIs - MDN Web Docs
close() method closes the WebSocket connection or connection attempt, if any. If the connection is already CLOSED , this method does nothing.
Read more >How to Close a WebSocket (Correctly) - Forty Years of Code
Either the client or the server sends a Close frame (WebSockets borrow ... its own Close frame in response, and then both parties...
Read more >Close the client to avoid the connections limit - Amazon Neptune
It is important to close the client when you are finished with it to ensure that the WebSocket connections are closed by the...
Read more >WebSockets - Closing a Connection - Tutorialspoint
Close event marks the end of a communication between the server and the client. Closing a connection is possible with the help of...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
While we’re waiting for an official implementation (and for anyone who’s looking at the issue https://github.com/apollographql/apollo-link/issues/197 and still wondering how to refresh
connectionParams
), here’s how my team and I were finally able to do it in React:The main trick was to use
SubscriptionClient
as the parameter to theWebSocketLink
instance. This gives us the option to close the connection when we need it, directly using the subscription client. In the above scenario, that’s also the mechanism we use in order to refresh our connection params.Hey @Sytten, maybe you can give
graphql-ws
a spin. 😄Offering a completely different Protocol you’d have to use the same lib server side too; but, no stress - there are recipes in the readme for using it with Apollo both server and client side!