https://github.com/desuuuu/gqlgenws
WebSocket transports for gqlgen
https://github.com/desuuuu/gqlgenws
go golang gqlgen graphql-ws subscriptions-transport-ws transport websocket
Last synced: about 1 year ago
JSON representation
WebSocket transports for gqlgen
- Host: GitHub
- URL: https://github.com/desuuuu/gqlgenws
- Owner: Desuuuu
- License: mit
- Created: 2022-07-08T20:57:41.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2022-11-02T17:02:56.000Z (over 3 years ago)
- Last Synced: 2025-01-31T00:19:13.254Z (over 1 year ago)
- Topics: go, golang, gqlgen, graphql-ws, subscriptions-transport-ws, transport, websocket
- Language: Go
- Homepage:
- Size: 34.2 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gqlgenws
[![Go Doc Badge]][Go Doc] [![Go Report Card Badge]][Go Report Card]
WebSocket transports for [gqlgen](https://github.com/99designs/gqlgen).
Provided protocol implementations follow their respective specification as
closely as possible.
## Protocols
* [graphql-ws](https://github.com/enisdenjo/graphql-ws) in the `graphqlws` package.
* [subscriptions-transport-ws](https://github.com/apollographql/subscriptions-transport-ws) in the `transportws` package.
## Usage
```go
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))
```
[Go Doc]: https://pkg.go.dev/github.com/Desuuuu/gqlgenws
[Go Doc Badge]: https://pkg.go.dev/badge/github.com/Desuuuu/gqlgenws.svg
[Go Report Card]: https://goreportcard.com/report/github.com/Desuuuu/gqlgenws
[Go Report Card Badge]: https://goreportcard.com/badge/github.com/Desuuuu/gqlgenws