Skip to content

lexycore/wsgraphql

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

54 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Doc Reference Go Report Card Maintainability Test Coverage

An implementation of websocket transport for graphql-go.

Currently following flavors are supported:

Inspired by 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 allowing to keep request-scoped connection/authentication data and operation-scoped state

Usage

Assuming gorilla websocket upgrader

import (
	"net/http"

	"github.com/lexycore/wsgraphql/v1"
	"github.com/lexycore/wsgraphql/v1/compat/gorillaws"
	"github.com/gorilla/websocket"
	"github.com/graphql-go/graphql"
)
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

About

graphql-go over websockets using apollographql protocol

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go 97.4%
  • HTML 1.6%
  • Makefile 1.0%