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
103
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-ws - npm Package Versions

1
11

4.0.0

Diff

Changelog

Source

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.
enisdenjo
published 3.2.0 •

Changelog

Source

3.2.0 (2020-12-17)

Features

enisdenjo
published 3.1.0 •

Changelog

Source

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

Changelog

Source

3.0.2 (2020-12-10)

Bug Fixes

  • client: No retries when disposed (0d5e6c2)
enisdenjo
published 3.0.1 •

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