graphql-ws
- Client
- ClientOptions
- CompleteMessage
- ConnectionAckMessage
- ConnectionInitMessage
- Context
- Disposable
- ErrorMessage
- ExecutionPatchResult
- ExecutionResult
- NextMessage
- PingMessage
- PongMessage
- Server
- ServerOptions
- Sink
- SubscribeMessage
- SubscribePayload
- WebSocket
- Event
- EventClosed
- EventClosedListener
- EventConnected
- EventConnectedListener
- EventConnecting
- EventConnectingListener
- EventError
- EventErrorListener
- EventListener
- EventMessage
- EventMessageListener
- EventOpened
- EventOpenedListener
- EventPing
- EventPingListener
- EventPong
- EventPongListener
- GraphQLExecutionContextValue
- ID
- JSONMessageReplacer
- JSONMessageReviver
- Message
- OperationResult
Ƭ Event: EventConnecting
| EventOpened
| EventConnected
| EventPing
| EventPong
| EventMessage
| EventClosed
| EventError
All events that could occur.
Ƭ EventClosed: "closed"
WebSocket connection has closed.
Ƭ EventClosedListener: (event
: unknown
) => void
▸ (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
Name | Type |
---|---|
event |
unknown |
void
Ƭ EventConnected: "connected"
Open WebSocket connection has been acknowledged.
Ƭ EventConnectedListener: (socket
: unknown
, payload
: ConnectionAckMessage
["payload"
]) => void
▸ (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
Name | Type |
---|---|
socket |
unknown |
payload |
ConnectionAckMessage ["payload" ] |
void
Ƭ EventConnecting: "connecting"
WebSocket started connecting.
Ƭ EventConnectingListener: () => void
▸ (): void
category
Client
void
Ƭ EventError: "error"
WebSocket connection had an error or client had an internal error.
Ƭ EventErrorListener: (error
: unknown
) => void
▸ (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
Name | Type |
---|---|
error |
unknown |
void
Ƭ 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
Name | Type |
---|---|
E |
extends Event |
Ƭ EventMessage: "message"
A message has been received.
Ƭ EventMessageListener: (message
: Message
) => void
▸ (message
): void
Called for all valid messages received by the client. Mainly useful for debugging and logging received messages.
category
Client
Name | Type |
---|---|
message |
Message |
void
Ƭ EventOpened: "opened"
WebSocket has opened.
Ƭ EventOpenedListener: (socket
: unknown
) => void
▸ (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
Name | Type |
---|---|
socket |
unknown |
void
Ƭ EventPing: "ping"
PingMessage
has been received or sent.
Ƭ EventPingListener: (received
: boolean
, payload
: PingMessage
["payload"
]) => void
▸ (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
Name | Type |
---|---|
received |
boolean |
payload |
PingMessage ["payload" ] |
void
Ƭ EventPong: "pong"
PongMessage
has been received or sent.
Ƭ EventPongListener: (received
: boolean
, payload
: PongMessage
["payload"
]) => void
▸ (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
Name | Type |
---|---|
received |
boolean |
payload |
PongMessage ["payload" ] |
void
▸ createClient(options
): Client
Creates a disposable GraphQL over WebSocket client.
Name | Type |
---|---|
options |
ClientOptions |
Ƭ ID: string
ID is a string type alias representing the globally unique ID used for identifying subscriptions established by the client.
Ƭ JSONMessageReplacer: (this
: any
, key
: string
, value
: any
) => any
▸ (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
Name | Type |
---|---|
this |
any |
key |
string |
value |
any |
any
Ƭ JSONMessageReviver: (this
: any
, key
: string
, value
: any
) => any
▸ (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
Name | Type |
---|---|
this |
any |
key |
string |
value |
any |
any
Ƭ 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
Name | Type |
---|---|
T |
extends MessageType MessageType |
• GRAPHQL_TRANSPORT_WS_PROTOCOL: "graphql-transport-ws"
The WebSocket sub-protocol used for the GraphQL over WebSocket Protocol.
▸ isMessage(val
): val is ConnectionAckMessage | PingMessage | PongMessage | ConnectionInitMessage | SubscribeMessage | NextMessage | ErrorMessage | CompleteMessage
Checks if the provided value is a message.
Name | Type |
---|---|
val |
unknown |
val is ConnectionAckMessage | PingMessage | PongMessage | ConnectionInitMessage | SubscribeMessage | NextMessage | ErrorMessage | CompleteMessage
▸ parseMessage(data
, reviver?
): Message
Parses the raw websocket message data to a valid message.
Name | Type |
---|---|
data |
unknown |
reviver? |
JSONMessageReviver |
▸ stringifyMessage<T
>(msg
, replacer?
): string
Stringifies a valid message ready to be sent through the socket.
Name | Type |
---|---|
T |
extends MessageType |
Name | Type |
---|---|
msg |
Message <T > |
replacer? |
JSONMessageReplacer |
string
Ƭ 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: Promise
<AsyncGenerator
<ExecutionResult
| ExecutionPatchResult
> | AsyncIterable
<ExecutionResult
| ExecutionPatchResult
> | ExecutionResult
> | AsyncGenerator
<ExecutionResult
| ExecutionPatchResult
> | AsyncIterable
<ExecutionResult
| ExecutionPatchResult
> | ExecutionResult
▸ 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.
Name | Type |
---|---|
E |
unknown |
Name | Type |
---|---|
options |
ServerOptions <E > |
Server
<E
>