forked from enisdenjo/graphql-ws
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(server): Use
@fastify/websocket
(enisdenjo#382)
Closes enisdenjo#381
- Loading branch information
Showing
18 changed files
with
604 additions
and
349 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import Fastify from 'fastify'; | ||
import fastifyWebsocket from '@fastify/websocket'; | ||
import { ports } from './ports.mjs'; | ||
import { makeHandler } from '../../lib/use/@fastify/websocket.mjs'; | ||
import { schema } from './schema.mjs'; | ||
|
||
const fastify = Fastify(); | ||
fastify.register(fastifyWebsocket); | ||
fastify.register(async (fastify) => { | ||
fastify.get('/graphql', { websocket: true }, makeHandler({ schema })); | ||
}); | ||
|
||
fastify.listen({ port: ports['@fastify/websocket'] }, (err) => { | ||
if (err) { | ||
fastify.log.error(err); | ||
return process.exit(1); | ||
} | ||
console.log( | ||
`@fastify/websocket - listening on port ${ports['@fastify/websocket']}...`, | ||
); | ||
}); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import './uWebSockets.mjs'; | ||
import './ws8.mjs'; | ||
import './ws7.mjs'; | ||
import './fastify-websocket_ws8.mjs'; | ||
import './fastify-websocket.mjs'; | ||
import './legacy_ws7.mjs'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
[graphql-ws](../README.md) / [use/@fastify/websocket](../modules/use__fastify_websocket.md) / Extra | ||
|
||
# Interface: Extra | ||
|
||
[use/@fastify/websocket](../modules/use__fastify_websocket.md).Extra | ||
|
||
The extra that will be put in the `Context`. | ||
|
||
## Table of contents | ||
|
||
### Properties | ||
|
||
- [connection](use__fastify_websocket.Extra.md#connection) | ||
- [request](use__fastify_websocket.Extra.md#request) | ||
|
||
## Properties | ||
|
||
### connection | ||
|
||
• `Readonly` **connection**: `SocketStream` | ||
|
||
The underlying socket connection between the server and the client. | ||
The WebSocket socket is located under the `socket` parameter. | ||
|
||
___ | ||
|
||
### request | ||
|
||
• `Readonly` **request**: `FastifyRequest`<`RouteGenericInterface`, `Server`, `IncomingMessage`, `FastifySchema`, `FastifyTypeProviderDefault`, `unknown`, `FastifyBaseLogger`, `ResolveFastifyRequestType`<`FastifyTypeProviderDefault`, `FastifySchema`, `RouteGenericInterface`\>\> | ||
|
||
The initial HTTP upgrade request before the actual | ||
socket and connection is established. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
[graphql-ws](../README.md) / use/@fastify/websocket | ||
|
||
# Module: use/@fastify/websocket | ||
|
||
## Table of contents | ||
|
||
### Interfaces | ||
|
||
- [Extra](../interfaces/use__fastify_websocket.Extra.md) | ||
|
||
### Functions | ||
|
||
- [makeHandler](use__fastify_websocket.md#makehandler) | ||
|
||
## Server/@fastify/websocket | ||
|
||
### makeHandler | ||
|
||
▸ **makeHandler**<`P`, `E`\>(`options`, `keepAlive?`): `fastifyWebsocket.WebsocketHandler` | ||
|
||
Make a handler to use on a [@fastify/websocket](https://github.com/fastify/fastify-websocket) route. | ||
This is a basic starter, feel free to copy the code over and adjust it to your needs | ||
|
||
#### Type parameters | ||
|
||
| Name | Type | | ||
| :------ | :------ | | ||
| `P` | extends `undefined` \| `Record`<`string`, `unknown`\> = `undefined` \| `Record`<`string`, `unknown`\> | | ||
| `E` | extends `Record`<`PropertyKey`, `unknown`\> = `Record`<`PropertyKey`, `never`\> | | ||
|
||
#### Parameters | ||
|
||
| Name | Type | Default value | | ||
| :------ | :------ | :------ | | ||
| `options` | [`ServerOptions`](../interfaces/server.ServerOptions.md)<`P`, [`Extra`](../interfaces/use__fastify_websocket.Extra.md) & `Partial`<`E`\>\> | `undefined` | | ||
| `keepAlive` | `number` | `12_000` | | ||
|
||
#### Returns | ||
|
||
`fastifyWebsocket.WebsocketHandler` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.