/gqlgenws

WebSocket transports for gqlgen

Primary LanguageGoMIT LicenseMIT

gqlgenws

Go Doc Badge Go Report Card Badge

WebSocket transports for gqlgen.

Provided protocol implementations follow their respective specification as closely as possible.

Protocols

Usage

srv := handler.New(executableSchema)

initFunc := func(r *http.Request, p wsutil.ObjectPayload) (context.Context, wsutil.ObjectPayload, error) {
    ctx := r.Context()
    // ...
    return ctx, nil, nil
}

p1 := &graphqlws.Protocol{
    InitFunc: initFunc,
    PingInterval: 25 * time.Second,
}

p2 := &transportws.Protocol{
    InitFunc: initFunc,
    KeepAliveInterval: 25 * time.Second,
}

// Use the protocol directly as a transport.
srv.AddTransport(p1)
srv.AddTransport(p2)

// OR

// Use with Negotiator to do protocol negotiation.
srv.AddTransport(wstransport.NewNegotiator(p1, p2))