Skip to content

Latest commit

 

History

History
572 lines (343 loc) · 14.1 KB

README.md

File metadata and controls

572 lines (343 loc) · 14.1 KB

graphql-ws

graphql-ws

Table of contents

Enumerations

Interfaces

Type aliases

Variables

Functions

Client

Event

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

All events that could occur.


EventClosed

Ƭ EventClosed: "closed"

WebSocket connection has closed.


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.

category Client

Parameters
Name Type
event unknown
Returns

void


EventConnected

Ƭ EventConnected: "connected"

Open WebSocket connection has been acknowledged.


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.

category Client

Parameters
Name Type
socket unknown
payload ConnectionAckMessage["payload"]
Returns

void


EventConnecting

Ƭ EventConnecting: "connecting"

WebSocket started connecting.


EventConnectingListener

Ƭ EventConnectingListener: () => void

Type declaration

▸ (): void

category Client

Returns

void


EventError

Ƭ EventError: "error"

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


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.

category Client

Parameters
Name Type
error unknown
Returns

void


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

Name Type
E extends Event

EventMessage

Ƭ EventMessage: "message"

A message has been received.


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.

category Client

Parameters
Name Type
message Message
Returns

void


EventOpened

Ƭ EventOpened: "opened"

WebSocket has opened.


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.

category Client

Parameters
Name Type
socket unknown
Returns

void


EventPing

Ƭ EventPing: "ping"

PingMessage has been received or sent.


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.

category Client

Parameters
Name Type
received boolean
payload PingMessage["payload"]
Returns

void


EventPong

Ƭ EventPong: "pong"

PongMessage has been received or sent.


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.

category Client

Parameters
Name Type
received boolean
payload PongMessage["payload"]
Returns

void


createClient

createClient(options): Client

Creates a disposable GraphQL over WebSocket client.

Parameters

Name Type
options ClientOptions

Returns

Client

Common

ID

Ƭ ID: string

ID is a string type alias representing the globally unique ID used for identifying subscriptions established by the client.


JSONMessageReplacer

Ƭ JSONMessageReplacer: (this: any, key: string, value: any) => any

Type declaration

▸ (this, key, value): any

Function that allows customization of the produced JSON string for the elements of an outgoing Message object.

Read more about using it: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#the_replacer_parameter

category Common

Parameters
Name Type
this any
key string
value any
Returns

any


JSONMessageReviver

Ƭ JSONMessageReviver: (this: any, key: string, value: any) => any

Type declaration

▸ (this, key, value): any

Function for transforming values within a message during JSON parsing The values are produced by parsing the incoming raw JSON.

Read more about using it: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#using_the_reviver_parameter

category Common

Parameters
Name Type
this any
key string
value any
Returns

any


Message

Ƭ Message<T>: T extends ConnectionAck ? ConnectionAckMessage : T extends ConnectionInit ? ConnectionInitMessage : T extends Ping ? PingMessage : T extends Pong ? PongMessage : T extends Subscribe ? SubscribeMessage : T extends Next ? NextMessage : T extends Error ? ErrorMessage : T extends Complete ? CompleteMessage : never

Type parameters

Name Type
T extends MessageTypeMessageType

GRAPHQL_TRANSPORT_WS_PROTOCOL

GRAPHQL_TRANSPORT_WS_PROTOCOL: "graphql-transport-ws"

The WebSocket sub-protocol used for the GraphQL over WebSocket Protocol.


isMessage

isMessage(val): val is ConnectionAckMessage | PingMessage | PongMessage | ConnectionInitMessage | SubscribeMessage | NextMessage | ErrorMessage | CompleteMessage

Checks if the provided value is a message.

Parameters

Name Type
val unknown

Returns

val is ConnectionAckMessage | PingMessage | PongMessage | ConnectionInitMessage | SubscribeMessage | NextMessage | ErrorMessage | CompleteMessage


parseMessage

parseMessage(data, reviver?): Message

Parses the raw websocket message data to a valid message.

Parameters

Name Type
data unknown
reviver? JSONMessageReviver

Returns

Message


stringifyMessage

stringifyMessage<T>(msg, replacer?): string

Stringifies a valid message ready to be sent through the socket.

Type parameters

Name Type
T extends MessageType

Parameters

Name Type
msg Message<T>
replacer? JSONMessageReplacer

Returns

string

Server

GraphQLExecutionContextValue

Ƭ GraphQLExecutionContextValue: object | symbol | number | string | boolean | undefined | null

A concrete GraphQL execution context value type.

Mainly used because TypeScript collapes unions with any or unknown to any or unknown. So, we use a custom type to allow definitions such as the context server option.


OperationResult

Ƭ OperationResult: Promise<AsyncGenerator<ExecutionResult | ExecutionPatchResult> | AsyncIterable<ExecutionResult | ExecutionPatchResult> | ExecutionResult> | AsyncGenerator<ExecutionResult | ExecutionPatchResult> | AsyncIterable<ExecutionResult | ExecutionPatchResult> | ExecutionResult


makeServer

makeServer<E>(options): Server<E>

Makes a Protocol complient WebSocket GraphQL server. The server is actually an API which is to be used with your favourite WebSocket server library!

Read more about the Protocol in the PROTOCOL.md documentation file.

Type parameters

Name Type
E unknown

Parameters

Name Type
options ServerOptions<E>

Returns

Server<E>