Documentation
¶
Index ¶
Constants ¶
const ( // Client -> Server MessageTypeConnectionInit = "connection_init" MessageTypeSubscribe = "subscribe" MessageTypeComplete = "complete" MessageTypePing = "ping" // Server -> Client MessageTypeConnectionAck = "connection_ack" MessageTypeNext = "next" MessageTypeError = "error" // MessageTypeComplete is used bidirectionally (already defined above) MessageTypePong = "pong" )
graphql-ws protocol message types (modern) https://github.com/enisdenjo/graphql-ws/blob/master/PROTOCOL.md
const ( LegacyMessageTypeStart = "start" // equivalent to "subscribe" LegacyMessageTypeStop = "stop" // equivalent to "complete" LegacyMessageTypeConnectionTerminate = "connection_terminate" // client wants to close )
Legacy subscriptions-transport-ws protocol message types. These are accepted for backward compatibility with older clients and gateways (e.g., Cosmo Router in AUTO sub-protocol mode). https://github.com/apollographql/subscriptions-transport-ws/blob/master/PROTOCOL.md
const SubprotocolGraphQLTransportWS = "graphql-transport-ws"
SubprotocolGraphQLTransportWS is the WebSocket sub-protocol for the modern graphql-ws protocol (https://github.com/enisdenjo/graphql-ws).
Variables ¶
This section is empty.
Functions ¶
func Handler ¶
func Handler(schema SchemaExecutor) http.HandlerFunc
Handler creates a WebSocket handler for GraphQL subscriptions
Types ¶
type ContextBuilderProvider ¶ added in v0.7.0
ContextBuilderProvider is an optional interface that SchemaExecutor can implement to provide per-request context building (e.g., for authentication). The WebSocket handler calls GetContextBuilder with the HTTP upgrade request so subscriptions receive the same auth context as queries/mutations.
type ErrorPayload ¶
type ErrorPayload struct {
Message string `json:"message"`
}
ErrorPayload is the payload for an error message
type GraphQLError ¶
type GraphQLError struct {
Message string `json:"message"`
Path []interface{} `json:"path,omitempty"`
}
GraphQLError represents a GraphQL error
type Message ¶
type Message struct {
ID string `json:"id,omitempty"`
Type string `json:"type"`
Payload json.RawMessage `json:"payload,omitempty"`
}
Message represents a graphql-ws protocol message
func CompleteMessage ¶
CompleteMessage creates a complete message
func ConnectionAckMessage ¶
func ConnectionAckMessage() Message
ConnectionAckMessage creates a connection_ack message
func ConnectionInitMessage ¶
func ConnectionInitMessage() Message
ConnectionInitMessage creates a connection_init message
func ErrorMessage ¶
ErrorMessage creates an error message
func NextMessage ¶
func NextMessage(id string, data interface{}, errors []GraphQLError) (Message, error)
NextMessage creates a next message with data
type NextPayload ¶
type NextPayload struct {
Data interface{} `json:"data,omitempty"`
Errors []GraphQLError `json:"errors,omitempty"`
}
NextPayload is the payload for a next message (subscription data)
type SchemaExecutor ¶
type SchemaExecutor interface {
ExecuteSubscription(ctx context.Context, query string, variables map[string]interface{}, operationName string) (<-chan interface{}, error)
}
SchemaExecutor defines the interface for executing GraphQL subscriptions This avoids import cycles with the main rocket package
type SubscribePayload ¶
type SubscribePayload struct {
Query string `json:"query"`
Variables map[string]interface{} `json:"variables,omitempty"`
OperationName string `json:"operationName,omitempty"`
}
SubscribePayload is the payload for a subscribe message