@tsed/apollo 7.0.0-alpha.1 → 7.0.0-beta.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 (33) hide show
  1. package/jest.config.js +14 -0
  2. package/lib/{ApolloModule.js → cjs/ApolloModule.js} +10 -6
  3. package/lib/cjs/ApolloModule.js.map +1 -0
  4. package/lib/{index.js → cjs/index.js} +4 -0
  5. package/lib/cjs/index.js.map +1 -0
  6. package/lib/{interfaces → cjs/interfaces}/ApolloSettings.js +0 -0
  7. package/lib/cjs/interfaces/ApolloSettings.js.map +1 -0
  8. package/lib/cjs/package.json +3 -0
  9. package/lib/cjs/services/ApolloService.js +131 -0
  10. package/lib/cjs/services/ApolloService.js.map +1 -0
  11. package/lib/esm/ApolloModule.js +49 -0
  12. package/lib/esm/ApolloModule.js.map +1 -0
  13. package/lib/esm/index.js +7 -0
  14. package/lib/esm/index.js.map +1 -0
  15. package/lib/esm/interfaces/ApolloSettings.js +2 -0
  16. package/lib/esm/interfaces/ApolloSettings.js.map +1 -0
  17. package/lib/esm/package.json +3 -0
  18. package/lib/esm/services/ApolloService.js +128 -0
  19. package/lib/esm/services/ApolloService.js.map +1 -0
  20. package/lib/{ApolloModule.d.ts → types/ApolloModule.d.ts} +0 -0
  21. package/lib/{index.d.ts → types/index.d.ts} +4 -0
  22. package/lib/types/interfaces/ApolloSettings.d.ts +14 -0
  23. package/lib/{services → types/services}/ApolloService.d.ts +16 -8
  24. package/package.json +37 -15
  25. package/readme.md +3 -5
  26. package/tsconfig.compile.esm.json +12 -0
  27. package/.mocharc.js +0 -5
  28. package/lib/ApolloModule.js.map +0 -1
  29. package/lib/index.js.map +0 -1
  30. package/lib/interfaces/ApolloSettings.d.ts +0 -11
  31. package/lib/interfaces/ApolloSettings.js.map +0 -1
  32. package/lib/services/ApolloService.js +0 -120
  33. package/lib/services/ApolloService.js.map +0 -1
package/jest.config.js ADDED
@@ -0,0 +1,14 @@
1
+ // For a detailed explanation regarding each configuration property, visit:
2
+ // https://jestjs.io/docs/en/configuration.html
3
+
4
+ module.exports = {
5
+ ...require("@tsed/jest-config")(__dirname, "apollo"),
6
+ coverageThreshold: {
7
+ global: {
8
+ statements: 100,
9
+ branches: 75,
10
+ functions: 100,
11
+ lines: 100
12
+ }
13
+ }
14
+ };
@@ -19,30 +19,34 @@ let ApolloModule = class ApolloModule {
19
19
  }
20
20
  }
21
21
  $afterListen() {
22
+ const host = this.configuration.getBestHost();
23
+ const displayLog = (key, path) => {
24
+ 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
+ };
22
27
  const { settings } = this;
23
28
  if (settings) {
24
- const host = this.configuration.getHttpPort();
25
29
  Object.entries(settings).map(async ([key, options]) => {
26
30
  const { path } = options;
27
- this.logger.info(`[${key}] Apollo server is available on http://${host.address}:${host.port}/${path.replace(/^\//, "")}`);
31
+ displayLog(key, path);
28
32
  });
29
33
  }
30
34
  }
31
35
  };
32
36
  tslib_1.__decorate([
33
- di_1.Inject(),
37
+ (0, di_1.Inject)(),
34
38
  tslib_1.__metadata("design:type", common_1.Logger)
35
39
  ], ApolloModule.prototype, "logger", void 0);
36
40
  tslib_1.__decorate([
37
- di_1.Inject(),
41
+ (0, di_1.Inject)(),
38
42
  tslib_1.__metadata("design:type", ApolloService_1.ApolloService)
39
43
  ], ApolloModule.prototype, "service", void 0);
40
44
  tslib_1.__decorate([
41
- di_1.Configuration(),
45
+ (0, di_1.Configuration)(),
42
46
  tslib_1.__metadata("design:type", Object)
43
47
  ], ApolloModule.prototype, "configuration", void 0);
44
48
  ApolloModule = tslib_1.__decorate([
45
- di_1.Module()
49
+ (0, di_1.Module)()
46
50
  ], ApolloModule);
47
51
  exports.ApolloModule = ApolloModule;
48
52
  //# sourceMappingURL=ApolloModule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApolloModule.js","sourceRoot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AC,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE,EAAE;gBACpD,MAAM,EAAC,IAAI,EAAC,GAAG,OAAO,CAAC;gBAEvB,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;YACxB,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;CACF,CAAA;AA3CC;IADC,IAAA,WAAM,GAAE;sCACS,eAAM;4CAAC;AAGzB;IADC,IAAA,WAAM,GAAE;sCACU,6BAAa;6CAAC;AAGjC;IADC,IAAA,kBAAa,GAAE;;mDACuB;AAR5B,YAAY;IADxB,IAAA,WAAM,GAAE;GACI,YAAY,CA6CxB;AA7CY,oCAAY","sourcesContent":["import {AfterListen, Logger, OnRoutesInit} from \"@tsed/common\";\nimport {Configuration, Inject, Module} from \"@tsed/di\";\nimport {ApolloSettings} from \"./interfaces/ApolloSettings\";\nimport {ApolloService} from \"./services/ApolloService\";\n\n@Module()\nexport class ApolloModule implements OnRoutesInit, AfterListen {\n @Inject()\n protected logger: Logger;\n\n @Inject()\n protected service: ApolloService;\n\n @Configuration()\n protected configuration: Configuration;\n\n get settings(): {[key: string]: ApolloSettings} | undefined {\n return this.configuration.get(\"apollo\");\n }\n\n $onRoutesInit(): Promise<any> | void {\n const {settings} = this;\n\n if (settings) {\n const promises = Object.entries(settings).map(async ([key, options]) => {\n return this.service.createServer(key, options);\n });\n\n return Promise.all(promises);\n }\n }\n\n $afterListen(): Promise<any> | void {\n const host = this.configuration.getBestHost();\n\n const displayLog = (key: string, path: string) => {\n const url = typeof host.port === \"number\" ? `${host.protocol}://${host.address}:${host.port}` : \"\";\n\n this.logger.info(`[${key}] Apollo server is available on ${url}${path.replace(/^\\//, \"\")}`);\n };\n\n const {settings} = this;\n\n if (settings) {\n Object.entries(settings).map(async ([key, options]) => {\n const {path} = options;\n\n displayLog(key, path);\n });\n }\n }\n}\n"]}
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
+ /**
3
+ * @file Automatically generated by barrelsby.
4
+ */
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  const tslib_1 = require("tslib");
7
+ tslib_1.__exportStar(require("./ApolloModule"), exports);
4
8
  tslib_1.__exportStar(require("./interfaces/ApolloSettings"), exports);
5
9
  tslib_1.__exportStar(require("./services/ApolloService"), exports);
