functionalfoundry / Graphqlws
Licence: mit
Implementation of the GraphQL over WebSocket protocol in Go.
Stars: ✭ 139
Projects that are alternatives of or similar to Graphqlws
Graphql Ws
Coherent, zero-dependency, lazy, simple, GraphQL over WebSocket Protocol compliant server and client.
Stars: ✭ 398 (+186.33%)
Mutual labels: graphql, server, websockets
Framework
Strongly-typed JavaScript object with support for validation and error handling.
Stars: ✭ 136 (-2.16%)
Mutual labels: graphql, backend
Swindon
An HTTP edge (frontend) server with smart websockets support
Stars: ✭ 87 (-37.41%)
Mutual labels: server, websockets
Omdb Graphql Wrapper
🚀 GraphQL wrapper for the OMDb API
Stars: ✭ 45 (-67.63%)
Mutual labels: graphql, server
Siler
⚡ Flat-files and plain-old PHP functions rockin'on as a set of general purpose high-level abstractions.
Stars: ✭ 1,056 (+659.71%)
Mutual labels: graphql, websockets
Socketcluster Server
Minimal server module for SocketCluster
Stars: ✭ 70 (-49.64%)
Mutual labels: server, websockets
Local Web Server
A lean, modular web server for rapid full-stack development.
Stars: ✭ 916 (+558.99%)
Mutual labels: server, backend
Async Graphql
A GraphQL server library implemented in Rust
Stars: ✭ 1,377 (+890.65%)
Mutual labels: graphql, server
Micro
Micro is a distributed cloud operating system
Stars: ✭ 10,778 (+7653.96%)
Mutual labels: server, backend
Kuzzle
Open-source Back-end, self-hostable & ready to use - Real-time, storage, advanced search - Web, Apps, Mobile, IoT -
Stars: ✭ 991 (+612.95%)
Mutual labels: websockets, backend
Ultimate Backend
Multi tenant SaaS starter kit with cqrs graphql microservice architecture, apollo federation, event source and authentication
Stars: ✭ 978 (+603.6%)
Mutual labels: graphql, backend
Subscriptions Transport Sse
A Server-Side-Events (SSE) client + server for GraphQL subscriptions
Stars: ✭ 55 (-60.43%)
Mutual labels: graphql, server
Blaze
⚡ File sharing progressive web app built using WebTorrent and WebSockets
Stars: ✭ 991 (+612.95%)
Mutual labels: websockets, backend
Graphql Microservices
Showcasing a graphql microservice setup
Stars: ✭ 68 (-51.08%)
Mutual labels: graphql, backend
Signalw
Even simpler and faster real-time web for ASP.NET Core.
Stars: ✭ 125 (-10.07%)
Mutual labels: server, websockets
Starlette
The little ASGI framework that shines. 🌟
Stars: ✭ 6,337 (+4458.99%)
Mutual labels: graphql, websockets
Uvicorn Gunicorn Starlette Docker
Docker image with Uvicorn managed by Gunicorn for high-performance Starlette web applications in Python 3.7 and 3.6 with performance auto-tuning. Optionally with Alpine Linux.
Stars: ✭ 92 (-33.81%)
Mutual labels: graphql, websockets
Note: We're looking for a new maintainer for graphqlws
. Please reach out via [email protected] if you're interested.
graphqlws
Implementation of the GraphQL over WebSocket protocol in Go. Brought to you by Functional Foundry.
Getting started
- Install dependencies:
go get github.com/sirupsen/logrus go get github.com/x-cray/logrus-prefixed-formatter go get github.com/google/uuid go get github.com/gorilla/websocket go get github.com/graphql-go/graphql
- Clone the repository:
mkdir -p "$GOPATH/src/github.com/functionalfoundry" cd "$GOPATH/src/github.com/functionalfoundry" git clone https://github.com/functionalfoundry/graphqlws
- Run the tests:
cd graphqlws go test
- Run the example server:
go run graphqlws/examples/server
Usage
Setup
package main
import (
"net/http"
"github.com/functionalfoundry/graphqlws"
"github.com/graphql-go/graphql"
)
func main() {
// Create a GraphQL schema
schema, err := graphql.NewSchema(...)
// Create a subscription manager
subscriptionManager := graphqlws.NewSubscriptionManager(&schema)
// Create a WebSocket/HTTP handler
graphqlwsHandler := graphqlws.NewHandler(graphqlws.HandlerConfig{
// Wire up the GraphqL WebSocket handler with the subscription manager
SubscriptionManager: subscriptionManager,
// Optional: Add a hook to resolve auth tokens into users that are
// then stored on the GraphQL WS connections
Authenticate: func(authToken string) (interface{}, error) {
// This is just a dumb example
return "Joe", nil
},
})
// The handler integrates seamlessly with existing HTTP servers
http.Handle("/subscriptions", graphqlwsHandler)
http.ListenAndServe(":8080", nil)
}
Working with subscriptions
// This assumes you have access to the above subscription manager
subscriptions := subscriptionManager.Subscriptions()
for conn, _ := range subscriptions {
// Things you have access to here:
conn.ID() // The connection ID
conn.User() // The user returned from the Authenticate function
for _, subscription := range subscriptions[conn] {
// Things you have access to here:
subscription.ID // The subscription ID (unique per conn)
subscription.OperationName // The name of the operation
subscription.Query // The subscription query/queries string
subscription.Variables // The subscription variables
subscription.Document // The GraphQL AST for the subscription
subscription.Fields // The names of top-level queries
subscription.Connection // The GraphQL WS connection
// Prepare an execution context for running the query
ctx := context.Context()
// Re-execute the subscription query
params := graphql.Params{
Schema: schema, // The GraphQL schema
RequestString: subscription.Query,
VariableValues: subscription.Variables,
OperationName: subscription.OperationName,
Context: ctx,
}
result := graphql.Do(params)
// Send query results back to the subscriber at any point
data := graphqlws.DataMessagePayload{
// Data can be anything (interface{})
Data: result.Data,
// Errors is optional ([]error)
Errors: graphqlws.ErrorsFromGraphQLErrors(result.Errors),
}
subscription.SendData(&data)
}
}
Logging
graphqlws
uses logrus for logging.
In the future we might remove those logs entirely to leave logging entirely to developers
using graphqlws
. Given the current solution, you can control the logging level of
graphqlws
by setting it through logrus
:
import (
log "github.com/sirupsen/logrus"
)
...
log.SetLevel(log.WarnLevel)
License
Copyright © 2017-2019 Functional Foundry, LLC.
Licensed under the MIT License.
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].