protocol

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrAckTimeout      = errors.New("connection_ack timeout")
	ErrAckNotReceived  = errors.New("expected connection_ack")
	ErrConnectionError = errors.New("connection error from server")
)

Functions

func NewGraphQLTransportWS

func NewGraphQLTransportWS() *graphqlTransportWS

func NewGraphQLWS

func NewGraphQLWS() *graphqlWS

Types

type Pinger

type Pinger interface {
	Ping(ctx context.Context, conn *websocket.Conn) error
	Pong(ctx context.Context, conn *websocket.Conn) error
}

Pinger is an optional interface for protocols that support client-initiated ping/pong (e.g. graphql-transport-ws). Protocols that only have server-initiated keep-alive (e.g. legacy graphql-ws with ka messages) do not implement this.

type Protocol

type Protocol interface {
	// Init performs the connection handshake with the server.
	Init(ctx context.Context, conn *websocket.Conn, payload map[string]any) error

	// Subscribe starts a subscription for the given operation.
	Subscribe(ctx context.Context, conn *websocket.Conn, id string, req *common.Request) error

	// Unsubscribe ends a subscription.
	Unsubscribe(ctx context.Context, conn *websocket.Conn, id string) error

	// Read blocks until the next message arrives and decodes it.
	Read(ctx context.Context, conn *websocket.Conn) (*WireMessage, error)
}

Protocol defines the message framing and behaviour used on a WS connection.

type WireMessage

type WireMessage struct {
	ID      string
	Type    WireMessageType
	Payload *common.ExecutionResult
	Err     error
}

WireMessage is a decoded wire-level protocol message. It is different from the common message format because it still contains the ID and internal type, which is not exposed to consumers.

func (*WireMessage) IntoClientMessage

func (m *WireMessage) IntoClientMessage() *common.Message

type WireMessageType

type WireMessageType uint8

WireMessageType identifies the message type.

const (
	MessageData WireMessageType = iota
	MessageError
	MessageComplete
	MessagePing
	MessagePong
)

func (WireMessageType) String

func (t WireMessageType) String() string

Jump to

Keyboard shortcuts

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