Skip to content

Releases: enisdenjo/graphql-sse

v2.2.0

22 Jun 12:22
Compare
Choose a tag to compare

2.2.0 (2023-06-22)

Features

  • client: Async iterator for subscriptions (#66) (fb8bf11)

Examples

Use the client

import { createClient } from 'graphql-sse';

const client = createClient({
  // singleConnection: true, preferred for HTTP/1 enabled servers and subscription heavy apps
  url: 'http://localhost:4000/graphql/stream',
});

// 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;
  }
})();

v2.1.4

12 Jun 11:24
Compare
Choose a tag to compare

2.1.4 (2023-06-12)

Bug Fixes

  • Request parameters query field can only be a string (16c9600), closes #65

v2.1.3

15 May 13:27
Compare
Choose a tag to compare

2.1.3 (2023-05-15)

Bug Fixes

  • client: Respect retry attempts when server goes away after connecting in single connection mode (#59) (e895c5b), closes #55
  • handler: Detect ExecutionArgs in onSubscribe return value (a16b921), closes #58

v2.1.2

10 May 19:57
Compare
Choose a tag to compare

2.1.2 (2023-05-10)

Bug Fixes

  • client: Respect retry attempts when server goes away after connecting (#57) (75c9f17), closes #55

v2.1.1

31 Mar 12:26
Compare
Choose a tag to compare

2.1.1 (2023-03-31)

Bug Fixes

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

v2.1.0

17 Feb 22:11
Compare
Choose a tag to compare

2.1.0 (2023-02-17)

Bug Fixes

  • use/express,use/fastify: Resolve body if previously parsed (6573e94)

Features

  • handler: Export handler options type for each integration (2a2e517)

v2.0.0

20 Dec 14:33
Compare
Choose a tag to compare

2.0.0 (2022-12-20)

Features

  • handler: Server and environment agnostic handler (#37) (22cf03d)

BREAKING CHANGES

  • handler: The handler is now server agnostic and can run anywhere
  • Core of graphql-sse is now server agnostic and as such offers a handler that implements a generic request/response model
  • Handler does not await for whole operation to complete anymore. Only the processing part (parsing, validating and executing)
  • GraphQL context is now typed
  • Hook arguments have been changed, they're not providing the Node native req/res anymore - they instead provide the generic request/response
  • onSubscribe hook can now return an execution result too (useful for caching for example)
  • Throwing in onNext and onComplete hooks will bubble the error to the returned iterator

Migration

Even though the core of graphql-sse is now completely server agnostic, there are adapters to ease the integration with existing solutions. Migrating is actually not a headache!

Beware that the adapters don't handle internal errors, it's your responsibility to take care of that and behave accordingly.

http

import http from 'http';
- import { createHandler } from 'graphql-sse';
+ import { createHandler } from 'graphql-sse/lib/use/http';

// Create the GraphQL over SSE handler
const handler = createHandler({ schema });

// Create an HTTP server using the handler on `/graphql/stream`
const server = http.createServer((req, res) => {
  if (req.url.startsWith('/graphql/stream')) {
    return handler(req, res);
  }
  res.writeHead(404).end();
});

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

http2

import fs from 'fs';
import http2 from 'http2';
- import { createHandler } from 'graphql-sse';
+ import { createHandler } from 'graphql-sse/lib/use/http2';

// Create the GraphQL over SSE handler
const handler = createHandler({ schema });

// Create an HTTP server using the handler on `/graphql/stream`
const server = http.createServer((req, res) => {
  if (req.url.startsWith('/graphql/stream')) {
    return handler(req, res);
  }
  res.writeHead(404).end();
});

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

express

import express from 'express'; // yarn add express
- import { createHandler } from 'graphql-sse';
+ import { createHandler } from 'graphql-sse/lib/use/express';

// Create the GraphQL over SSE handler
const handler = createHandler({ schema });

// Create an express app
const app = express();

// Serve all methods on `/graphql/stream`
app.use('/graphql/stream', handler);

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

fastify

import Fastify from 'fastify'; // yarn add fastify
- import { createHandler } from 'graphql-sse';
+ import { createHandler } from 'graphql-sse/lib/use/fastify';

// Create the GraphQL over SSE handler
const handler = createHandler({ schema });

// Create a fastify app
const fastify = Fastify();

// Serve all methods on `/graphql/stream`
fastify.all('/graphql/stream', handler);

fastify.listen({ port: 4000 });
console.log('Listening to port 4000');

v1.3.2

06 Dec 19:53
Compare
Choose a tag to compare

1.3.2 (2022-12-06)

Bug Fixes

  • handler: Correct typings and support for http2 (08d6ca3), closes #38

v1.3.1

05 Dec 11:16
Compare
Choose a tag to compare

1.3.1 (2022-12-05)

Bug Fixes

  • client: Abort request when reporting error (91057bd)
  • client: Operation requests are of application/json content-type (0084de7)

v1.3.0

20 Jul 19:33
Compare
Choose a tag to compare

1.3.0 (2022-07-20)

Features

  • client: Accept referrer and referrerPolicy fetch options (#32) (dbaa90a)