Test subscription with pure WebSocketClient #1399
Replies: 3 comments 1 reply
-
Thanks for checking. Could you be more specific in stating the version it was last working with? We did update websocket subscriptions to support the newer graphql-ws protocol (the older one is around for backwards compatibility, but not actively maintained) almost a year ago. The code here has not changed much since then. |
Beta Was this translation helpful? Give feedback.
-
Yes, the old version maybe work with the legacy subscrptions-transport-ws protocol, the original version I just used a But now I tried to change the codes to satisfy the new graphql-ws protocol like this. val initMessage = mapOf(
"payload" to emptyMap<String, Any>(),
"type" to "connection_init"
)
val subscribeMessage = mapOf(
"payload" to subscriptionsQuery,
"type" to "subscribe",
"id" to "1"
)
session.sendMessage(TextMessage(initMessage.toJson()))
session.sendMessage(TextMessage(subscribeMessage.toJson())) After the client is connected, send a connection_init and subscribe type messages in the I am not sure where is needed to improve? I need to add some headers to declare where subprotocols I am using to connect? |
Beta Was this translation helpful? Give feedback.
-
yes, you will need the sub-protocol header to indicate that you are using
the new protocol in that case. Else it defaults to the older one.
For reference,
https://github.com/enisdenjo/graphql-ws/blob/master/PROTOCOL.md#successful-connection-initialisation
…On Wed, Jan 25, 2023 at 12:35 AM Hantsy Bai ***@***.***> wrote:
Yes, the old version maybe work with the legacy subscrptions-transport-ws
protocol.
But now I tried to change the codes to satisfy the new graphql-ws protocol
like this.
val initMessage = mapOf(
"payload" to emptyMap<String, Any>(),
"type" to "connection_init"
)
val subscribeMessage = mapOf(
"payload" to subscriptionsQuery,
"type" to "subscribe",
"id" to "1"
)
session.sendMessage(TextMessage(initMessage.toJson()))
session.sendMessage(TextMessage(subscribeMessage.toJson()))
After the client is connected, send a connection_init and subscribe type
messages in the afterConnectionEstablished method, it did not trigger the
handleMessage in the server side(no any log in the console).
I am not sure where is needed to improve?
I need to add some headers to declare where subprotocols I am using to
connect?
—
Reply to this email directly, view it on GitHub
<#1399 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AJ5JPXLCL2OZSXH2YLBV23DWUDQWNANCNFSM6AAAAAAUCY5P4A>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
I have dgs-kotlin example, it is based on traditional Spring WebMVC stack, it is already updated to the latest DGS 6/Spring Boot 3.0.
I tried to use a
StandardWebSocketClient
to connect subscriptions endpoint in integration tests.It uses a custom WebSocketHandler to save a copy of incoming messages, but when I ran the tests, it seems the method
handleTextMessage
of this webscoket handler never be called.The complete codes is here.
I remembered this test was working in the earlier commits.
Beta Was this translation helpful? Give feedback.
All reactions