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.
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');
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');
Breaking changes
graphql-sse
is now server agnostic and as such offers a handler that implements a generic request/response modelonSubscribe
hook can now return an execution result too (useful for caching for example)onNext
andonComplete
hooks will bubble the error to the returned iteratorMigration
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
http2
express
fastify
TODO
use/fetch
adapteruse/http
adapteruse/http2
adapteruse/express
adapteruse/fastify
adapter