Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
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.
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.
var ErrSubscriptionExists = errors.New("subscription ID already exists")
Functions ¶
This section is empty.
Types ¶
type ErrFailedUpgrade ¶
func (ErrFailedUpgrade) Error ¶
func (e ErrFailedUpgrade) Error() string
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.