WebSocket transports for gqlgen.
Provided protocol implementations follow their respective specification as closely as possible.
- graphql-ws in the
graphqlws
package. - subscriptions-transport-ws in the
transportws
package.
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))