graphql-go
graphql-go copied to clipboard
No way to return an error once the WebSocket connection is established
There is no way to return an error once a connection is established.
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 <-errCh:
// TODO: how to send error back to client
return
case msg, ok := <-msgCh:
if !ok {
return
}
ch <- &MessageResolver{
Message: msg,
}
}
}
}()
return ch, nil
}