@tsed/graphql-ws 8.8.0-beta.1 → 8.8.0-beta.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.
@@ -1,18 +1,23 @@
1
- import { __decorate, __metadata } from "tslib";
1
+ import { __decorate } from "tslib";
2
2
  import Http from "node:http";
3
3
  import Https from "node:https";
4
- import { Constant, Inject, InjectorService, Module } from "@tsed/di";
5
- import { useServer } from "graphql-ws/lib/use/ws";
4
+ import { constant, inject, logger, Module } from "@tsed/di";
5
+ import { useServer } from "graphql-ws/use/ws";
6
+ import { WebSocketServer } from "ws";
6
7
  let GraphQLWSModule = class GraphQLWSModule {
8
+ constructor() {
9
+ this.settings = constant("graphqlWs", {});
10
+ this.httpServer = inject(Http.Server);
11
+ this.httpsServer = inject(Https.Server);
12
+ }
7
13
  async createWSServer(settings) {
8
- // @ts-ignore
9
- const { WebSocketServer } = await import("ws");
10
- const wsServer = new WebSocketServer({
14
+ const opts = {
11
15
  ...(this.settings.wsServerOptions || {}),
12
16
  ...settings.wsServerOptions,
13
17
  server: this.httpsServer || this.httpServer,
14
18
  path: settings.path
15
- });
19
+ };
20
+ const wsServer = new WebSocketServer(opts);
16
21
  return useServer({
17
22
  ...(this.settings.wsUseServerOptions || {}),
18
23
  ...settings.wsUseServerOptions,
@@ -21,7 +26,7 @@ let GraphQLWSModule = class GraphQLWSModule {
21
26
  }
22
27
  async $alterApolloServerPlugins(plugins, settings) {
23
28
  const wsServer = await this.createWSServer(settings);
24
- this.injector.logger.info(`Create GraphQL WS server on: ${settings.path}`);
29
+ logger().info(`Create GraphQL WS server on: ${settings.path}`);
25
30
  return plugins.concat({
26
31
  serverWillStart() {
27
32
  return {
@@ -33,22 +38,6 @@ let GraphQLWSModule = class GraphQLWSModule {
33
38
  });
34
39
  }
35
40
  };
36
- __decorate([
37
- Constant("graphqlWs", {}),
38
- __metadata("design:type", Object)
39
- ], GraphQLWSModule.prototype, "settings", void 0);
40
- __decorate([
41
- Inject(Http.Server),
42
- __metadata("design:type", Object)
43
- ], GraphQLWSModule.prototype, "httpServer", void 0);
44
- __decorate([
45
- Inject(Https.Server),
46
- __metadata("design:type", Object)
47
- ], GraphQLWSModule.prototype, "httpsServer", void 0);
48
- __decorate([
49
- Inject(),
50
- __metadata("design:type", InjectorService)
51
- ], GraphQLWSModule.prototype, "injector", void 0);
52
41
  GraphQLWSModule = __decorate([
53
42
  Module()
54
43
  ], GraphQLWSModule);
@@ -1 +1 @@
1
- {"version":3,"file":"GraphQLWSModule.js","sourceRoot":"","sources":["../../src/GraphQLWSModule.ts"],"names":[],"mappings":";AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,KAAK,MAAM,YAAY,CAAC;AAE/B,OAAO,EAAC,QAAQ,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EAAC,MAAM,UAAU,CAAC;AAEnE,OAAO,EAAC,SAAS,EAAC,MAAM,uBAAuB,CAAC;AAKzC,IAAM,eAAe,GAArB,MAAM,eAAe;IAa1B,KAAK,CAAC,cAAc,CAAC,QAA0B;QAC7C,aAAa;QACb,MAAM,EAAC,eAAe,EAAC,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,CAAC;QAE7C,MAAM,QAAQ,GAAG,IAAI,eAAe,CAAC;YACnC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,eAAe,IAAI,EAAE,CAAC;YACxC,GAAG,QAAQ,CAAC,eAAe;YAC3B,MAAM,EAAE,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,UAAW;YAC5C,IAAI,EAAE,QAAQ,CAAC,IAAI;SACpB,CAAC,CAAC;QAEH,OAAO,SAAS,CACd;YACE,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,kBAAkB,IAAI,EAAE,CAAC;YAC3C,GAAG,QAAQ,CAAC,kBAAkB;YAC9B,MAAM,EAAE,QAAQ,CAAC,MAAM;SACxB,EACD,QAAQ,CACT,CAAC;IACJ,CAAC;IAED,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,CAAsB,KAAK,CAAC,MAAM,CAAC,CAAC;IAqClE,CAAC;IAnCC,KAAK,CAAC,cAAc,CAAC,QAA0B;QAC7C,MAAM,IAAI,GAAG;YACX,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,eAAe,IAAI,EAAE,CAAC;YACxC,GAAG,QAAQ,CAAC,eAAe;YAC3B,MAAM,EAAE,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,UAAW;YAC5C,IAAI,EAAE,QAAQ,CAAC,IAAI;SACpB,CAAC;QAEF,MAAM,QAAQ,GAAG,IAAI,eAAe,CAAC,IAAI,CAAC,CAAC;QAE3C,OAAO,SAAS,CACd;YACE,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,kBAAkB,IAAI,EAAE,CAAC;YAC3C,GAAG,QAAQ,CAAC,kBAAkB;YAC9B,MAAM,EAAE,QAAQ,CAAC,MAAM;SACxB,EACD,QAAQ,CACT,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,yBAAyB,CAAC,OAAc,EAAE,QAA0B;QACxE,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;QAErD,MAAM,EAAE,CAAC,IAAI,CAAC,gCAAgC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC;QAE/D,OAAO,OAAO,CAAC,MAAM,CAAC;YACpB,eAAe;gBACb,OAAO;oBACL,KAAK,CAAC,WAAW;wBACf,MAAM,QAAQ,CAAC,OAAO,EAAE,CAAC;oBAC3B,CAAC;iBACF,CAAC;YACJ,CAAC;SACK,CAAC,CAAC;IACZ,CAAC;CACF,CAAA;AAxCY,eAAe;IAD3B,MAAM,EAAE;GACI,eAAe,CAwC3B"}
@@ -1,10 +1,8 @@
1
- import type { Disposable } from "graphql-ws";
2
1
  import { GraphQLWSOptions } from "./GraphQLWSOptions.js";
3
2
  export declare class GraphQLWSModule {
4
3
  private settings;
5
4
  private httpServer;
6
5
  private httpsServer;
7
- private injector;
8
- createWSServer(settings: GraphQLWSOptions): Promise<Disposable>;
6
+ createWSServer(settings: GraphQLWSOptions): Promise<import("graphql-ws").Disposable>;
9
7
  $alterApolloServerPlugins(plugins: any[], settings: GraphQLWSOptions): Promise<any[]>;
10
8
  }
@@ -1,15 +1,15 @@
1
- import { ServerOptions } from "graphql-ws/lib/server";
2
- import { ServerOptions as WSServerOptions } from "ws";
1
+ import type { ServerOptions as UseServerOptions } from "graphql-ws";
2
+ import type { ServerOptions as WSServerOptions } from "ws";
3
3
  export interface GraphQLWSOptions {
4
4
  path: string;
5
- schema: any;
6
- wsUseServerOptions?: ServerOptions;
5
+ schema: UseServerOptions["schema"];
6
+ wsUseServerOptions?: UseServerOptions;
7
7
  wsServerOptions?: WSServerOptions;
8
8
  }
9
9
  declare global {
10
10
  namespace TsED {
11
11
  interface ApolloSettings {
12
- wsUseServerOptions?: ServerOptions;
12
+ wsUseServerOptions?: UseServerOptions;
13
13
  wsServerOptions?: WSServerOptions;
14
14
  }
15
15
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
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.8.0-beta.1",
5
+ "version": "8.8.0-beta.2",
6
6
  "source": "./src/index.ts",
7
7
  "main": "./lib/esm/index.js",
8
8
  "module": "./lib/esm/index.js",
@@ -24,22 +24,25 @@
24
24
  "tslib": "2.7.0"
25
25
  },
26
26
  "devDependencies": {
27
- "@tsed/barrels": "8.8.0-beta.1",
28
- "@tsed/core": "8.8.0-beta.1",
29
- "@tsed/di": "8.8.0-beta.1",
27
+ "@tsed/barrels": "8.8.0-beta.2",
28
+ "@tsed/core": "8.8.0-beta.2",
29
+ "@tsed/di": "8.8.0-beta.2",
30
30
  "@tsed/logger": "^7.0.1",
31
- "@tsed/platform-http": "8.8.0-beta.1",
32
- "@tsed/typescript": "8.8.0-beta.1",
31
+ "@tsed/platform-http": "8.8.0-beta.2",
32
+ "@tsed/typescript": "8.8.0-beta.2",
33
+ "@types/ws": "8.18.1",
33
34
  "eslint": "9.12.0",
34
- "graphql-ws": "5.16.0",
35
- "typescript": "5.4.5"
35
+ "graphql-ws": "6.0.4",
36
+ "typescript": "5.4.5",
37
+ "ws": "8.18.1"
36
38
  },
37
39
  "peerDependencies": {
38
- "@tsed/core": ">=8.8.0-beta.1",
39
- "@tsed/di": ">=8.8.0-beta.1",
40
+ "@tsed/core": ">=8.8.0-beta.2",
41
+ "@tsed/di": ">=8.8.0-beta.2",
40
42
  "@tsed/logger": ">=7.0.1",
41
- "@tsed/platform-http": ">=8.8.0-beta.1",
42
- "graphql-ws": ">=5.14.2"
43
+ "@tsed/platform-http": ">=8.8.0-beta.2",
44
+ "graphql-ws": ">=6.0.4",
45
+ "ws": ">=8.18.1"
43
46
  },
44
47
  "repository": "https://github.com/tsedio/tsed",
45
48
  "bugs": {
package/readme.md CHANGED
@@ -37,7 +37,7 @@ You need to install `@tsed/apollo` before using this module.
37
37
  To begin, install the GraphQL WS module for TS.ED:
38
38
 
39
39
  ```bash
40
- npm install --save @tsed/graphql-ws graphql-ws
40
+ npm install --save @tsed/graphql-ws graphql-ws ws @types/ws
41
41
  ```
42
42
 
43
43
  Now, we can configure the Ts.ED server by importing `@tsed/gr` in your Server:
@@ -1,36 +1,27 @@
1
1
  import Http from "node:http";
2
2
  import Https from "node:https";
3
3
 
4
- import {Constant, Inject, InjectorService, Module} from "@tsed/di";
5
- import type {Disposable} from "graphql-ws";
6
- import {useServer} from "graphql-ws/lib/use/ws";
4
+ import {constant, inject, logger, Module} from "@tsed/di";
5
+ import {useServer} from "graphql-ws/use/ws";
6
+ import {WebSocketServer} from "ws";
7
7
 
8
8
  import {GraphQLWSOptions} from "./GraphQLWSOptions.js";
9
9
 
10
10
  @Module()
11
11
  export class GraphQLWSModule {
12
- @Constant("graphqlWs", {})
13
- private settings: GraphQLWSOptions;
14
-
15
- @Inject(Http.Server)
16
- private httpServer: Http.Server | null;
17
-
18
- @Inject(Https.Server)
19
- private httpsServer: Https.Server | null;
20
-
21
- @Inject()
22
- private injector: InjectorService;
12
+ private settings = constant<GraphQLWSOptions>("graphqlWs", {} as GraphQLWSOptions);
13
+ private httpServer = inject<Http.Server | null>(Http.Server);
14
+ private httpsServer = inject<Https.Server | null>(Https.Server);
23
15
 
24
16
  async createWSServer(settings: GraphQLWSOptions) {
25
- // @ts-ignore
26
- const {WebSocketServer} = await import("ws");
27
-
28
- const wsServer = new WebSocketServer({
17
+ const opts = {
29
18
  ...(this.settings.wsServerOptions || {}),
30
19
  ...settings.wsServerOptions,
31
20
  server: this.httpsServer || this.httpServer!,
32
21
  path: settings.path
33
- });
22
+ };
23
+
24
+ const wsServer = new WebSocketServer(opts);
34
25
 
35
26
  return useServer(
36
27
  {
@@ -45,7 +36,7 @@ export class GraphQLWSModule {
45
36
  async $alterApolloServerPlugins(plugins: any[], settings: GraphQLWSOptions) {
46
37
  const wsServer = await this.createWSServer(settings);
47
38
 
48
- this.injector.logger.info(`Create GraphQL WS server on: ${settings.path}`);
39
+ logger().info(`Create GraphQL WS server on: ${settings.path}`);
49
40
 
50
41
  return plugins.concat({
51
42
  serverWillStart() {
@@ -1,18 +1,17 @@
1
- // @ts-ignore
2
- import {ServerOptions} from "graphql-ws/lib/server";
3
- import {ServerOptions as WSServerOptions} from "ws";
1
+ import type {ServerOptions as UseServerOptions} from "graphql-ws";
2
+ import type {ServerOptions as WSServerOptions} from "ws";
4
3
 
5
4
  export interface GraphQLWSOptions {
6
5
  path: string;
7
- schema: any;
8
- wsUseServerOptions?: ServerOptions;
6
+ schema: UseServerOptions["schema"];
7
+ wsUseServerOptions?: UseServerOptions;
9
8
  wsServerOptions?: WSServerOptions;
10
9
  }
11
10
 
12
11
  declare global {
13
12
  namespace TsED {
14
13
  interface ApolloSettings {
15
- wsUseServerOptions?: ServerOptions;
14
+ wsUseServerOptions?: UseServerOptions;
16
15
  wsServerOptions?: WSServerOptions;
17
16
  }
18
17
  }