@tsed/apollo 6.90.0 → 6.93.0
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/services/ApolloService.d.ts +0 -2
- package/lib/cjs/services/ApolloService.js +6 -12
- package/lib/cjs/services/ApolloService.js.map +1 -1
- package/lib/esm/services/ApolloService.js +7 -13
- package/lib/esm/services/ApolloService.js.map +1 -1
- package/lib/types/services/ApolloService.d.ts +0 -2
- package/package.json +7 -7
|
@@ -6,6 +6,8 @@ const di_1 = require("@tsed/di");
|
|
|
6
6
|
const logger_1 = require("@tsed/logger");
|
|
7
7
|
const common_1 = require("@tsed/common");
|
|
8
8
|
const apollo_server_core_1 = require("apollo-server-core");
|
|
9
|
+
const http_1 = (0, tslib_1.__importDefault)(require("http"));
|
|
10
|
+
const https_1 = (0, tslib_1.__importDefault)(require("https"));
|
|
9
11
|
let ApolloService = class ApolloService {
|
|
10
12
|
constructor() {
|
|
11
13
|
/**
|
|
@@ -92,11 +94,11 @@ let ApolloService = class ApolloService {
|
|
|
92
94
|
playground && process.env.NODE_ENV === "production"
|
|
93
95
|
? (0, apollo_server_core_1.ApolloServerPluginLandingPageDisabled)()
|
|
94
96
|
: (0, apollo_server_core_1.ApolloServerPluginLandingPageGraphQLPlayground)(),
|
|
95
|
-
this.
|
|
97
|
+
this.httpServer &&
|
|
96
98
|
(0, apollo_server_core_1.ApolloServerPluginDrainHttpServer)({
|
|
97
99
|
httpServer: this.httpServer
|
|
98
100
|
}),
|
|
99
|
-
this.
|
|
101
|
+
this.httpsServer &&
|
|
100
102
|
(0, apollo_server_core_1.ApolloServerPluginDrainHttpServer)({
|
|
101
103
|
httpServer: this.httpsServer
|
|
102
104
|
}),
|
|
@@ -112,24 +114,16 @@ let ApolloService = class ApolloService {
|
|
|
112
114
|
(0, di_1.Inject)(),
|
|
113
115
|
(0, tslib_1.__metadata)("design:type", logger_1.Logger)
|
|
114
116
|
], ApolloService.prototype, "logger", void 0);
|
|
115
|
-
(0, tslib_1.__decorate)([
|
|
116
|
-
(0, di_1.Constant)("httpPort"),
|
|
117
|
-
(0, tslib_1.__metadata)("design:type", Object)
|
|
118
|
-
], ApolloService.prototype, "httpPort", void 0);
|
|
119
|
-
(0, tslib_1.__decorate)([
|
|
120
|
-
(0, di_1.Constant)("httpsPort"),
|
|
121
|
-
(0, tslib_1.__metadata)("design:type", Object)
|
|
122
|
-
], ApolloService.prototype, "httpsPort", void 0);
|
|
123
117
|
(0, tslib_1.__decorate)([
|
|
124
118
|
(0, di_1.Inject)(),
|
|
125
119
|
(0, tslib_1.__metadata)("design:type", common_1.PlatformApplication)
|
|
126
120
|
], ApolloService.prototype, "app", void 0);
|
|
127
121
|
(0, tslib_1.__decorate)([
|
|
128
|
-
(0, di_1.Inject)(
|
|
122
|
+
(0, di_1.Inject)(http_1.default.Server),
|
|
129
123
|
(0, tslib_1.__metadata)("design:type", Object)
|
|
130
124
|
], ApolloService.prototype, "httpServer", void 0);
|
|
131
125
|
(0, tslib_1.__decorate)([
|
|
132
|
-
(0, di_1.Inject)(
|
|
126
|
+
(0, di_1.Inject)(https_1.default.Server),
|
|
133
127
|
(0, tslib_1.__metadata)("design:type", Object)
|
|
134
128
|
], ApolloService.prototype, "httpsServer", void 0);
|
|
135
129
|
ApolloService = (0, tslib_1.__decorate)([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApolloService.js","sourceRoot":"","sources":["../../../src/services/ApolloService.ts"],"names":[],"mappings":";;;;AAAA,iCAAmD;AACnD,yCAAoC;AACpC,
|
|
1
|
+
{"version":3,"file":"ApolloService.js","sourceRoot":"","sources":["../../../src/services/ApolloService.ts"],"names":[],"mappings":";;;;AAAA,iCAAmD;AACnD,yCAAoC;AACpC,yCAAiD;AAEjD,2DAK4B;AAI5B,6DAAwB;AACxB,+DAA0B;AAG1B,IAAa,aAAa,GAA1B,MAAa,aAAa;IAA1B;QAOE;;;;WAIG;QACO,YAAO,GAMb,IA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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;AAjIC;IADC,IAAA,aAAQ,EAAC,eAAe,CAAC;;mDACL;AAGrB;IADC,IAAA,WAAM,GAAE;2CACS,eAAM;6CAAC;AAgBzB;IADC,IAAA,WAAM,GAAE;2CACI,4BAAmB;0CAAC;AAGjC;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,CAmIzB;AAnIY,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;\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 = 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 await server.applyMiddleware({\n path: settings.path,\n ...middlewareOptions,\n app: this.app.raw\n });\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 createInstance(options: Config, server?: ApolloCustomServerCB): 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 private getPlugins(serverSettings: ApolloSettings): any[] {\n const playground = serverSettings.playground || serverSettings.playground === undefined;\n\n return [\n playground && process.env.NODE_ENV === \"production\"\n ? ApolloServerPluginLandingPageDisabled()\n : ApolloServerPluginLandingPageGraphQLPlayground(),\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,8 +1,10 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
2
|
import { Constant, Inject, Service } from "@tsed/di";
|
|
3
3
|
import { Logger } from "@tsed/logger";
|
|
4
|
-
import {
|
|
4
|
+
import { PlatformApplication } from "@tsed/common";
|
|
5
5
|
import { ApolloServerPluginDrainHttpServer, ApolloServerPluginLandingPageDisabled, ApolloServerPluginLandingPageGraphQLPlayground } from "apollo-server-core";
|
|
6
|
+
import Http from "http";
|
|
7
|
+
import Https from "https";
|
|
6
8
|
let ApolloService = class ApolloService {
|
|
7
9
|
constructor() {
|
|
8
10
|
/**
|
|
@@ -89,11 +91,11 @@ let ApolloService = class ApolloService {
|
|
|
89
91
|
playground && process.env.NODE_ENV === "production"
|
|
90
92
|
? ApolloServerPluginLandingPageDisabled()
|
|
91
93
|
: ApolloServerPluginLandingPageGraphQLPlayground(),
|
|
92
|
-
this.
|
|
94
|
+
this.httpServer &&
|
|
93
95
|
ApolloServerPluginDrainHttpServer({
|
|
94
96
|
httpServer: this.httpServer
|
|
95
97
|
}),
|
|
96
|
-
this.
|
|
98
|
+
this.httpsServer &&
|
|
97
99
|
ApolloServerPluginDrainHttpServer({
|
|
98
100
|
httpServer: this.httpsServer
|
|
99
101
|
}),
|
|
@@ -109,24 +111,16 @@ __decorate([
|
|
|
109
111
|
Inject(),
|
|
110
112
|
__metadata("design:type", Logger)
|
|
111
113
|
], ApolloService.prototype, "logger", void 0);
|
|
112
|
-
__decorate([
|
|
113
|
-
Constant("httpPort"),
|
|
114
|
-
__metadata("design:type", Object)
|
|
115
|
-
], ApolloService.prototype, "httpPort", void 0);
|
|
116
|
-
__decorate([
|
|
117
|
-
Constant("httpsPort"),
|
|
118
|
-
__metadata("design:type", Object)
|
|
119
|
-
], ApolloService.prototype, "httpsPort", void 0);
|
|
120
114
|
__decorate([
|
|
121
115
|
Inject(),
|
|
122
116
|
__metadata("design:type", PlatformApplication)
|
|
123
117
|
], ApolloService.prototype, "app", void 0);
|
|
124
118
|
__decorate([
|
|
125
|
-
Inject(
|
|
119
|
+
Inject(Http.Server),
|
|
126
120
|
__metadata("design:type", Object)
|
|
127
121
|
], ApolloService.prototype, "httpServer", void 0);
|
|
128
122
|
__decorate([
|
|
129
|
-
Inject(
|
|
123
|
+
Inject(Https.Server),
|
|
130
124
|
__metadata("design:type", Object)
|
|
131
125
|
], ApolloService.prototype, "httpsServer", void 0);
|
|
132
126
|
ApolloService = __decorate([
|
|
@@ -1 +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,
|
|
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;IAiHhB,CAAC;IAtGC,KAAK,CAAC,YAAY,CAAC,EAAU,EAAE,QAAwB;QACrD,IAAI,IAAI,C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AAC,cAAc,CAAC,OAAO,IAAI,EAAE,CAAC;SAClC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;IACpB,CAAC;CACF,CAAA;AAjIC;IADC,QAAQ,CAAC,eAAe,CAAC;;mDACL;AAGrB;IADC,MAAM,EAAE;8BACS,MAAM;6CAAC;AAgBzB;IADC,MAAM,EAAE;8BACI,mBAAmB;0CAAC;AAGjC;IADC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;;iDACmB;AAGvC;IADC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC;;kDACoB;AA3B9B,aAAa;IADzB,OAAO,EAAE;GACG,aAAa,CAmIzB;SAnIY,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;\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 = 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 await server.applyMiddleware({\n path: settings.path,\n ...middlewareOptions,\n app: this.app.raw\n });\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 createInstance(options: Config, server?: ApolloCustomServerCB): 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 private getPlugins(serverSettings: ApolloSettings): any[] {\n const playground = serverSettings.playground || serverSettings.playground === undefined;\n\n return [\n playground && process.env.NODE_ENV === \"production\"\n ? ApolloServerPluginLandingPageDisabled()\n : ApolloServerPluginLandingPageGraphQLPlayground(),\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": "6.
|
|
3
|
+
"version": "6.93.0",
|
|
4
4
|
"description": "Apollo package for Ts.ED framework",
|
|
5
5
|
"source": "./src/index.ts",
|
|
6
6
|
"main": "./lib/cjs/index.js",
|
|
@@ -22,9 +22,9 @@
|
|
|
22
22
|
},
|
|
23
23
|
"private": false,
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@tsed/common": "6.
|
|
26
|
-
"@tsed/core": "6.
|
|
27
|
-
"@tsed/di": "6.
|
|
25
|
+
"@tsed/common": "6.93.0",
|
|
26
|
+
"@tsed/core": "6.93.0",
|
|
27
|
+
"@tsed/di": "6.93.0",
|
|
28
28
|
"@tsed/logger": "^6.0.0",
|
|
29
29
|
"@types/graphql": "14.5.0",
|
|
30
30
|
"apollo-datasource": "^3.2.0",
|
|
@@ -36,9 +36,9 @@
|
|
|
36
36
|
"graphql": "15.7.2"
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"@tsed/common": "^6.
|
|
40
|
-
"@tsed/core": "^6.
|
|
41
|
-
"@tsed/di": "^6.
|
|
39
|
+
"@tsed/common": "^6.93.0",
|
|
40
|
+
"@tsed/core": "^6.93.0",
|
|
41
|
+
"@tsed/di": "^6.93.0",
|
|
42
42
|
"@tsed/logger": ">6.0.0",
|
|
43
43
|
"apollo-datasource": ">=3.0.0",
|
|
44
44
|
"apollo-datasource-rest": ">=3.0.0",
|