matiasanaya/go-graphql-subscription-example

Qn: webSocket connection handling

Closed this issue · 2 comments

Hi @matiasanaya
I have couple of question about webSocket connections

  1. Like here, we are managing subscribers per event type. If there are n subscription event type, would one client share same underlying socket for all these n events?

  2. Is it possible to reuse this socket for a system message outside graphql request? Say, I need to send some kind of system notification on all users currently connected.

edit: I see here that graphqlws meant to use with graphql. Hope there is an easy way to extend it as the implementation is quite small. Still digging :-)

Thank you.
bsr.

Hi @bsr203, let me try answer these.

  1. This is up to the client, but I believe the apollo client will open only one connection and send (plus receive) all the events through that one connection. The server definitively supports this. In case you want to know more, the websocket transport is implemented by github.com/matiasanaya/graphql-transport-ws following the GraphQL over WebSocket Protocol, which details these interactions.

  2. I don't know, you'd need to build your own client and transport layer on the server, I don't think my implementation exposes any hooks for you to do this. That being said it seems like what you are talking about is the job of subscriptions in GraphQL, so why side step it instead of adding one more subscription for system messages?

Hope this helps. Cheers!

@matiasanaya thank you so much for the detailed response. I spent some more time over the implementation and I guess I can tweak if I need to. You are right that, I should be able to use apollo for system messages as well. thanks again. cheers.