Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrConnectionClosed = errors.New("connection closed")
Functions ¶
This section is empty.
Types ¶
type ExecutionResult ¶
type ExecutionResult struct {
Data json.RawMessage `json:"data,omitempty"`
Errors json.RawMessage `json:"errors,omitempty"`
Extensions json.RawMessage `json:"extensions,omitempty"`
}
ExecutionResult is the GraphQL response payload for data and error messages.
type Handler ¶
type Handler func(msg *Message)
Handler receives subscription messages. It is called synchronously on the transport's read goroutine; a slow handler blocks message delivery.
type Message ¶
type Message struct {
Type MessageType
Payload *ExecutionResult
Err error // only set when Type == MessageTypeConnectionError
}
Message is a single subscription event delivered to a Handler.
type MessageType ¶
type MessageType uint8
MessageType identifies the kind of message delivered on a subscription channel.
const ( MessageTypeUnknown MessageType = iota MessageTypeData // normal data payload MessageTypeError // GraphQL-level error from server (has Payload) MessageTypeComplete // subscription completed normally MessageTypeConnectionError // connection-level error (has Err) )
func (MessageType) IsTerminal ¶
func (t MessageType) IsTerminal() bool
IsTerminal reports whether the message type signals end-of-stream.
type Options ¶
type Options struct {
Endpoint string
Headers http.Header
InitPayload map[string]any
Transport TransportType
// Only affects the WebSocket transport.
WSSubprotocol WSSubprotocol
// Only affects the SSE transport.
SSEMethod SSEMethod
}
Options configures a single subscription request (endpoint, headers, transport selection).
type Request ¶
type Request struct {
Query string `json:"query"`
OperationName string `json:"operationName,omitempty"`
Variables json.RawMessage `json:"variables,omitempty"`
Extensions json.RawMessage `json:"extensions,omitempty"`
}
Request is a GraphQL operation sent to the server when subscribing.
type TransportType ¶
type TransportType string
TransportType selects the subscription transport mechanism.
const ( TransportWS TransportType = "ws" // WebSocket connection TransportSSE TransportType = "sse" // Server-Sent Events over HTTP )
type WSSubprotocol ¶
type WSSubprotocol string
WSSubprotocol selects the GraphQL-over-WebSocket subprotocol.
const ( SubprotocolAuto WSSubprotocol = "" // Auto, negotiated with the server SubprotocolGraphQLTransportWS WSSubprotocol = "graphql-transport-ws" // Modern protocol from The Guild SubprotocolGraphQLWS WSSubprotocol = "graphql-ws" // Legacy Apollo protocol, deprecated )
func (WSSubprotocol) Subprotocols ¶
func (s WSSubprotocol) Subprotocols() []string
Subprotocols returns the WebSocket subprotocol strings to offer during the upgrade handshake.