Documentation
¶
Index ¶
- Variables
- func NewHandler(config HandlerConfig) http.Handler
- type AuthenticateFunc
- type ChanMgr
- type Connection
- type ConnectionConfig
- type ConnectionEventHandlers
- type DataMessagePayload
- type HandlerConfig
- type InitMessagePayload
- type Logger
- type OperationMessage
- type ResultChan
- type StartMessagePayload
Constants ¶
This section is empty.
Variables ¶
var ConnKey any = "conn"
ConnKey the connection key
Functions ¶
func NewHandler ¶
func NewHandler(config HandlerConfig) http.Handler
NewHandler creates a new handler
Types ¶
type AuthenticateFunc ¶
AuthenticateFunc is a function that resolves an auth token into a user (or returns an error if that isn't possible).
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 ¶
DataMessagePayload defines the result data of an operation.
type HandlerConfig ¶
type HandlerConfig struct {
Logger Logger
Authenticate AuthenticateFunc
Schema graphql.Schema
RootValue map[string]any
}
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 OperationMessage ¶
type OperationMessage struct {
ID string `json:"id"`
Type string `json:"type"`
Payload any `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
}