Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Zaba505/gws
A WebSocket client and server for GraphQL
https://github.com/Zaba505/gws
go golang graphql graphql-websocket websockets
Last synced: 14 days ago
JSON representation
A WebSocket client and server for GraphQL
- Host: GitHub
- URL: https://github.com/Zaba505/gws
- Owner: Zaba505
- License: mit
- Created: 2020-06-08T19:51:36.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-09-04T06:02:11.000Z (about 4 years ago)
- Last Synced: 2024-07-31T20:52:46.167Z (3 months ago)
- Topics: go, golang, graphql, graphql-websocket, websockets
- Language: Go
- Size: 89.8 KB
- Stars: 7
- Watchers: 2
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - gws - Apollos' "GraphQL over Websocket" client and server implementation. (Query Language / HTTP Clients)
- zero-alloc-awesome-go - gws - Apollos' "GraphQL over Websocket" client and server implementation. (Query Language / HTTP Clients)
- awesome-go-extra - gws - 06-08T19:51:36Z|2020-09-04T06:02:11Z| (Query Language / HTTP Clients)
README
[![Go Report Card](https://goreportcard.com/badge/github.com/zaba505/gws)](https://goreportcard.com/report/github.com/zaba505/gws)
[![GoDoc](https://godoc.org/github.com/Zaba505/gws?status.svg)](https://pkg.go.dev/github.com/zaba505/gws?tab=doc)
[![build](https://github.com/Zaba505/gws/workflows/build/badge.svg)](https://github.com/Zaba505/gws/actions)
[![codecov](https://codecov.io/gh/Zaba505/gws/branch/master/graph/badge.svg)](https://codecov.io/gh/Zaba505/gws)
[![Mentioned in Awesome Go](https://awesome.re/mentioned-badge.svg)](https://github.com/avelino/awesome-go)# gws
A WebSocket client and server for GraphQL.`gws` implements Apollos' "GraphQL over WebSocket" protocol,
which can be found in PROTOCOL.md. It provides an RPC-like API for both
client and server usage.## Getting Started
`gws` provides both a client and server implementation for the
"GraphQL over Websocket" protocol.### Client
To create a client, you must first dial the server like:
```go
conn, err := gws.Dial(context.TODO(), "ws://example.com")
// Don't forget to handle the error
````gws.Dial` will return high-level abstraction around the
underlying connection. This is very similar to gRPCs'
behaviour. After dialing the server, now simply wrap the
return conn and begin performing queries, like:
```go
client := gws.NewClient(conn)resp, err := client.Query(context.TODO(), &gws.Request{Query: "{ hello { world } }"})
// Don't forget to handle the errorvar data struct{
Hello struct{
World string
}
}
err = json.Unmarshal(resp.Data, &data)
```### Server
The server implementation provided isn't actually a standalone
server but instead just a specially configured `http.Handler`.
This is because the underlying protocol is simply WebSocket,
which runs on top of HTTP. Creating a bare bones handler is
as simple as the following:
```go
msgHandler := func(s *Stream, req *Request) error {
// Handle request
return nil
}http.ListenAndServe(":8080", gws.NewHandler(gws.HandlerFunc(msgHandler)))
```