Skip to content

Releases: enisdenjo/graphql-ws

v5.16.0

27 Mar 20:24
Compare
Choose a tag to compare

5.16.0 (2024-03-27)

Bug Fixes

  • server: Return all subscriptions regardless of the return invocation order (f442288)
  • server: should not send error messages if socket closes before onSubscribe hooks resolves (db47a66), closes #539

Features

  • server: Close code and reason are optional (6ae6e6f), closes #547

v5.15.0

12 Feb 17:57
Compare
Choose a tag to compare

5.15.0 (2024-02-12)

Bug Fixes

  • client: Use TerminatedCloseEvent class extending an Error for rejecting promises when terminating (74b4ceb), closes #531
  • server: Dispose of subscriptions on close even if added late to the subscriptions list (#534) (e45d6b1), closes #532

Features

  • server: Add is retry flag to connect events (#507) (9ad853f)

v5.14.3

20 Dec 12:18
Compare
Choose a tag to compare

5.14.3 (2023-12-20)

Bug Fixes

  • client: Use closures instead of bindings (with this) (812129d)
  • remove package.json workspaces entry in release (63a831e), closes #524

v5.14.2

23 Oct 14:52
Compare
Choose a tag to compare

5.14.2 (2023-10-23)

Bug Fixes

  • client: correct close code for Bad Gateway reason (#512) (0438650)

v5.14.1

28 Sep 18:05
Compare
Choose a tag to compare

5.14.1 (2023-09-28)

Bug Fixes

  • server: Acknowledge connection before notifying the client to avoid race conditions with slow sends (#506) (8cb82bd), closes #501

v5.14.0

22 Jun 12:26
Compare
Choose a tag to compare

5.14.0 (2023-06-22)

Features

  • client: Async iterator for subscriptions (#486) (fb4b967)

Examples

Use the client

import { createClient } from 'graphql-ws';

const client = createClient({
  url: 'ws://localhost:4000/graphql',
});

// query
(async () => {
  const query = client.iterate({
    query: '{ hello }',
  });

  const { value } = await query.next();
  expect(value).toEqual({ hello: 'world' });
})();

// subscription
(async () => {
  const subscription = client.iterate({
    query: 'subscription { greetings }',
  });

  for await (const event of subscription) {
    expect(event).toEqual({ greetings: 'Hi' });

    // complete a running subscription by breaking the iterator loop
    break;
  }
})();

v5.13.1

15 May 11:50
Compare
Choose a tag to compare

5.13.1 (2023-05-15)

Bug Fixes

  • Remove unnecessary bun-types directives (e9a56f7), closes #478

v5.13.0

12 May 11:31
Compare
Choose a tag to compare

5.13.0 (2023-05-12)

Features

Examples

Start the server with Bun

import { makeHandler, handleProtocols } from 'graphql-ws/lib/use/lib/bun';
import { schema } from './previous-step';

Bun.serve({
  fetch(req, server) {
    const [path, _search] = req.url.split('?');
    if (!path.endsWith('/graphql')) {
      return new Response('Not Found', { status: 404 });
    }
    if (req.headers.get('upgrade') != 'websocket') {
      return new Response('Upgrade Required', { status: 426 });
    }
    if (handleProtocols(req.headers.get('sec-websocket-protocol') || '')) {
      return new Response('Bad Request', { status: 404 });
    }
    if (!server.upgrade(req)) {
      return new Response('Internal Server Error', { status: 500 });
    }
    return new Response();
  },
  websocket: makeHandler({ schema }),
  port: 4000,
});

console.log('Listening to port 4000');

Start the server with Deno

import { serve } from 'https://deno.land/std/http/mod.ts';
import {
  makeHandler,
  GRAPHQL_TRANSPORT_WS_PROTOCOL,
} from 'https://esm.sh/graphql-ws/lib/use/deno';
import { schema } from './previous-step.ts';

const handler = makeHandler({ schema });

serve(
  (req: Request) => {
    const [path, _search] = req.url.split('?');
    if (!path.endsWith('/graphql')) {
      return new Response('Not Found', { status: 404 });
    }
    if (req.headers.get('upgrade') != 'websocket') {
      return new Response('Upgrade Required', { status: 426 });
    }
    const { socket, response } = Deno.upgradeWebSocket(req, {
      protocol: GRAPHQL_TRANSPORT_WS_PROTOCOL,
      idleTimeout: 12_000,
    });
    handler(socket);
    return response;
  },
  { port: 4000 },
);

v5.12.1

31 Mar 12:22
Compare
Choose a tag to compare

5.12.1 (2023-03-31)

Bug Fixes

  • Add file extensions to imports/exports in ESM type definitions (48775be)

v5.12.0

06 Mar 01:40
Compare
Choose a tag to compare

5.12.0 (2023-03-06)

Features