@tsed/apollo 8.0.0-alpha.3 → 8.0.0-alpha.5

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 (64) hide show
  1. package/lib/cjs/ApolloModule.js +12 -7
  2. package/lib/cjs/ApolloModule.js.map +1 -1
  3. package/lib/cjs/constants/constants.js +2 -1
  4. package/lib/cjs/constants/constants.js.map +1 -1
  5. package/lib/cjs/decorators/dataSource.js +2 -2
  6. package/lib/cjs/decorators/injectApolloContext.js +23 -0
  7. package/lib/cjs/decorators/injectApolloContext.js.map +1 -0
  8. package/lib/cjs/index.js +5 -0
  9. package/lib/cjs/index.js.map +1 -1
  10. package/lib/cjs/interfaces/AlterApolloContext.js +3 -0
  11. package/lib/cjs/interfaces/AlterApolloContext.js.map +1 -0
  12. package/lib/cjs/interfaces/AlterApolloServerPlugins.js +3 -0
  13. package/lib/cjs/interfaces/AlterApolloServerPlugins.js.map +1 -0
  14. package/lib/cjs/interfaces/AlterApolloSettings.js +3 -0
  15. package/lib/cjs/interfaces/AlterApolloSettings.js.map +1 -0
  16. package/lib/cjs/interfaces/ApolloContext.js +3 -0
  17. package/lib/cjs/interfaces/ApolloContext.js.map +1 -0
  18. package/lib/cjs/services/ApolloService.js +73 -53
  19. package/lib/cjs/services/ApolloService.js.map +1 -1
  20. package/lib/esm/ApolloModule.js +13 -8
  21. package/lib/esm/ApolloModule.js.map +1 -1
  22. package/lib/esm/constants/constants.js +1 -0
  23. package/lib/esm/constants/constants.js.map +1 -1
  24. package/lib/esm/decorators/dataSource.js +2 -2
  25. package/lib/esm/decorators/injectApolloContext.js +19 -0
  26. package/lib/esm/decorators/injectApolloContext.js.map +1 -0
  27. package/lib/esm/index.js +5 -0
  28. package/lib/esm/index.js.map +1 -1
  29. package/lib/esm/interfaces/AlterApolloContext.js +2 -0
  30. package/lib/esm/interfaces/AlterApolloContext.js.map +1 -0
  31. package/lib/esm/interfaces/AlterApolloServerPlugins.js +2 -0
  32. package/lib/esm/interfaces/AlterApolloServerPlugins.js.map +1 -0
  33. package/lib/esm/interfaces/AlterApolloSettings.js +2 -0
  34. package/lib/esm/interfaces/AlterApolloSettings.js.map +1 -0
  35. package/lib/esm/interfaces/ApolloContext.js +2 -0
  36. package/lib/esm/interfaces/ApolloContext.js.map +1 -0
  37. package/lib/esm/services/ApolloService.js +73 -53
  38. package/lib/esm/services/ApolloService.js.map +1 -1
  39. package/lib/types/ApolloModule.d.ts +3 -2
  40. package/lib/types/constants/constants.d.ts +1 -0
  41. package/lib/types/decorators/dataSource.d.ts +2 -2
  42. package/lib/types/decorators/injectApolloContext.d.ts +5 -0
  43. package/lib/types/index.d.ts +5 -0
  44. package/lib/types/interfaces/AlterApolloContext.d.ts +5 -0
  45. package/lib/types/interfaces/AlterApolloServerPlugins.d.ts +5 -0
  46. package/lib/types/interfaces/AlterApolloSettings.d.ts +7 -0
  47. package/lib/types/interfaces/ApolloContext.d.ts +4 -0
  48. package/lib/types/interfaces/ApolloSettings.d.ts +22 -10
  49. package/lib/types/services/ApolloService.d.ts +18 -14
  50. package/lib/types-esm/ApolloModule.d.ts +3 -2
  51. package/lib/types-esm/constants/constants.d.ts +1 -0
  52. package/lib/types-esm/decorators/dataSource.d.ts +2 -2
  53. package/lib/types-esm/decorators/injectApolloContext.d.ts +5 -0
  54. package/lib/types-esm/index.d.ts +5 -0
  55. package/lib/types-esm/interfaces/AlterApolloContext.d.ts +5 -0
  56. package/lib/types-esm/interfaces/AlterApolloServerPlugins.d.ts +5 -0
  57. package/lib/types-esm/interfaces/AlterApolloSettings.d.ts +7 -0
  58. package/lib/types-esm/interfaces/ApolloContext.d.ts +4 -0
  59. package/lib/types-esm/interfaces/ApolloSettings.d.ts +22 -10
  60. package/lib/types-esm/services/ApolloService.d.ts +18 -14
  61. package/package.json +17 -21
  62. package/readme.md +1 -24
  63. package/vitest.config.mts +4 -4
  64. package/.nycrc +0 -26