6
10
  //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,yDAA+B;AAC/B,sEAA4C;AAC5C,mEAAyC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./ApolloModule\";\nexport * from \"./interfaces/ApolloSettings\";\nexport * from \"./services/ApolloService\";\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApolloSettings.js","sourceRoot":"","sources":["../../../src/interfaces/ApolloSettings.ts"],"names":[],"mappings":"","sourcesContent":["import type {ApolloServerBase, Config, ApolloServerPluginLandingPageGraphQLPlaygroundOptions} from \"apollo-server-core\";\n\nexport type ApolloMiddlewareOptions = Record<string, any>;\nexport type ApolloServer = ApolloServerBase & {getMiddleware(settings: ApolloMiddlewareOptions): any};\nexport type ApolloCustomServerCB = (config: ApolloConfig) => ApolloServer;\nexport type ApolloConfig = Config;\n\nexport interface ApolloSettings extends ApolloConfig {\n // Basic options\n path: string;\n server?: ApolloCustomServerCB;\n playground?: boolean | ApolloServerPluginLandingPageGraphQLPlaygroundOptions;\n // ApplyMiddleware Options\n // See options descriptions on https://www.apollographql.com/docs/apollo-server/api/apollo-server.html\n serverRegistration?: ApolloMiddlewareOptions;\n middlewareOptions?: ApolloMiddlewareOptions;\n}\n"]}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -0,0 +1,131 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ApolloService = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const di_1 = require("@tsed/di");
