Skip to main content
Version: v10.0.0

GraphqlWsAdapterOptionsType

Options of the GraphQL WebSocket connection, passed as adapterOptions to the Socket . They can be changed per connection attempt with socket.onConnect .


Import
import { GraphqlWsAdapterOptionsType } from "@hyper-fetch/graphql"

Preview​

type GraphqlWsAdapterOptionsType = {
WebSocket?: typeof WebSocket;
autoConnect?: boolean;
connectionParams?: GraphqlWsConnectionParamsType | () => GraphqlWsConnectionParamsType | undefined | Promise<(GraphqlWsConnectionParamsType | undefined)>;
keepAlive?: GraphqlWsKeepAliveOptionsType;
lazy?: boolean;
lazyCloseTimeout?: number;
}

Structure​

GraphqlWsAdapterOptionsType
NameTypeDescription
WebSocket
typeof WebSocket

The WebSocket class to use, for example from the ws package. Defaults to the global one (browsers, Node.js 22+, Bun, Deno).

autoConnect
boolean

Connect when the socket is created. Only the first connection depends on it - a socket connected by hand also reconnects after a lost connection and when the app goes back online. Ignored with lazy .

connectionParams
GraphqlWsConnectionParamsType | () => GraphqlWsConnectionParamsType | undefined | Promise<(GraphqlWsConnectionParamsType | undefined)>

Sent with connection_init on every connection, before any subscription starts. A function runs on every connection attempt, so a reconnect sends a fresh token. When it throws or rejects, the connection is closed with 4005 and not retried.

keepAlive
GraphqlWsKeepAliveOptionsType

Sends ping on a quiet connection and reconnects when the server does not answer

lazy
boolean

Connect when the first subscription starts and close the connection when the last one stops, after

lazyCloseTimeout . A socket without subscriptions holds no connection.

lazyCloseTimeout
number

With lazy , how long the connection stays open after the last subscription stopped, in milliseconds. A subscription started in this time reuses the connection.