Skip to content

Commit 150e87a

Browse files
chore(release): 🎉 2.0.0 [skip ci]
# [2.0.0](v1.3.2...v2.0.0) (2022-12-20) ### Features * **handler:** Server and environment agnostic handler ([#37](#37)) ([22cf03d](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`](https://nodejs.org/api/http.html) ```diff 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`](https://nodejs.org/api/http2.html) ```diff 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`](https://expressjs.com/) ```diff 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`](https://www.fastify.io/) ```diff 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'); ```
1 parent 0413e40 commit 150e87a

File tree

2 files changed

+111
-1
lines changed

2 files changed

+111
-1
lines changed

CHANGELOG.md

+110
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,113 @@
1+
# [2.0.0](https://github.com/enisdenjo/graphql-sse/compare/v1.3.2...v2.0.0) (2022-12-20)
2+
3+
4+
### Features
5+
6+
* **handler:** Server and environment agnostic handler ([#37](https://github.com/enisdenjo/graphql-sse/issues/37)) ([22cf03d](https://github.com/enisdenjo/graphql-sse/commit/22cf03d3c214019a3bf538742bbceac766c17353))
7+
8+
9+
### BREAKING CHANGES
10+
11+
* **handler:** The handler is now server agnostic and can run _anywhere_
12+
13+
- Core of `graphql-sse` is now server agnostic and as such offers a handler that implements a generic request/response model
14+
- Handler does not await for whole operation to complete anymore. Only the processing part (parsing, validating and executing)
15+
- GraphQL context is now typed
16+
- Hook arguments have been changed, they're not providing the Node native req/res anymore - they instead provide the generic request/response
17+
- `onSubscribe` hook can now return an execution result too (useful for caching for example)
18+
- Throwing in `onNext` and `onComplete` hooks will bubble the error to the returned iterator
19+
20+
### Migration
21+
22+
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!
23+
24+
Beware that the adapters **don't** handle internal errors, it's your responsibility to take care of that and behave accordingly.
25+
26+
#### [`http`](https://nodejs.org/api/http.html)
27+
28+
```diff
29+
import http from 'http';
30+
- import { createHandler } from 'graphql-sse';
31+
+ import { createHandler } from 'graphql-sse/lib/use/http';
32+
33+
// Create the GraphQL over SSE handler
34+
const handler = createHandler({ schema });
35+
36+
// Create an HTTP server using the handler on `/graphql/stream`
37+
const server = http.createServer((req, res) => {
38+
if (req.url.startsWith('/graphql/stream')) {
39+
return handler(req, res);
40+
}
41+
res.writeHead(404).end();
42+
});
43+
44+
server.listen(4000);
45+
console.log('Listening to port 4000');
46+
```
47+
48+
#### [`http2`](https://nodejs.org/api/http2.html)
49+
50+
```diff
51+
import fs from 'fs';
52+
import http2 from 'http2';
53+
- import { createHandler } from 'graphql-sse';
54+
+ import { createHandler } from 'graphql-sse/lib/use/http2';
55+
56+
// Create the GraphQL over SSE handler
57+
const handler = createHandler({ schema });
58+
59+
// Create an HTTP server using the handler on `/graphql/stream`
60+
const server = http.createServer((req, res) => {
61+
if (req.url.startsWith('/graphql/stream')) {
62+
return handler(req, res);
63+
}
64+
res.writeHead(404).end();
65+
});
66+
67+
server.listen(4000);
68+
console.log('Listening to port 4000');
69+
```
70+
71+
#### [`express`](https://expressjs.com/)
72+
73+
```diff
74+
import express from 'express'; // yarn add express
75+
- import { createHandler } from 'graphql-sse';
76+
+ import { createHandler } from 'graphql-sse/lib/use/express';
77+
78+
// Create the GraphQL over SSE handler
79+
const handler = createHandler({ schema });
80+
81+
// Create an express app
82+
const app = express();
83+
84+
// Serve all methods on `/graphql/stream`
85+
app.use('/graphql/stream', handler);
86+
87+
server.listen(4000);
88+
console.log('Listening to port 4000');
89+
```
90+
91+
#### [`fastify`](https://www.fastify.io/)
92+
93+
```diff
94+
import Fastify from 'fastify'; // yarn add fastify
95+
- import { createHandler } from 'graphql-sse';
96+
+ import { createHandler } from 'graphql-sse/lib/use/fastify';
97+
98+
// Create the GraphQL over SSE handler
99+
const handler = createHandler({ schema });
100+
101+
// Create a fastify app
102+
const fastify = Fastify();
103+
104+
// Serve all methods on `/graphql/stream`
105+
fastify.all('/graphql/stream', handler);
106+
107+
fastify.listen({ port: 4000 });
108+
console.log('Listening to port 4000');
109+
```
110+
1111
## [1.3.2](https://github.com/enisdenjo/graphql-sse/compare/v1.3.1...v1.3.2) (2022-12-06)
2112

3113

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "graphql-sse",
3-
"version": "1.3.2",
3+
"version": "2.0.0",
44
"description": "Zero-dependency, HTTP/1 safe, simple, GraphQL over Server-Sent Events Protocol server and client",
55
"keywords": [
66
"graphql",

0 commit comments

Comments
 (0)