6
+ const logger_1 = require("@tsed/logger");
7
+ const common_1 = require("@tsed/common");
8
+ const apollo_server_core_1 = require("apollo-server-core");
9
+ const http_1 = tslib_1.__importDefault(require("http"));
10
+ const https_1 = tslib_1.__importDefault(require("https"));
11
+ let ApolloService = class ApolloService {
12
+ constructor() {
13
+ /**
14
+ *
15
+ * @type {Map<any, any>}
16
+ * @private
17
+ */
18
+ this.servers = new Map();
19
+ }
20
+ async createServer(id, settings) {
21
+ if (this.has(id)) {
22
+ return this.get(id);
23
+ }
24
+ try {
25
+ const { path, middlewareOptions = {}, server: customServer, ...config } = settings;
26
+ this.logger.info(`Create server with Apollo for: ${id}`);
27
+ this.logger.debug(`options: ${JSON.stringify({ path })}`);
28
+ const server = await this.createInstance({
29
+ ...config,
30
+ plugins: this.getPlugins(settings)
31
+ }, customServer);
32
+ if (server) {
33
+ this.servers.set(id || "default", {
34
+ instance: server,
35
+ schema: settings.schema
36
+ });
37
+ await server.start();
38
+ const middleware = server.getMiddleware({
39
+ path: settings.path,
40
+ ...middlewareOptions
41
+ });
42
+ this.app.getRouter().use(middleware);
43
+ return server;
44
+ }
45
+ }
46
+ catch (err) {
47
+ /* istanbul ignore next */
48
+ this.logger.error(err);
49
+ /* istanbul ignore next */
50
+ process.exit(-1);
51
+ }
52
+ }
53
+ /**
54
+ * Get an instance of ApolloServer from his id
55
+ * @returns ApolloServer
56
+ */
57
+ get(id = "default") {
58
+ var _a;
59
+ return (_a = this.servers.get(id)) === null || _a === void 0 ? void 0 : _a.instance;
60
+ }
61
+ /**
62
+ * Get an instance of GraphQL schema from his id
63
+ * @returns GraphQLSchema
64
+ */
65
+ getSchema(id = "default") {
66
+ var _a;
67
+ return (_a = this.servers.get(id)) === null || _a === void 0 ? void 0 : _a.schema;
68
+ }
69
+ /**
70
+ *
71
+ * @param {string} id
72
+ * @returns {boolean}
73
+ */
74
+ has(id = "default") {
75
+ return this.servers.has(id);
76
+ }
77
+ async createInstance(options, server) {
78
+ // istanbul ignore next
79
+ if (server) {
80
+ return server(options);
81
+ }
82
+ // istanbul ignore next
83
+ try {
84
+ const { ApolloServer: Server } = await Promise.resolve().then(() => tslib_1.__importStar(require(`apollo-server-${this.platformName || "express"}`)));
85
+ return new Server(options);
86
+ }
87
+ catch (er) {
88
+ this.logger.error(`Platform "${this.platformName}" not supported by @tsed/apollo`);
89
+ }
90
+ }
91
+ getPlugins(serverSettings) {
92
+ const playground = serverSettings.playground || (serverSettings.playground === undefined && process.env.NODE_ENV !== "production");
93
+ return [
94
+ playground ? (0, apollo_server_core_1.ApolloServerPluginLandingPageGraphQLPlayground)() : (0, apollo_server_core_1.ApolloServerPluginLandingPageDisabled)(),
95
+ this.httpServer &&
96
+ (0, apollo_server_core_1.ApolloServerPluginDrainHttpServer)({
97
+ httpServer: this.httpServer
98
+ }),
99
+ this.httpsServer &&
100
+ (0, apollo_server_core_1.ApolloServerPluginDrainHttpServer)({
101
+ httpServer: this.httpsServer
102
+ }),
103
+ ...(serverSettings.plugins || [])
104
+ ].filter(Boolean);
105
+ }
106
+ };
107
+ tslib_1.__decorate([
108
+ (0, di_1.Constant)("PLATFORM_NAME"),
109
+ tslib_1.__metadata("design:type", String)
110
+ ], ApolloService.prototype, "platformName", void 0);
111
+ tslib_1.__decorate([
112
+ (0, di_1.Inject)(),
113
+ tslib_1.__metadata("design:type", logger_1.Logger)
114
+ ], ApolloService.prototype, "logger", void 0);
115
+ tslib_1.__decorate([
116
+ (0, di_1.Inject)(),
117
+ tslib_1.__metadata("design:type", common_1.PlatformApplication)
118
+ ], ApolloService.prototype, "app", void 0);
119
+ tslib_1.__decorate([
120
+ (0, di_1.Inject)(http_1.default.Server),
121
+ tslib_1.__metadata("design:type", Object)
122
+ ], ApolloService.prototype, "httpServer", void 0);
123
+ tslib_1.__decorate([
124
+ (0, di_1.Inject)(https_1.default.Server),
125
+ tslib_1.__metadata("design:type", Object)
126
+ ], ApolloService.prototype, "httpsServer", void 0);
127
+ ApolloService = tslib_1.__decorate([
128
+ (0, di_1.Service)()
129
+ ], ApolloService);
130
+ exports.ApolloService = ApolloService;
131
+ //# sourceMappingURL=ApolloService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApolloService.js","sourceRoot":"","sources":["../../../src/services/ApolloService.ts"],"names":[],"mappings":";;;;AAAA,iCAAmD;AACnD,yCAAoC;AACpC,yCAAiD;AAEjD,2DAK4B;AAI5B,wDAAwB;AACxB,0DAA0B;AAG1B,IAAa,aAAa,GAA1B,MAAa,aAAa;IAA1B;QAOE;;;;WAIG;QACO,YAAO,GAMb,IAAI,GAAG,EAAE,CAAC;IAgHhB,CAAC;IArGC,KAAK,CAAC,YAAY,CAAC,EAAU,EAAE,QAAwB;QACrD,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;YAChB,OAAO,IAAI,CAAC,GAAG,CAAC,EAAE,CAAE,CAAC;SACtB;QAED,IAAI;YACF,MAAM,EAAC,IAAI,EAAE,iBAAiB,GAAG,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,EAAC,GAAG,QAAQ,CAAC;YAEjF,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,kCAAkC,EAAE,EAAE,CAAC,CAAC;YACzD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,IAAI,CAAC,SAAS,CAAC,EAAC,IAAI,EAAC,CAAC,EAAE,CAAC,CAAC;YAExD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,cAAc,CACtC;gBACE,GAAG,MAAM;gBACT,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC;aACnC,EACD,YAAY,CACb,CAAC;YAEF,IAAI,MAAM,EAAE;gBACV,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,IAAI,SAAS,EAAE;oBAChC,QAAQ,EAAE,MAAM;oBAChB,MAAM,EAAE,QAAQ,CAAC,MAAM;iBACxB,CAAC,CAAC;gBAEH,MAAM,MAAM,CAAC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AC,KAAK,CAAC,aAAa,IAAI,CAAC,YAAY,iCAAiC,CAAC,CAAC;SACpF;IACH,CAAC;IAEO,UAAU,CAAC,cAA8B;QAC/C,MAAM,UAAU,GAAG,cAAc,CAAC,UAAU,IAAI,CAAC,cAAc,CAAC,UAAU,KAAK,SAAS,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY,CAAC,CAAC;QAEnI,OAAO;YACL,UAAU,CAAC,CAAC,CAAC,IAAA,mEAA8C,GAAE,CAAC,CAAC,CAAC,IAAA,0DAAqC,GAAE;YACvG,IAAI,CAAC,UAAU;gBACb,IAAA,sDAAiC,EAAC;oBAChC,UAAU,EAAE,IAAI,CAAC,UAAU;iBAC5B,CAAC;YACJ,IAAI,CAAC,WAAW;gBACd,IAAA,sDAAiC,EAAC;oBAChC,UAAU,EAAE,IAAI,CAAC,WAAW;iBAC7B,CAAC;YACJ,GAAG,CAAC,cAAc,CAAC,OAAO,IAAI,EAAE,CAAC;SAClC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACpB,CAAC;CACF,CAAA;AAhIC;IADC,IAAA,aAAQ,EAAC,eAAe,CAAC;;mDACL;AAGrB;IADC,IAAA,WAAM,GAAE;sCACS,eAAM;6CAAC;AAgBzB;IADC,IAAA,WAAM,GAAE;sCACI,4BAAmB;0CAAW;AAG3C;IADC,IAAA,WAAM,EAAC,cAAI,CAAC,MAAM,CAAC;;iDACmB;AAGvC;IADC,IAAA,WAAM,EAAC,eAAK,CAAC,MAAM,CAAC;;kDACoB;AA3B9B,aAAa;IADzB,IAAA,YAAO,GAAE;GACG,aAAa,CAkIzB;AAlIY,sCAAa","sourcesContent":["import {Constant, Inject, Service} from \"@tsed/di\";\nimport {Logger} from \"@tsed/logger\";\nimport {PlatformApplication} from \"@tsed/common\";\nimport type {Config} from \"apollo-server-core\";\nimport {\n ApolloServerBase,\n ApolloServerPluginDrainHttpServer,\n ApolloServerPluginLandingPageDisabled,\n ApolloServerPluginLandingPageGraphQLPlayground\n} from \"apollo-server-core\";\nimport type {GraphQLSchema} from \"graphql\";\nimport type {ApolloServer, ApolloSettings} from \"../interfaces/ApolloSettings\";\nimport {ApolloCustomServerCB} from \"../interfaces/ApolloSettings\";\nimport Http from \"http\";\nimport Https from \"https\";\n\n@Service()\nexport class ApolloService {\n @Constant(\"PLATFORM_NAME\")\n platformName: string;\n\n @Inject()\n protected logger: Logger;\n\n /**\n *\n * @type {Map<any, any>}\n * @private\n */\n protected servers: Map<\n string,\n {\n instance: ApolloServerBase;\n schema: GraphQLSchema | undefined;\n }\n > = new Map();\n\n @Inject()\n private app: PlatformApplication<any, any>;\n\n @Inject(Http.Server)\n private httpServer: Http.Server | null;\n\n @Inject(Https.Server)\n private httpsServer: Https.Server | null;\n\n async createServer(id: string, settings: ApolloSettings): Promise<any> {\n if (this.has(id)) {\n return this.get(id)!;\n }\n\n try {\n const {path, middlewareOptions = {}, server: customServer, ...config} = settings;\n\n this.logger.info(`Create server with Apollo for: ${id}`);\n this.logger.debug(`options: ${JSON.stringify({path})}`);\n\n const server = await this.createInstance(\n {\n ...config,\n plugins: this.getPlugins(settings)\n },\n customServer\n );\n\n if (server) {\n this.servers.set(id || \"default\", {\n instance: server,\n schema: settings.schema\n });\n\n await server.start();\n\n const middleware = server.getMiddleware({\n path: settings.path,\n ...middlewareOptions\n });\n\n this.app.getRouter().use(middleware);\n\n return server;\n }\n } catch (err) {\n /* istanbul ignore next */\n this.logger.error(err);\n /* istanbul ignore next */\n process.exit(-1);\n }\n }\n\n /**\n * Get an instance of ApolloServer from his id\n * @returns ApolloServer\n */\n get(id: string = \"default\"): ApolloServerBase | undefined {\n return this.servers.get(id)?.instance;\n }\n\n /**\n * Get an instance of GraphQL schema from his id\n * @returns GraphQLSchema\n */\n getSchema(id: string = \"default\"): GraphQLSchema | undefined {\n return this.servers.get(id)?.schema;\n }\n\n /**\n *\n * @param {string} id\n * @returns {boolean}\n */\n has(id: string = \"default\"): boolean {\n return this.servers.has(id);\n }\n\n protected async createInstance(options: Config, server?: ApolloCustomServerCB): Promise<ApolloServer | undefined> {\n // istanbul ignore next\n if (server) {\n return server(options);\n }\n\n // istanbul ignore next\n try {\n const {ApolloServer: Server} = await import(`apollo-server-${this.platformName || \"express\"}`);\n\n return new Server(options);\n } catch (er) {\n this.logger.error(`Platform \"${this.platformName}\" not supported by @tsed/apollo`);\n }\n }\n\n private getPlugins(serverSettings: ApolloSettings): any[] {\n const playground = serverSettings.playground || (serverSettings.playground === undefined && process.env.NODE_ENV !== \"production\");\n\n return [\n playground ? ApolloServerPluginLandingPageGraphQLPlayground() : ApolloServerPluginLandingPageDisabled(),\n this.httpServer &&\n ApolloServerPluginDrainHttpServer({\n httpServer: this.httpServer\n }),\n this.httpsServer &&\n ApolloServerPluginDrainHttpServer({\n httpServer: this.httpsServer\n }),\n ...(serverSettings.plugins || [])\n ].filter(Boolean);\n }\n}\n"]}
@@ -0,0 +1,49 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import { Logger } from "@tsed/common";
3
+ import { Configuration, Inject, Module } from "@tsed/di";
4
+ import { ApolloService } from "./services/ApolloService.js";
5
+ let ApolloModule = class ApolloModule {
6
+ get settings() {
7
+ return this.configuration.get("apollo");
8
+ }
9
+ $onRoutesInit() {
10
+ const { settings } = this;
11
+ if (settings) {
12
+ const promises = Object.entries(settings).map(async ([key, options]) => {
13
+ return this.service.createServer(key, options);
14
+ });
15
+ return Promise.all(promises);
16
+ }
17
+ }
18
+ $afterListen() {
19
+ const host = this.configuration.getBestHost();
20
+ const displayLog = (key, path) => {
21
+ 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
+ };
24
+ const { settings } = this;
25
+ if (settings) {
26
+ Object.entries(settings).map(async ([key, options]) => {
27
+ const { path } = options;
28
+ displayLog(key, path);
29
+ });
30
+ }
31
+ }
32
+ };
33
+ __decorate([
34
+ Inject(),
35
+ __metadata("design:type", Logger)
36
+ ], ApolloModule.prototype, "logger", void 0);
37
+ __decorate([
38
+ Inject(),
39
+ __metadata("design:type", ApolloService)
40
+ ], ApolloModule.prototype, "service", void 0);
41
+ __decorate([
42
+ Configuration(),
43
+ __metadata("design:type", Object)
44
+ ], ApolloModule.prototype, "configuration", void 0);
45
+ ApolloModule = __decorate([
46
+ Module()
47
+ ], ApolloModule);
48
+ export { ApolloModule };
49
+ //# sourceMappingURL=ApolloModule.js.map
@@ -0,0 +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,0BAA0B,CAAC;AAGvD,IAAa,YAAY,GAAzB,MAAa,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,KAAK,EAAE,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE,EAAE;gBACrE,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;YACjD,CAAC,CAAC,CAAC;YAEH,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;SAC9B;IACH,CAAC;IAED,YAAY;QACV,MAAM,IAAI,GAAG,IAAI,CAAC,aAAa,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,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC;QAC9F,CAAC,CAAC;QAEF,MAAM,EAAC,QAAQ,EAAC,GAAG,IAAI,CAAC;QAExB,IAAI,QAAQ,EAAE;YACZ,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE,EAAE;gBACpD,MAAM,EAAC,IAAI,EAAC,GAAG,OAAO,CAAC;gBAEvB,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;YACxB,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;CACF,CAAA;AA3CC;IADC,MAAM,EAAE;8BACS,MAAM;4CAAC;AAGzB;IADC,MAAM,EAAE;8BACU,aAAa;6CAAC;AAGjC;IADC,aAAa,EAAE;;mDACuB;AAR5B,YAAY;IADxB,MAAM,EAAE;GACI,YAAY,CA6CxB;SA7CY,YAAY","sourcesContent":["import {AfterListen, Logger, OnRoutesInit} from \"@tsed/common\";\nimport {Configuration, Inject, Module} from \"@tsed/di\";\nimport {ApolloSettings} from \"./interfaces/ApolloSettings\";\nimport {ApolloService} from \"./services/ApolloService\";\n\n@Module()\nexport class ApolloModule implements OnRoutesInit, AfterListen {\n @Inject()\n protected logger: Logger;\n\n @Inject()\n protected service: ApolloService;\n\n @Configuration()\n protected configuration: Configuration;\n\n get settings(): {[key: string]: ApolloSettings} | undefined {\n return this.configuration.get(\"apollo\");\n }\n\n $onRoutesInit(): Promise<any> | void {\n const {settings} = this;\n\n if (settings) {\n const promises = Object.entries(settings).map(async ([key, options]) => {\n return this.service.createServer(key, options);\n });\n\n return Promise.all(promises);\n }\n }\n\n $afterListen(): Promise<any> | void {\n const host = this.configuration.getBestHost();\n\n const displayLog = (key: string, path: string) => {\n const url = typeof host.port === \"number\" ? `${host.protocol}://${host.address}:${host.port}` : \"\";\n\n this.logger.info(`[${key}] Apollo server is available on ${url}${path.replace(/^\\//, \"\")}`);\n };\n\n const {settings} = this;\n\n if (settings) {\n Object.entries(settings).map(async ([key, options]) => {\n const {path} = options;\n\n displayLog(key, path);\n });\n }\n }\n}\n"]}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @file Automatically generated by barrelsby.
3
+ */
4
+ export * from "./ApolloModule.js";
5
+ export * from "./interfaces/ApolloSettings.js";
6
+ export * from "./services/ApolloService.js";
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,0BAA0B,CAAC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./ApolloModule\";\nexport * from \"./interfaces/ApolloSettings\";\nexport * from \"./services/ApolloService\";\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=ApolloSettings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApolloSettings.js","sourceRoot":"","sources":["../../../src/interfaces/ApolloSettings.ts"],"names":[],"mappings":"","sourcesContent":["import type {ApolloServerBase, Config, ApolloServerPluginLandingPageGraphQLPlaygroundOptions} from \"apollo-server-core\";\n\nexport type ApolloMiddlewareOptions = Record<string, any>;\nexport type ApolloServer = ApolloServerBase & {getMiddleware(settings: ApolloMiddlewareOptions): any};\nexport type ApolloCustomServerCB = (config: ApolloConfig) => ApolloServer;\nexport type ApolloConfig = Config;\n\nexport interface ApolloSettings extends ApolloConfig {\n // Basic options\n path: string;\n server?: ApolloCustomServerCB;\n playground?: boolean | ApolloServerPluginLandingPageGraphQLPlaygroundOptions;\n // ApplyMiddleware Options\n // See options descriptions on https://www.apollographql.com/docs/apollo-server/api/apollo-server.html\n serverRegistration?: ApolloMiddlewareOptions;\n middlewareOptions?: ApolloMiddlewareOptions;\n}\n"]}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -0,0 +1,128 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import { Constant, Inject, Service } from "@tsed/di";
3
+ import { Logger } from "@tsed/logger";
4
+ import { PlatformApplication } from "@tsed/common";
5
+ import { ApolloServerPluginDrainHttpServer, ApolloServerPluginLandingPageDisabled, ApolloServerPluginLandingPageGraphQLPlayground } from "apollo-server-core";
6
+ import Http from "http";
7
+ import Https from "https";
8
+ let ApolloService = class ApolloService {
9
+ constructor() {
10
+ /**
11
+ *
12
+ * @type {Map<any, any>}
13
+ * @private
14
+ */
15
+ this.servers = new Map();
16
+ }
17
+ async createServer(id, settings) {
18
+ if (this.has(id)) {
19
+ return this.get(id);
20
+ }
21
+ try {
22
+ const { path, middlewareOptions = {}, server: customServer, ...config } = settings;
23
+ this.logger.info(`Create server with Apollo for: ${id}`);
24
+ this.logger.debug(`options: ${JSON.stringify({ path })}`);
25
+ const server = await this.createInstance({
26
+ ...config,
27
+ plugins: this.getPlugins(settings)
28
+ }, customServer);
29
+ if (server) {
30
+ this.servers.set(id || "default", {
31
+ instance: server,
32
+ schema: settings.schema
33
+ });
34
+ await server.start();
35
+ const middleware = server.getMiddleware({
36
+ path: settings.path,
37
+ ...middlewareOptions
38
+ });
39
+ this.app.getRouter().use(middleware);
40
+ return server;
41
+ }
42
+ }
43
+ catch (err) {
44
+ /* istanbul ignore next */
45
+ this.logger.error(err);
46
+ /* istanbul ignore next */
47
+ process.exit(-1);
48
+ }
49
+ }
50
+ /**
51
+ * Get an instance of ApolloServer from his id
52
+ * @returns ApolloServer
53
+ */
54
+ get(id = "default") {
55
+ var _a;
56
+ return (_a = this.servers.get(id)) === null || _a === void 0 ? void 0 : _a.instance;
57
+ }
58
+ /**
59
+ * Get an instance of GraphQL schema from his id
60
+ * @returns GraphQLSchema
61
+ */
62
+ getSchema(id = "default") {
63
+ var _a;
64
+ return (_a = this.servers.get(id)) === null || _a === void 0 ? void 0 : _a.schema;
65
+ }
66
+ /**
67
+ *
68
+ * @param {string} id
69
+ * @returns {boolean}
70
+ */
71
+ has(id = "default") {
72
+ return this.servers.has(id);
73
+ }
74
+ async createInstance(options, server) {
75
+ // istanbul ignore next
76
+ if (server) {
77
+ return server(options);
78
+ }
79
+ // istanbul ignore next
80
+ try {
81
+ const { ApolloServer: Server } = await import(`apollo-server-${this.platformName || "express"}`);
82
+ return new Server(options);
83
+ }
84
+ catch (er) {
85
+ this.logger.error(`Platform "${this.platformName}" not supported by @tsed/apollo`);
86
+ }
87
+ }
88
+ getPlugins(serverSettings) {
89
+ const playground = serverSettings.playground || (serverSettings.playground === undefined && process.env.NODE_ENV !== "production");
90
+ return [
91
+ playground ? ApolloServerPluginLandingPageGraphQLPlayground() : ApolloServerPluginLandingPageDisabled(),
92
+ this.httpServer &&
93
+ ApolloServerPluginDrainHttpServer({
94
+ httpServer: this.httpServer
95
+ }),
96
+ this.httpsServer &&
97
+ ApolloServerPluginDrainHttpServer({
98
+ httpServer: this.httpsServer
99
+ }),
100
+ ...(serverSettings.plugins || [])
101
+ ].filter(Boolean);
102
+ }
103
+ };
104
+ __decorate([
105
+ Constant("PLATFORM_NAME"),
106
+ __metadata("design:type", String)
107
+ ], ApolloService.prototype, "platformName", void 0);
108
+ __decorate([
109
+ Inject(),
110
+ __metadata("design:type", Logger)
111
+ ], ApolloService.prototype, "logger", void 0);
112
+ __decorate([
113
+ Inject(),
114
+ __metadata("design:type", PlatformApplication)
115
+ ], ApolloService.prototype, "app", void 0);
116
+ __decorate([
117
+ Inject(Http.Server),
118
+ __metadata("design:type", Object)
119
+ ], ApolloService.prototype, "httpServer", void 0);
120
+ __decorate([
121
+ Inject(Https.Server),
122
+ __metadata("design:type", Object)
123
+ ], ApolloService.prototype, "httpsServer", void 0);
124
+ ApolloService = __decorate([
125
+ Service()
126
+ ], ApolloService);
127
+ export { ApolloService };
128
+ //# sourceMappingURL=ApolloService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ApolloService.js","sourceRoot":"","sources":["../../../src/services/ApolloService.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAC,MAAM,UAAU,CAAC;AACnD,OAAO,EAAC,MAAM,EAAC,MAAM,cAAc,CAAC;AACpC,OAAO,EAAC,mBAAmB,EAAC,MAAM,cAAc,CAAC;AAEjD,OAAO,EAEL,iCAAiC,EACjC,qCAAqC,EACrC,8CAA8C,EAC/C,MAAM,oBAAoB,CAAC;AAI5B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,MAAM,OAAO,CAAC;AAG1B,IAAa,aAAa,GAA1B,MAAa,aAAa;IAA1B;QAOE;;;;WAIG;QACO,YAAO,GAMb,IAAI,GAAG,EAAE,CAAC;IAgHhB,CAAC;IArGC,KAAK,CAAC,YAAY,CAAC,EAAU,EAAE,QAAwB;QACrD,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;YAChB,OAAO,IAAI,CAAC,GAAG,CAAC,EAAE,CAAE,CAAC;SACtB;QAED,IAAI;YACF,MAAM,EAAC,IAAI,EAAE,iBAAiB,GAAG,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,EAAC,GAAG,QAAQ,CAAC;YAEjF,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,kCAAkC,EAAE,EAAE,CAAC,CAAC;YACzD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,IAAI,CAAC,SAAS,CAAC,EAAC,IAAI,EAAC,CAAC,E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C,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC;;kDACoB;AA3B9B,aAAa;IADzB,OAAO,EAAE;GACG,aAAa,CAkIzB;SAlIY,aAAa","sourcesContent":["import {Constant, Inject, Service} from \"@tsed/di\";\nimport {Logger} from \"@tsed/logger\";\nimport {PlatformApplication} from \"@tsed/common\";\nimport type {Config} from \"apollo-server-core\";\nimport {\n ApolloServerBase,\n ApolloServerPluginDrainHttpServer,\n ApolloServerPluginLandingPageDisabled,\n ApolloServerPluginLandingPageGraphQLPlayground\n} from \"apollo-server-core\";\nimport type {GraphQLSchema} from \"graphql\";\nimport type {ApolloServer, ApolloSettings} from \"../interfaces/ApolloSettings\";\nimport {ApolloCustomServerCB} from \"../interfaces/ApolloSettings\";\nimport Http from \"http\";\nimport Https from \"https\";\n\n@Service()\nexport class ApolloService {\n @Constant(\"PLATFORM_NAME\")\n platformName: string;\n\n @Inject()\n protected logger: Logger;\n\n /**\n *\n * @type {Map<any, any>}\n * @private\n */\n protected servers: Map<\n string,\n {\n instance: ApolloServerBase;\n schema: GraphQLSchema | undefined;\n }\n > = new Map();\n\n @Inject()\n private app: PlatformApplication<any, any>;\n\n @Inject(Http.Server)\n private httpServer: Http.Server | null;\n\n @Inject(Https.Server)\n private httpsServer: Https.Server | null;\n\n async createServer(id: string, settings: ApolloSettings): Promise<any> {\n if (this.has(id)) {\n return this.get(id)!;\n }\n\n try {\n const {path, middlewareOptions = {}, server: customServer, ...config} = settings;\n\n this.logger.info(`Create server with Apollo for: ${id}`);\n this.logger.debug(`options: ${JSON.stringify({path})}`);\n\n const server = await this.createInstance(\n {\n ...config,\n plugins: this.getPlugins(settings)\n },\n customServer\n );\n\n if (server) {\n this.servers.set(id || \"default\", {\n instance: server,\n schema: settings.schema\n });\n\n await server.start();\n\n const middleware = server.getMiddleware({\n path: settings.path,\n ...middlewareOptions\n });\n\n this.app.getRouter().use(middleware);\n\n return server;\n }\n } catch (err) {\n /* istanbul ignore next */\n this.logger.error(err);\n /* istanbul ignore next */\n process.exit(-1);\n }\n }\n\n /**\n * Get an instance of ApolloServer from his id\n * @returns ApolloServer\n */\n get(id: string = \"default\"): ApolloServerBase | undefined {\n return this.servers.get(id)?.instance;\n }\n\n /**\n * Get an instance of GraphQL schema from his id\n * @returns GraphQLSchema\n */\n getSchema(id: string = \"default\"): GraphQLSchema | undefined {\n return this.servers.get(id)?.schema;\n }\n\n /**\n *\n * @param {string} id\n * @returns {boolean}\n */\n has(id: string = \"default\"): boolean {\n return this.servers.has(id);\n }\n\n protected async createInstance(options: Config, server?: ApolloCustomServerCB): Promise<ApolloServer | undefined> {\n // istanbul ignore next\n if (server) {\n return server(options);\n }\n\n // istanbul ignore next\n try {\n const {ApolloServer: Server} = await import(`apollo-server-${this.platformName || \"express\"}`);\n\n return new Server(options);\n } catch (er) {\n this.logger.error(`Platform \"${this.platformName}\" not supported by @tsed/apollo`);\n }\n }\n\n private getPlugins(serverSettings: ApolloSettings): any[] {\n const playground = serverSettings.playground || (serverSettings.playground === undefined && process.env.NODE_ENV !== \"production\");\n\n return [\n playground ? ApolloServerPluginLandingPageGraphQLPlayground() : ApolloServerPluginLandingPageDisabled(),\n this.httpServer &&\n ApolloServerPluginDrainHttpServer({\n httpServer: this.httpServer\n }),\n this.httpsServer &&\n ApolloServerPluginDrainHttpServer({\n httpServer: this.httpsServer\n }),\n ...(serverSettings.plugins || [])\n ].filter(Boolean);\n }\n}\n"]}
@@ -1,2 +1,6 @@
1
+ /**
2
+ * @file Automatically generated by barrelsby.
3
+ */
4
+ export * from "./ApolloModule";
1
5
  export * from "./interfaces/ApolloSettings";
