graphql-sse

Zero-dependency, HTTP/1 safe, simple, GraphQL over Server-Sent Events Protocol server and client.

MIT License

Downloads
928.6K
Stars
383
Committers
12

Bot releases are visible (Hide)

graphql-sse - v2.5.3 Latest Release

Published by enisdenjo 7 months ago

2.5.3 (2024-03-27)

Bug Fixes

  • use/fastify: Include middleware headers (134c1b0), closes #91
graphql-sse - v2.5.2

Published by enisdenjo 10 months ago

2.5.2 (2023-12-20)

Bug Fixes

  • remove package.json workspaces entry in release (c6dc093)
graphql-sse - v2.5.1

Published by enisdenjo 10 months ago

2.5.1 (2023-12-14)

Bug Fixes

  • use/koa: Use parsed body from request (#87) (b290b90)
graphql-sse - v2.5.0

Published by enisdenjo 10 months ago

2.5.0 (2023-12-13)

Features

  • use/koa: expose full Koa context to options (#86) (b37a6f9)
graphql-sse - v2.4.1

Published by enisdenjo 10 months ago

2.4.1 (2023-12-13)

Bug Fixes

graphql-sse - v2.4.0

Published by enisdenjo 11 months ago

2.4.0 (2023-11-29)

Bug Fixes

  • client: Use closures instead of bindings (with this) (8ecdf3c)

Features

  • client: Event listeners for both operation modes (#84) (6274f44)
graphql-sse - v2.3.0

Published by enisdenjo about 1 year ago

2.3.0 (2023-09-07)

Features

Examples

Server usage with Koa

import Koa from 'koa'; // yarn add koa
import mount from 'koa-mount'; // yarn add koa-mount
import { createHandler } from 'graphql-sse/lib/use/koa';
import { schema } from './my-graphql';

// Create a Koa app
const app = new Koa();

// Serve all methods on `/graphql/stream`
app.use(mount('/graphql/stream', createHandler({ schema })));

app.listen({ port: 4000 });
console.log('Listening to port 4000');
graphql-sse - v2.2.3

Published by enisdenjo about 1 year ago

2.2.3 (2023-08-23)

Bug Fixes

  • use/http,use/http2,use/express,use/fastify: Check writable instead of closed before writing to response (3c71f69), closes #69
graphql-sse - v2.2.2

Published by enisdenjo about 1 year ago

2.2.2 (2023-08-22)

Bug Fixes

  • use/http,use/http2,use/express,use/fastify: Handle cases where response's close event is late (#75) (4457cba), closes #69
graphql-sse - v2.2.1

Published by enisdenjo about 1 year ago

2.2.1 (2023-07-31)

Bug Fixes

  • handler: Always include the data field in stream messages (#71) (4643c9a)
graphql-sse - v2.2.0

Published by enisdenjo over 1 year ago

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;
  }
})();
graphql-sse - v2.1.4

Published by enisdenjo over 1 year ago

2.1.4 (2023-06-12)

Bug Fixes

  • Request parameters query field can only be a string (16c9600), closes #65
graphql-sse - v2.1.3

Published by enisdenjo over 1 year ago

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
graphql-sse - v2.1.2

Published by enisdenjo over 1 year ago

2.1.2 (2023-05-10)

Bug Fixes

  • client: Respect retry attempts when server goes away after connecting (#57) (75c9f17), closes #55
graphql-sse - v2.1.1

Published by enisdenjo over 1 year ago

2.1.1 (2023-03-31)

Bug Fixes

  • Add file extensions to imports/exports in ESM type definitions (bbf23b1)
graphql-sse - v2.1.0

Published by enisdenjo over 1 year ago

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)
graphql-sse - v2.0.0

Published by enisdenjo almost 2 years ago

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');
graphql-sse - v1.3.2

Published by enisdenjo almost 2 years ago

1.3.2 (2022-12-06)

Bug Fixes

  • handler: Correct typings and support for http2 (08d6ca3), closes #38
graphql-sse - v1.3.1

Published by enisdenjo almost 2 years ago

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)
graphql-sse - v1.3.0

Published by enisdenjo about 2 years ago

1.3.0 (2022-07-20)

Features

  • client: Accept referrer and referrerPolicy fetch options (#32) (dbaa90a)
Package Rankings
Top 1.98% on Npmjs.org
Top 9.73% on Proxy.golang.org
Top 26.22% on Repo1.maven.org
Badges
Extracted from project README's
Continuous integration graphql-sse
Related Projects