Skip to content

Commit e1b7f82

Browse files
authored
fix(graphql): send connection_init message during handshake
The implementation of `graphql-transport-ws` fails on the first message as it's only sent if the connection controller is in the `connected` state. For this protocol, the state is instead set to `handshake` during the first `_write()`. https://github.com/zino-hofmann/graphql-flutter/blob/02be959597f0ffe0c21a227a2d1fdb02b3f56831/packages/graphql/lib/src/links/websocket_link/websocket_client.dart#L250-L256 Without this, the connection fails with the following log: ``` flutter: Initialising connection flutter: There was an error causing connection lost: Bad state: No element flutter: Disconnected from websocket. ```
1 parent 02be959 commit e1b7f82

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

packages/graphql/lib/src/links/websocket_link/websocket_client.dart

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -370,13 +370,18 @@ class SocketClient {
370370
}
371371

372372
void _write(final GraphQLSocketMessage message) {
373-
if (_connectionStateController.value == SocketConnectionState.connected) {
374-
socketChannel!.sink.add(
375-
json.encode(
376-
message,
377-
toEncodable: (dynamic m) => m.toJson(),
378-
),
379-
);
373+
switch (_connectionStateController.value) {
374+
case SocketConnectionState.connected:
375+
case SocketConnectionState.handshake:
376+
socketChannel!.sink.add(
377+
json.encode(
378+
message,
379+
toEncodable: (dynamic m) => m.toJson(),
380+
),
381+
);
382+
break;
383+
default:
384+
break;
380385
}
381386
}
382387

0 commit comments

Comments
 (0)