Description
While using graphql, I have specific requirement which force me to use a custom connectFn, so I can provide a custom WebSocketChannel.
By creating 2 stream controllers ( one for upstream and other for downstream) and pass the sink and stream to the websocket channel, I'm able to implement custom networking.
The problem resides in the way graphql interacts with the sink. From what seen in graphql(this library) code:
socketChannel!.sink.add(
json.encode(
message,
toEncodable: (dynamic m) => m.toJson(),
),
);
a String is sent to the sink ( the result of json.encode is a string).
This clashes with the WebSocketChannel constructor signature, which clearly mandates a List of int:
In the stream connected to the sink, i receive a list of ints that are not convertible to string; and honestly, i don't know what they are. ( Perhaps some toString of the object hash?! ).
Example message ( this should be the first ack sent to the server ):
flutter: ======================================================
flutter: PRINTING POSSIBLE CONVERSIONS FROM UPSTREAM MESSAGE
flutter: originalEvent: [129, 154, 77, 223, 32, 209]
flutter: base64Event: FormatException: Invalid character (at character 1)
Mß Ñ
^
flutter: obj: [129, 154, 77, 223, 32, 209]
flutter: obj: Mß Ñ
Reroduce
A runnable example (flutter app) can be found at this repo.
Just follow the instructions on the readme, or just run the project and look into the console.
Expected behavior
I would expect the data that comes from the sink would be easily convertable to string. I would expect to see a string with json inside.
device / execution context
Are you on iOS, android, web, in a simulator, running from the terminal etc? This is especially important for localhost connection issues.
OK I just add some more content here, this is expected, but maybe would be good to have some helper function to help to encode and to decode the response.
Description While using graphql, I have specific requirement which force me to use a custom connectFn, so I can provide a custom WebSocketChannel. By creating 2 stream controllers ( one for upstream and other for downstream) and pass the sink and stream to the websocket channel, I'm able to implement custom networking. The problem resides in the way graphql interacts with the sink. From what seen in graphql(this library) code:
a String is sent to the sink ( the result of json.encode is a string). This clashes with the WebSocketChannel constructor signature, which clearly mandates a List of int:
In the stream connected to the sink, i receive a list of ints that are not convertible to string; and honestly, i don't know what they are. ( Perhaps some toString of the object hash?! ). Example message ( this should be the first ack sent to the server ):
Reroduce A runnable example (flutter app) can be found at this repo. Just follow the instructions on the readme, or just run the project and look into the console.
Expected behavior I would expect the data that comes from the sink would be easily convertable to string. I would expect to see a string with json inside.
device / execution context Are you on iOS, android, web, in a simulator, running from the terminal etc? This is especially important for
localhost
connection issues.