From c455e368becea5ca5e506e2b366cdacff358465a Mon Sep 17 00:00:00 2001 From: Gabor <> Date: Sun, 5 Jun 2022 16:10:26 +0200 Subject: [PATCH 1/3] Expose socket client --- .../graphql/lib/src/links/websocket_link/websocket_link.dart | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/graphql/lib/src/links/websocket_link/websocket_link.dart b/packages/graphql/lib/src/links/websocket_link/websocket_link.dart index 2590277e0..3250c68ab 100644 --- a/packages/graphql/lib/src/links/websocket_link/websocket_link.dart +++ b/packages/graphql/lib/src/links/websocket_link/websocket_link.dart @@ -45,6 +45,8 @@ class WebSocketLink extends Link { ); } + SocketClient? get getSocketClient => _socketClient; + /// Disposes the underlying socket client explicitly. Only use this, if you want to disconnect from /// the current server in favour of another one. If that's the case, create a new [WebSocketLink] instance. Future dispose() async { From a0316fd32b4a19db72939e67336475c2caddc6fa Mon Sep 17 00:00:00 2001 From: Gabor Date: Tue, 19 Dec 2023 11:52:51 +0100 Subject: [PATCH 2/3] Make _messages a broadcast stream --- .../lib/src/links/websocket_link/websocket_client.dart | 9 +++++++-- 1 file changed, 7 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 1809cd65e..daaa6a2b8 100644 --- a/packages/graphql/lib/src/links/websocket_link/websocket_client.dart +++ b/packages/graphql/lib/src/links/websocket_link/websocket_client.dart @@ -636,8 +636,13 @@ class GraphQLWebSocketChannel extends StreamChannelMixin Stream? _messages; /// Stream of messages from the endpoint parsed as GraphQLSocketMessages - Stream get messages => _messages ??= - stream.map(GraphQLSocketMessage.parse); + Stream get messages { + if (_messages == null) _messages = stream.map((event) { + return GraphQLSocketMessage.parse(event); + }).asBroadcastStream(); + + return _messages!; + } String? get protocol => _webSocket.protocol; From 694aa26ddc8c085ecaaf820d8118e2b5cb92bca1 Mon Sep 17 00:00:00 2001 From: Gabor Date: Sat, 3 Feb 2024 18:31:43 +0100 Subject: [PATCH 3/3] Format code --- .../lib/src/links/websocket_link/websocket_client.dart | 7 ++++--- 1 file changed, 4 insertions(+), 3 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 daaa6a2b8..490ca2d1d 100644 --- a/packages/graphql/lib/src/links/websocket_link/websocket_client.dart +++ b/packages/graphql/lib/src/links/websocket_link/websocket_client.dart @@ -637,9 +637,10 @@ class GraphQLWebSocketChannel extends StreamChannelMixin /// Stream of messages from the endpoint parsed as GraphQLSocketMessages Stream get messages { - if (_messages == null) _messages = stream.map((event) { - return GraphQLSocketMessage.parse(event); - }).asBroadcastStream(); + if (_messages == null) + _messages = stream.map((event) { + return GraphQLSocketMessage.parse(event); + }).asBroadcastStream(); return _messages!; }