-
Notifications
You must be signed in to change notification settings - Fork 493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No way to return an error once the WebSocket connection is established #648
Comments
@lstrihic can u share full code example to see how can enable and use ws for graphql-go subscription, thank u |
Basically the full example is in the description not sure what else you want me to provide. (updated description code a bit) I hope this helps. |
there is no full example on description |
I believe that in such cases you have to include some error message or state inside of your message schema. For example, one of the members of the MessageResolver could be an func (r *Resolver) OnMessage(ctx context.Context, args struct {
ChatID string
}) (chan *MessageResolver, error) {
ch := make(chan *MessageResolver)
msgCh, errCh := r.Service.Subscribe(args.ChatID)
go func() {
defer close(ch)
for {
select{
case <-ctx.Done():
return
case err := <-errCh:
// TODO: how to send error back to client
ch <- &MessageResolver{
Err: err, // treat errors as part of your data
Message: nil, // this is redundant, but added for clarity
}
return
case msg, ok := <-msgCh:
if !ok {
return
}
ch <- &MessageResolver{
Message: msg,
}
}
}
}()
return ch, nil
} Feel free to reopen if you believe that this is an issue with the library. |
@pavelnikolov yes, you are right, I can do that, but that is not the way to do it. To me it seems like a walk around solution. Error should be returned by the library, and it should be structured like this:
So I wanna be able to somehow tell the library that there is an error and a library should return the error. |
In that case, feel free to reopen the ticket and I'll look into it. By the way PRs are more than welcome. The resolver would return an error exactly in the format you provided if the error occurred initially. After that it's just messages in this simple implementation. |
There is no way to return an error once a connection is established.
The text was updated successfully, but these errors were encountered: