graphql-ws
Advanced tools
Comparing version 1.9.1 to 1.9.2
@@ -1,4 +0,13 @@ | ||
# [1.9.1](https://github.com/enisdenjo/graphql-ws/compare/v1.8.2...v1.9.0) (2020-10-24) | ||
## [1.9.2](https://github.com/enisdenjo/graphql-ws/compare/v1.9.1...v1.9.2) (2020-10-31) | ||
### Bug Fixes | ||
* **server:** Make sure to use `onSubscribe` result exclusively ([51fdb7c](https://github.com/enisdenjo/graphql-ws/commit/51fdb7c75487c399267f04a4ea2146f2e964d4cf)) | ||
* Export useful types ([e4cc4d4](https://github.com/enisdenjo/graphql-ws/commit/e4cc4d4df8efb77aed14053a32af3464dc2a95db)) | ||
* **client:** Accept nullish values for `operationName` and `variables` ([2d60dda](https://github.com/enisdenjo/graphql-ws/commit/2d60dda93c09b0c8d7b69241833174f991d7b450)) | ||
## [1.9.1](https://github.com/enisdenjo/graphql-ws/compare/v1.8.2...v1.9.0) (2020-10-25) | ||
### Features | ||
@@ -10,3 +19,6 @@ | ||
### ⚠️ Deprecated | ||
Package has been renamed from [`graphql-transport-ws`](https://www.npmjs.com/package/graphql-transport-ws) to [`graphql-ws`](https://www.npmjs.com/package/graphql-ws). | ||
### Features | ||
@@ -39,3 +51,6 @@ | ||
### ⚠️ Deprecated | ||
Package has been renamed from [`graphql-transport-ws`](https://www.npmjs.com/package/graphql-transport-ws) to [`graphql-ws`](https://www.npmjs.com/package/graphql-ws). | ||
### Bug Fixes | ||
@@ -47,3 +62,6 @@ | ||
### ⚠️ Deprecated | ||
Package has been renamed from [`graphql-transport-ws`](https://www.npmjs.com/package/graphql-transport-ws) to [`graphql-ws`](https://www.npmjs.com/package/graphql-ws). | ||
### Bug Fixes | ||
@@ -56,3 +74,6 @@ | ||
### ⚠️ Deprecated | ||
Package has been renamed from [`graphql-transport-ws`](https://www.npmjs.com/package/graphql-transport-ws) to [`graphql-ws`](https://www.npmjs.com/package/graphql-ws). | ||
### Features | ||
@@ -64,3 +85,6 @@ | ||
### ⚠️ Deprecated | ||
Package has been renamed from [`graphql-transport-ws`](https://www.npmjs.com/package/graphql-transport-ws) to [`graphql-ws`](https://www.npmjs.com/package/graphql-ws). | ||
### Bug Fixes | ||
@@ -78,3 +102,6 @@ | ||
### ⚠️ Deprecated | ||
Package has been renamed from [`graphql-transport-ws`](https://www.npmjs.com/package/graphql-transport-ws) to [`graphql-ws`](https://www.npmjs.com/package/graphql-ws). | ||
### Features | ||
@@ -86,3 +113,6 @@ | ||
### ⚠️ Deprecated | ||
Package has been renamed from [`graphql-transport-ws`](https://www.npmjs.com/package/graphql-transport-ws) to [`graphql-ws`](https://www.npmjs.com/package/graphql-ws). | ||
### Bug Fixes | ||
@@ -99,3 +129,6 @@ | ||
### ⚠️ Deprecated | ||
Package has been renamed from [`graphql-transport-ws`](https://www.npmjs.com/package/graphql-transport-ws) to [`graphql-ws`](https://www.npmjs.com/package/graphql-ws). | ||
### Bug Fixes | ||
@@ -107,3 +140,6 @@ | ||
### ⚠️ Deprecated | ||
Package has been renamed from [`graphql-transport-ws`](https://www.npmjs.com/package/graphql-transport-ws) to [`graphql-ws`](https://www.npmjs.com/package/graphql-ws). | ||
### Performance Improvements | ||
@@ -115,3 +151,6 @@ | ||
### ⚠️ Deprecated | ||
Package has been renamed from [`graphql-transport-ws`](https://www.npmjs.com/package/graphql-transport-ws) to [`graphql-ws`](https://www.npmjs.com/package/graphql-ws). | ||
### Bug Fixes | ||
@@ -128,3 +167,6 @@ | ||
### ⚠️ Deprecated | ||
Package has been renamed from [`graphql-transport-ws`](https://www.npmjs.com/package/graphql-transport-ws) to [`graphql-ws`](https://www.npmjs.com/package/graphql-ws). | ||
### Features | ||
@@ -139,3 +181,6 @@ | ||
### ⚠️ Deprecated | ||
Package has been renamed from [`graphql-transport-ws`](https://www.npmjs.com/package/graphql-transport-ws) to [`graphql-ws`](https://www.npmjs.com/package/graphql-ws). | ||
### Features | ||
@@ -147,3 +192,6 @@ | ||
### ⚠️ Deprecated | ||
Package has been renamed from [`graphql-transport-ws`](https://www.npmjs.com/package/graphql-transport-ws) to [`graphql-ws`](https://www.npmjs.com/package/graphql-ws). | ||
### Bug Fixes | ||
@@ -156,3 +204,6 @@ | ||
### ⚠️ Deprecated | ||
Package has been renamed from [`graphql-transport-ws`](https://www.npmjs.com/package/graphql-transport-ws) to [`graphql-ws`](https://www.npmjs.com/package/graphql-ws). | ||
### Bug Fixes | ||
@@ -170,3 +221,6 @@ | ||
### ⚠️ Deprecated | ||
Package has been renamed from [`graphql-transport-ws`](https://www.npmjs.com/package/graphql-transport-ws) to [`graphql-ws`](https://www.npmjs.com/package/graphql-ws). | ||
### Bug Fixes | ||
@@ -178,3 +232,6 @@ | ||
### ⚠️ Deprecated | ||
Package has been renamed from [`graphql-transport-ws`](https://www.npmjs.com/package/graphql-transport-ws) to [`graphql-ws`](https://www.npmjs.com/package/graphql-ws). | ||
### Bug Fixes | ||
@@ -193,3 +250,6 @@ | ||
### ⚠️ Deprecated | ||
Package has been renamed from [`graphql-transport-ws`](https://www.npmjs.com/package/graphql-transport-ws) to [`graphql-ws`](https://www.npmjs.com/package/graphql-ws). | ||
### Features | ||
@@ -196,0 +256,0 @@ |
@@ -15,5 +15,9 @@ /** | ||
export interface ClientOptions { | ||
/** URL of the GraphQL server to connect. */ | ||
/** URL of the GraphQL over WebSocket Protocol compliant server to connect. */ | ||
url: string; | ||
/** Optional parameters that the client specifies when establishing a connection with the server. */ | ||
/** | ||
* Optional parameters, passed through the `payload` field with the `ConnectionInit` message, | ||
* that the client specifies when establishing a connection with the server. You can use this | ||
* for securely passing arguments for authentication. | ||
*/ | ||
connectionParams?: Record<string, unknown> | (() => Record<string, unknown>); | ||
@@ -23,2 +27,3 @@ /** | ||
* or after the first listener subscribed. | ||
* | ||
* @default true | ||
@@ -29,2 +34,3 @@ */ | ||
* How many times should the client try to reconnect on abnormal socket closure before it errors out? | ||
* | ||
* @default 5 | ||
@@ -35,2 +41,3 @@ */ | ||
* How long should the client wait until attempting to retry. | ||
* | ||
* @default 3 * 1000 (3 seconds) | ||
@@ -42,2 +49,3 @@ */ | ||
* you can ensure to catch all client relevant emitted events. | ||
* | ||
* The listeners passed in will **always** be the first ones | ||
@@ -44,0 +52,0 @@ * to get the emitted event before other registered listeners. |
@@ -45,2 +45,3 @@ "use strict"; | ||
} | ||
// websocket status emitter, subscriptions are handled differently | ||
const emitter = (() => { | ||
@@ -325,3 +326,2 @@ const listeners = { | ||
}); | ||
// TODO-db-200909 wont be removed on throw, but should it? the socket is closed on throw | ||
socket.removeEventListener('message', messageHandler); | ||
@@ -328,0 +328,0 @@ // cancelled, shouldnt try again |
export * from './client'; | ||
export * from './server'; | ||
export * from './message'; | ||
export * from './types'; | ||
export * from './protocol'; |
@@ -16,1 +16,3 @@ "use strict"; | ||
__exportStar(require("./message"), exports); | ||
__exportStar(require("./types"), exports); | ||
__exportStar(require("./protocol"), exports); |
@@ -30,3 +30,3 @@ "use strict"; | ||
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 (!utils_1.hasOwnProperty(val, 'payload') || | ||
@@ -41,6 +41,10 @@ val.payload === undefined || | ||
(!utils_1.hasOwnProperty(val.payload, 'operationName') || | ||
utils_1.hasOwnStringProperty(val.payload, 'operationName')) && | ||
val.payload.operationName === undefined || | ||
val.payload.operationName === null || | ||
typeof val.payload.operationName === 'string') && | ||
(utils_1.hasOwnStringProperty(val.payload, 'query') || // string query or persisted query id | ||
utils_1.hasOwnObjectProperty(val.payload, 'query')) && // document node query | ||
(!utils_1.hasOwnProperty(val.payload, 'variables') || | ||
val.payload.variables === undefined || | ||
val.payload.variables === null || | ||
utils_1.hasOwnObjectProperty(val.payload, 'variables'))); | ||
@@ -47,0 +51,0 @@ case MessageType.Next: |
@@ -49,2 +49,6 @@ /** | ||
* used to execute the query and mutation operations. | ||
* | ||
* Throwing an error from within this function will | ||
* close the socket with the `Error` message | ||
* in the close event reason. | ||
*/ | ||
@@ -55,9 +59,13 @@ execute: (args: ExecutionArgs) => OperationResult; | ||
* used to execute the subscription operation. | ||
* | ||
* Throwing an error from within this function will | ||
* close the socket with the `Error` message | ||
* in the close event reason. | ||
*/ | ||
subscribe: (args: ExecutionArgs) => OperationResult; | ||
/** | ||
* The amount of time for which the | ||
* server will wait for `ConnectionInit` message. | ||
* The amount of time for which the server will wait | ||
* for `ConnectionInit` message. | ||
* | ||
* Set the value to `Infinity`, '', 0, null or undefined to skip waiting. | ||
* Set the value to `Infinity`, `''`, `0`, `null` or `undefined` to skip waiting. | ||
* | ||
@@ -76,2 +84,3 @@ * If the wait timeout has passed and the client | ||
* the clients and the server is operating and to prevent the link from being broken due to idling. | ||
* | ||
* Set to nullish value to disable. | ||
@@ -85,6 +94,7 @@ * | ||
* client requests the connection initialisation | ||
* through the message `ConnectionInit`. The message | ||
* payload (`connectionParams` on the client) is | ||
* present in the `Context.connectionParams`. | ||
* through the message `ConnectionInit`. | ||
* | ||
* The message payload (`connectionParams` from the | ||
* client) is present in the `Context.connectionParams`. | ||
* | ||
* - Returning `true` or nothing from the callback will | ||
@@ -97,7 +107,5 @@ * allow the client to connect. | ||
* | ||
* - Throwing an error from the callback will | ||
* terminate the socket by dispatching the | ||
* close event `4400: <error-message>`, where | ||
* the `<error-message>` is the message of the | ||
* thrown `Error`. | ||
* Throwing an error from within this function will | ||
* close the socket with the `Error` message | ||
* in the close event reason. | ||
*/ | ||
@@ -125,2 +133,6 @@ onConnect?: (ctx: Context) => Promise<boolean | void> | boolean | void; | ||
* execution args which are then returned by the function. | ||
* | ||
* Throwing an error from within this function will | ||
* close the socket with the `Error` message | ||
* in the close event reason. | ||
*/ | ||
@@ -136,3 +148,3 @@ onSubscribe?: (ctx: Context, message: SubscribeMessage) => Promise<ExecutionArgs | readonly GraphQLError[] | void> | ExecutionArgs | readonly GraphQLError[] | void; | ||
* The `OperationResult` argument is the result of operation | ||
* execution. It can be an iterator or already value. | ||
* execution. It can be an iterator or already a value. | ||
* | ||
@@ -144,2 +156,6 @@ * If you want the single result and the events from a streaming | ||
* execution result manipulation. | ||
* | ||
* Throwing an error from within this function will | ||
* close the socket with the `Error` message | ||
* in the close event reason. | ||
*/ | ||
@@ -155,2 +171,6 @@ onOperation?: (ctx: Context, message: SubscribeMessage, args: ExecutionArgs, result: OperationResult) => Promise<OperationResult | void> | OperationResult | void; | ||
* Returned result will be injected in the error message payload. | ||
* | ||
* Throwing an error from within this function will | ||
* close the socket with the `Error` message | ||
* in the close event reason. | ||
*/ | ||
@@ -167,2 +187,6 @@ onError?: (ctx: Context, message: ErrorMessage, errors: readonly GraphQLError[]) => Promise<readonly GraphQLError[] | void> | readonly GraphQLError[] | void; | ||
* Returned result will be injected in the next message payload. | ||
* | ||
* Throwing an error from within this function will | ||
* close the socket with the `Error` message | ||
* in the close event reason. | ||
*/ | ||
@@ -174,2 +198,6 @@ onNext?: (ctx: Context, message: NextMessage, args: ExecutionArgs, result: ExecutionResult) => Promise<ExecutionResult | void> | ExecutionResult | void; | ||
* the complete message to the client. | ||
* | ||
* Throwing an error from within this function will | ||
* close the socket with the `Error` message | ||
* in the close event reason. | ||
*/ | ||
@@ -176,0 +204,0 @@ onComplete?: (ctx: Context, message: CompleteMessage) => Promise<void> | void; |
@@ -240,5 +240,4 @@ "use strict"; | ||
} | ||
// if you've provided your own root through | ||
// `onSubscribe`, prefer that over the root's root | ||
if (!execArgs.rootValue) { | ||
// if onsubscribe didnt return anything, inject roots | ||
if (!maybeExecArgsOrErrors) { | ||
execArgs.rootValue = roots === null || roots === void 0 ? void 0 : roots[operationAST.operation]; | ||
@@ -301,2 +300,3 @@ } | ||
catch (err) { | ||
// TODO-db-201031 we percieve this as a client bad request error, but is it always? | ||
ctx.socket.close(4400, err.message); | ||
@@ -303,0 +303,0 @@ } |
{ | ||
"name": "graphql-ws", | ||
"version": "1.9.1", | ||
"version": "1.9.2", | ||
"description": "Coherent, zero-dependency, lazy, simple, GraphQL over WebSocket Protocol compliant server and client", | ||
@@ -64,17 +64,17 @@ "keywords": [ | ||
"@types/jest": "^26.0.15", | ||
"@types/ws": "^7.2.7", | ||
"@typescript-eslint/eslint-plugin": "^4.5.0", | ||
"@typescript-eslint/parser": "^4.5.0", | ||
"@types/ws": "^7.2.9", | ||
"@typescript-eslint/eslint-plugin": "^4.6.0", | ||
"@typescript-eslint/parser": "^4.6.0", | ||
"babel-jest": "^26.6.1", | ||
"eslint": "^7.11.0", | ||
"eslint-config-prettier": "^6.14.0", | ||
"eslint": "^7.12.1", | ||
"eslint-config-prettier": "^6.15.0", | ||
"eslint-plugin-prettier": "^3.1.4", | ||
"graphql": "^15.3.0", | ||
"graphql": "^15.4.0", | ||
"jest": "^26.6.1", | ||
"prettier": "^2.1.2", | ||
"semantic-release": "^17.2.1", | ||
"semantic-release": "^17.2.2", | ||
"typedoc": "^0.19.2", | ||
"typedoc-plugin-markdown": "^3.0.11", | ||
"typescript": "^4.0.3" | ||
"typescript": "^4.0.5" | ||
} | ||
} |
@@ -23,10 +23,2 @@ # GraphQL over WebSocket Protocol | ||
## Keep-Alive | ||
The server will occasionally check if the client is still "alive", available and listening. In order to perform this check, implementation leverages the standardized [Pings and Pongs: The Heartbeat of WebSockets](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API/Writing_WebSocket_servers#Pings_and_Pongs_The_Heartbeat_of_WebSockets). | ||
Keep-Alive interval and the "pong wait" timeout can be tuned by using the accompanying configuration parameter on the server. | ||
Ping and Pong feature is a mandatory requirement by [The WebSocket Protocol](https://tools.ietf.org/html/rfc6455#section-5.5.2). All clients that don't support it are **not** RFC6455 compliant and will simply have their socket terminated after the pong wait has passed. | ||
## Message types | ||
@@ -40,4 +32,2 @@ | ||
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`. | ||
@@ -50,12 +40,6 @@ | ||
type: 'connection_init'; | ||
payload?: Record<string, unknown>; // connectionParams | ||
payload?: Record<string, unknown>; | ||
} | ||
``` | ||
The server will respond by either: | ||
- Dispatching a `ConnectionAck` message acknowledging that the connection has been successfully established. The server does not implement the `onConnect` callback or the implemented callback has returned `true`. | ||
- Closing the socket with a close event `4403: Forbidden` indicating that the connection request has been denied because of access control. The server has returned `false` in the `onConnect` callback. | ||
- Closing the socket with a close event `4400: <error-message>` indicating that the connection request has been denied because of an implementation specific error. The server has thrown an error in the `onConnect` callback, the thrown error's message is the `<error-message>` in the close event. | ||
### `ConnectionAck` | ||
@@ -65,3 +49,3 @@ | ||
Potential response to the `ConnectionInit` message from the client acknowledging a successful connection with the server. | ||
Expected response to the `ConnectionInit` message from the client acknowledging a successful connection with the server. | ||
@@ -161,24 +145,6 @@ ```typescript | ||
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. _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`) | ||
### Erroneous 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. _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`) | ||
### Connection initialisation timeout | ||
@@ -192,3 +158,2 @@ | ||
1. _Server_ closes the socket by dispatching the event `4408: Connection initialisation timeout` | ||
1. _Client_ reports an error using the close event reason (which is `Connection initialisation timeout`) | ||
@@ -204,14 +169,4 @@ ### Single result operation | ||
<br>_All future communication is linked through this unique ID_ | ||
1. _Server_ triggers the `onSubscribe` callback | ||
- If `ExecutionArgs` are **not** returned, the arguments will be formed and validated using the payload | ||
- If `ExecutionArgs` are returned, they will be used directly | ||
1. _Server_ executes the single result GraphQL operation using the arguments provided above | ||
1. _Server_ triggers the `onNext` callback | ||
- If `ExecutionResult` is **not** returned, the direct result from the operation will be dispatched with the `Next` message | ||
- If `ExecutionResult` is returned, it will be dispatched with the `Next` message | ||
1. _Server_ triggers the `onComplete` callback | ||
1. _Server_ executes the single result GraphQL operation | ||
1. _Server_ dispatches the result with the `Next` message | ||
1. _Server_ dispatches the `Complete` message indicating that the execution has completed | ||
@@ -228,8 +183,3 @@ | ||
<br>_All future communication is linked through this unique ID_ | ||
1. _Server_ triggers the `onSubscribe` callback | ||
- If `ExecutionArgs` are **not** returned, the arguments will be formed and validated using the payload | ||
- If `ExecutionArgs` are returned, they will be used directly | ||
1. _Server_ executes the streaming GraphQL operation using the arguments provided above | ||
1. _Server_ executes the streaming GraphQL operation | ||
1. _Server_ checks if the generated ID is unique across active streaming subscriptions | ||
@@ -240,7 +190,3 @@ | ||
1. _Server_ triggers the `onNext` callback | ||
- If `ExecutionResult` is **not** returned, the direct events from the source stream will be dispatched with the `Next` message | ||
- If `ExecutionResult` is returned, it will be dispatched with the `Next` message instead of every event from the source stram | ||
1. _Server_ dispatches results over time with the `Next` message | ||
1. - _Client_ stops the subscription by dispatching a `Complete` message | ||
@@ -251,2 +197,1 @@ - _Server_ completes the source stream | ||
- _Client_ completes the stream observer | ||
1. _Server_ triggers the `onComplete` callback, if specified |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
98366
1282
0