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 a15ea25c..fcdd492b 100644 --- a/packages/graphql/lib/src/links/websocket_link/websocket_client.dart +++ b/packages/graphql/lib/src/links/websocket_link/websocket_client.dart @@ -637,8 +637,14 @@ 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; 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 018d1d24..0525a930 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 {