Skip to content

Releases: enisdenjo/graphql-ws

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)

v1.13.0

12 Nov 23:21
Compare
Choose a tag to compare

1.13.0 (2020-11-12)

Bug Fixes

  • client: One cleanup per subscription (#67) (5a5ae4d)
  • Stop sending messages after receiving complete (#65) (3f4f836)

Features

  • client: connectionParams may return a promise (#71) (33f210c)
  • client: Allow keeping the connection alive for some time before lazy closing (#69) (555c2c3)

v1.12.0

07 Nov 10:12
Compare
Choose a tag to compare

1.12.0 (2020-11-07)

Bug Fixes

  • client: Close with error message during connecting issues (f8ecdd7)

Features

  • Send optional payload with the ConnectionAck message (#60) (1327e77)

v1.11.0

04 Nov 22:46
Compare
Choose a tag to compare

1.11.0 (2020-11-04)

Bug Fixes

  • Node 10 is the min supported version (19844d7)
  • Support more graphql versions (de69b4e)
  • server: Close socket if onSubscribe returns invalid array (#53) (0464a54)
  • server: Consistently set rootValue and contextValue, if not overridden (#49) (7aa3bcd)
  • server: Distribute server error to all clients even if one error listener throws (#56) (b96dbb9)
  • server: Don't surface bad request error details in production (#55) (70317b2)

Features

  • cjs, esm and umd builds with minification and compression for the browser (#58) (ebb8dfe)

Performance Improvements

  • Reduce runtime prototype traversal for hasOwnProperty (#52) (1bb9218)