@tsed/apollo 8.15.4 → 8.16.0-rc.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,32 +1,29 @@
1
+ import { __decorate, __metadata } from "tslib";
1
2
  import Http from "node:http";
2
3
  import Https from "node:https";
3
4
  import { ApolloServer } from "@apollo/server";
4
5
  import { ApolloServerPluginLandingPageDisabled } from "@apollo/server/plugin/disabled";
5
6
  import { ApolloServerPluginDrainHttpServer } from "@apollo/server/plugin/drainHttpServer";
6
7
  import { ApolloServerPluginLandingPageLocalDefault } from "@apollo/server/plugin/landingPage/default";
7
- import { constant, context, inject, injectable, injector, LocalsContainer, logger } from "@tsed/di";
8
- import { $asyncAlter } from "@tsed/hooks";
8
+ import { Constant, context, Inject, InjectorService, LocalsContainer, Service } from "@tsed/di";
9
+ import { Logger } from "@tsed/logger";
9
10
  import { PlatformApplication } from "@tsed/platform-http";
10
11
  import { APOLLO_CONTEXT, DATASOURCES_PROVIDERS } from "../constants/constants.js";
11
- export class ApolloService {
12
+ let ApolloService = class ApolloService {
12
13
  constructor() {
13
- this.platformName = constant("PLATFORM_NAME");
14
14
  /**
15
15
  *
16
16
  * @type {Map<any, any>}
17
17
  * @private
18
18
  */
19
19
  this.servers = new Map();
20
- this.app = inject(PlatformApplication);
21
- this.httpServer = inject(Http.Server);
22
- this.httpsServer = inject(Https.Server);
23
20
  }
24
21
  async createServer(id, settings) {
25
22
  if (!this.has(id)) {
26
23
  try {
27
24
  const { dataSources, path, middlewareOptions = {}, server: customServer, ...config } = settings;
28
- logger().info(`Create server with Apollo for: ${id}`);
29
- logger().debug(`options: ${JSON.stringify({ path })}`);
25
+ this.logger.info(`Create server with Apollo for: ${id}`);
26
+ this.logger.debug(`options: ${JSON.stringify({ path })}`);
30
27
  const plugins = await this.getPlugins(settings);
31
28
  const server = this.createInstance({
32
29
  ...config,
@@ -57,7 +54,7 @@ export class ApolloService {
57
54
  }));
58
55
  break;
59
56
  default:
60
- logger().warn({
57
+ this.logger.warn({
61
58
  event: "APOLLO_UNKNOWN_PLATFORM",
62
59
  message: "Platform not supported. Please use Ts.ED platform (express, koa)"
63
60
  });
@@ -65,7 +62,7 @@ export class ApolloService {
65
62
  }
66
63
  }
67
64
  catch (er) {
68
- logger().error({
65
+ this.logger.error({
69
66
  event: "APOLLO_BOOTSTRAP_ERROR",
70
67
  error_name: er.name,
71
68
  message: er.message,
@@ -111,9 +108,8 @@ export class ApolloService {
111
108
  * create a new dataSources function to use with apollo server config
112
109
  */
113
110
  createContextHandler(server, settings) {
114
- const dataSourcesContainer = injector()
115
- .getProviders(DATASOURCES_PROVIDERS)
116
- .reduce((map, provider) => {
111
+ const { injector } = this;
112
+ const dataSourcesContainer = injector.getProviders(DATASOURCES_PROVIDERS).reduce((map, provider) => {
117
113
  let { name } = provider.store.get(DATASOURCES_PROVIDERS);
118
114
  name = name || provider.className;
119
115
  const sourceName = `${name[0].toLowerCase()}${name.slice(1)}`;
@@ -127,13 +123,13 @@ export class ApolloService {
127
123
  ...(settings.dataSources?.() || {})
128
124
  }
129
125
  };
130
- const alteredContext = await $asyncAlter("$alterApolloContext", apolloContext, [$ctx]);
126
+ const alteredContext = await this.injector.alterAsync("$alterApolloContext", apolloContext, $ctx);
131
127
  $ctx.set(APOLLO_CONTEXT, alteredContext);
132
128
  const locals = new LocalsContainer();
133
129
  locals.set(APOLLO_CONTEXT, alteredContext);
134
130
  locals.set(ApolloServer, server);
135
131
  dataSourcesContainer.forEach((provider, key) => {
136
- alteredContext.dataSources[key] = inject(provider.token, { locals });
132
+ alteredContext.dataSources[key] = injector.invoke(provider.token, { locals });
137
133
  });
138
134
  return alteredContext;
139
135
  };
@@ -143,7 +139,7 @@ export class ApolloService {
143
139
  }
144
140
  async getPlugins(serverSettings) {
145
141
  const playground = serverSettings.playground || (serverSettings.playground === undefined && process.env.NODE_ENV !== "production");
146
- const result = await $asyncAlter("$alterApolloServerPlugins", [
142
+ const result = await this.injector.alterAsync("$alterApolloServerPlugins", [
147
143
  this.httpServer &&
148
144
  ApolloServerPluginDrainHttpServer({
149
145
  httpServer: this.httpServer
@@ -153,10 +149,37 @@ export class ApolloService {
153
149
  httpServer: this.httpsServer
154
150
  }),
155
151
  ...(serverSettings.plugins || [])
156
- ].filter(Boolean), [serverSettings]);
152
+ ].filter(Boolean), serverSettings);
157
153
  return result
158
154
  .concat([playground ? ApolloServerPluginLandingPageLocalDefault({ embed: true }) : ApolloServerPluginLandingPageDisabled()])
159
155
  .filter(Boolean);
160
156
  }
161
- }
162
- injectable(ApolloService);
157
+ };
158
+ __decorate([
159
+ Constant("PLATFORM_NAME"),
160
+ __metadata("design:type", String)
161
+ ], ApolloService.prototype, "platformName", void 0);
162
+ __decorate([
163
+ Inject(),
164
+ __metadata("design:type", Logger)
165
+ ], ApolloService.prototype, "logger", void 0);
166
+ __decorate([
167
+ Inject(),
168
+ __metadata("design:type", PlatformApplication)
169
+ ], ApolloService.prototype, "app", void 0);
170
+ __decorate([
171
+ Inject(Http.Server),
172
+ __metadata("design:type", Object)
173
+ ], ApolloService.prototype, "httpServer", void 0);
174
+ __decorate([
175
+ Inject(Https.Server),
176
+ __metadata("design:type", Object)
177
+ ], ApolloService.prototype, "httpsServer", void 0);
178
+ __decorate([
179
+ Inject(),
180
+ __metadata("design:type", InjectorService)
181
+ ], ApolloService.prototype, "injector", void 0);
182
+ ApolloService = __decorate([
183
+ Service()
184
+ ], ApolloService);
185
+ export { ApolloService };
@@ -1,15 +1,12 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
- /// <reference types="node" resolution-mode="require"/>
3
- import Http from "node:http";
4
- import Https from "node:https";
5
1
  import { ApolloServer, ApolloServerOptions } from "@apollo/server";
6
2
  import type { IExecutableSchemaDefinition } from "@graphql-tools/schema";
7
- import { PlatformApplication } from "@tsed/platform-http";
3
+ import { Logger } from "@tsed/logger";
8
4
  import type { GraphQLSchema } from "graphql";
9
5
  import { ApolloContext } from "../interfaces/ApolloContext.js";
10
6
  import type { ApolloCustomServerCB, ApolloSettings } from "../interfaces/ApolloSettings.js";
11
7
  export declare class ApolloService {
12
- platformName: string | undefined;
8
+ platformName: string;
9
+ protected logger: Logger;
13
10
  /**
14
11
  *
15
12
  * @type {Map<any, any>}
@@ -21,9 +18,10 @@ export declare class ApolloService {
21
18
  typeDefs?: IExecutableSchemaDefinition<ApolloContext>["typeDefs"];
22
19
  resolvers?: IExecutableSchemaDefinition<ApolloContext>["resolvers"];
23
20
  }>;
24
- protected app: PlatformApplication<any>;
25
- protected httpServer: Http.Server<typeof Http.IncomingMessage, typeof Http.ServerResponse> | null;
26
- protected httpsServer: Https.Server<typeof Http.IncomingMessage, typeof Http.ServerResponse> | null;
21
+ private app;
22
+ private httpServer;
23
+ private httpsServer;
24
+ private injector;
27
25
  createServer(id: string, settings: ApolloSettings): Promise<ApolloServer<ApolloContext>>;
28
26
  /**
29
27
  * Get an instance of ApolloServer from his id
@@ -49,7 +47,7 @@ export declare class ApolloService {
49
47
  /**
50
48
  * create a new dataSources function to use with apollo server config
51
49
  */
52
- createContextHandler(server: ApolloServer<ApolloContext>, settings: ApolloSettings): () => Promise<ApolloContext>;
50
+ createContextHandler(server: ApolloServer<ApolloContext>, settings: ApolloSettings): () => Promise<any>;
53
51
  protected createInstance(options: ApolloServerOptions<ApolloContext>, server?: ApolloCustomServerCB<ApolloContext>): ApolloServer<ApolloContext>;
54
52
  private getPlugins;
55
53
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@tsed/apollo",
3
3
  "description": "Apollo package for Ts.ED framework",
4
4
  "type": "module",
5
- "version": "8.15.4",
5
+ "version": "8.16.0-rc.2",
6
6
  "source": "./src/index.ts",
7
7
  "main": "./lib/esm/index.js",
8
8
  "module": "./lib/esm/index.js",
@@ -29,12 +29,12 @@
29
29
  "@apollo/datasource-rest": "6.3.0",
30
30
  "@apollo/server": "^4.11.0",
31
31
  "@as-integrations/koa": "1.1.1",
32
- "@tsed/barrels": "8.15.4",
33
- "@tsed/core": "8.15.4",
34
- "@tsed/di": "8.15.4",
35
- "@tsed/logger": ">=7.0.1",
36
- "@tsed/platform-http": "8.15.4",
37
- "@tsed/typescript": "8.15.4",
32
+ "@tsed/barrels": "8.16.0-rc.2",
33
+ "@tsed/core": "8.16.0-rc.2",
34
+ "@tsed/di": "8.16.0-rc.2",
35
+ "@tsed/logger": "^8.0.0-rc.1",
36
+ "@tsed/platform-http": "8.16.0-rc.2",
37
+ "@tsed/typescript": "8.16.0-rc.2",
38
38
  "apollo-datasource-http": "0.21.0",
39
39
  "apollo-server-testing": "2.26.2",
40
40
  "eslint": "9.12.0",
@@ -46,7 +46,7 @@
46
46
  "@apollo/server": ">=4.10.4",
47
47
  "@tsed/core": ">=8.0.0",
48
48
  "@tsed/di": ">=8.0.0",
49
- "@tsed/logger": ">=7.0.1",
49
+ "@tsed/logger": ">=8.0.0-rc.1",
50
50
  "@tsed/platform-http": ">=8.0.0",
51
51
  "graphql": ">16.0.0"
52
52
  },
@@ -56,5 +56,8 @@
56
56
  },
57
57
  "homepage": "https://github.com/tsedio/tsed/tree/production/packages/graphql/apollo",
58
58
  "author": "Romain Lenzotti",
59
- "license": "MIT"
59
+ "license": "MIT",
60
+ "publishConfig": {
61
+ "tag": "rc"
62
+ }
60
63
  }