From 1003c4b61d37912a45dbc2fdbf3c88ad2353659f Mon Sep 17 00:00:00 2001 From: aarsham Date: Tue, 20 Feb 2024 13:33:49 +0330 Subject: [PATCH 1/3] fix(graphql): remove unnecessary null checks in SocketClient **Fixes** - Removed unnecessary null checks(!) on SocketChannel instance in SocketClient onConnectionLost() method which cause an error when client cannot connect (#1379). this prevents reconnecting when there is a working connection later. --- .../lib/src/links/websocket_link/websocket_client.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/graphql/lib/src/links/websocket_link/websocket_client.dart b/packages/graphql/lib/src/links/websocket_link/websocket_client.dart index fcdd492b..44341533 100644 --- a/packages/graphql/lib/src/links/websocket_link/websocket_client.dart +++ b/packages/graphql/lib/src/links/websocket_link/websocket_client.dart @@ -372,8 +372,8 @@ class SocketClient { } void onConnectionLost([Object? e]) async { - var code = socketChannel!.closeCode; - var reason = socketChannel!.closeReason; + var code = socketChannel?.closeCode; + var reason = socketChannel?.closeReason; await _closeSocketChannel(); if (e != null) { From be11b4cd1210e4d898a1a381a56c59bbcdeee6c5 Mon Sep 17 00:00:00 2001 From: aarsham Date: Wed, 21 Feb 2024 20:41:12 +0330 Subject: [PATCH 2/3] fix(graphql): resolve duplicate events on socket reconnect Resolved an issue in WebSocketClient where multiple listeners were added to `waitForConnectedState` when socket reconnects after subscription been requtesed with disconnected socket, causing duplicate events to be received by subscriptions. --- .../graphql/lib/src/links/websocket_link/websocket_client.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/graphql/lib/src/links/websocket_link/websocket_client.dart b/packages/graphql/lib/src/links/websocket_link/websocket_client.dart index 44341533..9f6ff470 100644 --- a/packages/graphql/lib/src/links/websocket_link/websocket_client.dart +++ b/packages/graphql/lib/src/links/websocket_link/websocket_client.dart @@ -502,6 +502,7 @@ class SocketClient { ) : waitForConnectedStateWithoutTimeout; + sub?.cancel(); sub = waitForConnectedState.listen((_) { final Stream dataErrorComplete = _messages.where( (GraphQLSocketMessage message) { From acdaabc955b9200b35e4f6b16ab208c85873a0e4 Mon Sep 17 00:00:00 2001 From: aarsham Date: Sat, 30 Mar 2024 14:35:14 +0330 Subject: [PATCH 3/3] fix(graphql): check for null data returned from fetchMore.updateQuery before writing to cache --- packages/graphql/lib/src/core/fetch_more.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/graphql/lib/src/core/fetch_more.dart b/packages/graphql/lib/src/core/fetch_more.dart index 10c1a8fe..915c5202 100644 --- a/packages/graphql/lib/src/core/fetch_more.dart +++ b/packages/graphql/lib/src/core/fetch_more.dart @@ -34,11 +34,11 @@ Future> fetchMoreImplementation( final data = fetchMoreOptions.updateQuery( previousResult.data, fetchMoreResult.data, - )!; + ); fetchMoreResult.data = data; - if (originalOptions.fetchPolicy != FetchPolicy.noCache) { + if (originalOptions.fetchPolicy != FetchPolicy.noCache && data != null) { queryManager.attemptCacheWriteFromClient( request, data,