Catch the highlights of GraphQLConf 2023! Click for recordings. Or check out our recap blog post.
Documentation
Modules
client

Module: client

Interfaces

Client

Event

Ƭ Event: EventConnecting | EventOpened | EventConnected | EventPing | EventPong | EventMessage | EventClosed | EventError

All events that could occur.

Defined in

src/client.ts:92 (opens in a new tab)


EventClosed

Ƭ EventClosed: "closed"

WebSocket connection has closed.

Defined in

src/client.ts:78 (opens in a new tab)


EventClosedListener

Ƭ EventClosedListener: (event: unknown) => void

Type declaration

▸ (event): void

The argument is actually the websocket CloseEvent, but to avoid bundling DOM typings because the client can run in Node env too, you should assert the websocket type during implementation.

Parameters
NameType
eventunknown
Returns

void

Defined in

src/client.ts:166 (opens in a new tab)


EventConnected

Ƭ EventConnected: "connected"

Open WebSocket connection has been acknowledged.

Defined in

src/client.ts:50 (opens in a new tab)


EventConnectedListener

Ƭ EventConnectedListener: (socket: unknown, payload: ConnectionAckMessage["payload"]) => void

Type declaration

▸ (socket, payload): void

The first argument is actually the WebSocket, but to avoid bundling DOM typings because the client can run in Node env too, you should assert the websocket type during implementation.

Also, the second argument is the optional payload that the server may send through the ConnectionAck message.

Parameters
NameType
socketunknown
payloadConnectionAckMessage["payload"]
Returns

void

Defined in

src/client.ts:124 (opens in a new tab)


EventConnecting

Ƭ EventConnecting: "connecting"

WebSocket started connecting.

Defined in

src/client.ts:36 (opens in a new tab)


EventConnectingListener

Ƭ EventConnectingListener: () => void

Type declaration

▸ (): void

Returns

void

Defined in

src/client.ts:103 (opens in a new tab)


EventError

Ƭ EventError: "error"

WebSocket connection had an error or client had an internal error.

Defined in

src/client.ts:85 (opens in a new tab)


EventErrorListener

Ƭ EventErrorListener: (error: unknown) => void

Type declaration

▸ (error): void

Events dispatched from the WebSocket onerror are handled in this listener, as well as all internal client errors that could throw.

Parameters
NameType
errorunknown
Returns

void

Defined in

src/client.ts:174 (opens in a new tab)


EventListener

Ƭ EventListener<E>: E extends EventConnecting ? EventConnectingListener : E extends EventOpened ? EventOpenedListener : E extends EventConnected ? EventConnectedListener : E extends EventPing ? EventPingListener : E extends EventPong ? EventPongListener : E extends EventMessage ? EventMessageListener : E extends EventClosed ? EventClosedListener : E extends EventError ? EventErrorListener : never

Type parameters

NameType
Eextends Event

Defined in

src/client.ts:177 (opens in a new tab)


EventMessage

Ƭ EventMessage: "message"

A message has been received.

Defined in

src/client.ts:71 (opens in a new tab)


EventMessageListener

Ƭ EventMessageListener: (message: Message) => void

Type declaration

▸ (message): void

Called for all valid messages received by the client. Mainly useful for debugging and logging received messages.

Parameters
NameType
messageMessage
Returns

void

Defined in

src/client.ts:157 (opens in a new tab)


EventOpened

Ƭ EventOpened: "opened"

WebSocket has opened.

Defined in

src/client.ts:43 (opens in a new tab)


EventOpenedListener

Ƭ EventOpenedListener: (socket: unknown) => void

Type declaration

▸ (socket): void

The first argument is actually the WebSocket, but to avoid bundling DOM typings because the client can run in Node env too, you should assert the websocket type during implementation.

Parameters
NameType
socketunknown
Returns

void

Defined in

src/client.ts:112 (opens in a new tab)


EventPing

Ƭ EventPing: "ping"

PingMessage has been received or sent.

Defined in

src/client.ts:57 (opens in a new tab)


EventPingListener

Ƭ EventPingListener: (received: boolean, payload: PingMessage["payload"]) => void

Type declaration

▸ (received, payload): void

The first argument communicates whether the ping was received from the server. If false, the ping was sent by the client.

Parameters
NameType
receivedboolean
payloadPingMessage["payload"]
Returns

void

Defined in

src/client.ts:135 (opens in a new tab)


EventPong

Ƭ EventPong: "pong"

PongMessage has been received or sent.

Defined in

src/client.ts:64 (opens in a new tab)


EventPongListener

Ƭ EventPongListener: (received: boolean, payload: PongMessage["payload"]) => void

Type declaration

▸ (received, payload): void

The first argument communicates whether the pong was received from the server. If false, the pong was sent by the client.

Parameters
NameType
receivedboolean
payloadPongMessage["payload"]
Returns

void

Defined in

src/client.ts:146 (opens in a new tab)


createClient

createClient<P>(options): Client

Creates a disposable GraphQL over WebSocket client.

Type parameters

NameType
Pextends undefined | Record<string, unknown> = undefined | Record<string, unknown>

Parameters

NameType
optionsClientOptions<P>

Returns

Client

Defined in

src/client.ts:470 (opens in a new tab)

Other

CloseCode

Re-exports CloseCode


CompleteMessage

Re-exports CompleteMessage


ConnectionAckMessage

Re-exports ConnectionAckMessage


ConnectionInitMessage

Re-exports ConnectionInitMessage


Disposable

Re-exports Disposable


ErrorMessage

Re-exports ErrorMessage


ExecutionPatchResult

Re-exports ExecutionPatchResult


ExecutionResult

Re-exports ExecutionResult


GRAPHQL_TRANSPORT_WS_PROTOCOL

Re-exports GRAPHQL_TRANSPORT_WS_PROTOCOL


ID

Re-exports ID


JSONMessageReplacer

Re-exports JSONMessageReplacer


JSONMessageReviver

Re-exports JSONMessageReviver


Message

Re-exports Message


MessageType

Re-exports MessageType


NextMessage

Re-exports NextMessage


PingMessage

Re-exports PingMessage


PongMessage

Re-exports PongMessage


Sink

Re-exports Sink


SubscribeMessage

Re-exports SubscribeMessage


SubscribePayload

Re-exports SubscribePayload


isMessage

Re-exports isMessage


parseMessage

Re-exports parseMessage


stringifyMessage

Re-exports stringifyMessage


validateMessage

Re-exports validateMessage