Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
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.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 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