|
| 1 | +[graphql-http](../README.md) / use/http2 |
| 2 | + |
| 3 | +# Module: use/http2 |
| 4 | + |
| 5 | +## Table of contents |
| 6 | + |
| 7 | +### Type Aliases |
| 8 | + |
| 9 | +- [HandlerOptions](use_http2.md#handleroptions) |
| 10 | + |
| 11 | +### Functions |
| 12 | + |
| 13 | +- [createHandler](use_http2.md#createhandler) |
| 14 | + |
| 15 | +## Server/http2 |
| 16 | + |
| 17 | +### HandlerOptions |
| 18 | + |
| 19 | +Ƭ **HandlerOptions**<`Context`\>: [`HandlerOptions`](../interfaces/handler.HandlerOptions.md)<`Http2ServerRequest`, `undefined`, `Context`\> |
| 20 | + |
| 21 | +Handler options when using the http adapter. |
| 22 | + |
| 23 | +#### Type parameters |
| 24 | + |
| 25 | +| Name | Type | |
| 26 | +| :------ | :------ | |
| 27 | +| `Context` | extends [`OperationContext`](handler.md#operationcontext) = `undefined` | |
| 28 | + |
| 29 | +___ |
| 30 | + |
| 31 | +### createHandler |
| 32 | + |
| 33 | +▸ **createHandler**<`Context`\>(`options`): (`req`: `Http2ServerRequest`, `res`: `Http2ServerResponse`) => `Promise`<`void`\> |
| 34 | + |
| 35 | +Create a GraphQL over HTTP Protocol compliant request handler for |
| 36 | +the Node environment http2 module. |
| 37 | + |
| 38 | + ```shell |
| 39 | +$ openssl req -x509 -newkey rsa:2048 -nodes -sha256 -subj '/CN=localhost' \ |
| 40 | + -keyout localhost-privkey.pem -out localhost-cert.pem |
| 41 | +``` |
| 42 | + |
| 43 | +```js |
| 44 | +import fs from 'fs'; |
| 45 | +import http2 from 'http2'; |
| 46 | +import { createHandler } from 'graphql-http/lib/use/http2'; |
| 47 | +import { schema } from './my-graphql-step'; |
| 48 | + |
| 49 | +const server = http2.createSecureServer( |
| 50 | + { |
| 51 | + key: fs.readFileSync('localhost-privkey.pem'), |
| 52 | + cert: fs.readFileSync('localhost-cert.pem'), |
| 53 | + }, |
| 54 | + createHandler({ schema }), |
| 55 | +); |
| 56 | + |
| 57 | +server.listen(4000); |
| 58 | +console.log('Listening to port 4000'); |
| 59 | +``` |
| 60 | + |
| 61 | +#### Type parameters |
| 62 | + |
| 63 | +| Name | Type | |
| 64 | +| :------ | :------ | |
| 65 | +| `Context` | extends [`OperationContext`](handler.md#operationcontext) = `undefined` | |
| 66 | + |
| 67 | +#### Parameters |
| 68 | + |
| 69 | +| Name | Type | |
| 70 | +| :------ | :------ | |
| 71 | +| `options` | [`HandlerOptions`](use_http2.md#handleroptions)<`Context`\> | |
| 72 | + |
| 73 | +#### Returns |
| 74 | + |
| 75 | +`fn` |
| 76 | + |
| 77 | +▸ (`req`, `res`): `Promise`<`void`\> |
| 78 | + |
| 79 | +##### Parameters |
| 80 | + |
| 81 | +| Name | Type | |
| 82 | +| :------ | :------ | |
| 83 | +| `req` | `Http2ServerRequest` | |
| 84 | +| `res` | `Http2ServerResponse` | |
| 85 | + |
| 86 | +##### Returns |
| 87 | + |
| 88 | +`Promise`<`void`\> |
0 commit comments