transport

package
v2.33.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 20 Imported by: 4 modules, 3 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrDialFailed = errors.New("websocket dial failed")

ErrDialFailed indicates that the WebSocket dial (TCP + HTTP upgrade) failed. The underlying cause is available via errors.Unwrap.

View Source
var ErrInitFailed = errors.New("protocol init failed")

ErrInitFailed indicates that the GraphQL protocol init (connection_init / connection_ack handshake) failed after a successful WebSocket dial. The underlying cause (e.g. protocol.ErrAckTimeout) is available via errors.Unwrap.

View Source
var ErrSubscriptionExists = errors.New("subscription ID already exists")

Functions

This section is empty.

Types

type ErrFailedSubscriptionConnection added in v2.21.1

type ErrFailedSubscriptionConnection struct {
	URL        string
	StatusCode int
}

ErrFailedSubscriptionConnection reports an HTTP response that rejected a WS or SSE connection.

func (ErrFailedSubscriptionConnection) Error added in v2.21.1

type ErrInvalidSubprotocol

type ErrInvalidSubprotocol string

func (ErrInvalidSubprotocol) Error

func (e ErrInvalidSubprotocol) Error() string

type SSETransport

type SSETransport struct {
	// contains filtered or unexported fields
}

SSETransport implements the Transport interface using Server-Sent Events. Unlike WebSocket, each subscription creates a separate HTTP request. TCP connection reuse is handled by http.Client's connection pool.

Supports both POST (graphql-sse spec) and GET (traditional SSE) methods.

func NewSSETransport

func NewSSETransport(ctx context.Context, client *http.Client, log abstractlogger.Logger) *SSETransport

NewSSETransport creates a new SSETransport with the provided http.Client. The transport will automatically close all connections when ctx is cancelled.

func (*SSETransport) ConnCount

func (t *SSETransport) ConnCount() int

ConnCount returns the number of active SSE connections.

func (*SSETransport) Subscribe

func (t *SSETransport) Subscribe(ctx context.Context, req *common.Request, opts common.Options, handler common.Handler) (func(), error)

Subscribe initiates a GraphQL subscription over SSE. Each call creates a new HTTP request (no multiplexing).

The HTTP method is determined by opts.SSEMethod:

  • SSEMethodPOST: POST with JSON body (graphql-sse spec)
  • SSEMethodGET: GET with query parameters (traditional SSE)

type WSTransport

type WSTransport struct {
	// contains filtered or unexported fields
}

func NewWSTransport

func NewWSTransport(ctx context.Context, opts WSTransportOptions) *WSTransport

NewWSTransport creates a new WSTransport. Connections are not closed when ctx is cancelled; instead they close themselves when their last subscriber is removed via the resolver's drain chain. The ping loop exits on ctx cancellation.

If PingInterval is set, a single goroutine sends protocol-level pings to all connections at that cadence. If PingTimeout is also set, connections that fail to respond with a pong within that window are shut down.

func (*WSTransport) ConnCount

func (t *WSTransport) ConnCount() int

func (*WSTransport) Subscribe

func (t *WSTransport) Subscribe(ctx context.Context, req *common.Request, opts common.Options, handler common.Handler) (func(), error)

Subscribe initiates a GraphQL subscription over WebSocket. It reuses an existing connection when one is available for the same endpoint, subprotocol, headers, and init payload, dialing a new one otherwise.

type WSTransportOptions

type WSTransportOptions struct {
	// UpgradeClient is the HTTP client used for the WebSocket upgrade request.
	UpgradeClient *http.Client

	// Logger is the logger used for transport and connection-level events.
	Logger abstractlogger.Logger

	// ReadLimit is the maximum message size in bytes the WebSocket connection
	// will accept.
	ReadLimit int64

	// PingInterval is how often the transport sends a ping to each connection.
	// Zero disables pinging.
	PingInterval time.Duration

	// PingTimeout is how long a connection may go without a pong before it is
	// considered dead. Only meaningful when PingInterval is set.
	PingTimeout time.Duration

	// AckTimeout is the maximum time to wait for a connection_ack during the
	// protocol init handshake. Passed to the protocol at construction.
	AckTimeout time.Duration

	// WriteTimeout is the deadline applied to each WebSocket write (subscribe,
	// unsubscribe, ping, pong). Passed to each connection.
	WriteTimeout time.Duration

	// IdleTimeout is the duration a connection stays open after its last
	// subscription is removed, allowing new subscriptions to reuse it without
	// re-dialing. Zero means close immediately.
	IdleTimeout time.Duration
}

WSTransportOptions configures a WSTransport.

Jump to

Keyboard shortcuts

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