websocket

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2025 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 https://github.com/enisdenjo/graphql-ws/blob/master/PROTOCOL.md

Variables

This section is empty.

Functions

func Handler

func Handler(schema SchemaExecutor) http.HandlerFunc

Handler creates a WebSocket handler for GraphQL subscriptions

Types

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