2
6
  export * from "./services/ApolloService";
@@ -0,0 +1,14 @@
1
+ import type { ApolloServerBase, Config, ApolloServerPluginLandingPageGraphQLPlaygroundOptions } from "apollo-server-core";
2
+ export declare type ApolloMiddlewareOptions = Record<string, any>;
3
+ export declare type ApolloServer = ApolloServerBase & {
4
+ getMiddleware(settings: ApolloMiddlewareOptions): any;
5
+ };
6
+ export declare type ApolloCustomServerCB = (config: ApolloConfig) => ApolloServer;
7
+ export declare type ApolloConfig = Config;
8
+ export interface ApolloSettings extends ApolloConfig {
9
+ path: string;
10
+ server?: ApolloCustomServerCB;
11
+ playground?: boolean | ApolloServerPluginLandingPageGraphQLPlaygroundOptions;
12
+ serverRegistration?: ApolloMiddlewareOptions;
13
+ middlewareOptions?: ApolloMiddlewareOptions;
14
+ }
@@ -1,22 +1,30 @@
1
- import { Logger } from "@tsed/common";
1
+ import { Logger } from "@tsed/logger";
2
2
  import type { Config } from "apollo-server-core";
3
+ import { ApolloServerBase } from "apollo-server-core";
3
4
  import type { GraphQLSchema } from "graphql";
