@tsed/apollo 8.16.0-rc.3 → 8.16.0-rc.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,29 +1,32 @@
|
|
|
1
|
-
import { __decorate, __metadata } from "tslib";
|
|
2
1
|
import Http from "node:http";
|
|
3
2
|
import Https from "node:https";
|
|
4
3
|
import { ApolloServer } from "@apollo/server";
|
|
5
4
|
import { ApolloServerPluginLandingPageDisabled } from "@apollo/server/plugin/disabled";
|
|
6
5
|
import { ApolloServerPluginDrainHttpServer } from "@apollo/server/plugin/drainHttpServer";
|
|
7
6
|
import { ApolloServerPluginLandingPageLocalDefault } from "@apollo/server/plugin/landingPage/default";
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
7
|
+
import { constant, context, inject, injectable, injector, LocalsContainer, logger } from "@tsed/di";
|
|
8
|
+
import { $asyncAlter } from "@tsed/hooks";
|
|
10
9
|
import { PlatformApplication } from "@tsed/platform-http";
|
|
11
10
|
import { APOLLO_CONTEXT, DATASOURCES_PROVIDERS } from "../constants/constants.js";
|
|
12
|
-
|
|
11
|
+
export class ApolloService {
|
|
13
12
|
constructor() {
|
|
13
|
+
this.platformName = constant("PLATFORM_NAME");
|
|
14
14
|
/**
|
|
15
15
|
*
|
|
16
16
|
* @type {Map<any, any>}
|
|
17
17
|
* @private
|
|
18
18
|
*/
|
|
19
19
|
this.servers = new Map();
|
|
20
|
+
this.app = inject(PlatformApplication);
|
|
21
|
+
this.httpServer = inject(Http.Server);
|
|
22
|
+
this.httpsServer = inject(Https.Server);
|
|
20
23
|
}
|
|
21
24
|
async createServer(id, settings) {
|
|
22
25
|
if (!this.has(id)) {
|
|
23
26
|
try {
|
|
24
27
|
const { dataSources, path, middlewareOptions = {}, server: customServer, ...config } = settings;
|
|
25
|
-
|
|
26
|
-
|
|
28
|
+
logger().info(`Create server with Apollo for: ${id}`);
|
|
29
|
+
logger().debug(`options: ${JSON.stringify({ path })}`);
|
|
27
30
|
const plugins = await this.getPlugins(settings);
|
|
28
31
|
const server = this.createInstance({
|
|
29
32
|
...config,
|
|
@@ -54,7 +57,7 @@ let ApolloService = class ApolloService {
|
|
|
54
57
|
}));
|
|
55
58
|
break;
|
|
56
59
|
default:
|
|
57
|
-
|
|
60
|
+
logger().warn({
|
|
58
61
|
event: "APOLLO_UNKNOWN_PLATFORM",
|
|
59
62
|
message: "Platform not supported. Please use Ts.ED platform (express, koa)"
|
|
60
63
|
});
|
|
@@ -62,7 +65,7 @@ let ApolloService = class ApolloService {
|
|
|
62
65
|
}
|
|
63
66
|
}
|
|
64
67
|
catch (er) {
|
|
65
|
-
|
|
68
|
+
logger().error({
|
|
66
69
|
event: "APOLLO_BOOTSTRAP_ERROR",
|
|
67
70
|
error_name: er.name,
|
|
68
71
|
message: er.message,
|
|
@@ -108,8 +111,9 @@ let ApolloService = class ApolloService {
|
|
|
108
111
|
* create a new dataSources function to use with apollo server config
|
|
109
112
|
*/
|
|
110
113
|
createContextHandler(server, settings) {
|
|
111
|
-
const
|
|
112
|
-
|
|
114
|
+
const dataSourcesContainer = injector()
|
|
115
|
+
.getProviders(DATASOURCES_PROVIDERS)
|
|
116
|
+
.reduce((map, provider) => {
|
|
113
117
|
let { name } = provider.store.get(DATASOURCES_PROVIDERS);
|
|
114
118
|
name = name || provider.className;
|
|
115
119
|
const sourceName = `${name[0].toLowerCase()}${name.slice(1)}`;
|
|
@@ -123,13 +127,13 @@ let ApolloService = class ApolloService {
|
|
|
123
127
|
...(settings.dataSources?.() || {})
|
|
124
128
|
}
|
|
125
129
|
};
|
|
126
|
-
const alteredContext = await
|
|
130
|
+
const alteredContext = await $asyncAlter("$alterApolloContext", apolloContext, [$ctx]);
|
|
127
131
|
$ctx.set(APOLLO_CONTEXT, alteredContext);
|
|
128
132
|
const locals = new LocalsContainer();
|
|
129
133
|
locals.set(APOLLO_CONTEXT, alteredContext);
|
|
130
134
|
locals.set(ApolloServer, server);
|
|
131
135
|
dataSourcesContainer.forEach((provider, key) => {
|
|
132
|
-
alteredContext.dataSources[key] =
|
|
136
|
+
alteredContext.dataSources[key] = inject(provider.token, { locals });
|
|
133
137
|
});
|
|
134
138
|
return alteredContext;
|
|
135
139
|
};
|
|
@@ -139,7 +143,7 @@ let ApolloService = class ApolloService {
|
|
|
139
143
|
}
|
|
140
144
|
async getPlugins(serverSettings) {
|
|
141
145
|
const playground = serverSettings.playground || (serverSettings.playground === undefined && process.env.NODE_ENV !== "production");
|
|
142
|
-
const result = await
|
|
146
|
+
const result = await $asyncAlter("$alterApolloServerPlugins", [
|
|
143
147
|
this.httpServer &&
|
|
144
148
|
ApolloServerPluginDrainHttpServer({
|
|
145
149
|
httpServer: this.httpServer
|
|
@@ -149,37 +153,10 @@ let ApolloService = class ApolloService {
|
|
|
149
153
|
httpServer: this.httpsServer
|
|
150
154
|
}),
|
|
151
155
|
...(serverSettings.plugins || [])
|
|
152
|
-
].filter(Boolean), serverSettings);
|
|
156
|
+
].filter(Boolean), [serverSettings]);
|
|
153
157
|
return result
|
|
154
158
|
.concat([playground ? ApolloServerPluginLandingPageLocalDefault({ embed: true }) : ApolloServerPluginLandingPageDisabled()])
|
|
155
159
|
.filter(Boolean);
|
|
156
160
|
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
Constant("PLATFORM_NAME"),
|
|
160
|
-
__metadata("design:type", String)
|
|
161
|
-
], ApolloService.prototype, "platformName", void 0);
|
|
162
|
-
__decorate([
|
|
163
|
-
Inject(),
|
|
164
|
-
__metadata("design:type", Logger)
|
|
165
|
-
], ApolloService.prototype, "logger", void 0);
|
|
166
|
-
__decorate([
|
|
167
|
-
Inject(),
|
|
168
|
-
__metadata("design:type", PlatformApplication)
|
|
169
|
-
], ApolloService.prototype, "app", void 0);
|
|
170
|
-
__decorate([
|
|
171
|
-
Inject(Http.Server),
|
|
172
|
-
__metadata("design:type", Object)
|
|
173
|
-
], ApolloService.prototype, "httpServer", void 0);
|
|
174
|
-
__decorate([
|
|
175
|
-
Inject(Https.Server),
|
|
176
|
-
__metadata("design:type", Object)
|
|
177
|
-
], ApolloService.prototype, "httpsServer", void 0);
|
|
178
|
-
__decorate([
|
|
179
|
-
Inject(),
|
|
180
|
-
__metadata("design:type", InjectorService)
|
|
181
|
-
], ApolloService.prototype, "injector", void 0);
|
|
182
|
-
ApolloService = __decorate([
|
|
183
|
-
Service()
|
|
184
|
-
], ApolloService);
|
|
185
|
-
export { ApolloService };
|
|
161
|
+
}
|
|
162
|
+
injectable(ApolloService);
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
2
|
+
/// <reference types="node" resolution-mode="require"/>
|
|
3
|
+
import Http from "node:http";
|
|
4
|
+
import Https from "node:https";
|
|
1
5
|
import { ApolloServer, ApolloServerOptions } from "@apollo/server";
|
|
2
6
|
import type { IExecutableSchemaDefinition } from "@graphql-tools/schema";
|
|
3
|
-
import {
|
|
7
|
+
import { PlatformApplication } from "@tsed/platform-http";
|
|
4
8
|
import type { GraphQLSchema } from "graphql";
|
|
5
9
|
import { ApolloContext } from "../interfaces/ApolloContext.js";
|
|
6
10
|
import type { ApolloCustomServerCB, ApolloSettings } from "../interfaces/ApolloSettings.js";
|
|
7
11
|
export declare class ApolloService {
|
|
8
|
-
platformName: string;
|
|
9
|
-
protected logger: Logger;
|
|
12
|
+
platformName: string | undefined;
|
|
10
13
|
/**
|
|
11
14
|
*
|
|
12
15
|
* @type {Map<any, any>}
|
|
@@ -18,10 +21,9 @@ export declare class ApolloService {
|
|
|
18
21
|
typeDefs?: IExecutableSchemaDefinition<ApolloContext>["typeDefs"];
|
|
19
22
|
resolvers?: IExecutableSchemaDefinition<ApolloContext>["resolvers"];
|
|
20
23
|
}>;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
private injector;
|
|
24
|
+
protected app: PlatformApplication<any>;
|
|
25
|
+
protected httpServer: Http.Server<typeof Http.IncomingMessage, typeof Http.ServerResponse> | null;
|
|
26
|
+
protected httpsServer: Https.Server<typeof Http.IncomingMessage, typeof Http.ServerResponse> | null;
|
|
25
27
|
createServer(id: string, settings: ApolloSettings): Promise<ApolloServer<ApolloContext>>;
|
|
26
28
|
/**
|
|
27
29
|
* Get an instance of ApolloServer from his id
|
|
@@ -47,7 +49,7 @@ export declare class ApolloService {
|
|
|
47
49
|
/**
|
|
48
50
|
* create a new dataSources function to use with apollo server config
|
|
49
51
|
*/
|
|
50
|
-
createContextHandler(server: ApolloServer<ApolloContext>, settings: ApolloSettings): () => Promise<
|
|
52
|
+
createContextHandler(server: ApolloServer<ApolloContext>, settings: ApolloSettings): () => Promise<ApolloContext>;
|
|
51
53
|
protected createInstance(options: ApolloServerOptions<ApolloContext>, server?: ApolloCustomServerCB<ApolloContext>): ApolloServer<ApolloContext>;
|
|
52
54
|
private getPlugins;
|
|
53
55
|
}
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@tsed/apollo",
|
|
3
3
|
"description": "Apollo package for Ts.ED framework",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"version": "8.16.0-rc.
|
|
5
|
+
"version": "8.16.0-rc.5",
|
|
6
6
|
"source": "./src/index.ts",
|
|
7
7
|
"main": "./lib/esm/index.js",
|
|
8
8
|
"module": "./lib/esm/index.js",
|
|
@@ -29,12 +29,12 @@
|
|
|
29
29
|
"@apollo/datasource-rest": "6.3.0",
|
|
30
30
|
"@apollo/server": "^4.11.0",
|
|
31
31
|
"@as-integrations/koa": "1.1.1",
|
|
32
|
-
"@tsed/barrels": "8.16.0-rc.
|
|
33
|
-
"@tsed/core": "8.16.0-rc.
|
|
34
|
-
"@tsed/di": "8.16.0-rc.
|
|
32
|
+
"@tsed/barrels": "8.16.0-rc.5",
|
|
33
|
+
"@tsed/core": "8.16.0-rc.5",
|
|
34
|
+
"@tsed/di": "8.16.0-rc.5",
|
|
35
35
|
"@tsed/logger": "^8.0.0",
|
|
36
|
-
"@tsed/platform-http": "8.16.0-rc.
|
|
37
|
-
"@tsed/typescript": "8.16.0-rc.
|
|
36
|
+
"@tsed/platform-http": "8.16.0-rc.5",
|
|
37
|
+
"@tsed/typescript": "8.16.0-rc.5",
|
|
38
38
|
"apollo-datasource-http": "0.21.0",
|
|
39
39
|
"apollo-server-testing": "2.26.2",
|
|
40
40
|
"eslint": "9.12.0",
|