@tsed/apollo 7.83.3 → 8.0.0-alpha.10

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.
Files changed (55) hide show
  1. package/lib/esm/ApolloModule.js +13 -8
  2. package/lib/esm/ApolloModule.js.map +1 -1
  3. package/lib/esm/constants/constants.js +1 -0
  4. package/lib/esm/constants/constants.js.map +1 -1
  5. package/lib/esm/decorators/dataSource.js +2 -2
  6. package/lib/esm/decorators/dataSource.js.map +1 -1
  7. package/lib/esm/decorators/injectApolloContext.js +19 -0
  8. package/lib/esm/decorators/injectApolloContext.js.map +1 -0
  9. package/lib/esm/index.js +5 -0
  10. package/lib/esm/index.js.map +1 -1
  11. package/lib/esm/interfaces/AlterApolloContext.js +2 -0
  12. package/lib/esm/interfaces/AlterApolloContext.js.map +1 -0
  13. package/lib/esm/interfaces/AlterApolloServerPlugins.js +2 -0
  14. package/lib/esm/interfaces/AlterApolloServerPlugins.js.map +1 -0
  15. package/lib/esm/interfaces/AlterApolloSettings.js +2 -0
  16. package/lib/esm/interfaces/AlterApolloSettings.js.map +1 -0
  17. package/lib/esm/interfaces/ApolloContext.js +2 -0
  18. package/lib/esm/interfaces/ApolloContext.js.map +1 -0
  19. package/lib/esm/services/ApolloService.js +73 -53
  20. package/lib/esm/services/ApolloService.js.map +1 -1
  21. package/lib/types/ApolloModule.d.ts +3 -2
  22. package/lib/types/constants/constants.d.ts +1 -0
  23. package/lib/types/decorators/dataSource.d.ts +2 -2
  24. package/lib/types/decorators/injectApolloContext.d.ts +5 -0
  25. package/lib/types/index.d.ts +5 -0
  26. package/lib/types/interfaces/AlterApolloContext.d.ts +5 -0
  27. package/lib/types/interfaces/AlterApolloServerPlugins.d.ts +5 -0
  28. package/lib/types/interfaces/AlterApolloSettings.d.ts +7 -0
  29. package/lib/types/interfaces/ApolloContext.d.ts +4 -0
  30. package/lib/types/interfaces/ApolloSettings.d.ts +22 -10
  31. package/lib/types/services/ApolloService.d.ts +18 -14
  32. package/package.json +29 -31
  33. package/readme.md +1 -24
  34. package/vitest.config.mts +5 -5
  35. package/.nycrc +0 -26
  36. package/lib/cjs/ApolloModule.js +0 -52
  37. package/lib/cjs/ApolloModule.js.map +0 -1
  38. package/lib/cjs/constants/constants.js +0 -5
  39. package/lib/cjs/constants/constants.js.map +0 -1
  40. package/lib/cjs/decorators/dataSource.js +0 -69
  41. package/lib/cjs/decorators/dataSource.js.map +0 -1
  42. package/lib/cjs/index.js +0 -12
  43. package/lib/cjs/index.js.map +0 -1
  44. package/lib/cjs/interfaces/ApolloSettings.js +0 -3
  45. package/lib/cjs/interfaces/ApolloSettings.js.map +0 -1
  46. package/lib/cjs/package.json +0 -3
  47. package/lib/cjs/services/ApolloService.js +0 -169
  48. package/lib/cjs/services/ApolloService.js.map +0 -1
  49. package/lib/esm/package.json +0 -3
  50. package/lib/types-esm/ApolloModule.d.ts +0 -14
  51. package/lib/types-esm/constants/constants.d.ts +0 -1
  52. package/lib/types-esm/decorators/dataSource.d.ts +0 -56
  53. package/lib/types-esm/index.d.ts +0 -8
  54. package/lib/types-esm/interfaces/ApolloSettings.d.ts +0 -20
  55. package/lib/types-esm/services/ApolloService.d.ts +0 -49
@@ -1,25 +1,26 @@
1
1
  import { __decorate, __metadata } from "tslib";
2
2
  import { Logger } from "@tsed/common";
3
- import { Configuration, Inject, Module } from "@tsed/di";
3
+ import { Configuration, Inject, InjectorService, Module } from "@tsed/di";
4
4
  import { ApolloService } from "./services/ApolloService.js";
