Documentation
Modules
use/express

Module: use/express

Interfaces

Server/express

createHandler

createHandler<Context>(options): (req: Request, res: Response) => Promise<void>

The ready-to-use handler for express (opens in a new tab).

Errors thrown from the provided options or callbacks (or even due to library misuse or potential bugs) will reject the handler or bubble to the returned iterator. They are considered internal errors and you should take care of them accordingly.

For production environments, its recommended not to transmit the exact internal error details to the client, but instead report to an error logging tool or simply the console.

import express from 'express'; // yarn add express
import { createHandler } from 'graphql-sse/lib/use/express';
import { schema } from './my-graphql';
 
const handler = createHandler({ schema });
 
const app = express();
 
app.use('/graphql/stream', async (req, res) => {
  try {
    await handler(req, res);
  } catch (err) {
    console.error(err);
    res.writeHead(500).end();
  }
});
 
server.listen(4000);
console.log('Listening to port 4000');

Type parameters

NameType
Contextextends OperationContext = undefined

Parameters

NameType
optionsHandlerOptions<Context>

Returns

fn

▸ (req, res): Promise<void>

Parameters
NameType
reqRequest
resResponse
Returns

Promise<void>

Defined in

src/use/express.ts:57 (opens in a new tab)

Server/fetch

HandlerOptions

Ƭ HandlerOptions<Context>: HandlerOptions<Request, RequestContext, Context>

Type parameters

NameType
Contextextends OperationContext = undefined

Defined in

src/use/express.ts:18 (opens in a new tab)