How to make sure my graphql subscription api is working?

58 views Asked by At

This is my subscription resolver in golang:

func (r *subscriptionResolver) CreateChatWithBot(ctx context.Context, req model.CreateChatWithBotRequest) (<-chan *model.CreateChatWithBotResults, error) {
    ch := make(chan *model.CreateChatWithBotResults)

    testString := []string{"This", "part", "is", "under", "construction", "...", " Be", "patient", "please!"}
    go func() {
        defer close(ch)
        for _, v := range testString {    
            select {
            case <-ctx.Done():
                return

            case ch <- &model.CreateChatWithBotResults{Response: pointer.Pointer(v)}:
            }
        }
    }()
    return ch, nil
}

When I use this API in postman, I only get the first word("This"). What could be the problem here?

{
    "data": {
        "createChatWithBot": {
            "response": "This"
        }
    }
}

I used gqlgen official document.

Update: I added more logs and noticed case with context.Done() executes in the second round of the for loop.

It worth mentioning that the server is running in GCP.

0

There are 0 answers