Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

graphql-ws

Package Overview
Dependencies
Maintainers
1
Versions
159
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-ws - npm Package Versions

1
16

3.0.1

Diff

Changelog

Source

3.0.1 (2020-12-10)

Performance Improvements

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

Changelog

Source

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),
    ),
  );
};
enisdenjo
published 2.0.1 •

Changelog

Source

2.0.1 (2020-12-03)

Bug Fixes

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

Changelog

Source

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)
);
enisdenjo
published 1.14.0 •

Changelog

Source

1.14.0 (2020-11-15)

Features

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

Changelog

Source

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)
enisdenjo
published 1.13.0 •

Changelog

Source

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)
enisdenjo
published 1.12.0 •

Changelog

Source

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)
enisdenjo
published 1.11.0 •

Changelog

Source

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)
enisdenjo
published 1.10.0 •

Changelog

Source

1.10.0 (2020-11-03)

Features

  • Subscribe message query must be a string (#45) (60d9cd5)
  • server: For dynamic usage, context option can be a function too (#46) (149b582)
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc