99designs / gqlgen

go generate based graphql server library
https://gqlgen.com
MIT License
9.96k stars 1.17k forks source link

client.SSE() block forever #3154

Open o8x opened 4 months ago

o8x commented 4 months ago

What happened?

I tried to complete a simple SSE example and passed the test using curl, but discovered the following problems while writing the go test case.

I found an unknown bug in client.SSE that will block forever once it is called. This bug appears to be for subscriptions only, as the two test cases in codegen/testserver/singlefile/defer_test.go work normally. I did not find an SSE test case for subscription in the project.

For Example:

server := handler.New(graph.NewExecutableSchema(graph.Config{
    Resolvers: &graph.Resolver{},
}))
server.AddTransport(transport.SSE{})
c := client.New(server)

sse := c.SSE(context.Background(), `subscription { 
    onTodoChange {
        action oldValue { id text done } newValue { id text done }
    }
}`)

// Never get here
var resp any
fmt.Println(sse.Next(&resp), resp)

Complete recurring use cases can be found here https://github.com/o8x/gqlgen/tree/sse-example/_examples/sse

What did you expect?

blocking in the sse.Next() method

Minimal graphql.schema and models to reproduce

type Todo {
    id: ID!
    text: String!
    done: Boolean!
}

enum TodoChangeAction {
    New
    ToggleDone
}

type TodoChangeMessage {
    newValue: Todo
    oldValue: Todo
    action: TodoChangeAction!
}

type Subscription {
    onTodoChange: TodoChangeMessage!
}

versions

StevenACoffman commented 4 months ago

I'm currently travelling, so this is hard to diagnose on just my cell phone. I would appreciate any help!