4
5
  import type { ApolloServer, ApolloSettings } from "../interfaces/ApolloSettings";
6
+ import { ApolloCustomServerCB } from "../interfaces/ApolloSettings";
5
7
  export declare class ApolloService {
6
- #private;
7
8
  platformName: string;
8
- private httpPort;
9
- private httpsPort;
9
+ protected logger: Logger;
10
+ /**
11
+ *
12
+ * @type {Map<any, any>}
13
+ * @private
14
+ */
15
+ protected servers: Map<string, {
16
+ instance: ApolloServerBase;
17
+ schema: GraphQLSchema | undefined;
18
+ }>;
10
19
  private app;
11
20
  private httpServer;
12
21
  private httpsServer;
13
- protected logger: Logger;
14
22
  createServer(id: string, settings: ApolloSettings): Promise<any>;
15
23
  /**
16
24
  * Get an instance of ApolloServer from his id
17
25
  * @returns ApolloServer
18
26
  */
19
- get(id?: string): ApolloServer | undefined;
27
+ get(id?: string): ApolloServerBase | undefined;
20
28
  /**
21
29
  * Get an instance of GraphQL schema from his id
22
30
  * @returns GraphQLSchema
@@ -28,6 +36,6 @@ export declare class ApolloService {
28
36
  * @returns {boolean}
29
37
  */
30
38
  has(id?: string): boolean;
31
- protected bindServer(server: ApolloServer, options: ApolloSettings): Promise<ApolloServer>;
32
- protected createInstance(options: Config, server?: (config: Config) => ApolloServer): ApolloServer | undefined;
39
+ protected createInstance(options: Config, server?: ApolloCustomServerCB): Promise<ApolloServer | undefined>;
40
+ private getPlugins;
33
41
  }
