|
1 |
| -import type { ServerOptions, ConnectionInitMessage } from 'graphql-ws' |
| 1 | +import { |
| 2 | + makeServer, |
| 3 | + DEPRECATED_GRAPHQL_WS_PROTOCOL, |
| 4 | + CloseCode, |
| 5 | + ServerOptions, |
| 6 | + ConnectionInitMessage, |
| 7 | +} from 'graphql-ws' |
2 | 8 | import {
|
3 | 9 | defineWebSocket,
|
4 | 10 | defineWebSocketHandler,
|
@@ -38,13 +44,10 @@ interface Client {
|
38 | 44 | * Use this over {@link defineGraphqlWebSocketHandler} if you need more control over the WebSocket server or
|
39 | 45 | * if you want to add custom hooks (e.g. for authentication or logging).
|
40 | 46 | */
|
41 |
| -export async function defineGraphqlWebSocket< |
| 47 | +export function defineGraphqlWebSocket< |
42 | 48 | P extends ConnectionInitMessage['payload'] = ConnectionInitMessage['payload'],
|
43 | 49 | E extends Record<PropertyKey, unknown> = Record<PropertyKey, never>,
|
44 |
| ->(options: ServerOptions<P, Extra & Partial<E>>): Promise<Partial<Hooks>> { |
45 |
| - // Local import since graphql-ws is only an optional peer dependency |
46 |
| - const { makeServer, DEPRECATED_GRAPHQL_WS_PROTOCOL, CloseCode } = |
47 |
| - await import('graphql-ws') |
| 50 | +>(options: ServerOptions<P, Extra & Partial<E>>): Partial<Hooks> { |
48 | 51 | const server = makeServer(options)
|
49 | 52 | const peers = new WeakMap<Peer, Client>()
|
50 | 53 | return defineWebSocket({
|
@@ -112,5 +115,5 @@ export async function defineGraphqlWebSocketHandler<
|
112 | 115 | >(
|
113 | 116 | options: ServerOptions<P, Extra & Partial<E>>,
|
114 | 117 | ): Promise<EventHandler<EventHandlerRequest, never>> {
|
115 |
| - return defineWebSocketHandler(await defineGraphqlWebSocket(options)) |
| 118 | + return defineWebSocketHandler(defineGraphqlWebSocket(options)) |
116 | 119 | }
|
0 commit comments