graphql-platform icon indicating copy to clipboard operation
graphql-platform copied to clipboard

StrawberryShake v12 that says it supports the graphql-ws protocol defaults its subprotocol to the wrong spec

Open elemental1313 opened this issue 3 years ago • 11 comments

Is your feature request related to a problem?

Hello! I saw that the StrawberryShake GQL Client had documentation to support the graphql-ws protocol as located here: https://chillicream.com/docs/strawberryshake/networking#protocols

But in the code I see that the default protocol that gets added is "graphql-ws" and not "graphql-transport-ws" (which the official documentation here states should be the correct subprotocol, I know, its weird that the project is called graphql-ws but the sub protocol they expect is graphql-transport-ws) which is what my graphql server im trying to connect to is using (not currently using hotchocolate) and the traffic manager that makes sure the protocols match up give me an error, since i cannot specify only "graphql-transport-ws" as the sole protocol.

Here is the file in question that has that default set: https://github.com/ChilliCream/hotchocolate/blob/d412413d5f93f74e897c1253e4786f61fc59f773/src/StrawberryShake/Client/src/Transport.WebSockets/Protocols/GraphQLWebSocket/GraphQLWebSocketProtocolFactory.cs

The solution you'd like

I would love the ability to be able to set my own default protocol or have the option to configure my StrawberryShake client to use graphql-transport-ws protocol for subscriptions. I assume the change would be in this file: https://github.com/ChilliCream/hotchocolate/blob/d412413d5f93f74e897c1253e4786f61fc59f773/src/StrawberryShake/Client/src/Transport.WebSockets/Protocols/GraphQLWebSocket/GraphQLWebSocketProtocolFactory.cs

(I tried to make an edit myself to submit as a suggestion but it didnt work locally how i thought it would, so wondering if someone in the community can help me or maybe look into this to see if im correct or not)

Product

Strawberry Shake

elemental1313 avatar Jun 28 '22 12:06 elemental1313

Having same issue after tying out this package. So full disclosure I'm just another potential consumer and and you may need to take what I have to say with a grain of salt. But from my investigation there isn't so much a default protocol here as there is only one available protocol implemented for the client at the moment. You can certainly add additional protocols to the connection request to the server via calling ConfigureWebSocketClient, however it will do little good as the client will immediately close the connection since it does not have an implementation for the protocol.

If you were felling like getting it working yourself it looks like you would need a separate IProtocolFacotry for the protocol (graphql-transport-ws) as well as a proper implementation of the ISocketProtocol interface that the factory returns that appropriately handles the graphql-transport-ws protocol. Then you could register that factory (presumably via AddProtocol on she ServiceCollection) and have it available for use with socket communication. Sadly I as mentioned did not see such implementation when searching in the code which means you would have to implement yourself.

TLDR; from what I can tell the client support for graphql-transport-ws protocol does not seem to be available (yet?). Perhaps the new protocol may be only supported in the server side code but at the moment not the client which is why its mentioned in the documentation?

kstaas1 avatar Jun 30 '22 20:06 kstaas1

Yes this is a better explanation of what I was seeing. It does sound like the client is missing this protocol support as you say ( I only noticed the protocol name in the code and assumed it had support for it as the documentation states). Anyway, I LOVE this client, it was so easy to adopt and queries work awesome. I just wanted the subscriptions to function as well with the graphql-transport-ws protocol. I do hope this gets edited in the future, I would love to attempt to figure this out myself but I dont have the time currently and clearly i need to read up a bit more on how the protocols work.

elemental1313 avatar Jul 06 '22 11:07 elemental1313

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Nov 03 '22 20:11 stale[bot]

Still looking for some assistance on this, perhaps in the future when I have time i could propose a solution but i just dont :(

elemental1313 avatar Nov 03 '22 20:11 elemental1313

We will add new subscription protocols in 13 ... this is on our backlog.

michaelstaib avatar Nov 18 '22 19:11 michaelstaib

Looking forward to it! Thanks!

elemental1313 avatar Nov 21 '22 12:11 elemental1313

I'm confused about the current state of subscription protocols after reading the documentation (which promises to deliver SignalR and GRPC in version 12?)

Can we get an update from the maintainers here?

kmcclellan avatar Mar 23 '23 18:03 kmcclellan

Im not a maintainer but I just wanted to pop in that I do think they realize this issue, as @michaelstaib stated above a couple months ago. Currently (from my own testing of the implementation) strawberryshake client (an amazing client that auto generates alot of the schema and code you need) utilizes the older graphql-ws protocol. However if you use their server Hot Chocolate, that can indeed utilize the graphql-transport-ws (a new way of communicating to graphql for subscribing), as they have a separate client for that.

The new graphql-transport-ws (more here ) has a different workflow for subscriptions, where it needs to first make a connection_init call, then a connection_ack, followed by Subscribe, Next, Complete, etc. So it has alot more going on and if that was in the strawberry shake client, then i could use it as a client to communicate to more modern graphql servers. However if you are using Hot Chocolate, then you should be all set as far as I know.

elemental1313 avatar Mar 23 '23 18:03 elemental1313

If I'm looking in the right place, it appears that currently Hot Chocolate also only supports the outdated protocol?

The reason I'm asking is that I need to know how GraphQL subscriptions handle unexpected connection interruptions. graphql-transport-ws includes Ping and Pong to support detecting these. Is there any documentation on this other protocol?

kmcclellan avatar Mar 23 '23 18:03 kmcclellan

For that older stuff you could try this link which is just graphql-ws's older version of the protocol i linked above. Doing a quick search, you are looking for the old protocol's "GQL_CONNECTION_KEEP_ALIVE". I suggest searching the repo for the phrase "keep alive" and you will see some good tests and other files that should help you. But in the mean time, this post and thread is about getting the graphql-transport-ws protocol type added to strawberryshake client for websockets 😄 (or perhaps a contributor can chime in, again im just a friendly stranger who REALLY likes this repo)

elemental1313 avatar Mar 23 '23 19:03 elemental1313