@tsed/apollo 7.81.0-rc.1 → 7.81.1
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/.nycrc +26 -0
- package/lib/cjs/ApolloModule.js +7 -13
- package/lib/cjs/ApolloModule.js.map +1 -1
- package/lib/cjs/constants/constants.js +1 -2
- package/lib/cjs/constants/constants.js.map +1 -1
- package/lib/cjs/decorators/dataSource.js +2 -2
- package/lib/cjs/index.js +0 -5
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/services/ApolloService.js +55 -72
- package/lib/cjs/services/ApolloService.js.map +1 -1
- package/lib/esm/ApolloModule.js +8 -14
- package/lib/esm/ApolloModule.js.map +1 -1
- package/lib/esm/constants/constants.js +0 -1
- package/lib/esm/constants/constants.js.map +1 -1
- package/lib/esm/decorators/dataSource.js +2 -2
- package/lib/esm/index.js +0 -5
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/services/ApolloService.js +55 -72
- package/lib/esm/services/ApolloService.js.map +1 -1
- package/lib/types/ApolloModule.d.ts +2 -3
- package/lib/types/constants/constants.d.ts +0 -1
- package/lib/types/decorators/dataSource.d.ts +2 -2
- package/lib/types/index.d.ts +0 -5
- package/lib/types/interfaces/ApolloSettings.d.ts +10 -22
- package/lib/types/services/ApolloService.d.ts +14 -18
- package/lib/types-esm/ApolloModule.d.ts +2 -3
- package/lib/types-esm/constants/constants.d.ts +0 -1
- package/lib/types-esm/decorators/dataSource.d.ts +2 -2
- package/lib/types-esm/index.d.ts +0 -5
- package/lib/types-esm/interfaces/ApolloSettings.d.ts +10 -22
- package/lib/types-esm/services/ApolloService.d.ts +14 -18
- package/package.json +22 -23
- package/readme.md +24 -1
- package/vitest.config.mts +5 -5
- package/lib/cjs/decorators/injectApolloContext.js +0 -28
- package/lib/cjs/decorators/injectApolloContext.js.map +0 -1
- package/lib/cjs/interfaces/AlterApolloContext.js +0 -3
- package/lib/cjs/interfaces/AlterApolloContext.js.map +0 -1
- package/lib/cjs/interfaces/AlterApolloServerPlugins.js +0 -3
- package/lib/cjs/interfaces/AlterApolloServerPlugins.js.map +0 -1
- package/lib/cjs/interfaces/AlterApolloSettings.js +0 -3
- package/lib/cjs/interfaces/AlterApolloSettings.js.map +0 -1
- package/lib/cjs/interfaces/ApolloContext.js +0 -3
- package/lib/cjs/interfaces/ApolloContext.js.map +0 -1
- package/lib/esm/decorators/injectApolloContext.js +0 -24
- package/lib/esm/decorators/injectApolloContext.js.map +0 -1
- package/lib/esm/interfaces/AlterApolloContext.js +0 -2
- package/lib/esm/interfaces/AlterApolloContext.js.map +0 -1
- package/lib/esm/interfaces/AlterApolloServerPlugins.js +0 -2
- package/lib/esm/interfaces/AlterApolloServerPlugins.js.map +0 -1
- package/lib/esm/interfaces/AlterApolloSettings.js +0 -2
- package/lib/esm/interfaces/AlterApolloSettings.js.map +0 -1
- package/lib/esm/interfaces/ApolloContext.js +0 -2
- package/lib/esm/interfaces/ApolloContext.js.map +0 -1
- package/lib/types/decorators/injectApolloContext.d.ts +0 -5
- package/lib/types/interfaces/AlterApolloContext.d.ts +0 -5
- package/lib/types/interfaces/AlterApolloServerPlugins.d.ts +0 -5
- package/lib/types/interfaces/AlterApolloSettings.d.ts +0 -7
- package/lib/types/interfaces/ApolloContext.d.ts +0 -4
- package/lib/types-esm/decorators/injectApolloContext.d.ts +0 -5
- package/lib/types-esm/interfaces/AlterApolloContext.d.ts +0 -5
- package/lib/types-esm/interfaces/AlterApolloServerPlugins.d.ts +0 -5
- package/lib/types-esm/interfaces/AlterApolloSettings.d.ts +0 -7
- package/lib/types-esm/interfaces/ApolloContext.d.ts +0 -4
package/.nycrc
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"include": [
|
|
3
|
+
"src/**/*.ts"
|
|
4
|
+
],
|
|
5
|
+
"exclude": [
|
|
6
|
+
"**/*.d.ts",
|
|
7
|
+
"node_modules",
|
|
8
|
+
"**/interfaces/**",
|
|
9
|
+
"**/index.ts"
|
|
10
|
+
],
|
|
11
|
+
"extension": [
|
|
12
|
+
".ts"
|
|
13
|
+
],
|
|
14
|
+
"require": [],
|
|
15
|
+
"reporter": [
|
|
16
|
+
"text-summary",
|
|
17
|
+
"html",
|
|
18
|
+
"lcov",
|
|
19
|
+
"json"
|
|
20
|
+
],
|
|
21
|
+
"check-coverage": true,
|
|
22
|
+
"statements": 100,
|
|
23
|
+
"branches": 76.74,
|
|
24
|
+
"functions": 100,
|
|
25
|
+
"lines": 100
|
|
26
|
+
}
|
package/lib/cjs/ApolloModule.js
CHANGED
|
@@ -9,25 +9,23 @@ let ApolloModule = class ApolloModule {
|
|
|
9
9
|
logger;
|
|
10
10
|
service;
|
|
11
11
|
configuration;
|
|
12
|
-
injector;
|
|
13
12
|
get settings() {
|
|
14
|
-
return this.configuration.get("apollo"
|
|
13
|
+
return this.configuration.get("apollo");
|
|
15
14
|
}
|
|
16
|
-
|
|
17
|
-
const { settings
|
|
15
|
+
$onRoutesInit() {
|
|
16
|
+
const { settings } = this;
|
|
18
17
|
if (settings) {
|
|
19
|
-
const promises = Object.entries(settings).map(
|
|
20
|
-
|
|
21
|
-
return this.service.createServer(id, options);
|
|
18
|
+
const promises = Object.entries(settings).map(([key, options]) => {
|
|
19
|
+
return this.service.createServer(key, options);
|
|
22
20
|
});
|
|
23
|
-
|
|
21
|
+
return Promise.all(promises);
|
|
24
22
|
}
|
|
25
23
|
}
|
|
26
24
|
$afterListen() {
|
|
27
25
|
const host = this.configuration.getBestHost();
|
|
28
26
|
const displayLog = (key, path) => {
|
|
29
27
|
const url = typeof host.port === "number" ? `${host.protocol}://${host.address}:${host.port}` : "";
|
|
30
|
-
this.logger.info(`[${key}] Apollo server is available on ${url}
|
|
28
|
+
this.logger.info(`[${key}] Apollo server is available on ${url}${path.replace(/^\//, "")}`);
|
|
31
29
|
};
|
|
32
30
|
const { settings } = this;
|
|
33
31
|
if (settings) {
|
|
@@ -50,10 +48,6 @@ tslib_1.__decorate([
|
|
|
50
48
|
(0, di_1.Configuration)(),
|
|
51
49
|
tslib_1.__metadata("design:type", Object)
|
|
52
50
|
], ApolloModule.prototype, "configuration", void 0);
|
|
53
|
-
tslib_1.__decorate([
|
|
54
|
-
(0, di_1.Inject)(di_1.InjectorService),
|
|
55
|
-
tslib_1.__metadata("design:type", di_1.InjectorService)
|
|
56
|
-
], ApolloModule.prototype, "injector", void 0);
|
|
57
51
|
ApolloModule = tslib_1.__decorate([
|
|
58
52
|
(0, di_1.Module)()
|
|
59
53
|
], ApolloModule);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApolloModule.js","sourceRoot":"","sources":["../../src/ApolloModule.ts"],"names":[],"mappings":";;;;AAAA,yCAA+D;AAC/D,
|
|
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;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,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,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,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;AA5CC;IAAC,IAAA,WAAM,GAAE;sCACS,eAAM;4CAAC;AAEzB;IAAC,IAAA,WAAM,GAAE;sCACU,gCAAa;6CAAC;AAEjC;IAAC,IAAA,kBAAa,GAAE;;mDACuB;AAR5B,YAAY;IADxB,IAAA,WAAM,GAAE;GACI,YAAY,CA6CxB;AA7CY,oCAAY"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.DATASOURCES_PROVIDERS = void 0;
|
|
4
4
|
exports.DATASOURCES_PROVIDERS = "graphql:datasources";
|
|
5
|
-
exports.APOLLO_CONTEXT = Symbol.for("APOLLO_CONTEXT");
|
|
6
5
|
//# 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"}
|
|
@@ -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 '
|
|
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 '
|
|
46
|
+
* import { RESTDataSource } from 'apollo-datasource-rest';
|
|
47
47
|
*
|
|
48
48
|
* @DataSource()
|
|
49
49
|
* export class MyDataSource extends RESTDataSource {
|
package/lib/cjs/index.js
CHANGED
|
@@ -7,11 +7,6 @@ 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);
|
|
15
10
|
tslib_1.__exportStar(require("./interfaces/ApolloSettings.js"), exports);
|
|
16
11
|
tslib_1.__exportStar(require("./services/ApolloService.js"), exports);
|
|
17
12
|
//# sourceMappingURL=index.js.map
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACH,4DAAkC;AAClC,mEAAyC;AACzC,qEAA2C;AAC3C,
|
|
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"}
|
|
@@ -2,17 +2,16 @@
|
|
|
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");
|
|
9
5
|
const common_1 = require("@tsed/common");
|
|
6
|
+
const core_1 = require("@tsed/core");
|
|
10
7
|
const di_1 = require("@tsed/di");
|
|
11
8
|
const logger_1 = require("@tsed/logger");
|
|
9
|
+
const apollo_server_core_1 = require("apollo-server-core");
|
|
12
10
|
const http_1 = tslib_1.__importDefault(require("http"));
|
|
13
11
|
const https_1 = tslib_1.__importDefault(require("https"));
|
|
14
12
|
const constants_js_1 = require("../constants/constants.js");
|
|
15
13
|
let ApolloService = class ApolloService {
|
|
14
|
+
dataSources;
|
|
16
15
|
platformName;
|
|
17
16
|
logger;
|
|
18
17
|
/**
|
|
@@ -25,6 +24,9 @@ let ApolloService = class ApolloService {
|
|
|
25
24
|
httpServer;
|
|
26
25
|
httpsServer;
|
|
27
26
|
injector;
|
|
27
|
+
constructor(dataSources) {
|
|
28
|
+
this.dataSources = dataSources;
|
|
29
|
+
}
|
|
28
30
|
async createServer(id, settings) {
|
|
29
31
|
if (!this.has(id)) {
|
|
30
32
|
try {
|
|
@@ -32,40 +34,22 @@ let ApolloService = class ApolloService {
|
|
|
32
34
|
this.logger.info(`Create server with Apollo for: ${id}`);
|
|
33
35
|
this.logger.debug(`options: ${JSON.stringify({ path })}`);
|
|
34
36
|
const plugins = await this.getPlugins(settings);
|
|
35
|
-
const server = this.createInstance({
|
|
37
|
+
const server = await this.createInstance({
|
|
36
38
|
...config,
|
|
37
|
-
plugins
|
|
39
|
+
plugins,
|
|
40
|
+
dataSources: this.createDataSources(dataSources)
|
|
38
41
|
}, customServer);
|
|
39
42
|
if (server) {
|
|
40
43
|
this.servers.set(id || "default", {
|
|
41
44
|
instance: server,
|
|
42
|
-
schema: settings.schema
|
|
43
|
-
typeDefs: settings.typeDefs,
|
|
44
|
-
resolvers: settings.resolvers
|
|
45
|
+
schema: settings.schema
|
|
45
46
|
});
|
|
46
47
|
await server.start();
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
...middlewareOptions,
|
|
53
|
-
context: contextHandler
|
|
54
|
-
}));
|
|
55
|
-
break;
|
|
56
|
-
case "koa":
|
|
57
|
-
const { koaMiddleware } = await import("@as-integrations/koa");
|
|
58
|
-
this.app.use(path, koaMiddleware(server, {
|
|
59
|
-
...middlewareOptions,
|
|
60
|
-
context: contextHandler
|
|
61
|
-
}));
|
|
62
|
-
break;
|
|
63
|
-
default:
|
|
64
|
-
this.logger.warn({
|
|
65
|
-
event: "APOLLO_UNKNOWN_PLATFORM",
|
|
66
|
-
message: "Platform not supported. Please use Ts.ED platform (express, koa)"
|
|
67
|
-
});
|
|
68
|
-
}
|
|
48
|
+
const middleware = server.getMiddleware({
|
|
49
|
+
path: settings.path,
|
|
50
|
+
...middlewareOptions
|
|
51
|
+
});
|
|
52
|
+
this.app.use(middleware);
|
|
69
53
|
}
|
|
70
54
|
}
|
|
71
55
|
catch (er) {
|
|
@@ -75,7 +59,8 @@ let ApolloService = class ApolloService {
|
|
|
75
59
|
message: er.message,
|
|
76
60
|
stack: er.stack
|
|
77
61
|
});
|
|
78
|
-
|
|
62
|
+
/* istanbul ignore next */
|
|
63
|
+
process.exit(-1);
|
|
79
64
|
}
|
|
80
65
|
}
|
|
81
66
|
return this.get(id);
|
|
@@ -88,21 +73,12 @@ let ApolloService = class ApolloService {
|
|
|
88
73
|
return this.servers.get(id)?.instance;
|
|
89
74
|
}
|
|
90
75
|
/**
|
|
91
|
-
* Get
|
|
76
|
+
* Get an instance of GraphQL schema from his id
|
|
92
77
|
* @returns GraphQLSchema
|
|
93
78
|
*/
|
|
94
79
|
getSchema(id = "default") {
|
|
95
80
|
return this.servers.get(id)?.schema;
|
|
96
81
|
}
|
|
97
|
-
/**
|
|
98
|
-
* Get TypeDefs of the ApolloServer from his id
|
|
99
|
-
*/
|
|
100
|
-
getTypeDefs(id = "default") {
|
|
101
|
-
return this.servers.get(id)?.typeDefs;
|
|
102
|
-
}
|
|
103
|
-
getResolvers(id = "default") {
|
|
104
|
-
return this.servers.get(id)?.resolvers;
|
|
105
|
-
}
|
|
106
82
|
/**
|
|
107
83
|
*
|
|
108
84
|
* @param {string} id
|
|
@@ -111,54 +87,59 @@ let ApolloService = class ApolloService {
|
|
|
111
87
|
has(id = "default") {
|
|
112
88
|
return this.servers.has(id);
|
|
113
89
|
}
|
|
90
|
+
async createInstance(options, server) {
|
|
91
|
+
if (server) {
|
|
92
|
+
return server(options);
|
|
93
|
+
}
|
|
94
|
+
const importServer = async () => {
|
|
95
|
+
switch (this.platformName) {
|
|
96
|
+
default:
|
|
97
|
+
this.logger.error(`Platform "${this.platformName}" not supported by @tsed/apollo`);
|
|
98
|
+
case "express":
|
|
99
|
+
return (await import("apollo-server-express")).ApolloServer;
|
|
100
|
+
case "koa":
|
|
101
|
+
return (await import("apollo-server-koa")).ApolloServer;
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
const Server = await importServer();
|
|
105
|
+
return new Server(options);
|
|
106
|
+
}
|
|
114
107
|
/**
|
|
115
108
|
* create a new dataSources function to use with apollo server config
|
|
109
|
+
* @param dataSources
|
|
116
110
|
*/
|
|
117
|
-
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
111
|
+
createDataSources(dataSources) {
|
|
112
|
+
const dataSourcesHash = this.dataSources.reduce((map, instance) => {
|
|
113
|
+
const klass = (0, core_1.classOf)(instance);
|
|
114
|
+
const store = core_1.Store.from(klass);
|
|
115
|
+
let { name } = store.get(constants_js_1.DATASOURCES_PROVIDERS);
|
|
116
|
+
name = name || (0, core_1.nameOf)(klass);
|
|
122
117
|
const sourceName = `${name[0].toLowerCase()}${name.slice(1)}`;
|
|
123
|
-
map
|
|
118
|
+
map[sourceName] = instance;
|
|
124
119
|
return map;
|
|
125
|
-
},
|
|
126
|
-
return
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
dataSources: {
|
|
130
|
-
...(settings.dataSources?.() || {})
|
|
131
|
-
}
|
|
120
|
+
}, {});
|
|
121
|
+
return () => {
|
|
122
|
+
return {
|
|
123
|
+
...dataSourcesHash,
|
|
124
|
+
...(dataSources ? dataSources() : {})
|
|
132
125
|
};
|
|
133
|
-
const alteredContext = await this.injector.alterAsync("$alterApolloContext", context, $ctx);
|
|
134
|
-
$ctx.set(constants_js_1.APOLLO_CONTEXT, alteredContext);
|
|
135
|
-
const locals = new common_1.LocalsContainer();
|
|
136
|
-
locals.set(constants_js_1.APOLLO_CONTEXT, alteredContext);
|
|
137
|
-
locals.set(server_1.ApolloServer, server);
|
|
138
|
-
dataSourcesContainer.forEach((provider, key) => {
|
|
139
|
-
alteredContext.dataSources[key] = injector.invoke(provider.token, locals);
|
|
140
|
-
});
|
|
141
|
-
return alteredContext;
|
|
142
126
|
};
|
|
143
127
|
}
|
|
144
|
-
createInstance(options, server) {
|
|
145
|
-
return server ? server(options) : new server_1.ApolloServer(options);
|
|
146
|
-
}
|
|
147
128
|
async getPlugins(serverSettings) {
|
|
148
129
|
const playground = serverSettings.playground || (serverSettings.playground === undefined && process.env.NODE_ENV !== "production");
|
|
149
|
-
const result = await this.injector.
|
|
130
|
+
const result = await this.injector.alter("$alterApolloServerPlugins", [
|
|
150
131
|
this.httpServer &&
|
|
151
|
-
(0,
|
|
132
|
+
(0, apollo_server_core_1.ApolloServerPluginDrainHttpServer)({
|
|
152
133
|
httpServer: this.httpServer
|
|
153
134
|
}),
|
|
154
135
|
this.httpsServer &&
|
|
155
|
-
(0,
|
|
136
|
+
(0, apollo_server_core_1.ApolloServerPluginDrainHttpServer)({
|
|
156
137
|
httpServer: this.httpsServer
|
|
157
138
|
}),
|
|
158
139
|
...(serverSettings.plugins || [])
|
|
159
140
|
].filter(Boolean), serverSettings);
|
|
160
141
|
return result
|
|
161
|
-
.concat([playground ? (0,
|
|
142
|
+
.concat([playground ? (0, apollo_server_core_1.ApolloServerPluginLandingPageLocalDefault)({ embed: true }) : (0, apollo_server_core_1.ApolloServerPluginLandingPageDisabled)()])
|
|
162
143
|
.filter(Boolean);
|
|
163
144
|
}
|
|
164
145
|
};
|
|
@@ -187,7 +168,9 @@ tslib_1.__decorate([
|
|
|
187
168
|
tslib_1.__metadata("design:type", common_1.InjectorService)
|
|
188
169
|
], ApolloService.prototype, "injector", void 0);
|
|
189
170
|
ApolloService = tslib_1.__decorate([
|
|
190
|
-
(0, di_1.Service)()
|
|
171
|
+
(0, di_1.Service)(),
|
|
172
|
+
tslib_1.__param(0, (0, di_1.Inject)(constants_js_1.DATASOURCES_PROVIDERS)),
|
|
173
|
+
tslib_1.__metadata("design:paramtypes", [Array])
|
|
191
174
|
], ApolloService);
|
|
192
175
|
exports.ApolloService = ApolloService;
|
|
193
176
|
//# sourceMappingURL=ApolloService.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ApolloService.js","sourceRoot":"","sources":["../../../src/services/ApolloService.ts"],"names":[],"mappings":";;;;AAAA,
|
|
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;IAgC6B;IA9BrD,YAAY,CAAS;IAGX,MAAM,CAAS;IAEzB;;;;OAIG;IACO,OAAO,GAMb,IAAI,GAAG,EAAE,CAAC;IAGN,GAAG,CAA2B;IAG9B,UAAU,CAAqB;IAG/B,WAAW,CAAsB;IAGjC,QAAQ,CAAkB;IAElC,YAAqD,WAAkB;QAAlB,gBAAW,GAAX,WAAW,CAAO;IAAG,CAAC;IAE3E,KAAK,CAAC,YAAY,CAAC,EAAU,EAAE,QAAwB;QACrD,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;YACjB,IAAI;gBACF,MAAM,EAAC,WAAW,EAAE,IAAI,EAAE,iBAAiB,GAAG,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,GAAG,MAAM,EAAC,GAAG,QAAQ,CAAC;gBAE9F,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,kCAAkC,EAAE,EAAE,CAAC,CAAC;gBACzD,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,IAAI,CAAC,SAAS,CAAC,EAAC,IAAI,EAAC,CAAC,EAAE,CAAC,CAAC;gBAExD,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC;gBAEhD,MAAM,MAAM,GAA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AAC;AAezB;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;AA9BvB,aAAa;IADzB,IAAA,YAAO,GAAE;IAiCK,mBAAA,IAAA,WAAM,EAAC,oCAAqB,CAAC,CAAA;;GAhC/B,aAAa,CAkLzB;AAlLY,sCAAa"}
|
package/lib/esm/ApolloModule.js
CHANGED
|
@@ -1,30 +1,28 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
2
|
import { Logger } from "@tsed/common";
|
|
3
|
-
import { Configuration, Inject, Module
|
|
3
|
+
import { Configuration, Inject, Module } from "@tsed/di";
|
|
4
4
|
import { ApolloService } from "./services/ApolloService.js";
|
|
5
5
|
let ApolloModule = class ApolloModule {
|
|
6
6
|
logger;
|
|
7
7
|
service;
|
|
8
8
|
configuration;
|
|
9
|
-
injector;
|
|
10
9
|
get settings() {
|
|
11
|
-
return this.configuration.get("apollo"
|
|
10
|
+
return this.configuration.get("apollo");
|
|
12
11
|
}
|
|
13
|
-
|
|
14
|
-
const { settings
|
|
12
|
+
$onRoutesInit() {
|
|
13
|
+
const { settings } = this;
|
|
15
14
|
if (settings) {
|
|
16
|
-
const promises = Object.entries(settings).map(
|
|
17
|
-
|
|
18
|
-
return this.service.createServer(id, options);
|
|
15
|
+
const promises = Object.entries(settings).map(([key, options]) => {
|
|
16
|
+
return this.service.createServer(key, options);
|
|
19
17
|
});
|
|
20
|
-
|
|
18
|
+
return Promise.all(promises);
|
|
21
19
|
}
|
|
22
20
|
}
|
|
23
21
|
$afterListen() {
|
|
24
22
|
const host = this.configuration.getBestHost();
|
|
25
23
|
const displayLog = (key, path) => {
|
|
26
24
|
const url = typeof host.port === "number" ? `${host.protocol}://${host.address}:${host.port}` : "";
|
|
27
|
-
this.logger.info(`[${key}] Apollo server is available on ${url}
|
|
25
|
+
this.logger.info(`[${key}] Apollo server is available on ${url}${path.replace(/^\//, "")}`);
|
|
28
26
|
};
|
|
29
27
|
const { settings } = this;
|
|
30
28
|
if (settings) {
|
|
@@ -47,10 +45,6 @@ __decorate([
|
|
|
47
45
|
Configuration(),
|
|
48
46
|
__metadata("design:type", Object)
|
|
49
47
|
], ApolloModule.prototype, "configuration", void 0);
|
|
50
|
-
__decorate([
|
|
51
|
-
Inject(InjectorService),
|
|
52
|
-
__metadata("design:type", InjectorService)
|
|
53
|
-
], ApolloModule.prototype, "injector", void 0);
|
|
54
48
|
ApolloModule = __decorate([
|
|
55
49
|
Module()
|
|
56
50
|
], 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,
|
|
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;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,QAAQ,EAAC,GAAG,IAAI,CAAC;QAExB,IAAI,QAAQ,EAAE;YACZ,MAAM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AE;;mDACuB;AAR5B,YAAY;IADxB,MAAM,EAAE;GACI,YAAY,CA6CxB;SA7CY,YAAY"}
|
|
@@ -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"}
|
|
@@ -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 '
|
|
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 '
|
|
42
|
+
* import { RESTDataSource } from 'apollo-datasource-rest';
|
|
43
43
|
*
|
|
44
44
|
* @DataSource()
|
|
45
45
|
* export class MyDataSource extends RESTDataSource {
|
package/lib/esm/index.js
CHANGED
|
@@ -4,11 +4,6 @@
|
|
|
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";
|
|
12
7
|
export * from "./interfaces/ApolloSettings.js";
|
|
13
8
|
export * from "./services/ApolloService.js";
|
|
14
9
|
//# sourceMappingURL=index.js.map
|
package/lib/esm/index.js.map
CHANGED
|
@@ -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,
|
|
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"}
|