@tsed/graphql-ws 8.0.1 → 8.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -2,13 +2,14 @@
2
2
  "name": "@tsed/graphql-ws",
3
3
  "description": "An extension to allow GraphQL over WebSockets using graphql-ws protocol",
4
4
  "type": "module",
5
- "version": "8.0.1",
5
+ "version": "8.0.2",
6
6
  "source": "./src/index.ts",
7
7
  "main": "./lib/esm/index.js",
8
8
  "module": "./lib/esm/index.js",
9
9
  "typings": "./lib/types/index.d.ts",
10
10
  "exports": {
11
11
  ".": {
12
+ "@tsed/source": "./src/index.ts",
12
13
  "types": "./lib/types/index.d.ts",
13
14
  "import": "./lib/esm/index.js",
14
15
  "default": "./lib/esm/index.js"
@@ -23,21 +24,21 @@
23
24
  "tslib": "2.7.0"
24
25
  },
25
26
  "devDependencies": {
26
- "@tsed/barrels": "8.0.1",
27
- "@tsed/core": "8.0.1",
28
- "@tsed/di": "8.0.1",
27
+ "@tsed/barrels": "8.0.2",
28
+ "@tsed/core": "8.0.2",
29
+ "@tsed/di": "8.0.2",
29
30
  "@tsed/logger": "^6.7.8",
30
- "@tsed/platform-http": "8.0.1",
31
- "@tsed/typescript": "8.0.1",
31
+ "@tsed/platform-http": "8.0.2",
32
+ "@tsed/typescript": "8.0.2",
32
33
  "eslint": "9.12.0",
33
34
  "graphql-ws": "5.16.0",
34
35
  "typescript": "5.4.5"
35
36
  },
36
37
  "peerDependencies": {
37
- "@tsed/core": "8.0.1",
38
- "@tsed/di": "8.0.1",
38
+ "@tsed/core": "8.0.2",
39
+ "@tsed/di": "8.0.2",
39
40
  "@tsed/logger": ">=6.7.5",
40
- "@tsed/platform-http": "8.0.1",
41
+ "@tsed/platform-http": "8.0.2",
41
42
  "graphql-ws": ">=5.14.2"
42
43
  },
43
44
  "repository": "https://github.com/tsedio/tsed",
@@ -0,0 +1,59 @@
1
+ import {Constant, Inject, InjectorService, Module} from "@tsed/di";
2
+ import type {Disposable} from "graphql-ws";
3
+ import {useServer} from "graphql-ws/lib/use/ws";
4
+ import Http from "http";
5
+ import Https from "https";
6
+
7
+ import {GraphQLWSOptions} from "./GraphQLWSOptions.js";
8
+
9
+ @Module()
10
+ export class GraphQLWSModule {
11
+ @Constant("graphqlWs", {})
12
+ private settings: GraphQLWSOptions;
13
+
14
+ @Inject(Http.Server)
15
+ private httpServer: Http.Server | null;
16
+
17
+ @Inject(Https.Server)
18
+ private httpsServer: Https.Server | null;
19
+
20
+ @Inject()
21
+ private injector: InjectorService;
22
+
23
+ async createWSServer(settings: GraphQLWSOptions) {
24
+ // @ts-ignore
25
+ const {WebSocketServer} = await import("ws");
26
+
27
+ const wsServer = new WebSocketServer({
28
+ ...(this.settings.wsServerOptions || {}),
29
+ ...settings.wsServerOptions,
30
+ server: this.httpsServer || this.httpServer!,
31
+ path: settings.path
32
+ });
33
+
34
+ return useServer(
35
+ {
36
+ ...(this.settings.wsUseServerOptions || {}),
37
+ ...settings.wsUseServerOptions,
38
+ schema: settings.schema
39
+ },
40
+ wsServer
41
+ );
42
+ }
43
+
44
+ async $alterApolloServerPlugins(plugins: any[], settings: GraphQLWSOptions) {
45
+ const wsServer = await this.createWSServer(settings);
46
+
47
+ this.injector.logger.info(`Create GraphQL WS server on: ${settings.path}`);
48
+
49
+ return plugins.concat({
50
+ serverWillStart() {
51
+ return {
52
+ async drainServer() {
53
+ await wsServer.dispose();
54
+ }
55
+ };
56
+ }
57
+ } as any);
58
+ }
59
+ }
@@ -0,0 +1,19 @@
1
+ // @ts-ignore
2
+ import {ServerOptions} from "graphql-ws/lib/server";
3
+ import {ServerOptions as WSServerOptions} from "ws";
4
+
5
+ export interface GraphQLWSOptions {
6
+ path: string;
7
+ schema: any;
8
+ wsUseServerOptions?: ServerOptions;
9
+ wsServerOptions?: WSServerOptions;
10
+ }
11
+
12
+ declare global {
13
+ namespace TsED {
14
+ interface ApolloSettings {
15
+ wsUseServerOptions?: ServerOptions;
16
+ wsServerOptions?: WSServerOptions;
17
+ }
18
+ }
19
+ }
package/src/index.ts ADDED
@@ -0,0 +1,5 @@
1
+ /**
2
+ * @file Automatically generated by @tsed/barrels.
3
+ */
4
+ export * from "./GraphQLWSModule.js";
5
+ export * from "./GraphQLWSOptions.js";