Skip to content

Commit

Permalink
docs(protocol): no connectionParams [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
enisdenjo committed Oct 31, 2020
1 parent 42301fc commit 5bd0321
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
10 changes: 4 additions & 6 deletions PROTOCOL.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,14 @@ Direction: **Client -> Server**

Indicates that the client wants to establish a connection within the existing socket. This connection is **not** the actual WebSocket communication channel, but is rather a frame within it asking the server to allow future operation requests.

The client can specify additional `connectionParams` which are sent through the `payload` field in the outgoing message.

The server must receive the connection initialisation message within the allowed waiting time specified in the `connectionInitWaitTimeout` parameter during the server setup. If the client does not request a connection within the allowed timeout, the server will close the socket with the event: `4408: Connection initialisation timeout`.

If the server receives more than one `ConnectionInit` message at any given time, the server will close the socket with the event `4429: Too many initialisation requests`.

```typescript
interface ConnectionInitMessage {
type: 'connection_init';
payload?: Record<string, unknown>; // connectionParams
payload?: Record<string, unknown>;
}
```

Expand Down Expand Up @@ -154,15 +152,15 @@ For the sake of clarity, the following examples demonstrate the communication pr

1. _Client_ sends a WebSocket handshake request with the sub-protocol: `graphql-transport-ws`
1. _Server_ accepts the handshake and establishes a WebSocket communication channel (which we call "socket")
1. _Client_ immediately dispatches a `ConnectionInit` message setting the `connectionParams` according to the server implementation
1. _Client_ immediately dispatches a `ConnectionInit` message optionally providing a payload as agreed with the server
1. _Server_ validates the connection initialisation request and dispatches a `ConnectionAck` message to the client on successful connection
1. _Client_ has received the acknowledgement message and is now ready to request operation executions

### Forbidden connection initialisation

1. _Client_ sends a WebSocket handshake request with the sub-protocol: `graphql-transport-ws`
1. _Server_ accepts the handshake and establishes a WebSocket communication channel (which we call "socket")
1. _Client_ immediately dispatches a `ConnectionInit` message setting the `connectionParams` according to the server implementation
1. _Client_ immediately dispatches a `ConnectionInit` message optionally providing a payload as agreed with the server
1. _Server_ validates the connection initialisation request and decides that the client is not allowed to establish a connection
1. _Server_ closes the socket by dispatching the event `4403: Forbidden`
1. _Client_ reports an error using the close event reason (which is `Forbidden`)
Expand All @@ -171,7 +169,7 @@ For the sake of clarity, the following examples demonstrate the communication pr

1. _Client_ sends a WebSocket handshake request with the sub-protocol: `graphql-transport-ws`
1. _Server_ accepts the handshake and establishes a WebSocket communication channel (which we call "socket")
1. _Client_ immediately dispatches a `ConnectionInit` message setting the `connectionParams` according to the server implementation
1. _Client_ immediately dispatches a `ConnectionInit` message optionally providing a payload as agreed with the server
1. _Server_ tries validating the connection initialisation request but an error `I'm a teapot` is thrown
1. _Server_ closes the socket by dispatching the event `4400: I'm a teapot`
1. _Client_ reports an error using the close event reason (which is `I'm a teapot`)
Expand Down
4 changes: 2 additions & 2 deletions src/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export enum MessageType {

export interface ConnectionInitMessage {
readonly type: MessageType.ConnectionInit;
readonly payload?: Record<string, unknown>; // connectionParams
readonly payload?: Record<string, unknown>;
}

export interface ConnectionAckMessage {
Expand Down Expand Up @@ -88,7 +88,7 @@ export function isMessage(val: unknown): val is Message {
// validate other properties depending on the `type`
switch (val.type) {
case MessageType.ConnectionInit:
// the connection init message can have optional object `connectionParams` in the payload
// the connection init message can have optional payload object
return (
!hasOwnProperty(val, 'payload') ||
val.payload === undefined ||
Expand Down

0 comments on commit 5bd0321

Please sign in to comment.