Releases: enisdenjo/graphql-ws
Releases · enisdenjo/graphql-ws
v5.1.0
v5.0.0
5.0.0 (2021-06-08)
Features
- Bidirectional ping/pong message types (#201) (1efaf83), closes #117
- client: Rename
keepAlive
option tolazyCloseTimeout
(3c1f13c) - uWebSockets: Drop deprecated
request
context extra (02ea5ee)
BREAKING CHANGES
- Because of the Protocol's strictness, an instant connection termination will happen whenever an invalid message is identified; meaning, all previous implementations will fail when receiving the new subprotocol ping/pong messages.
Beware, the client will NOT ping the server by default. Please make sure to upgrade your stack in order to support the new ping/pong message types.
A simple recipe showcasing a client that times out if no pong is received and measures latency, looks like this:
import { createClient } from 'graphql-ws';
let activeSocket,
timedOut,
pingSentAt = 0,
latency = 0;
createClient({
url: 'ws://i.time.out:4000/and-measure/latency',
keepAlive: 10_000, // ping server every 10 seconds
on: {
connected: (socket) => (activeSocket = socket),
ping: (received) => {
if (!received /* sent */) {
pingSentAt = Date.now();
timedOut = setTimeout(() => {
if (activeSocket.readyState === WebSocket.OPEN)
activeSocket.close(4408, 'Request Timeout');
}, 5_000); // wait 5 seconds for the pong and then close the connection
}
},
pong: (received) => {
if (received) {
latency = Date.now() - pingSentAt;
clearTimeout(timedOut); // pong is received, clear connection close timeout
}
},
},
});
- uWebSockets: The deprecated uWebSockets
request
context extra field has been dropped because it is stack allocated and cannot be used ouside the internalupgrade
callback. - client: Client
keepAlive
option has been renamed tolazyCloseTimeout
in order to eliminate ambiguity with the client to server pings keep-alive option.
v4.9.0
4.9.0 (2021-06-06)
Features
Server usage with fastify-websocket
import Fastify from 'fastify'; // yarn add fastify
import fastifyWebsocket from 'fastify-websocket'; // yarn add fastify-websocket
import { makeHandler } from 'graphql-ws/lib/use/fastify-websocket';
const fastify = Fastify();
fastify.register(fastifyWebsocket);
fastify.get(
'/graphql',
{ websocket: true },
makeHandler(
// from the previous step
{ schema, roots },
),
);
fastify.listen(4000, (err) => {
if (err) {
fastify.log.error(err);
return process.exit(1);
}
console.log('Listening to port 4000');
});
v4.8.0
v4.7.0
v4.6.0
v4.5.2
v4.5.1
v4.5.0
v4.4.4
4.4.4 (2021-04-28)
Bug Fixes
- client:
complete
should not be called after subscriptionerror
(1fba419) - client: Subscription can be disposed only once (abd9c28), closes #170
Note about complete
not being called after subscription error
Promises and Async Iterators can reject/throw/error
or resolve/return/complete
only once, subsequent calls to either will simply be ignored.
Furthermore, as per the Observer pattern, from RxJS docs:
In an Observable Execution, zero to infinite Next notifications may be delivered. If either an Error or Complete notification is delivered, then nothing else can be delivered afterwards.