@tsed/apollo 7.0.0-beta.12 → 7.0.0-beta.15
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.
- package/lib/cjs/ApolloModule.js +3 -0
- package/lib/cjs/ApolloModule.js.map +1 -1
- package/lib/cjs/services/ApolloService.js +15 -14
- package/lib/cjs/services/ApolloService.js.map +1 -1
- package/lib/esm/ApolloModule.js +3 -0
- package/lib/esm/ApolloModule.js.map +1 -1
- package/lib/esm/services/ApolloService.js +15 -14
- package/lib/esm/services/ApolloService.js.map +1 -1
- package/package.json +10 -10
- package/readme.md +1 -1
package/lib/cjs/ApolloModule.js
CHANGED
|
@@ -6,6 +6,9 @@ const common_1 = require("@tsed/common");
|
|
|
6
6
|
const di_1 = require("@tsed/di");
|
|
7
7
|
const ApolloService_1 = require("./services/ApolloService");
|
|
8
8
|
let ApolloModule = class ApolloModule {
|
|
9
|
+
logger;
|
|
10
|
+
service;
|
|
11
|
+
configuration;
|
|
9
12
|
get settings() {
|
|
10
13
|
return this.configuration.get("apollo");
|
|
11
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApolloModule.js","sourceRoot":"","sources":["../../src/ApolloModule.ts"],"names":[],"mappings":";;;;AAAA,yCAA+D;AAC/D,iCAAuD;AAEvD,4DAAuD;AAGvD,IAAa,YAAY,GAAzB,MAAa,YAAY;
|
|
1
|
+
{"version":3,"file":"ApolloModule.js","sourceRoot":"","sources":["../../src/ApolloModule.ts"],"names":[],"mappings":";;;;AAAA,yCAA+D;AAC/D,iCAAuD;AAEvD,4DAAuD;AAGvD,IAAa,YAAY,GAAzB,MAAa,YAAY;IAEb,MAAM,CAAS;IAGf,OAAO,CAAgB;IAGvB,aAAa,CAAgB;IAEvC,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC1C,CAAC;IAED,aAAa;QACX,MAAM,EAAC,QAA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AAM;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"]}
|
|
@@ -2,21 +2,24 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ApolloService = void 0;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const common_1 = require("@tsed/common");
|
|
5
6
|
const di_1 = require("@tsed/di");
|
|
6
7
|
const logger_1 = require("@tsed/logger");
|
|
7
|
-
const common_1 = require("@tsed/common");
|
|
8
8
|
const apollo_server_core_1 = require("apollo-server-core");
|
|
9
9
|
const http_1 = tslib_1.__importDefault(require("http"));
|
|
10
10
|
const https_1 = tslib_1.__importDefault(require("https"));
|
|
11
11
|
let ApolloService = class ApolloService {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
platformName;
|
|
13
|
+
logger;
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* @type {Map<any, any>}
|
|
17
|
+
* @private
|
|
18
|
+
*/
|
|
19
|
+
servers = new Map();
|
|
20
|
+
app;
|
|
21
|
+
httpServer;
|
|
22
|
+
httpsServer;
|
|
20
23
|
async createServer(id, settings) {
|
|
21
24
|
if (this.has(id)) {
|
|
22
25
|
return this.get(id);
|
|
@@ -39,7 +42,7 @@ let ApolloService = class ApolloService {
|
|
|
39
42
|
path: settings.path,
|
|
40
43
|
...middlewareOptions
|
|
41
44
|
});
|
|
42
|
-
this.app.
|
|
45
|
+
this.app.use(middleware);
|
|
43
46
|
return server;
|
|
44
47
|
}
|
|
45
48
|
}
|
|
@@ -55,16 +58,14 @@ let ApolloService = class ApolloService {
|
|
|
55
58
|
* @returns ApolloServer
|
|
56
59
|
*/
|
|
57
60
|
get(id = "default") {
|
|
58
|
-
|
|
59
|
-
return (_a = this.servers.get(id)) === null || _a === void 0 ? void 0 : _a.instance;
|
|
61
|
+
return this.servers.get(id)?.instance;
|
|
60
62
|
}
|
|
61
63
|
/**
|
|
62
64
|
* Get an instance of GraphQL schema from his id
|
|
63
65
|
* @returns GraphQLSchema
|
|
64
66
|
*/
|
|
65
67
|
getSchema(id = "default") {
|
|
66
|
-
|
|
67
|
-
return (_a = this.servers.get(id)) === null || _a === void 0 ? void 0 : _a.schema;
|
|
68
|
+
return this.servers.get(id)?.schema;
|
|
68
69
|
}
|
|
69
70
|
/**
|
|
70
71
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApolloService.js","sourceRoot":"","sources":["../../../src/services/ApolloService.ts"],"names":[],"mappings":";;;;AAAA,iCAAmD;AACnD,yCAAoC;
|
|
1
|
+
{"version":3,"file":"ApolloService.js","sourceRoot":"","sources":["../../../src/services/ApolloService.ts"],"names":[],"mappings":";;;;AAAA,yCAAiD;AACjD,iCAAmD;AACnD,yCAAoC;AAEpC,2DAK4B;AAE5B,wDAAwB;AACxB,0DAA0B;AAK1B,IAAa,aAAa,GAA1B,MAAa,aAAa;IAExB,YAAY,CAAS;IAGX,MAAM,CAAS;IAEzB;;;;OAIG;IACO,OAAO,GAMb,IAAI,GAAG,EAAE,CAAC;IAGN,GAAG,CAA2B;IAG9B,UAAU,CAAqB;IAG/B,WAAW,CAAsB;IAEzC,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;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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;0CAAM;AAGtC;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 {PlatformApplication} from \"@tsed/common\";\nimport {Constant, Inject, Service} from \"@tsed/di\";\nimport {Logger} from \"@tsed/logger\";\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 Http from \"http\";\nimport Https from \"https\";\nimport type {ApolloServer, ApolloSettings} from \"../interfaces/ApolloSettings\";\nimport {ApolloCustomServerCB} from \"../interfaces/ApolloSettings\";\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>;\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.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"]}
|
package/lib/esm/ApolloModule.js
CHANGED
|
@@ -3,6 +3,9 @@ import { Logger } from "@tsed/common";
|
|
|
3
3
|
import { Configuration, Inject, Module } from "@tsed/di";
|
|
4
4
|
import { ApolloService } from "./services/ApolloService.js";
|
|
5
5
|
let ApolloModule = class ApolloModule {
|
|
6
|
+
logger;
|
|
7
|
+
service;
|
|
8
|
+
configuration;
|
|
6
9
|
get settings() {
|
|
7
10
|
return this.configuration.get("apollo");
|
|
8
11
|
}
|
|
@@ -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,0BAA0B,CAAC;AAGvD,IAAa,YAAY,GAAzB,MAAa,YAAY;
|
|
1
|
+
{"version":3,"file":"ApolloModule.js","sourceRoot":"","sources":["../../src/ApolloModule.ts"],"names":[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AAC,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"]}
|
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
|
+
import { PlatformApplication } from "@tsed/common";
|
|
2
3
|
import { Constant, Inject, Service } from "@tsed/di";
|
|
3
4
|
import { Logger } from "@tsed/logger";
|
|
4
|
-
import { PlatformApplication } from "@tsed/common";
|
|
5
5
|
import { ApolloServerPluginDrainHttpServer, ApolloServerPluginLandingPageDisabled, ApolloServerPluginLandingPageGraphQLPlayground } from "apollo-server-core";
|
|
6
6
|
import Http from "http";
|
|
7
7
|
import Https from "https";
|
|
8
8
|
let ApolloService = class ApolloService {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
platformName;
|
|
10
|
+
logger;
|
|
11
|
+
/**
|
|
12
|
+
*
|
|
13
|
+
* @type {Map<any, any>}
|
|
14
|
+
* @private
|
|
15
|
+
*/
|
|
16
|
+
servers = new Map();
|
|
17
|
+
app;
|
|
18
|
+
httpServer;
|
|
19
|
+
httpsServer;
|
|
17
20
|
async createServer(id, settings) {
|
|
18
21
|
if (this.has(id)) {
|
|
19
22
|
return this.get(id);
|
|
@@ -36,7 +39,7 @@ let ApolloService = class ApolloService {
|
|
|
36
39
|
path: settings.path,
|
|
37
40
|
...middlewareOptions
|
|
38
41
|
});
|
|
39
|
-
this.app.
|
|
42
|
+
this.app.use(middleware);
|
|
40
43
|
return server;
|
|
41
44
|
}
|
|
42
45
|
}
|
|
@@ -52,16 +55,14 @@ let ApolloService = class ApolloService {
|
|
|
52
55
|
* @returns ApolloServer
|
|
53
56
|
*/
|
|
54
57
|
get(id = "default") {
|
|
55
|
-
|
|
56
|
-
return (_a = this.servers.get(id)) === null || _a === void 0 ? void 0 : _a.instance;
|
|
58
|
+
return this.servers.get(id)?.instance;
|
|
57
59
|
}
|
|
58
60
|
/**
|
|
59
61
|
* Get an instance of GraphQL schema from his id
|
|
60
62
|
* @returns GraphQLSchema
|
|
61
63
|
*/
|
|
62
64
|
getSchema(id = "default") {
|
|
63
|
-
|
|
64
|
-
return (_a = this.servers.get(id)) === null || _a === void 0 ? void 0 : _a.schema;
|
|
65
|
+
return this.servers.get(id)?.schema;
|
|
65
66
|
}
|
|
66
67
|
/**
|
|
67
68
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApolloService.js","sourceRoot":"","sources":["../../../src/services/ApolloService.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,
|
|
1
|
+
{"version":3,"file":"ApolloService.js","sourceRoot":"","sources":["../../../src/services/ApolloService.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,mBAAmB,EAAC,MAAM,cAAc,CAAC;AACjD,OAAO,EAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAC,MAAM,UAAU,CAAC;AACnD,OAAO,EAAC,MAAM,EAAC,MAAM,cAAc,CAAC;AAEpC,OAAO,EAEL,iCAAiC,EACjC,qCAAqC,EACrC,8CAA8C,EAC/C,MAAM,oBAAoB,CAAC;AAE5B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,MAAM,OAAO,CAAC;AAK1B,IAAa,aAAa,GAA1B,MAAa,aAAa;IAExB,YAAY,CAAS;IAGX,MAAM,CAAS;IAEzB;;;;OAIG;IACO,OAAO,GAMb,IAAI,GAAG,EAAE,CAAC;IAGN,GAAG,CAA2B;IAG9B,UAAU,CAAqB;IAG/B,WAAW,CAAsB;IAEzC,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,MA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hIC;IADC,QAAQ,CAAC,eAAe,CAAC;;mDACL;AAGrB;IADC,MAAM,EAAE;8BACS,MAAM;6CAAC;AAgBzB;IADC,MAAM,EAAE;8BACI,mBAAmB;0CAAM;AAGtC;IADC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;;iDACmB;AAGvC;IADC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC;;kDACoB;AA3B9B,aAAa;IADzB,OAAO,EAAE;GACG,aAAa,CAkIzB;SAlIY,aAAa","sourcesContent":["import {PlatformApplication} from \"@tsed/common\";\nimport {Constant, Inject, Service} from \"@tsed/di\";\nimport {Logger} from \"@tsed/logger\";\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 Http from \"http\";\nimport Https from \"https\";\nimport type {ApolloServer, ApolloSettings} from \"../interfaces/ApolloSettings\";\nimport {ApolloCustomServerCB} from \"../interfaces/ApolloSettings\";\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>;\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.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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/apollo",
|
|
3
|
-
"version": "7.0.0-beta.
|
|
3
|
+
"version": "7.0.0-beta.15",
|
|
4
4
|
"description": "Apollo package for Ts.ED framework",
|
|
5
5
|
"source": "./src/index.ts",
|
|
6
6
|
"main": "./lib/cjs/index.js",
|
|
@@ -20,14 +20,14 @@
|
|
|
20
20
|
"test": "cross-env NODE_ENV=test jest"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"tslib": "2.
|
|
23
|
+
"tslib": "2.4.0"
|
|
24
24
|
},
|
|
25
25
|
"private": false,
|
|
26
26
|
"devDependencies": {
|
|
27
|
-
"@tsed/common": "7.0.0-beta.
|
|
28
|
-
"@tsed/core": "7.0.0-beta.
|
|
29
|
-
"@tsed/di": "7.0.0-beta.
|
|
30
|
-
"@tsed/logger": ">=6.
|
|
27
|
+
"@tsed/common": "7.0.0-beta.15",
|
|
28
|
+
"@tsed/core": "7.0.0-beta.15",
|
|
29
|
+
"@tsed/di": "7.0.0-beta.15",
|
|
30
|
+
"@tsed/logger": ">=6.2.0",
|
|
31
31
|
"@types/graphql": "14.5.0",
|
|
32
32
|
"apollo-datasource": "^3.2.0",
|
|
33
33
|
"apollo-datasource-rest": "^3.3.0",
|
|
@@ -38,10 +38,10 @@
|
|
|
38
38
|
"graphql": "15.7.2"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"@tsed/common": "^7.0.0-beta.
|
|
42
|
-
"@tsed/core": "^7.0.0-beta.
|
|
43
|
-
"@tsed/di": "^7.0.0-beta.
|
|
44
|
-
"@tsed/logger": ">=6.
|
|
41
|
+
"@tsed/common": "^7.0.0-beta.15",
|
|
42
|
+
"@tsed/core": "^7.0.0-beta.15",
|
|
43
|
+
"@tsed/di": "^7.0.0-beta.15",
|
|
44
|
+
"@tsed/logger": ">=6.2.0",
|
|
45
45
|
"apollo-datasource": ">=3.0.0",
|
|
46
46
|
"apollo-datasource-rest": ">=3.0.0",
|
|
47
47
|
"apollo-server-core": ">=3.0.0",
|
package/readme.md
CHANGED
|
@@ -113,7 +113,7 @@ Support this project by becoming a sponsor. Your logo will show up here with a l
|
|
|
113
113
|
|
|
114
114
|
The MIT License (MIT)
|
|
115
115
|
|
|
116
|
-
Copyright (c) 2016 -
|
|
116
|
+
Copyright (c) 2016 - 2022 Romain Lenzotti
|
|
117
117
|
|
|
118
118
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
119
119
|
|