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

No way to return an error once the WebSocket connection is established

Open lstrihic opened this issue 5 months ago • 6 comments

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
}

lstrihic avatar Sep 20 '24 19:09 lstrihic