|
| 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 | + |
1 | 111 | ## [1.3.2](https://github.com/enisdenjo/graphql-sse/compare/v1.3.1...v1.3.2) (2022-12-06)
|
2 | 112 |
|
3 | 113 |
|
|
0 commit comments