Skip to content

Latest commit

 

History

History
214 lines (131 loc) · 5.83 KB

common.md

File metadata and controls

214 lines (131 loc) · 5.83 KB

graphql-ws / common

Module: common

Table of contents

Enumerations

Interfaces

Type Aliases

Variables

Functions

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

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

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 MessageType = MessageType

GRAPHQL_TRANSPORT_WS_PROTOCOL

Const GRAPHQL_TRANSPORT_WS_PROTOCOL: "graphql-transport-ws"

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


isMessage

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

Checks if the provided value is a valid GraphQL over WebSocket message.

deprecated Use validateMessage instead.

Parameters

Name Type
val unknown

Returns

val is ConnectionInitMessage | ConnectionAckMessage | PingMessage | PongMessage | 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


validateMessage

validateMessage(val): Message

Validates the message against the GraphQL over WebSocket Protocol.

Invalid messages will throw descriptive errors.

Parameters

Name Type
val unknown

Returns

Message