wsgraphql

module
v1.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 11, 2022 License: MIT

README

Go Doc Reference Go Report Card Maintainability Test Coverage

An implementation of apollo graphql websocket protocol for graphql-go.

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/eientei/wsgraphql/v1"
	"github.com/eientei/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,
	nil,
	wsgraphql.WithUpgrader(gorillaws.Wrap(&websocket.Upgrader{
		Subprotocols: []string{wsgraphql.WebsocketSubprotocol},
	})),
)
if err != nil {
	panic(err)
}

http.Handle("/query", srv)

err = http.ListenAndServe(":8080", nil)
if err != nil {
	panic(err)
}

Examples

See /v1/examples

Directories

Path Synopsis
v1
Package wsgraphql provides interfaces for server and client
Package wsgraphql provides interfaces for server and client
apollows
Package apollows provides implementation of GraphQL over WebSocket Protocol as defined by apollo graphql see https://github.com/apollographql/subscriptions-transport-ws/blob/master/PROTOCOL.md for reference
Package apollows provides implementation of GraphQL over WebSocket Protocol as defined by apollo graphql see https://github.com/apollographql/subscriptions-transport-ws/blob/master/PROTOCOL.md for reference
compat/gorillaws
Package gorillaws provides compatibility for gorilla websocket upgrader
Package gorillaws provides compatibility for gorilla websocket upgrader
mutable
Package mutable provides v1.mutable context, that can store multiple values and be updated after creation
Package mutable provides v1.mutable context, that can store multiple values and be updated after creation

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL