# Module: use/fastify

## Interfaces

- [RequestContext](/content/graphql/sse/docs/interfaces/use_fastify.RequestContext)

## Server/fastify

### HandlerOptions

Ƭ **HandlerOptions** <`Context`>: [`HandlerOptions`](/content/graphql/sse/docs/interfaces/handler.HandlerOptions) <`FastifyRequest`, [`RequestContext`](/content/graphql/sse/docs/interfaces/use_fastify.RequestContext), `Context`>

#### Type parameters

| Name | Type |
| --- | --- |
| `Context` | extends [`OperationContext`](/content/graphql/sse/docs/modules/handler#operationcontext/index.html) = `undefined` |

#### Defined in

[src/use/fastify.ts:18](https://github.com/enisdenjo/graphql-sse/blob/13f2fb8/src/use/fastify.ts#L18)

* * *

### createHandler

▸ **createHandler** <`Context`>(`options`): (`req`: `FastifyRequest`, `reply`: `FastifyReply`) = >`Promise`<`void`>

The ready-to-use handler for [fastify](https://www.fastify.io/).

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.

```typescript
import Fastify from 'fastify'; // yarn add fastify
import { createHandler } from 'graphql-sse/lib/use/fastify';

const handler = createHandler({ schema });

const fastify = Fastify();

fastify.all('/graphql/stream', async (req, reply) => {
  try {
    await handler(req, reply);
  } catch (err) {
    console.error(err);
    reply.code(500).send();
  }
});

fastify.listen({ port: 4000 });
console.log('Listening to port 4000');
```

#### Type parameters

#### Parameters

| Name | Type |
| --- | --- |
| `options` | [`HandlerOptions`](/content/graphql/sse/docs/modules/use_fastify#handleroptions/index.html) <`Context`> |

#### Returns

`fn`

▸ (`req`, `reply`): `Promise`<`void`>

##### Parameters

| Name | Type |
| --- | --- |
| `req` | `FastifyRequest` |
| `reply` | `FastifyReply` |

##### Returns

`Promise`<`void`>

#### Defined in

[src/use/fastify.ts:56](https://github.com/enisdenjo/graphql-sse/blob/13f2fb8/src/use/fastify.ts#L56)

[use/express](/content/graphql/sse/docs/modules/use_express/index.html) [use/fetch](/content/graphql/sse/docs/modules/use_fetch/index.html)
