From 45f88f6886e5175162caaa6944e69a11ef7fe346 Mon Sep 17 00:00:00 2001 From: Sunyeop Lee Date: Thu, 21 Jul 2022 17:22:16 +0900 Subject: [PATCH] fix(graphql): fix `SocketClient` to close subscription on socket close Fixes #1183 --- .../src/links/websocket_link/websocket_client.dart | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) 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 6d2f8c881..a6a6aacd1 100644 --- a/packages/graphql/lib/src/links/websocket_link/websocket_client.dart +++ b/packages/graphql/lib/src/links/websocket_link/websocket_client.dart @@ -495,7 +495,19 @@ class SocketClient { .where((message) => message is SubscriptionComplete) .take(1); - subscriptionComplete.listen((_) => response.close()); + subscriptionComplete.listen( + (_) => response.close(), + onDone: () { + if (!config.autoReconnect) { + response.close(); + } + }, + onError: (_) { + if (!config.autoReconnect) { + response.close(); + } + }, + ); dataErrorComplete .where((message) => message is SubscriptionData)