https://github.com/eientei/wsgraphql
graphql-go over websockets using graphql-[transport-]ws protocols
https://github.com/eientei/wsgraphql
apollo-graphql apollographl apollographql-subscriptions go go-library golang graphql graphql-api graphql-server graphql-subscriptions graphql-ws websocket
Last synced: 5 months ago
JSON representation
graphql-go over websockets using graphql-[transport-]ws protocols
- Host: GitHub
- URL: https://github.com/eientei/wsgraphql
- Owner: eientei
- License: mit
- Created: 2019-02-04T22:44:19.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-08-05T13:53:31.000Z (almost 3 years ago)
- Last Synced: 2024-11-15T12:48:16.565Z (over 1 year ago)
- Topics: apollo-graphql, apollographl, apollographql-subscriptions, go, go-library, golang, graphql, graphql-api, graphql-server, graphql-subscriptions, graphql-ws, websocket
- Language: Go
- Homepage: https://gitlab.eientei.org/eientei/wsgraphql
- Size: 116 KB
- Stars: 9
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://godoc.org/github.com/eientei/wsgraphql/v1)
[](https://goreportcard.com/report/github.com/eientei/wsgraphql)
[](https://codeclimate.com/github/eientei/wsgraphql)
[](https://codeclimate.com/github/eientei/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
- Interceptors 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/eientei/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/eientei/wsgraphql/v1"
"github.com/eientei/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