https://github.com/bitquery/wsgraphql
graphql-go over websockets using graphql-[transport-]ws protocols
https://github.com/bitquery/wsgraphql
Last synced: 12 days ago
JSON representation
graphql-go over websockets using graphql-[transport-]ws protocols
- Host: GitHub
- URL: https://github.com/bitquery/wsgraphql
- Owner: bitquery
- License: mit
- Fork: true (eientei/wsgraphql)
- Created: 2022-08-31T08:57:54.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-09-08T14:22:14.000Z (over 3 years ago)
- Last Synced: 2024-06-20T11:49:06.972Z (over 1 year ago)
- Language: Go
- Homepage: https://gitlab.eientei.org/eientei/wsgraphql
- Size: 96.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://godoc.org/github.com/bitquery/wsgraphql/v1)
[](https://goreportcard.com/report/github.com/bitquery/wsgraphql)
[](https://codeclimate.com/github/bitquery/wsgraphql)
[](https://codeclimate.com/github/bitquery/wsgraphql)
An implementation of websocket transport for
[graphql-go](https://github.com/graphql-go/graphql).
Currently following flavors are supported:
- `graphql-ws` subprotocol, older spec: https://github.com/apollographql/subscriptions-transport-ws/blob/master/PROTOCOL.md
- `graphql-transport-ws` subprotocol, newer spec: https://github.com/enisdenjo/graphql-ws/blob/master/PROTOCOL.md
Inspired by [graphqlws](https://github.com/functionalfoundry/graphqlws)
Key features:
- Subscription support
- Callbacks at every stage of communication process for easy customization
- Supports both websockets and plain http queries, with http chunked response for plain http subscriptions
- [Mutable context](https://godoc.org/github.com/bitquery/wsgraphql/v1/mutable) allowing to keep request-scoped
connection/authentication data and operation-scoped state
Usage
-----
Assuming [gorilla websocket](https://github.com/gorilla/websocket) upgrader
```go
import (
"net/http"
"github.com/bitquery/wsgraphql/v1"
"github.com/bitquery/wsgraphql/v1/compat/gorillaws"
"github.com/gorilla/websocket"
"github.com/graphql-go/graphql"
)
```
```go
schema, err := graphql.NewSchema(...)
if err != nil {
panic(err)
}
srv, err := wsgraphql.NewServer(
schema,
wsgraphql.WithUpgrader(gorillaws.Wrap(&websocket.Upgrader{
Subprotocols: []string{
wsgraphql.WebsocketSubprotocolGraphqlWS.String(),
wsgraphql.WebsocketSubprotocolGraphqlTransportWS.String(),
},
})),
)
if err != nil {
panic(err)
}
http.Handle("/query", srv)
err = http.ListenAndServe(":8080", nil)
if err != nil {
panic(err)
}
```
Examples
--------
See [/v1/examples](/v1/examples)
- [minimal-graphql-ws](/v1/examples/minimal-graphql-ws) `graphql-ws` / older subscriptions-transport-ws server setup
- [minimal-graphql-transport-ws](/v1/examples/minimal-graphql-transport-ws) `graphql-transport-ws` / newer graphql-ws server setup
- [simpleserver](/v1/examples/simpleserver) complete example with subscriptions, mutations and queries