Closed amorey closed 1 year ago
Hi @amorey
Thanks for reporting. There would be some breaking changes after the update. I'll check soon
I have reproduced your issue. There are several points:
subscriptionClient = subscriptionClient.
WithTimeout(5 * time.Second).
OnError(func(sc *SubscriptionClient, err error) error {
log.Println(err)
})
I'll add an update to handle the timeout behavior of the WebSocket client soon.
@hgiasac Thanks for looking into the issue! I have a question about this line in the logs:
2023/03/07 12:43:10 {"id":"88b45ff2-b349-420c-866e-1a23d694649b","type":"complete"} server
Is this being received by the client? If so, how does the client respond? What happens to the underlying websocket connection?
According to the subscription spec, the message type notifies that the subscription operation was end. It is sent from the server. The WebSocket connection still continues to run if there is at least 1 other running subscription. If there isn't any subscription the client will automatically close.
Ahh I see, thanks for the explanation! Then it sounds like the issue I'm having is that I want to detect the end of the subscription but OnDisconnect()
is called when the websocket connection is closed, not necessarily when the subscription is ended. Is there a way to detect the end of the subscription with go-graphql-client
? If not, is this something you would consider adding to the client?
Yes, I'll improve this event
Just to confirm. You expect the OnDisconnect
event to be called whenever the WebSocket connection is disconnected, right? That makes sense because the event doesn't need to be triggered when the client is closed
That'd be great, thank you. In my specific use case, I'm using go-graphql-client
in a unit test to ensure that the server is ending a subscription properly so I want to detect when the server emits a GQL_COMPLETE
event.
Hi @amorey
Please check out the PR https://github.com/hasura/go-graphql-client/pull/82 to verify if it solves your issue, thanks
Works great! Thanks!
I have a subscription resolver that closes the connection server-side and when I upgraded to go-graphql-client v0.9.1 I noticed that the SubscriptionClient stopped calling the OnDisconnected() method on server-close. I'm attaching a test file that demonstrates this behavior (see below).
This is the log output in v0.9.0 ("OnDisconnected" present):
And this is the log output in v0.9.1 ("OnDisconnected" missing):
Is this behavior expected?
Here is the test file (will run in root directory of go-graphql-client):