websocket

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Feb 19, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
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

View Source
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

View Source
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

type ContextBuilderProvider interface {
	GetContextBuilder() func(r *http.Request) context.Context
}

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

func CompleteMessage(id string) Message

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

func ErrorMessage(id string, errorMsg string) (Message, error)

ErrorMessage creates an error message

func NextMessage

func NextMessage(id string, data interface{}, errors []GraphQLError) (Message, error)

NextMessage creates a next message with data

func PongMessage

func PongMessage() Message

PongMessage creates a pong message

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

Jump to

Keyboard shortcuts

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