Releases: enisdenjo/graphql-ws
Releases · enisdenjo/graphql-ws
v4.0.0
4.0.0 (2021-01-13)
Bug Fixes
- server: Client can complete/cancel any operation (0ad1c4c)
- server: Enforce ID uniqueness across all operations and during the whole subscription life (#96) (65d1bfa)
Features
- server: Add
onDisconnect
callback (#94) (2a61268) - server: Log a warning for unsupported subprotocols (88a12ef), closes #92
BREAKING CHANGES
- server: The return function of
server.opened
(closed
) now requires the close event code and reason for reporting to theonDisconnect
callback. - server: The
Context.subscriptions
record value can be either anAsyncIterator
or aPromise
.
v3.2.0
v3.1.0
v3.0.2
v3.0.1
v3.0.0
3.0.0 (2020-12-09)
Features
BREAKING CHANGES
- client: Client
retryTimeout
option has been replaced with the newretryWait
.
retryWait
allows you to control the retry timeout strategy by resolving the returned promise when ready. The default implements the randomised exponential backoff like so:
// this is the default
const retryWait = async function randomisedExponentialBackoff(retries: number) {
let retryDelay = 1000; // start with 1s delay
for (let i = 0; i < retries; i++) {
retryDelay *= 2; // square `retries` times
}
await new Promise((resolve) =>
setTimeout(
// resolve pending promise with added random timeout from 300ms to 3s
resolve,
retryDelay + Math.floor(Math.random() * (3000 - 300) + 300),
),
);
};
v2.0.1
v2.0.0
2.0.0 (2020-11-20)
Features
BREAKING CHANGES
- server: You now "make" a ready-to-use server that can be used with any WebSocket implementation!
Summary of breaking changes:
- No more
keepAlive
. The user should provide its own keep-alive implementation. (I highly recommend WebSocket Ping and Pongs) - No more HTTP
request
in the server context. - No more WebSocket in the server context (you're the one that creates it).
- You use your own WebSocket server
- Server exports only
makeServer
(no morecreateServer
)
Benefits
- You're responsible for the server (any optimisation or adjustment can be applied)
- Any WebSocket server can be used (or even mocked if necessary)
- You control the disposal of the server (close or transfer clients however you wish)
- New
extra
field in theContext
for storing custom values useful for callbacks - Full control of authentication flow
- Full control over error handling
- True zero-dependency
Migrating from v1
Only the server has to be migrated. Since this release allows you to use your favourite WebSocket library (or your own implementation), using ws is just one way of using graphql-ws
. This is how to use the implementation shipped with the lib:
/**
* ❌ instead of the lib creating a WebSocket server internally with the provided arguments
*/
import https from 'https';
import { createServer } from 'graphql-ws';
const server = https.createServer(...);
createServer(
{
onConnect(ctx) {
// were previously directly on the context
ctx.request as IncomingRequest
ctx.socket as WebSocket
},
...rest,
},
{
server,
path: '/graphql',
},
);
/**
* ✅ you have to supply the server yourself
*/
import https from 'https';
import ws from 'ws'; // yarn add ws
import { useServer } from 'graphql-ws/lib/use/ws'; // notice the import path
const server = https.createServer(...);
const wsServer = new ws.Server({
server,
path: '/graphql',
});
useServer(
{
onConnect(ctx) {
// are now in the `extra` field
ctx.extra.request as IncomingRequest
ctx.extra.socket as WebSocket
},
...rest,
},
wsServer,
// optional keepAlive with ping pongs (defaults to 12 seconds)
);