graphqlws

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ConnKey interface{} = "conn"

ConnKey the connection key

Functions

func NewHandler

func NewHandler(config HandlerConfig) http.Handler

NewHandler creates a new handler

Types

type AuthenticateFunc

type AuthenticateFunc func(data map[string]interface{}, conn Connection) (context.Context, error)

AuthenticateFunc is a function that resolves an auth token into a user (or returns an error if that isn't possible).

type ChanMgr

type ChanMgr struct {
	// contains filtered or unexported fields
}

func (*ChanMgr) Add

func (c *ChanMgr) Add(cid, oid string, ch chan *graphql.Result)

func (*ChanMgr) Del

func (c *ChanMgr) Del(cid, oid string) bool

func (*ChanMgr) DelConn

func (c *ChanMgr) DelConn(cid string) bool

type Connection

type Connection interface {
	// ID returns the unique ID of the connection.
	ID() string

	// Context returns the context for the connection
	Context() context.Context

	// WS the websocket
	WS() *websocket.Conn

	// SendData sends results of executing an operation (typically a
	// subscription) to the client.
	SendData(string, *DataMessagePayload)

	// SendError sends an error to the client.
	SendError(error)
}

Connection is an interface to represent GraphQL WebSocket connections. Each connection is associated with an ID that is unique to the server.

func NewConnection

func NewConnection(ws *websocket.Conn, config ConnectionConfig) Connection

NewConnection establishes a GraphQL WebSocket connection. It implements the GraphQL WebSocket protocol by managing its internal state and handling the client-server communication.

type ConnectionConfig

type ConnectionConfig struct {
	Logger        Logger
	Authenticate  AuthenticateFunc
	EventHandlers ConnectionEventHandlers
}

ConnectionConfig defines the configuration parameters of a GraphQL WebSocket connection.

type ConnectionEventHandlers

type ConnectionEventHandlers struct {
	// Close is called whenever the connection is closed, regardless of
	// whether this happens because of an error or a deliberate termination
	// by the client.
	Close func(Connection)

	// StartOperation is called whenever the client demands that a GraphQL
	// operation be started (typically a subscription). Event handlers
	// are expected to take the necessary steps to register the operation
	// and send data back to the client with the results eventually.
	StartOperation func(Connection, string, *StartMessagePayload) []error

	// StopOperation is called whenever the client stops a previously
	// started GraphQL operation (typically a subscription). Event handlers
	// are expected to unregister the operation and stop sending result
	// data to the client.
	StopOperation func(Connection, string)
}

ConnectionEventHandlers define the event handlers for a connection. Event handlers allow other system components to react to events such as the connection closing or an operation being started or stopped.

type DataMessagePayload

type DataMessagePayload struct {
	Data   interface{} `json:"data"`
	Errors []error     `json:"errors"`
}

DataMessagePayload defines the result data of an operation.

type HandlerConfig

type HandlerConfig struct {
	Logger       Logger
	Authenticate AuthenticateFunc
	Schema       graphql.Schema
	RootValue    map[string]interface{}
}

HandlerConfig config

type InitMessagePayload

type InitMessagePayload struct {
	AuthToken     string `json:"authToken"`
	Authorization string `json:"Authorization"`
}

InitMessagePayload defines the parameters of a connection init message.

type Logger

type Logger interface {
	Infof(format string, data ...interface{})
	Debugf(format string, data ...interface{})
	Errorf(format string, data ...interface{})
	Warnf(format string, data ...interface{})
}

type OperationMessage

type OperationMessage struct {
	ID      string      `json:"id"`
	Type    string      `json:"type"`
	Payload interface{} `json:"payload"`
}

OperationMessage represents a GraphQL WebSocket message.

func (OperationMessage) String

func (msg OperationMessage) String() string

type ResultChan

type ResultChan struct {
	// contains filtered or unexported fields
}

type StartMessagePayload

type StartMessagePayload struct {
	Query         string                 `json:"query"`
	Variables     map[string]interface{} `json:"variables"`
	OperationName string                 `json:"operationName"`
}

StartMessagePayload defines the parameters of an operation that a client requests to be started.

Jump to

Keyboard shortcuts

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