package/package.json CHANGED
@@ -1,35 +1,57 @@
1
1
  {
2
2
  "name": "@tsed/apollo",
3
- "version": "7.0.0-alpha.1",
3
+ "version": "7.0.0-beta.10",
4
4
  "description": "Apollo package for Ts.ED framework",
5
- "main": "./lib/index.js",
6
- "typings": "./lib/index.d.ts",
5
+ "source": "./src/index.ts",
6
+ "main": "./lib/cjs/index.js",
7
+ "module": "./lib/esm/index.js",
8
+ "typings": "./lib/types/index.d.ts",
9
+ "exports": {
10
+ "types": "./lib/types/index.d.ts",
11
+ "import": "./lib/esm/index.js",
12
+ "require": "./lib/cjs/index.js",
13
+ "default": "./lib/esm/index.js"
14
+ },
7
15
  "scripts": {
8
- "build": "tsc --build tsconfig.compile.json",
9
- "start": "ts-node -r tsconfig-paths/register test/app/index.ts",
10
- "test": "cross-env NODE_ENV=test nyc mocha"
16
+ "build": "yarn barrels && yarn run build:esm && yarn run build:cjs",
17
+ "build:cjs": "tsc --build tsconfig.compile.json",
18
+ "build:esm": "tsc --build tsconfig.compile.esm.json",
19
+ "barrels": "yarn barrelsby --delete -d ./src -e \"\\.spec\\.ts\" -e \"__mock__\" -e \".benchmark.ts\"",
20
+ "test": "cross-env NODE_ENV=test jest"
11
21
  },
12
22
  "dependencies": {
13
- "tslib": "2.2.0"
23
+ "tslib": "2.3.1"
14
24
  },
15
25
  "private": false,
16
26
  "devDependencies": {
17
- "@tsed/common": "7.0.0-alpha.1",
18
- "@tsed/core": "7.0.0-alpha.1",
27
+ "@tsed/common": "7.0.0-beta.10",
28
+ "@tsed/core": "7.0.0-beta.10",
29
+ "@tsed/di": "7.0.0-beta.10",
30
+ "@tsed/logger": ">=6.1.1",
19
31
  "@types/graphql": "14.5.0",
20
- "apollo-server-core": "^2.17.0",
21
- "apollo-server-testing": "2.18.2",
22
- "graphql": "15.5.0"
32
+ "apollo-datasource": "^3.2.0",
33
+ "apollo-datasource-rest": "^3.3.0",
34
+ "apollo-server-core": "^3.4.0",
35
+ "apollo-server-express": "^3.4.0",
36
+ "apollo-server-koa": "^3.4.0",
37
+ "apollo-server-testing": "^2.25.2",
38
+ "graphql": "15.7.2"
23
39
  },
24
40
  "peerDependencies": {
25
- "apollo-server-core": "^2.17.0",
26
- "graphql": "15.5.0"
41
+ "@tsed/common": "^7.0.0-beta.10",
42
+ "@tsed/core": "^7.0.0-beta.10",
43
+ "@tsed/di": "^7.0.0-beta.10",
44
+ "@tsed/logger": ">=6.1.1",
45
+ "apollo-datasource": ">=3.0.0",
46
+ "apollo-datasource-rest": ">=3.0.0",
47
+ "apollo-server-core": ">=3.0.0",
48
+ "graphql": ">15.0.0"
27
49
  },
28
50
  "repository": "https://github.com/tsedio/tsed",
29
51
  "bugs": {
30
52
  "url": "https://github.com/tsedio/tsed/issues"
31
53
  },
32
- "homepage": "https://github.com/tsedio/tsed/tree/alpha/packages/graphql/apollo",
54
+ "homepage": "https://github.com/tsedio/tsed/tree/beta/packages/graphql/apollo",
33
55
  "author": "Romain Lenzotti",
34
56
  "license": "MIT"
35
57
  }
package/readme.md CHANGED
@@ -58,7 +58,7 @@ import "@tsed/apollo";
58
58
 
