Skip to content

Releases: enisdenjo/graphql-ws

v4.0.0

13 Jan 00:24
Compare
Choose a tag to compare

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 the onDisconnect callback.
  • server: The Context.subscriptions record value can be either an AsyncIterator or a Promise.

v3.2.0

17 Dec 11:32
Compare
Choose a tag to compare

3.2.0 (2020-12-17)

Features

v3.1.0

11 Dec 12:04
Compare
Choose a tag to compare

3.1.0 (2020-12-11)

Bug Fixes

  • client: Time retries and socket change waits (7c707db), closes #85

Features

  • client: onNonLazyError allows you to catch errors reported in non-lazy mode (cd1e7df)

v3.0.2

10 Dec 17:40
Compare
Choose a tag to compare

3.0.2 (2020-12-10)

Bug Fixes

  • client: No retries when disposed (0d5e6c2)

v3.0.1

10 Dec 13:44
Compare
Choose a tag to compare

3.0.1 (2020-12-10)

Performance Improvements

  • client: Await timeouts only in recursive connects (55c8fc8)

v3.0.0

09 Dec 21:57
Compare
Choose a tag to compare

3.0.0 (2020-12-09)

Features

  • client: Retry with randomised exponential backoff or provide your own strategy (#84) (d3e7a17)

BREAKING CHANGES

  • client: Client retryTimeout option has been replaced with the new retryWait.

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

03 Dec 09:10
Compare
Choose a tag to compare

2.0.1 (2020-12-03)

Bug Fixes

  • client: Close event's wasClean is not necessary (2c65f0e), closes #81

v2.0.0

20 Nov 02:43
Compare
Choose a tag to compare

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 more createServer)

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 the Context 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)
);

v1.14.0

15 Nov 10:57
Compare
Choose a tag to compare

1.14.0 (2020-11-15)

Features

  • server: context may return a promise (cd5c2f8), closes #74

v1.13.1

14 Nov 23:51
Compare
Choose a tag to compare

1.13.1 (2020-11-14)

Bug Fixes

  • client: Some close events are not worth retrying (4d9134b)
  • message: Allow data field to be of any type (533248e), closes #72
  • message: Allow payload field to be of any type for NextMessage (7cebbfe), closes #72
  • Use ID type for message id field (87ebd35)