@@ -7,22 +7,23 @@ const di_1 = require("@tsed/di");
7
7
  const ApolloService_js_1 = require("./services/ApolloService.js");
8
8
  let ApolloModule = class ApolloModule {
9
9
  get settings() {
10
- return this.configuration.get("apollo");
10
+ return this.configuration.get("apollo", this.configuration.get("graphql", this.configuration.get("typegraphql")));
11
11
  }
12
- $onRoutesInit() {
13
- const { settings } = this;
12
+ async $onRoutesInit() {
13
+ const { settings, injector } = this;
14
14
  if (settings) {
15
- const promises = Object.entries(settings).map(([key, options]) => {
16
- return this.service.createServer(key, options);
15
+ const promises = Object.entries(settings).map(async ([id, options]) => {
16
+ options = await injector.alterAsync("$alterApolloSettings", { id, ...options });
17
+ return this.service.createServer(id, options);
17
18
  });
18
- return Promise.all(promises);
19
+ await Promise.all(promises);
19
20
  }
20
21
  }
21
22
  $afterListen() {
22
23
  const host = this.configuration.getBestHost();
23
24
  const displayLog = (key, path) => {
24
25
  const url = typeof host.port === "number" ? `${host.protocol}://${host.address}:${host.port}` : "";
25
- this.logger.info(`[${key}] Apollo server is available on ${url}${path.replace(/^\//, "")}`);
26
+ this.logger.info(`[${key}] Apollo server is available on ${url}/${path.replace(/^\//, "")}`);
26
27
  };
27
28
  const { settings } = this;
28
29
  if (settings) {
@@ -45,6 +46,10 @@ tslib_1.__decorate([
45
46
  (0, di_1.Configuration)(),
46
47
  tslib_1.__metadata("design:type", Object)
47
48
  ], ApolloModule.prototype, "configuration", void 0);
49
+ tslib_1.__decorate([
50
+ (0, di_1.Inject)(di_1.InjectorService),
51
+ tslib_1.__metadata("design:type", di_1.InjectorService)
52
+ ], ApolloModule.prototype, "injector", void 0);
48
53
  ApolloModule = tslib_1.__decorate([
49
54
  (0, di_1.Module)()
50
55
  ], ApolloModule);
@@ -1 +1 @@
1
- {"version":3,"file":"ApolloModule.js","sourceRoot":"","sources":["../../src/ApolloModule.ts"],"names":[],"mappings":";;;;AAAA,yCAA+D;AAC/D,iCAAuD;AAEvD,kEAA0D;AAGnD,IAAM,YAAY,GAAlB,MAAM,YAAY;IAUvB,IAAI,QAAQ;QACV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CAAC,WAAW,EAAE,CAAC;QAE9C,MAAM,UAAU,GAAG,CAAC,GAAW,EAAE,IAAY,EAAE,EAAE;YAC/C,MAAM,GAAG,GAAG,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,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;YACZ,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;SACJ;IACH,CAAC;CACF,CAAA;AAjDC;IAAC,IAAA,WAAM,GAAE;sCACS,eAAM;4CAAC;AAEzB;IAAC,IAAA,WAAM,GAAE;sCACU,gCAAa;6CAAC;AAEjC;IAAC,IAAA,kBAAa,GAAE;;mDACuB;AAEvC;IAAC,IAAA,WAAM,EAAC,oBAAe,CAAC;sCACJ,oBAAe;8CAAC;AAXzB,YAAY;IADxB,IAAA,WAAM,GAAE;GACI,YAAY,CAkDxB;AAlDY,oCAAY"}
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DATASOURCES_PROVIDERS = void 0;
3
+ exports.APOLLO_CONTEXT = exports.DATASOURCES_PROVIDERS = void 0;
4
4
  exports.DATASOURCES_PROVIDERS = "graphql:datasources";
5
+ exports.APOLLO_CONTEXT = Symbol.for("APOLLO_CONTEXT");
5
6
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/constants/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,qBAAqB,GAAG,qBAAqB,CAAC"}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/constants/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,qBAAqB,GAAG,qBAAqB,CAAC;AAC9C,QAAA,cAAc,GAAG,MAAM,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC"}
@@ -9,7 +9,7 @@ const constants_js_1 = require("../constants/constants.js");
9
9
  *
10
10
  * ```typescript
11
11
  * import { DataSourceService } from "@tsed/graphql";
12
- * import { RESTDataSource } from 'apollo-datasource-rest';
12
+ * import { RESTDataSource } from '@apollo/datasource-rest';
13
13
  *
14
14
  * @DataSource()
15
15
  * export class MyDataSource extends RESTDataSource {
@@ -43,7 +43,7 @@ exports.DataSource = DataSource;
43
43
  *
44
44
  * ```typescript
45
45
  * import { DataSourceService } from "@tsed/graphql";
46
- * import { RESTDataSource } from 'apollo-datasource-rest';
46
+ * import { RESTDataSource } from '@apollo/datasource-rest';
47
47
  *
48
48
  * @DataSource()
49
49
  * export class MyDataSource extends RESTDataSource {
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.InjectApolloContext = void 0;
4
+ const core_1 = require("@tsed/core");
5
+ const di_1 = require("@tsed/di");
6
+ const constants_1 = require("../constants/constants");
7
+ /**
8
+ * Inject the Apollo context in the decorated property.
9
+ * @decorator
10
+ */
11
+ function InjectApolloContext() {
12
+ return (...args) => {
13
+ switch ((0, core_1.decoratorTypeOf)(args)) {
14
+ case core_1.DecoratorTypes.PARAM_CTOR:
15
+ (0, di_1.Inject)(constants_1.APOLLO_CONTEXT)(...args);
16
+ break;
17
+ case core_1.DecoratorTypes.PROP:
18
+ return (0, di_1.InjectContext)(($ctx) => $ctx.get(constants_1.APOLLO_CONTEXT))(args[0], args[1]);
19
+ }
20
+ };
21
+ }
22
+ exports.InjectApolloContext = InjectApolloContext;
23
+ //# sourceMappingURL=injectApolloContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"injectApolloContext.js","sourceRoot":"","sources":["../../../src/decorators/injectApolloContext.ts"],"names":[],"mappings":";;;AAAA,qCAAgF;AAChF,iCAA+C;AAC/C,sDAAsD;AAEtD;;;GAGG;AACH,SAAgB,mBAAmB;IACjC,OAAO,CAAC,GAAG,IAAyB,EAAE,EAAE;QACtC,QAAQ,IAAA,sBAAe,EAAC,IAAI,CAAC,EAAE;YAC7B,KAAK,qBAAc,CAAC,UAAU;gBAC5B,IAAA,WAAM,EAAC,0BAAc,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;gBAChC,MAAM;YAER,KAAK,qBAAc,CAAC,IAAI;gBACtB,OAAO,IAAA,kBAAa,EAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,0BAAc,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;SAC9E;IACH,CAAC,CAAC;AACJ,CAAC;AAXD,kDAWC"}
package/lib/cjs/index.js CHANGED
@@ -7,6 +7,11 @@ const tslib_1 = require("tslib");
7
7
  tslib_1.__exportStar(require("./ApolloModule.js"), exports);
8
8
  tslib_1.__exportStar(require("./constants/constants.js"), exports);
9
9
  tslib_1.__exportStar(require("./decorators/dataSource.js"), exports);
10
+ tslib_1.__exportStar(require("./decorators/injectApolloContext.js"), exports);
11
+ tslib_1.__exportStar(require("./interfaces/AlterApolloContext.js"), exports);
12
+ tslib_1.__exportStar(require("./interfaces/AlterApolloServerPlugins.js"), exports);
13
+ tslib_1.__exportStar(require("./interfaces/AlterApolloSettings.js"), exports);
14
+ tslib_1.__exportStar(require("./interfaces/ApolloContext.js"), exports);
10
15
  tslib_1.__exportStar(require("./interfaces/ApolloSettings.js"), exports);
11
16
  tslib_1.__exportStar(require("./services/ApolloService.js"), exports);
12
17
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,4DAAkC;AAClC,mEAAyC;AACzC,qEAA2C;AAC3C,yEAA+C;AAC/C,sEAA4C"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,4DAAkC;AAClC,mEAAyC;AACzC,qEAA2C;AAC3C,8EAAoD;AACpD,6EAAmD;AACnD,mFAAyD;AACzD,8EAAoD;AACpD,wEAA8C;AAC9C,yEAA+C;AAC/C,sEAA4C"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=AlterApolloContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AlterApolloContext.js","sourceRoot":"","sources":["../../../src/interfaces/AlterApolloContext.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=AlterApolloServerPlugins.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AlterApolloServerPlugins.js","sourceRoot":"","sources":["../../../src/interfaces/AlterApolloServerPlugins.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=AlterApolloSettings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AlterApolloSettings.js","sourceRoot":"","sources":["../../../src/interfaces/AlterApolloSettings.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=ApolloContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApolloContext.js","sourceRoot":"","sources":["../../../src/interfaces/ApolloContext.ts"],"names":[],"mappings":""}
@@ -2,17 +2,18 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ApolloService = void 0;
4
4
  const tslib_1 = require("tslib");
5
+ const server_1 = require("@apollo/server");
6
+ const disabled_1 = require("@apollo/server/plugin/disabled");
7
+ const drainHttpServer_1 = require("@apollo/server/plugin/drainHttpServer");
8
+ const default_1 = require("@apollo/server/plugin/landingPage/default");
5
9
  const common_1 = require("@tsed/common");
6
- const core_1 = require("@tsed/core");
7
10
  const di_1 = require("@tsed/di");
8
11
  const logger_1 = require("@tsed/logger");
9
- const apollo_server_core_1 = require("apollo-server-core");
10
12
  const http_1 = tslib_1.__importDefault(require("http"));
11
13
  const https_1 = tslib_1.__importDefault(require("https"));
12
14
  const constants_js_1 = require("../constants/constants.js");
13
15
  let ApolloService = class ApolloService {
14
- constructor(dataSources) {
15
- this.dataSources = dataSources;
16
+ constructor() {
16
17
  /**
17
18
  *
18
19
  * @type {Map<any, any>}
@@ -27,22 +28,40 @@ let ApolloService = class ApolloService {
27
28
  this.logger.info(`Create server with Apollo for: ${id}`);
28
29
  this.logger.debug(`options: ${JSON.stringify({ path })}`);
29
30
  const plugins = await this.getPlugins(settings);
30
- const server = await this.createInstance({
31
+ const server = this.createInstance({
31
32
  ...config,
32
- plugins,
33
- dataSources: this.createDataSources(dataSources)
33
+ plugins
34
34
  }, customServer);
35
35
  if (server) {
36
36
  this.servers.set(id || "default", {
37
37
  instance: server,
38
- schema: settings.schema
38
+ schema: settings.schema,
39
+ typeDefs: settings.typeDefs,
40
+ resolvers: settings.resolvers
39
41
  });
40
42
  await server.start();
41
- const middleware = server.getMiddleware({
42
- path: settings.path,
43
- ...middlewareOptions
44
- });
45
- this.app.use(middleware);
43
+ const contextHandler = this.createContextHandler(server, settings);
44
+ switch (this.platformName) {
45
+ case "express":
46
+ const { expressMiddleware } = await import("@apollo/server/express4");
47
+ this.app.use(path, expressMiddleware(server, {
48
+ ...middlewareOptions,
49
+ context: contextHandler
50
+ }));
51
+ break;
52
+ case "koa":
53
+ const { koaMiddleware } = await import("@as-integrations/koa");
54
+ this.app.use(path, koaMiddleware(server, {
55
+ ...middlewareOptions,
56
+ context: contextHandler
57
+ }));
58
+ break;
59
+ default:
60
+ this.logger.warn({
61
+ event: "APOLLO_UNKNOWN_PLATFORM",
62
+ message: "Platform not supported. Please use Ts.ED platform (express, koa)"
63
+ });
64
+ }
46
65
  }
47
66
  }
48
67
  catch (er) {
@@ -52,8 +71,7 @@ let ApolloService = class ApolloService {
52
71
  message: er.message,
53
72
  stack: er.stack
54
73
  });
55
- /* istanbul ignore next */
56
- process.exit(-1);
74
+ throw er;
57
75
  }
58
76
  }
59
77
  return this.get(id);
@@ -66,12 +84,21 @@ let ApolloService = class ApolloService {
66
84
  return this.servers.get(id)?.instance;
67
85
  }
68
86
  /**
69
- * Get an instance of GraphQL schema from his id
87
+ * Get schema of the ApolloServer from his id
70
88
  * @returns GraphQLSchema
71
89
  */
72
90
  getSchema(id = "default") {
73
91
  return this.servers.get(id)?.schema;
74
92
  }
93
+ /**
94
+ * Get TypeDefs of the ApolloServer from his id
95
+ */
96
+ getTypeDefs(id = "default") {
97
+ return this.servers.get(id)?.typeDefs;
98
+ }
99
+ getResolvers(id = "default") {
100
+ return this.servers.get(id)?.resolvers;
101
+ }
75
102
  /**
76
103
  *
77
104
  * @param {string} id
@@ -80,59 +107,54 @@ let ApolloService = class ApolloService {
80
107
  has(id = "default") {
81
108
  return this.servers.has(id);
82
109
  }
83
- async createInstance(options, server) {
84
- if (server) {
85
- return server(options);
86
- }
87
- const importServer = async () => {
88
- switch (this.platformName) {
89
- default:
90
- this.logger.error(`Platform "${this.platformName}" not supported by @tsed/apollo`);
91
- case "express":
92
- return (await import("apollo-server-express")).ApolloServer;
93
- case "koa":
94
- return (await import("apollo-server-koa")).ApolloServer;
95
- }
96
- };
97
- const Server = await importServer();
98
- return new Server(options);
99
- }
100
110
  /**
101
111
  * create a new dataSources function to use with apollo server config
102
- * @param dataSources
103
112
  */
104
- createDataSources(dataSources) {
105
- const dataSourcesHash = this.dataSources.reduce((map, instance) => {
106
- const klass = (0, core_1.classOf)(instance);
107
- const store = core_1.Store.from(klass);
108
- let { name } = store.get(constants_js_1.DATASOURCES_PROVIDERS);
109
- name = name || (0, core_1.nameOf)(klass);
113
+ createContextHandler(server, settings) {
114
+ const { injector } = this;
115
+ const dataSourcesContainer = injector.getProviders(constants_js_1.DATASOURCES_PROVIDERS).reduce((map, provider) => {
116
+ let { name } = provider.store.get(constants_js_1.DATASOURCES_PROVIDERS);
117
+ name = name || provider.className;
110
118
  const sourceName = `${name[0].toLowerCase()}${name.slice(1)}`;
111
- map[sourceName] = instance;
119
+ map.set(sourceName, provider);
112
120
  return map;
113
- }, {});
114
- return () => {
115
- return {
116
- ...dataSourcesHash,
117
- ...(dataSources ? dataSources() : {})
121
+ }, new Map());
122
+ return async () => {
123
+ const $ctx = (0, common_1.useContext)();
124
+ const context = {
125
+ dataSources: {
126
+ ...(settings.dataSources?.() || {})
127
+ }
118
128
  };
129
+ const alteredContext = await this.injector.alterAsync("$alterApolloContext", context, $ctx);
130
+ $ctx.set(constants_js_1.APOLLO_CONTEXT, alteredContext);
131
+ const locals = new common_1.LocalsContainer();
132
+ locals.set(constants_js_1.APOLLO_CONTEXT, alteredContext);
133
+ locals.set(server_1.ApolloServer, server);
134
+ dataSourcesContainer.forEach((provider, key) => {
135
+ alteredContext.dataSources[key] = injector.invoke(provider.token, locals);
136
+ });
137
+ return alteredContext;
119
138
  };
120
139
  }
140
+ createInstance(options, server) {
141
+ return server ? server(options) : new server_1.ApolloServer(options);
142
+ }
121
143
  async getPlugins(serverSettings) {
122
144
  const playground = serverSettings.playground || (serverSettings.playground === undefined && process.env.NODE_ENV !== "production");
123
- const result = await this.injector.alter("$alterApolloServerPlugins", [
145
+ const result = await this.injector.alterAsync("$alterApolloServerPlugins", [
124
146
  this.httpServer &&
125
- (0, apollo_server_core_1.ApolloServerPluginDrainHttpServer)({
147
+ (0, drainHttpServer_1.ApolloServerPluginDrainHttpServer)({
126
148
  httpServer: this.httpServer
127
149
  }),
128
150
  this.httpsServer &&
129
- (0, apollo_server_core_1.ApolloServerPluginDrainHttpServer)({
151
+ (0, drainHttpServer_1.ApolloServerPluginDrainHttpServer)({
130
152
  httpServer: this.httpsServer
131
153
  }),
132
154
  ...(serverSettings.plugins || [])
133
155
  ].filter(Boolean), serverSettings);
134
156
  return result
135
- .concat([playground ? (0, apollo_server_core_1.ApolloServerPluginLandingPageLocalDefault)({ embed: true }) : (0, apollo_server_core_1.ApolloServerPluginLandingPageDisabled)()])
157
+ .concat([playground ? (0, default_1.ApolloServerPluginLandingPageLocalDefault)({ embed: true }) : (0, disabled_1.ApolloServerPluginLandingPageDisabled)()])
136
158
  .filter(Boolean);
137
159
  }
138
160
  };
@@ -161,9 +183,7 @@ tslib_1.__decorate([
161
183
  tslib_1.__metadata("design:type", common_1.InjectorService)
162
184
  ], ApolloService.prototype, "injector", void 0);
163
185
  ApolloService = tslib_1.__decorate([
164
- (0, di_1.Service)(),
165
- tslib_1.__param(0, (0, di_1.Inject)(constants_js_1.DATASOURCES_PROVIDERS)),
166
- tslib_1.__metadata("design:paramtypes", [Array])
186
+ (0, di_1.Service)()
167
187
  ], ApolloService);
168
188
  exports.ApolloService = ApolloService;
169
189
  //# sourceMappingURL=ApolloService.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ApolloService.js","sourceRoot":"","sources":["../../../src/services/ApolloService.ts"],"names":[],"mappings":";;;;AAAA,yCAAkE;AAClE,qCAAkD;AAClD,iCAAmD;AACnD,yCAAoC;AAEpC,2DAK4B;AAG5B,wDAAwB;AACxB,0DAA0B;AAC1B,4DAAgE;AAKzD,IAAM,aAAa,GAAnB,MAAM,aAAa;IAgCxB,YAAqD,WAA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CAAC,cAAc,CAAC,OAAO,IAAI,EAAE,CAAC;SAClC,CAAC,MAAM,CAAC,OAAO,CAAC,EACjB,cAAc,CACf,CAAC;QAEF,OAAO,MAAM;aACV,MAAM,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAA,mDAAyC,EAAC,EAAC,KAAK,EAAE,IAAI,EAAC,CAAC,CAAC,CAAC,CAAC,IAAA,gDAAqC,GAAE,CAAC,CAAC;aACzH,MAAM,CAAC,OAAO,CAAC,CAAC;IACrB,CAAC;CACF,CAAA;AAnNC;IAAC,IAAA,aAAQ,EAAC,eAAe,CAAC;;mDACL;AAErB;IAAC,IAAA,WAAM,GAAE;sCACS,eAAM;6CAAC;AAiBzB;IAAC,IAAA,WAAM,GAAE;sCACI,4BAAmB;0CAAM;AAEtC;IAAC,IAAA,WAAM,EAAC,cAAI,CAAC,MAAM,CAAC;;iDACmB;AAEvC;IAAC,IAAA,WAAM,EAAC,eAAK,CAAC,MAAM,CAAC;;kDACoB;AAEzC;IAAC,IAAA,WAAM,GAAE;sCACS,wBAAe;+CAAC;AAhCvB,aAAa;IADzB,IAAA,YAAO,GAAE;GACG,aAAa,CAoNzB;AApNY,sCAAa"}
@@ -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, Module, InjectorService } 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;gBAC/D,OAAO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AM,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;YACZ,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;SACJ;IACH,CAAC;CACF,CAAA;AAjDC;IAAC,MAAM,EAAE;8BACS,MAAM;4CAAC;AAEzB;IAAC,MAAM,EAAE;8BACU,aAAa;6CAAC;AAEjC;IAAC,aAAa,EAAE;;mDACuB;AAEvC;IAAC,MAAM,CAAC,eAAe,CAAC;8BACJ,eAAe;8CAAC;AAXzB,YAAY;IADxB,MAAM,EAAE;GACI,YAAY,CAkDxB;SAlDY,YAAY"}
@@ -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 {
@@ -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;AAC/C,OAAO,EAAC,cAAc,EAAC,MAAM,wBAAwB,CAAC;AAEtD;;;GAGG;AACH,MAAM,UAAU,mBAAmB;IACjC,OAAO,CAAC,GAAG,IAAyB,EAAE,EAAE;QACtC,QAAQ,eAAe,CAAC,IAAI,CAAC,EAAE;YAC7B,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;SAC9E;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":""}