5
5
  let ApolloModule = class ApolloModule {
6
6
  get settings() {
7
- return this.configuration.get("apollo");
7
+ return this.configuration.get("apollo", this.configuration.get("graphql", this.configuration.get("typegraphql")));
8
8
  }
9
- $onRoutesInit() {
10
- const { settings } = this;
9
+ async $onRoutesInit() {
10
+ const { settings, injector } = this;
11
11
  if (settings) {
12
- const promises = Object.entries(settings).map(([key, options]) => {
13
- return this.service.createServer(key, options);
12
+ const promises = Object.entries(settings).map(async ([id, options]) => {
13
+ options = await injector.alterAsync("$alterApolloSettings", { id, ...options });
14
+ return this.service.createServer(id, options);
14
15
  });
15
- return Promise.all(promises);
16
+ await Promise.all(promises);
16
17
  }
17
18
  }
18
19
  $afterListen() {
19
20
  const host = this.configuration.getBestHost();
20
21
  const displayLog = (key, path) => {
21
22
  const url = typeof host.port === "number" ? `${host.protocol}://${host.address}:${host.port}` : "";
22
- this.logger.info(`[${key}] Apollo server is available on ${url}${path.replace(/^\//, "")}`);
23
+ this.logger.info(`[${key}] Apollo server is available on ${url}/${path.replace(/^\//, "")}`);
23
24
  };
24
25
  const { settings } = this;
25
26
  if (settings) {
@@ -42,6 +43,10 @@ __decorate([
42
43
  Configuration(),
43
44
  __metadata("design:type", Object)
44
45
  ], ApolloModule.prototype, "configuration", void 0);
46
+ __decorate([
47
+ Inject(InjectorService),
48
+ __metadata("design:type", InjectorService)
49
+ ], ApolloModule.prototype, "injector", void 0);
45
50
  ApolloModule = __decorate([
46
51
  Module()
47
52
  ], ApolloModule);
@@ -1 +1 @@
1
- {"version":3,"file":"ApolloModule.js","sourceRoot":"","sources":["../../src/ApolloModule.ts"],"names":[],"mappings":";AAAA,OAAO,EAAc,MAAM,EAAe,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAC,aAAa,EAAE,MAAM,EAAE,MAAM,EAAC,MAAM,UAAU,CAAC;AAEvD,OAAO,EAAC,aAAa,EAAC,MAAM,6BAA6B,CAAC;AAGnD,IAAM,YAAY,GAAlB,MAAM,YAAY;IAUvB,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC1C,CAAC;IAED,aAAa;QACX,MAAM,EAAC,QAAQ,EAAC,GAAG,IAAI,CAAC;QAExB,IAAI,QAAQ,EAAE;YACZ,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE,EAAE;g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G,IAAI,CAAC,QAAQ,MAAM,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YAEnG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,GAAG,mCAAmC,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC;QAC/F,CAAC,CAAC;QAEF,MAAM,EAAC,QAAQ,EAAC,GAAG,IAAI,CAAC;QAExB,IAAI,QAAQ,EAAE,CAAC;YACb,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE,EAAE;gBAC9C,MAAM,EAAC,IAAI,EAAC,GAAG,OAAO,CAAC;gBAEvB,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;YACxB,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF,CAAA;AAhDW;IADT,MAAM,EAAE;8BACS,MAAM;4CAAC;AAGf;IADT,MAAM,EAAE;8BACU,aAAa;6CAAC;AAGvB;IADT,aAAa,EAAE;;mDACuB;AAG7B;IADT,MAAM,CAAC,eAAe,CAAC;8BACJ,eAAe;8CAAC;AAXzB,YAAY;IADxB,MAAM,EAAE;GACI,YAAY,CAkDxB"}
@@ -1,2 +1,3 @@
1
1
  export const DATASOURCES_PROVIDERS = "graphql:datasources";
2
+ export const APOLLO_CONTEXT = Symbol.for("APOLLO_CONTEXT");
2
3
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/constants/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,qBAAqB,GAAG,qBAAqB,CAAC"}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/constants/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,qBAAqB,GAAG,qBAAqB,CAAC;AAC3D,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC"}
@@ -6,7 +6,7 @@ import { DATASOURCES_PROVIDERS } from "../constants/constants.js";
6
6
  *
7
7
  * ```typescript
8
8
  * import { DataSourceService } from "@tsed/graphql";
9
- * import { RESTDataSource } from 'apollo-datasource-rest';
9
+ * import { RESTDataSource } from '@apollo/datasource-rest';
10
10
  *
11
11
  * @DataSource()
12
12
  * export class MyDataSource extends RESTDataSource {
@@ -39,7 +39,7 @@ export function DataSource(name) {
39
39
  *
40
40
  * ```typescript
41
41
  * import { DataSourceService } from "@tsed/graphql";
42
- * import { RESTDataSource } from 'apollo-datasource-rest';
42
+ * import { RESTDataSource } from '@apollo/datasource-rest';
43
43
  *
44
44
  * @DataSource()
45
45
  * export class MyDataSource extends RESTDataSource {
@@ -1 +1 @@
1
- {"version":3,"file":"dataSource.js","sourceRoot":"","sources":["../../../src/decorators/dataSource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,aAAa,EAAC,MAAM,YAAY,CAAC;AACnD,OAAO,EAAC,UAAU,EAAE,aAAa,EAAC,MAAM,UAAU,CAAC;AACnD,OAAO,EAAC,qBAAqB,EAAC,MAAM,2BAA2B,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,UAAU,CAAC,IAAa;IACtC,OAAO,aAAa,CAClB,UAAU,CAAC;QACT,IAAI,EAAE,qBAAqB;QAC3B,KAAK,EAAE,aAAa,CAAC,QAAQ;KAC9B,CAAC,EACF,QAAQ,CAAC,qBAAqB,EAAE,EAAC,IAAI,EAAC,CAAC,CACxC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,UAAU,CAAC"}
1
+ {"version":3,"file":"dataSource.js","sourceRoot":"","sources":["../../../src/decorators/dataSource.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,QAAQ,EAAE,aAAa,EAAC,MAAM,YAAY,CAAC;AACnD,OAAO,EAAC,UAAU,EAAE,aAAa,EAAC,MAAM,UAAU,CAAC;AAEnD,OAAO,EAAC,qBAAqB,EAAC,MAAM,2BAA2B,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,UAAU,CAAC,IAAa;IACtC,OAAO,aAAa,CAClB,UAAU,CAAC;QACT,IAAI,EAAE,qBAAqB;QAC3B,KAAK,EAAE,aAAa,CAAC,QAAQ;KAC9B,CAAC,EACF,QAAQ,CAAC,qBAAqB,EAAE,EAAC,IAAI,EAAC,CAAC,CACxC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,UAAU,CAAC"}
@@ -0,0 +1,19 @@
1
+ import { decoratorTypeOf, DecoratorTypes } from "@tsed/core";
2
+ import { Inject, InjectContext } from "@tsed/di";
3
+ import { APOLLO_CONTEXT } from "../constants/constants.js";
4
+ /**
5
+ * Inject the Apollo context in the decorated property.
6
+ * @decorator
7
+ */
8
+ export function InjectApolloContext() {
9
+ return (...args) => {
10
+ switch (decoratorTypeOf(args)) {
11
+ case DecoratorTypes.PARAM_CTOR:
12
+ Inject(APOLLO_CONTEXT)(...args);
13
+ break;
14
+ case DecoratorTypes.PROP:
15
+ return InjectContext(($ctx) => $ctx.get(APOLLO_CONTEXT))(args[0], args[1]);
16
+ }
17
+ };
18
+ }
19
+ //# sourceMappingURL=injectApolloContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"injectApolloContext.js","sourceRoot":"","sources":["../../../src/decorators/injectApolloContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,eAAe,EAAE,cAAc,EAAC,MAAM,YAAY,CAAC;AAChF,OAAO,EAAC,MAAM,EAAE,aAAa,EAAC,MAAM,UAAU,CAAC;AAE/C,OAAO,EAAC,cAAc,EAAC,MAAM,2BAA2B,CAAC;AAEzD;;;GAGG;AACH,MAAM,UAAU,mBAAmB;IACjC,OAAO,CAAC,GAAG,IAAyB,EAAE,EAAE;QACtC,QAAQ,eAAe,CAAC,IAAI,CAAC,EAAE,CAAC;YAC9B,KAAK,cAAc,CAAC,UAAU;gBAC5B,MAAM,CAAC,cAAc,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;gBAChC,MAAM;YAER,KAAK,cAAc,CAAC,IAAI;gBACtB,OAAO,aAAa,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/E,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
package/lib/esm/index.js CHANGED
@@ -4,6 +4,11 @@
4
4
  export * from "./ApolloModule.js";
5
5
  export * from "./constants/constants.js";
6
6
  export * from "./decorators/dataSource.js";
7
+ export * from "./decorators/injectApolloContext.js";
8
+ export * from "./interfaces/AlterApolloContext.js";
9
+ export * from "./interfaces/AlterApolloServerPlugins.js";
10
+ export * from "./interfaces/AlterApolloSettings.js";
11
+ export * from "./interfaces/ApolloContext.js";
7
12
  export * from "./interfaces/ApolloSettings.js";
8
13
  export * from "./services/ApolloService.js";
9
14
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,6BAA6B,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,qCAAqC,CAAC;AACpD,cAAc,oCAAoC,CAAC;AACnD,cAAc,0CAA0C,CAAC;AACzD,cAAc,qCAAqC,CAAC;AACpD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,6BAA6B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=AlterApolloContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AlterApolloContext.js","sourceRoot":"","sources":["../../../src/interfaces/AlterApolloContext.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=AlterApolloServerPlugins.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AlterApolloServerPlugins.js","sourceRoot":"","sources":["../../../src/interfaces/AlterApolloServerPlugins.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=AlterApolloSettings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AlterApolloSettings.js","sourceRoot":"","sources":["../../../src/interfaces/AlterApolloSettings.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ApolloContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApolloContext.js","sourceRoot":"","sources":["../../../src/interfaces/ApolloContext.ts"],"names":[],"mappings":""}
@@ -1,15 +1,16 @@
1
- import { __decorate, __metadata, __param } from "tslib";
2
- import { InjectorService, PlatformApplication } from "@tsed/common";
3
- import { classOf, nameOf, Store } from "@tsed/core";
1
+ import { __decorate, __metadata } from "tslib";
2
+ import { ApolloServer } from "@apollo/server";
3
+ import { ApolloServerPluginLandingPageDisabled } from "@apollo/server/plugin/disabled";
4
+ import { ApolloServerPluginDrainHttpServer } from "@apollo/server/plugin/drainHttpServer";
5
+ import { ApolloServerPluginLandingPageLocalDefault } from "@apollo/server/plugin/landingPage/default";
6
+ import { InjectorService, LocalsContainer, PlatformApplication, useContext } from "@tsed/common";
4
7
  import { Constant, Inject, Service } from "@tsed/di";
5
8
  import { Logger } from "@tsed/logger";
6
- import { ApolloServerPluginDrainHttpServer, ApolloServerPluginLandingPageDisabled, ApolloServerPluginLandingPageLocalDefault } from "apollo-server-core";
7
9
  import Http from "http";
8
10
  import Https from "https";
9
- import { DATASOURCES_PROVIDERS } from "../constants/constants.js";
11
+ import { APOLLO_CONTEXT, DATASOURCES_PROVIDERS } from "../constants/constants.js";
10
12
  let ApolloService = class ApolloService {
11
- constructor(dataSources) {
12
- this.dataSources = dataSources;
13
+ constructor() {
13
14
  /**
14
15
  *
15
16
  * @type {Map<any, any>}
@@ -24,22 +25,40 @@ let ApolloService = class ApolloService {
24
25
  this.logger.info(`Create server with Apollo for: ${id}`);
25
26
  this.logger.debug(`options: ${JSON.stringify({ path })}`);
26
27
  const plugins = await this.getPlugins(settings);
27
- const server = await this.createInstance({
28
+ const server = this.createInstance({
28
29
  ...config,
29
- plugins,
30
- dataSources: this.createDataSources(dataSources)
30
+ plugins
31
31
  }, customServer);
32
32
  if (server) {
33
33
  this.servers.set(id || "default", {
34
34
  instance: server,
35
- schema: settings.schema
35
+ schema: settings.schema,
36
+ typeDefs: settings.typeDefs,
37
+ resolvers: settings.resolvers
36
38
  });
37
39
  await server.start();
38
- const middleware = server.getMiddleware({
39
- path: settings.path,
40
- ...middlewareOptions
41
- });
42
- this.app.use(middleware);
40
+ const contextHandler = this.createContextHandler(server, settings);
41
+ switch (this.platformName) {
42
+ case "express":
43
+ const { expressMiddleware } = await import("@apollo/server/express4");
44
+ this.app.use(path, expressMiddleware(server, {
45
+ ...middlewareOptions,
46
+ context: contextHandler
47
+ }));
48
+ break;
49
+ case "koa":
50
+ const { koaMiddleware } = await import("@as-integrations/koa");
51
+ this.app.use(path, koaMiddleware(server, {
52
+ ...middlewareOptions,
53
+ context: contextHandler
54
+ }));
55
+ break;
56
+ default:
57
+ this.logger.warn({
58
+ event: "APOLLO_UNKNOWN_PLATFORM",
59
+ message: "Platform not supported. Please use Ts.ED platform (express, koa)"
60
+ });
61
+ }
43
62
  }
44
63
  }
45
64
  catch (er) {
@@ -49,8 +68,7 @@ let ApolloService = class ApolloService {
49
68
  message: er.message,
50
69
  stack: er.stack
51
70
  });
52
- /* istanbul ignore next */
53
- process.exit(-1);
71
+ throw er;
54
72
  }
55
73
  }
56
74
  return this.get(id);
@@ -63,12 +81,21 @@ let ApolloService = class ApolloService {
63
81
  return this.servers.get(id)?.instance;
64
82
  }
65
83
  /**
66
- * Get an instance of GraphQL schema from his id
84
+ * Get schema of the ApolloServer from his id
67
85
  * @returns GraphQLSchema
68
86
  */
69
87
  getSchema(id = "default") {
70
88
  return this.servers.get(id)?.schema;
71
89
  }
90
+ /**
91
+ * Get TypeDefs of the ApolloServer from his id
92
+ */
93
+ getTypeDefs(id = "default") {
94
+ return this.servers.get(id)?.typeDefs;
95
+ }
96
+ getResolvers(id = "default") {
97
+ return this.servers.get(id)?.resolvers;
98
+ }
72
99
  /**
73
100
  *
74
101
  * @param {string} id
@@ -77,47 +104,42 @@ let ApolloService = class ApolloService {
77
104
  has(id = "default") {
78
105
  return this.servers.has(id);
79
106
  }
80
- async createInstance(options, server) {
81
- if (server) {
82
- return server(options);
83
- }
84
- const importServer = async () => {
85
- switch (this.platformName) {
86
- default:
87
- this.logger.error(`Platform "${this.platformName}" not supported by @tsed/apollo`);
88
- case "express":
89
- return (await import("apollo-server-express")).ApolloServer;
90
- case "koa":
91
- return (await import("apollo-server-koa")).ApolloServer;
92
- }
93
- };
94
- const Server = await importServer();
95
- return new Server(options);
96
- }
97
107
  /**
98
108
  * create a new dataSources function to use with apollo server config
99
- * @param dataSources
100
109
  */
101
- createDataSources(dataSources) {
102
- const dataSourcesHash = this.dataSources.reduce((map, instance) => {
103
- const klass = classOf(instance);
104
- const store = Store.from(klass);
105
- let { name } = store.get(DATASOURCES_PROVIDERS);
106
- name = name || nameOf(klass);
110
+ createContextHandler(server, settings) {
111
+ const { injector } = this;
112
+ const dataSourcesContainer = injector.getProviders(DATASOURCES_PROVIDERS).reduce((map, provider) => {
113
+ let { name } = provider.store.get(DATASOURCES_PROVIDERS);
114
+ name = name || provider.className;
107
115
  const sourceName = `${name[0].toLowerCase()}${name.slice(1)}`;
108
- map[sourceName] = instance;
116
+ map.set(sourceName, provider);
109
117
  return map;
110
- }, {});
111
- return () => {
112
- return {
113
- ...dataSourcesHash,
114
- ...(dataSources ? dataSources() : {})
118
+ }, new Map());
119
+ return async () => {
120
+ const $ctx = useContext();
121
+ const context = {
122
+ dataSources: {
123
+ ...(settings.dataSources?.() || {})
124
+ }
115
125
  };
126
+ const alteredContext = await this.injector.alterAsync("$alterApolloContext", context, $ctx);
127
+ $ctx.set(APOLLO_CONTEXT, alteredContext);
128
+ const locals = new LocalsContainer();
129
+ locals.set(APOLLO_CONTEXT, alteredContext);
130
+ locals.set(ApolloServer, server);
131
+ dataSourcesContainer.forEach((provider, key) => {
132
+ alteredContext.dataSources[key] = injector.invoke(provider.token, locals);
133
+ });
134
+ return alteredContext;
116
135
  };
117
136
  }
137
+ createInstance(options, server) {
138
+ return server ? server(options) : new ApolloServer(options);
139
+ }
118
140
  async getPlugins(serverSettings) {
119
141
  const playground = serverSettings.playground || (serverSettings.playground === undefined && process.env.NODE_ENV !== "production");
120
- const result = await this.injector.alter("$alterApolloServerPlugins", [
142
+ const result = await this.injector.alterAsync("$alterApolloServerPlugins", [
121
143
  this.httpServer &&
122
144
  ApolloServerPluginDrainHttpServer({
123
145
  httpServer: this.httpServer
@@ -158,9 +180,7 @@ __decorate([
158
180
  __metadata("design:type", InjectorService)
159
181
  ], ApolloService.prototype, "injector", void 0);
160
182
  ApolloService = __decorate([
161
- Service(),
162
- __param(0, Inject(DATASOURCES_PROVIDERS)),
163
- __metadata("design:paramtypes", [Array])
183
+ Service()
164
184
  ], ApolloService);
165
185
  export { ApolloService };
166
186
  //# sourceMappingURL=ApolloService.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,CAAC;aACzH,MAAM,CAAC,OAAO,CAAC,CAAC;IACrB,CAAC;CACF,CAAA;AAlNC;IADC,QAAQ,CAAC,eAAe,CAAC;;mDACL;AAGX;IADT,MAAM,EAAE;8BACS,MAAM;6CAAC;AAkBjB;IADP,MAAM,EAAE;8BACI,mBAAmB;0CAAM;AAG9B;IADP,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;;iDACmB;AAG/B;IADP,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC;;kDACoB;AAGjC;IADP,MAAM,EAAE;8BACS,eAAe;+CAAC;AAhCvB,aAAa;IADzB,OAAO,EAAE;GACG,aAAa,CAoNzB"}
@@ -1,14 +1,15 @@
1
1
  import { AfterListen, Logger, OnRoutesInit } from "@tsed/common";
2
- import { Configuration } from "@tsed/di";
2
+ import { Configuration, InjectorService } from "@tsed/di";
3
3
  import { ApolloSettings } from "./interfaces/ApolloSettings.js";
4
4
  import { ApolloService } from "./services/ApolloService.js";
5
5
  export declare class ApolloModule implements OnRoutesInit, AfterListen {
6
6
  protected logger: Logger;
7
7
  protected service: ApolloService;
8
8
  protected configuration: Configuration;
9
+ protected injector: InjectorService;
9
10
  get settings(): {
10
11
  [key: string]: ApolloSettings;
11
12
  } | undefined;
12
- $onRoutesInit(): Promise<any> | void;
13
+ $onRoutesInit(): Promise<void>;
13
14
  $afterListen(): Promise<any> | void;
14
15
  }
@@ -1 +1,2 @@
1
1
  export declare const DATASOURCES_PROVIDERS = "graphql:datasources";
2
+ export declare const APOLLO_CONTEXT: unique symbol;
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * ```typescript
5
5
  * import { DataSourceService } from "@tsed/graphql";
6
- * import { RESTDataSource } from 'apollo-datasource-rest';
6
+ * import { RESTDataSource } from '@apollo/datasource-rest';
7
7
  *
8
8
  * @DataSource()
9
9
  * export class MyDataSource extends RESTDataSource {
@@ -31,7 +31,7 @@ export declare function DataSource(name?: string): ClassDecorator;
31
31
  *
32
32
  * ```typescript
33
33
  * import { DataSourceService } from "@tsed/graphql";
34
- * import { RESTDataSource } from 'apollo-datasource-rest';
34
+ * import { RESTDataSource } from '@apollo/datasource-rest';
35
35
  *
36
36
  * @DataSource()
37
37
  * export class MyDataSource extends RESTDataSource {
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Inject the Apollo context in the decorated property.
3
+ * @decorator
4
+ */
5
+ export declare function InjectApolloContext(): any;
@@ -4,5 +4,10 @@
4
4
  export * from "./ApolloModule.js";
5
5
  export * from "./constants/constants.js";
6
6
  export * from "./decorators/dataSource.js";
7
+ export * from "./decorators/injectApolloContext.js";
8
+ export * from "./interfaces/AlterApolloContext.js";
9
+ export * from "./interfaces/AlterApolloServerPlugins.js";
10
+ export * from "./interfaces/AlterApolloSettings.js";
11
+ export * from "./interfaces/ApolloContext.js";
7
12
  export * from "./interfaces/ApolloSettings.js";
8
13
  export * from "./services/ApolloService.js";
@@ -0,0 +1,5 @@
1
+ import type { PlatformContext } from "@tsed/common";
2
+ import type { ApolloContext } from "./ApolloContext.js";
3
+ export interface AlterApolloContext<Context extends ApolloContext = ApolloContext> {
4
+ $alterApolloContext(context: Context, $ctx: PlatformContext): Context | Promise<Context>;
5
+ }
@@ -0,0 +1,5 @@
1
+ import type { ApolloServerPlugin } from "@apollo/server";
2
+ import type { ApolloSettings } from "./ApolloSettings.js";
3
+ export interface AlterApolloServerPlugins {
4
+ $alterApolloServerPlugins(plugins: ApolloServerPlugin[], serverSettings: ApolloSettings): ApolloServerPlugin[] | Promise<ApolloServerPlugin[]>;
5
+ }
@@ -0,0 +1,7 @@
1
+ import type { ApolloContext } from "./ApolloContext.js";
2
+ import type { ApolloSettingsWithID } from "./ApolloSettings.js";
3
+ export interface AlterApolloSettings<Context extends ApolloContext = ApolloContext> {
4
+ $alterApolloSettings(settings: ApolloSettingsWithID<Context>): (ApolloSettingsWithID<Context> & {
5
+ id: string;
6
+ }) | Promise<ApolloSettingsWithID<Context>>;
7
+ }
@@ -0,0 +1,4 @@
1
+ import type { BaseContext } from "@apollo/server";
2
+ export interface ApolloContext extends BaseContext {
3
+ dataSources: Record<string, unknown>;
4
+ }
@@ -1,20 +1,32 @@
1
- import type { ApolloServerBase, ApolloServerPluginLandingPageGraphQLPlaygroundOptions, Config } from "apollo-server-core";
1
+ import type { ApolloServer, ApolloServerOptions, ApolloServerOptionsWithSchema } from "@apollo/server";
2
+ import type { GatewayInterface } from "@apollo/server-gateway-interface";
3
+ import type { IExecutableSchemaDefinition } from "@graphql-tools/schema";
4
+ import type { GraphQLSchema } from "graphql/index.js";
5
+ import type { ApolloContext } from "./ApolloContext.js";
2
6
  export type ApolloMiddlewareOptions = Record<string, any>;
3
- export type ApolloServer = ApolloServerBase & {
4
- getMiddleware(settings: ApolloMiddlewareOptions): any;
5
- };
6
- export type ApolloCustomServerCB = (config: ApolloConfig) => ApolloServer;
7
- export type ApolloConfig = Config;
7
+ export type ApolloCustomServerCB<TContext extends ApolloContext> = (config: ApolloServerOptions<TContext>) => ApolloServer<TContext>;
8
8
  declare global {
9
9
  namespace TsED {
10
10
  interface ApolloSettings {
11
11
  }
12
12
  }
13
13
  }
14
- export interface ApolloSettings extends ApolloConfig, TsED.ApolloSettings {
14
+ export type ApolloServerOptionsBase<TContext extends ApolloContext = ApolloContext> = Omit<ApolloServerOptionsWithSchema<TContext>, "schema" | "typeDefs" | "resolvers" | "gateway">;
15
+ export type ApolloSettings<TContext extends ApolloContext = ApolloContext> = ApolloServerOptionsBase<TContext> & TsED.ApolloSettings & {
15
16
  path: string;
16
- server?: ApolloCustomServerCB;
17
- playground?: boolean | ApolloServerPluginLandingPageGraphQLPlaygroundOptions;
17
+ server?: ApolloCustomServerCB<TContext>;
18
+ playground?: boolean;
18
19
  serverRegistration?: ApolloMiddlewareOptions;
19
20
  middlewareOptions?: ApolloMiddlewareOptions;
20
- }
21
+ schema?: GraphQLSchema;
22
+ typeDefs?: IExecutableSchemaDefinition<TContext>["typeDefs"];
23
+ resolvers?: IExecutableSchemaDefinition<TContext>["resolvers"];
24
+ gateway?: GatewayInterface;
25
+ /**
26
+ * @deprecated use $alterApolloContext instead
27
+ */
28
+ dataSources?: () => Record<string, unknown>;
29
+ };
30
+ export type ApolloSettingsWithID<TContext extends ApolloContext = ApolloContext> = ApolloSettings<TContext> & {
31
+ id: string;
32
+ };
@@ -1,11 +1,10 @@
1
+ import { ApolloServer, ApolloServerOptions } from "@apollo/server";
2
+ import type { IExecutableSchemaDefinition } from "@graphql-tools/schema";
1
3
  import { Logger } from "@tsed/logger";
2
- import type { Config } from "apollo-server-core";
3
- import { ApolloServerBase } from "apollo-server-core";
4
4
  import type { GraphQLSchema } from "graphql";
5
- import type { ApolloServer, ApolloSettings } from "../interfaces/ApolloSettings.js";
6
- import { ApolloCustomServerCB } from "../interfaces/ApolloSettings.js";
5
+ import { ApolloContext } from "../interfaces/ApolloContext.js";
6
+ import type { ApolloCustomServerCB, ApolloSettings } from "../interfaces/ApolloSettings.js";
7
7
  export declare class ApolloService {
8
- protected dataSources: any[];
9
8
  platformName: string;
10
9
  protected logger: Logger;
11
10
  /**
@@ -14,36 +13,41 @@ export declare class ApolloService {
14
13
  * @private
15
14
  */
16
15
  protected servers: Map<string, {
17
- instance: ApolloServerBase;
18
- schema: GraphQLSchema | undefined;
16
+ instance: ApolloServer<ApolloContext>;
17
+ schema?: GraphQLSchema;
18
+ typeDefs?: IExecutableSchemaDefinition<ApolloContext>["typeDefs"];
19
+ resolvers?: IExecutableSchemaDefinition<ApolloContext>["resolvers"];
19
20
  }>;
20
21
  private app;
21
22
  private httpServer;
22
23
  private httpsServer;
23
24
  private injector;
24
- constructor(dataSources: any[]);
25
- createServer(id: string, settings: ApolloSettings): Promise<ApolloServer>;
25
+ createServer(id: string, settings: ApolloSettings): Promise<ApolloServer<ApolloContext>>;
26
26
  /**
27
27
  * Get an instance of ApolloServer from his id
28
28
  * @returns ApolloServer
29
29
  */
30
- get(id?: string): ApolloServerBase | undefined;
30
+ get(id?: string): ApolloServer<ApolloContext> | undefined;
31
31
  /**
32
- * Get an instance of GraphQL schema from his id
32
+ * Get schema of the ApolloServer from his id
33
33
  * @returns GraphQLSchema
34
34
  */
35
35
  getSchema(id?: string): GraphQLSchema | undefined;
36
+ /**
37
+ * Get TypeDefs of the ApolloServer from his id
38
+ */
39
+ getTypeDefs(id?: string): import("@graphql-tools/utils").TypeSource | undefined;
40
+ getResolvers(id?: string): import("@graphql-tools/utils").IResolvers<any, ApolloContext> | import("@graphql-tools/utils").IResolvers<any, ApolloContext>[] | undefined;
36
41
  /**
37
42
  *
38
43
  * @param {string} id
39
44
  * @returns {boolean}
40
45
  */
41
46
  has(id?: string): boolean;
42
- protected createInstance(options: Config, server?: ApolloCustomServerCB): Promise<ApolloServer | undefined>;
43
47
  /**
44
48
  * create a new dataSources function to use with apollo server config
45
- * @param dataSources
46
49
  */
47
- protected createDataSources(dataSources: Function | undefined): () => any;
50
+ createContextHandler(server: ApolloServer<ApolloContext>, settings: ApolloSettings): () => Promise<any>;
51
+ protected createInstance(options: ApolloServerOptions<ApolloContext>, server?: ApolloCustomServerCB<ApolloContext>): ApolloServer<ApolloContext>;
48
52
  private getPlugins;
49
53
  }