graphql-ws
Advanced tools
Comparing version 4.5.0 to 4.5.1
@@ -0,1 +1,8 @@ | ||
## [4.5.1](https://github.com/enisdenjo/graphql-ws/compare/v4.5.0...v4.5.1) (2021-05-18) | ||
### Bug Fixes | ||
* **server:** Init context first on connection open ([a80e753](https://github.com/enisdenjo/graphql-ws/commit/a80e7534cc0570fa111e15f196ba53fdb5ced667)), closes [#181](https://github.com/enisdenjo/graphql-ws/issues/181) | ||
# [4.5.0](https://github.com/enisdenjo/graphql-ws/compare/v4.4.4...v4.5.0) (2021-04-29) | ||
@@ -2,0 +9,0 @@ |
@@ -281,3 +281,3 @@ "use strict"; | ||
try { | ||
const [socket, release, waitForReleaseOrThrowOnClose,] = await connect(); | ||
const [socket, release, waitForReleaseOrThrowOnClose] = await connect(); | ||
// if done while waiting for connect, release the connection lock right away | ||
@@ -284,0 +284,0 @@ if (done) |
@@ -53,2 +53,7 @@ /** | ||
* with the regular `Context` will be passed in through the arguments too. | ||
* | ||
* Note that the context function is invoked on each operation only once. | ||
* Meaning, for subscriptions, only at the point of initialising the subscription; | ||
* not on every subscription event emission. Read more about the context lifecycle | ||
* in subscriptions here: https://github.com/graphql/graphql-js/issues/894. | ||
*/ | ||
@@ -55,0 +60,0 @@ context?: GraphQLExecutionContextValue | ((ctx: Context<E>, message: SubscribeMessage, args: ExecutionArgs) => Promise<GraphQLExecutionContextValue> | GraphQLExecutionContextValue); |
@@ -33,2 +33,8 @@ "use strict"; | ||
opened(socket, extra) { | ||
const ctx = { | ||
connectionInitReceived: false, | ||
acknowledged: false, | ||
subscriptions: {}, | ||
extra, | ||
}; | ||
if (socket.protocol !== common_1.GRAPHQL_TRANSPORT_WS_PROTOCOL) { | ||
@@ -41,8 +47,2 @@ socket.close(1002, 'Protocol Error'); | ||
} | ||
const ctx = { | ||
connectionInitReceived: false, | ||
acknowledged: false, | ||
subscriptions: {}, | ||
extra, | ||
}; | ||
// kick the client off (close socket) if the connection has | ||
@@ -49,0 +49,0 @@ // not been initialised after the specified wait timeout |
{ | ||
"name": "graphql-ws", | ||
"version": "4.5.0", | ||
"version": "4.5.1", | ||
"description": "Coherent, zero-dependency, lazy, simple, GraphQL over WebSocket Protocol compliant server and client", | ||
@@ -75,8 +75,8 @@ "keywords": [ | ||
"devDependencies": { | ||
"@babel/core": "^7.13.16", | ||
"@babel/core": "^7.14.3", | ||
"@babel/plugin-proposal-class-properties": "^7.13.0", | ||
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.13.8", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.13.8", | ||
"@babel/plugin-proposal-optional-chaining": "^7.13.12", | ||
"@babel/preset-env": "^7.13.15", | ||
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.14.2", | ||
"@babel/plugin-proposal-object-rest-spread": "^7.14.2", | ||
"@babel/plugin-proposal-optional-chaining": "^7.14.2", | ||
"@babel/preset-env": "^7.14.2", | ||
"@babel/preset-typescript": "^7.13.0", | ||
@@ -87,20 +87,20 @@ "@rollup/plugin-typescript": "^8.2.1", | ||
"@types/jest": "^26.0.23", | ||
"@types/ws": "^7.4.2", | ||
"@typescript-eslint/eslint-plugin": "^4.22.0", | ||
"@typescript-eslint/parser": "^4.22.0", | ||
"@types/ws": "^7.4.4", | ||
"@typescript-eslint/eslint-plugin": "^4.24.0", | ||
"@typescript-eslint/parser": "^4.24.0", | ||
"babel-jest": "^26.6.3", | ||
"eslint": "^7.25.0", | ||
"eslint": "^7.26.0", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-prettier": "^3.4.0", | ||
"glob": "^7.1.6", | ||
"glob": "^7.1.7", | ||
"graphql": "^15.5.0", | ||
"jest": "^26.6.3", | ||
"prettier": "^2.2.1", | ||
"prettier": "^2.3.0", | ||
"replacestream": "^4.0.3", | ||
"rollup": "^2.45.2", | ||
"rollup": "^2.48.0", | ||
"rollup-plugin-terser": "^7.0.2", | ||
"semantic-release": "^17.4.2", | ||
"semantic-release": "^17.4.3", | ||
"tslib": "^2.2.0", | ||
"typedoc": "^0.20.36", | ||
"typedoc-plugin-markdown": "^3.7.2", | ||
"typedoc-plugin-markdown": "^3.8.1", | ||
"typescript": "^4.2.4", | ||
@@ -107,0 +107,0 @@ "uWebSockets.js": "uNetworking/uWebSockets.js#v19.2.0", |
@@ -263,3 +263,3 @@ <div align="center"> | ||
// or | ||
import { Observable } from '@apollo/client'; | ||
import { Observable } from '@apollo/client/core'; | ||
// or | ||
@@ -407,3 +407,8 @@ import { Observable } from 'rxjs'; | ||
```typescript | ||
import { ApolloLink, Operation, FetchResult, Observable } from '@apollo/client'; | ||
import { | ||
ApolloLink, | ||
Operation, | ||
FetchResult, | ||
Observable, | ||
} from '@apollo/client/core'; | ||
import { print, GraphQLError } from 'graphql'; | ||
@@ -502,11 +507,49 @@ import { createClient, ClientOptions, Client } from 'graphql-ws'; | ||
```typescript | ||
import { createClient, Client } from 'graphql-ws'; | ||
import { createClient, Client, ClientOptions } from 'graphql-ws'; | ||
import { giveMeAFreshToken } from './token-giver'; | ||
let restartRequestedBeforeConnected = false; | ||
let gracefullyRestart = () => { | ||
restartRequestedBeforeConnected = true; | ||
}; | ||
interface RestartableClient extends Client { | ||
restart(): void; | ||
} | ||
const client = createClient({ | ||
function createRestartableClient(options: ClientOptions): RestartableClient { | ||
let restartRequested = false; | ||
let restart = () => { | ||
restartRequested = true; | ||
}; | ||
const client = createClient({ | ||
...options, | ||
on: { | ||
...options.on, | ||
connected: (socket) => { | ||
options.on?.connected?.(socket); | ||
restart = () => { | ||
if (socket.readyState === WebSocket.OPEN) { | ||
// if the socket is still open for the restart, do the restart | ||
socket.close(4205, 'Client Restart'); | ||
} else { | ||
// otherwise the socket might've closed, indicate that you want | ||
// a restart on the next connected event | ||
restartRequested = true; | ||
} | ||
}; | ||
// just in case you were eager to restart | ||
if (restartRequested) { | ||
restartRequested = false; | ||
restart(); | ||
} | ||
}, | ||
}, | ||
}); | ||
return { | ||
...client, | ||
restart: () => restart(), | ||
}; | ||
} | ||
const client = createRestartableClient({ | ||
url: 'wss://graceful.restart/is/a/non-fatal/close-code', | ||
@@ -517,20 +560,5 @@ connectionParams: async () => { | ||
}, | ||
on: { | ||
connected: (socket) => { | ||
gracefullyRestart = () => { | ||
if (socket.readyState === WebSocket.OPEN) { | ||
socket.close(4205, 'Client Restart'); | ||
} | ||
}; | ||
// just in case you were eager to restart | ||
if (restartRequestedBeforeConnected) { | ||
restartRequestedBeforeConnected = false; | ||
gracefullyRestart(); | ||
} | ||
}, | ||
}, | ||
}); | ||
// all subscriptions through `client.subscribe` will resubscribe on graceful restarts | ||
// all subscriptions from `client.subscribe` will resubscribe after `client.restart` | ||
``` | ||
@@ -537,0 +565,0 @@ |
@@ -400,3 +400,3 @@ (function (global, factory) { | ||
try { | ||
const [socket, release, waitForReleaseOrThrowOnClose,] = await connect(); | ||
const [socket, release, waitForReleaseOrThrowOnClose] = await connect(); | ||
// if done while waiting for connect, release the connection lock right away | ||
@@ -403,0 +403,0 @@ if (done) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
244716
3291
1480