File tree Expand file tree Collapse file tree
src/GraphQL/Client/BaseClients Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -48,16 +48,41 @@ const createClientWithWebsockets = function (opts) {
4848 } ,
4949 } ) ;
5050
51+ // Close codes that indicate expected/benign disconnects
52+ // 1000: Normal closure, 1001: Going away (tab close, navigation, mobile backgrounding)
53+ const expectedCloseCodes = new Set ( [ 1000 , 1001 ] ) ;
54+
5155 const wsLink = new GraphQLWsLink (
5256 createWsClient ( {
5357 webSocketImpl : globalThis . WebSocket ,
5458 url : opts . websocketUrl ,
5559 timeout : 30000 ,
60+ retryAttempts : Infinity ,
61+ shouldRetry : ( ) => true ,
5662 connectionParams : {
5763 headers : opts . authToken
5864 ? { Authorization : `Bearer ${ opts . authToken } ` }
5965 : { } ,
6066 } ,
67+ on : {
68+ closed : ( event ) => {
69+ if ( expectedCloseCodes . has ( event . code ) ) {
70+ return ;
71+ }
72+ console . warn ( "[graphql-ws] Socket closed unexpectedly" , {
73+ code : event . code ,
74+ reason : event . reason ,
75+ wasClean : event . wasClean ,
76+ url : opts . websocketUrl ,
77+ } ) ;
78+ } ,
79+ error : ( error ) => {
80+ console . error ( "[graphql-ws] WebSocket error" , {
81+ error,
82+ url : opts . websocketUrl ,
83+ } ) ;
84+ } ,
85+ } ,
6186 } ) ,
6287 ) ;
6388
You can’t perform that action at this time.
0 commit comments