59
59
  @Configuration({
60
60
  apollo: {
61
- 'server1': {
61
+ server1: {
62
62
  path: "/",
63
63
  schema: {},
64
64
  resolvers: []
@@ -81,9 +81,9 @@ import {ApolloServer} from "apollo-server-express";
81
81
  export class UsersService implements AfterRoutesInit {
82
82
  @Injec()
83
83
  apolloService: ApolloService;
84
-
84
+
85
85
  private server: ApolloServer;
86
-
86
+
87
87
  $afterRoutesInit() {
88
88
  this.server = this.apolloService.get("server1");
89
89
  }
@@ -98,14 +98,12 @@ Please read [contributing guidelines here](https://tsed.io/CONTRIBUTING.html)
98
98
 
99
99
  <a href="https://github.com/tsedio/ts-express-decorators/graphs/contributors"><img src="https://opencollective.com/tsed/contributors.svg?width=890" /></a>
100
100
 
101
-
102
101
  ## Backers
103
102
 
104
103
  Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/tsed#backer)]
105
104
 
106
105
  <a href="https://opencollective.com/tsed#backers" target="_blank"><img src="https://opencollective.com/tsed/backers.svg?width=890"></a>
107
106
 
108
-
109
107
  ## Sponsors
110
108
 
111
109
  Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/tsed#sponsor)]
@@ -0,0 +1,12 @@
1
+ {
2
+ "extends": "./tsconfig.compile.json",
3
+ "compilerOptions": {
4
+ "baseUrl": ".",
5
+ "module": "ES2020",
6
+ "rootDir": "src",
7
+ "outDir": "./lib/esm",
8
+ "declaration": true,
9
+ "declarationDir": "./lib/types"
10
+ },
11
+ "exclude": ["node_modules", "test", "lib", "benchmark", "coverage", "spec", "**/*.benchmark.ts", "**/*.spec.ts", "keys", "jest.config.js"]
12
+ }
package/.mocharc.js DELETED
@@ -1,5 +0,0 @@
1
- module.exports = {
2
- ...require('@tsed/mocha-config')(),
3
- spec: ["{src,test}/**/*.spec.ts"],
4
- exclude: [],
5
- };
@@ -1 +0,0 @@
1
- {"version":3,"file":"ApolloModule.js","sourceRoot":"","sources":["../src/ApolloModule.ts"],"names":[],"mappings":";;;;AAAA,yCAA6G;AAC7G,iCAAiE;AAEjE,4DAAuD;AAGvD,IAAa,YAAY,GAAzB,MAAa,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,KAAK,EAAE,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE,EAAE;gBACrE,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;YACjD,CAAC,CAAC,CAAC;YAEH,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;SAC9B;IACH,CAAC;IAED,YAAY;QACV,MAAM,EAAC,QAAQ,EAAC,GAAG,IAAI,CAAC;QAExB,IAAI,QAAQ,EAAE;YACZ,MAAM,IAAI,GAAG,IAAI,CAAC,aAAa,CAAC,WAAW,EAAE,CAAC;YAE9C,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE,EAAE;gBACpD,MAAM,EAAC,IAAI,EAAC,GAAG,OAAO,CAAC;gBACvB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,GAAG,0CAA0C,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC;YAC5H,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;CACF,CAAA;AApCC;IADC,WAAM,EAAE;sCACS,eAAM;4CAAC;AAGzB;IADC,WAAM,EAAE;sCACU,6BAAa;6CAAC;AAGjC;IADC,kBAAa,EAAE;;mDACuB;AAR5B,YAAY;IADxB,WAAM,EAAE;GACI,YAAY,CAsCxB;AAtCY,oCAAY","sourcesContent":["import {AfterListen, HttpServer, HttpsServer, Logger, OnRoutesInit, PlatformApplication} from \"@tsed/common\";\nimport {Configuration, Constant, Inject, Module} from \"@tsed/di\";\nimport {ApolloServer, ApolloSettings} from \"./interfaces/ApolloSettings\";\nimport {ApolloService} from \"./services/ApolloService\";\n\n@Module()\nexport class ApolloModule implements OnRoutesInit, AfterListen {\n @Inject()\n protected logger: Logger;\n\n @Inject()\n protected service: ApolloService;\n\n @Configuration()\n protected configuration: Configuration;\n\n get settings(): {[key: string]: ApolloSettings} | undefined {\n return this.configuration.get(\"apollo\");\n }\n\n $onRoutesInit(): Promise<any> | void {\n const {settings} = this;\n\n if (settings) {\n const promises = Object.entries(settings).map(async ([key, options]) => {\n return this.service.createServer(key, options);\n });\n\n return Promise.all(promises);\n }\n }\n\n $afterListen(): Promise<any> | void {\n const {settings} = this;\n\n if (settings) {\n const host = this.configuration.getHttpPort();\n\n Object.entries(settings).map(async ([key, options]) => {\n const {path} = options;\n this.logger.info(`[${key}] Apollo server is available on http://${host.address}:${host.port}/${path.replace(/^\\//, \"\")}`);\n });\n }\n }\n}\n"]}
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,sEAA4C;AAC5C,mEAAyC","sourcesContent":["export * from \"./interfaces/ApolloSettings\";\nexport * from \"./services/ApolloService\";\n"]}
@@ -1,11 +0,0 @@
1
- import type { Config } from "apollo-server-core";
2
- import type { ApolloServerBase } from "apollo-server-core";
3
- export declare type ApolloServer = ApolloServerBase & {
4
- applyMiddleware(settings: any): any;
5
- };
6
- export interface ApolloSettings extends Config {
7
- path: string;
8
- server?: (config: Config) => ApolloServer;
9
- serverRegistration?: Record<string, any>;
10
- installSubscriptionHandlers?: boolean;
11
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"ApolloSettings.js","sourceRoot":"","sources":["../../src/interfaces/ApolloSettings.ts"],"names":[],"mappings":"","sourcesContent":["import type {Config} from \"apollo-server-core\";\nimport type {ApolloServerBase} from \"apollo-server-core\";\n\nexport type ApolloServer = ApolloServerBase & {applyMiddleware(settings: any): any};\n\nexport interface ApolloSettings extends Config {\n // Basic options\n path: string;\n server?: (config: Config) => ApolloServer;\n\n // apollo-server-express\n // apollo-server-express options\n // See options descriptions on https://www.apollographql.com/docs/apollo-server/api/apollo-server.html\n serverRegistration?: Record<string, any>;\n installSubscriptionHandlers?: boolean;\n}\n"]}
@@ -1,120 +0,0 @@
1
- "use strict";
2
- var _servers;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.ApolloService = void 0;
5
- const tslib_1 = require("tslib");
6
- const common_1 = require("@tsed/common");
7
- let ApolloService = class ApolloService {
8
- constructor() {
9
- /**
10
- *
11
- * @type {Map<any, any>}
12
- * @private
13
- */
14
- _servers.set(this, new Map());
15
- }
16
- async createServer(id, settings) {
17
- if (this.has(id)) {
18
- return this.get(id);
19
- }
20
- try {
21
- const { path, installSubscriptionHandlers, serverRegistration = {}, server: customServer, ...serverSettings } = settings;
22
- this.logger.info(`Create server with Apollo for: ${id}`);
23
- this.logger.debug(`options: ${JSON.stringify({ path })}`);
24
- const server = this.createInstance(serverSettings, customServer);
25
- if (server) {
26
- tslib_1.__classPrivateFieldGet(this, _servers).set(id || "default", {
27
- instance: server,
28
- schema: settings.schema
29
- });
30
- return this.bindServer(server, settings);
31
- }
32
- }
33
- catch (err) {
34
- /* istanbul ignore next */
35
- this.logger.error(err);
36
- /* istanbul ignore next */
37
- process.exit(-1);
38
- }
39
- }
40
- /**
41
- * Get an instance of ApolloServer from his id
42
- * @returns ApolloServer
43
- */
44
- get(id = "default") {
45
- var _a;
46
- return (_a = tslib_1.__classPrivateFieldGet(this, _servers).get(id)) === null || _a === void 0 ? void 0 : _a.instance;
47
- }
48
- /**
49
- * Get an instance of GraphQL schema from his id
50
- * @returns GraphQLSchema
51
- */
52
- getSchema(id = "default") {
53
- var _a;
54
- return (_a = tslib_1.__classPrivateFieldGet(this, _servers).get(id)) === null || _a === void 0 ? void 0 : _a.schema;
55
- }
56
- /**
57
- *
58
- * @param {string} id
59
- * @returns {boolean}
60
- */
61
- has(id = "default") {
62
- return tslib_1.__classPrivateFieldGet(this, _servers).has(id);
63
- }
64
- async bindServer(server, options) {
65
- await server.applyMiddleware({ path: options.path, ...options.serverRegistration, app: this.app.raw });
66
- if (options.installSubscriptionHandlers && (this.httpPort || this.httpsPort)) {
67
- this.httpPort && server.installSubscriptionHandlers(this.httpServer);
68
- this.httpPort && server.installSubscriptionHandlers(this.httpsServer);
69
- }
70
- return server;
71
- }
72
- createInstance(options, server) {
73
- // istanbul ignore next
74
- if (server) {
75
- return server(options);
76
- }
77
- // istanbul ignore next
78
- try {
79
- const Server = require(`apollo-server-${this.platformName || "express"}`).ApolloServer;
80
- return new Server(options);
81
- }
82
- catch (er) {
83
- this.logger.error(`Platform "${this.platformName}" not supported by @tsed/apollo`);
84
- }
85
- }
86
- };
87
- _servers = new WeakMap();
88
- tslib_1.__decorate([
89
- common_1.Constant("PLATFORM_NAME"),
90
- tslib_1.__metadata("design:type", String)
91
- ], ApolloService.prototype, "platformName", void 0);
92
- tslib_1.__decorate([
93
- common_1.Constant("httpPort"),
94
- tslib_1.__metadata("design:type", Object)
95
- ], ApolloService.prototype, "httpPort", void 0);
96
- tslib_1.__decorate([
97
- common_1.Constant("httpsPort"),
98
- tslib_1.__metadata("design:type", Object)
99
- ], ApolloService.prototype, "httpsPort", void 0);
100
- tslib_1.__decorate([
101
- common_1.Inject(),
102
- tslib_1.__metadata("design:type", common_1.PlatformApplication)
103
- ], ApolloService.prototype, "app", void 0);
104
- tslib_1.__decorate([
105
- common_1.Inject(common_1.HttpServer),
106
- tslib_1.__metadata("design:type", Object)
107
- ], ApolloService.prototype, "httpServer", void 0);
108
- tslib_1.__decorate([
109
- common_1.Inject(common_1.HttpsServer),
110
- tslib_1.__metadata("design:type", Object)
111
- ], ApolloService.prototype, "httpsServer", void 0);
112
- tslib_1.__decorate([
113
- common_1.Inject(),
114
- tslib_1.__metadata("design:type", common_1.Logger)
115
- ], ApolloService.prototype, "logger", void 0);
116
- ApolloService = tslib_1.__decorate([
117
- common_1.Service()
118
- ], ApolloService);
119
- exports.ApolloService = ApolloService;
120
- //# sourceMappingURL=ApolloService.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ApolloService.js","sourceRoot":"","sources":["../../src/services/ApolloService.ts"],"names":[],"mappings":";;;;;AAAA,yCAA6G;AAM7G,IAAa,aAAa,GAA1B,MAAa,aAAa;IAA1B;QAsBE;;;;WAIG;QACH,mBAMI,IAAI,GAAG,EAAE,EAAC;IAkFhB,CAAC;IAhFC,KAAK,CAAC,YAAY,CAAC,EAAU,EAAE,QAAwB;Q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0CAAC;AAGjC;IADC,eAAM,CAAC,mBAAU,CAAC;;iDACY;AAG/B;IADC,eAAM,CAAC,oBAAW,CAAC;;kDACa;AAGjC;IADC,eAAM,EAAE;sCACS,eAAM;6CAAC;AApBd,aAAa;IADzB,gBAAO,EAAE;GACG,aAAa,CAmHzB;AAnHY,sCAAa","sourcesContent":["import {Constant, HttpServer, HttpsServer, Inject, Logger, PlatformApplication, Service} from \"@tsed/common\";\nimport type {Config} from \"apollo-server-core\";\nimport type {GraphQLSchema} from \"graphql\";\nimport type {ApolloServer, ApolloSettings} from \"../interfaces/ApolloSettings\";\n\n@Service()\nexport class ApolloService {\n @Constant(\"PLATFORM_NAME\")\n platformName: string;\n\n @Constant(\"httpPort\")\n private httpPort: string | number;\n\n @Constant(\"httpsPort\")\n private httpsPort: string | number;\n\n @Inject()\n private app: PlatformApplication;\n\n @Inject(HttpServer)\n private httpServer: HttpServer;\n\n @Inject(HttpsServer)\n private httpsServer: HttpsServer;\n\n @Inject()\n protected logger: Logger;\n\n /**\n *\n * @type {Map<any, any>}\n * @private\n */\n #servers: Map<\n string,\n {\n instance: ApolloServer;\n schema: GraphQLSchema | undefined;\n }\n > = new Map();\n\n async createServer(id: string, settings: ApolloSettings): Promise<any> {\n if (this.has(id)) {\n return this.get(id)!;\n }\n\n try {\n const {path, installSubscriptionHandlers, serverRegistration = {}, server: customServer, ...serverSettings} = settings;\n\n this.logger.info(`Create server with Apollo for: ${id}`);\n this.logger.debug(`options: ${JSON.stringify({path})}`);\n\n const server = this.createInstance(serverSettings, customServer);\n\n if (server) {\n this.#servers.set(id || \"default\", {\n instance: server,\n schema: settings.schema\n });\n\n return this.bindServer(server, settings);\n }\n } catch (err) {\n /* istanbul ignore next */\n this.logger.error(err);\n /* istanbul ignore next */\n process.exit(-1);\n }\n }\n\n /**\n * Get an instance of ApolloServer from his id\n * @returns ApolloServer\n */\n get(id: string = \"default\"): ApolloServer | undefined {\n return this.#servers.get(id)?.instance;\n }\n\n /**\n * Get an instance of GraphQL schema from his id\n * @returns GraphQLSchema\n */\n getSchema(id: string = \"default\"): GraphQLSchema | undefined {\n return this.#servers.get(id)?.schema;\n }\n\n /**\n *\n * @param {string} id\n * @returns {boolean}\n */\n has(id: string = \"default\"): boolean {\n return this.#servers.has(id);\n }\n\n protected async bindServer(server: ApolloServer, options: ApolloSettings) {\n await server.applyMiddleware({path: options.path, ...options.serverRegistration, app: this.app.raw});\n\n if (options.installSubscriptionHandlers && (this.httpPort || this.httpsPort)) {\n this.httpPort && server.installSubscriptionHandlers(this.httpServer);\n this.httpPort && server.installSubscriptionHandlers(this.httpsServer);\n }\n\n return server;\n }\n\n protected createInstance(options: Config, server?: (config: Config) => ApolloServer): ApolloServer | undefined {\n // istanbul ignore next\n if (server) {\n return server(options);\n }\n\n // istanbul ignore next\n try {\n const Server = require(`apollo-server-${this.platformName || \"express\"}`).ApolloServer;\n\n return new Server(options);\n } catch (er) {\n this.logger.error(`Platform \"${this.platformName}\" not supported by @tsed/apollo`);\n }\n }\n}\n"]}