@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
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import { __decorate, __metadata } from "tslib";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { ApolloServerPluginDrainHttpServer } from "@apollo/server/plugin/drainHttpServer";
|
|
5
|
-
import { ApolloServerPluginLandingPageLocalDefault } from "@apollo/server/plugin/landingPage/default";
|
|
6
|
-
import { getContext, InjectorService, LocalsContainer, PlatformApplication } from "@tsed/common";
|
|
1
|
+
import { __decorate, __metadata, __param } from "tslib";
|
|
2
|
+
import { InjectorService, PlatformApplication } from "@tsed/common";
|
|
3
|
+
import { classOf, nameOf, Store } from "@tsed/core";
|
|
7
4
|
import { Constant, Inject, Service } from "@tsed/di";
|
|
8
5
|
import { Logger } from "@tsed/logger";
|
|
6
|
+
import { ApolloServerPluginDrainHttpServer, ApolloServerPluginLandingPageDisabled, ApolloServerPluginLandingPageLocalDefault } from "apollo-server-core";
|
|
9
7
|
import Http from "http";
|
|
10
8
|
import Https from "https";
|
|
11
|
-
import {
|
|
9
|
+
import { DATASOURCES_PROVIDERS } from "../constants/constants.js";
|
|
12
10
|
let ApolloService = class ApolloService {
|
|
11
|
+
dataSources;
|
|
13
12
|
platformName;
|
|
14
13
|
logger;
|
|
15
14
|
/**
|
|
@@ -22,6 +21,9 @@ let ApolloService = class ApolloService {
|
|
|
22
21
|
httpServer;
|
|
23
22
|
httpsServer;
|
|
24
23
|
injector;
|
|
24
|
+
constructor(dataSources) {
|
|
25
|
+
this.dataSources = dataSources;
|
|
26
|
+
}
|
|
25
27
|
async createServer(id, settings) {
|
|
26
28
|
if (!this.has(id)) {
|
|
27
29
|
try {
|
|
@@ -29,40 +31,22 @@ let ApolloService = class ApolloService {
|
|
|
29
31
|
this.logger.info(`Create server with Apollo for: ${id}`);
|
|
30
32
|
this.logger.debug(`options: ${JSON.stringify({ path })}`);
|
|
31
33
|
const plugins = await this.getPlugins(settings);
|
|
32
|
-
const server = this.createInstance({
|
|
34
|
+
const server = await this.createInstance({
|
|
33
35
|
...config,
|
|
34
|
-
plugins
|
|
36
|
+
plugins,
|
|
37
|
+
dataSources: this.createDataSources(dataSources)
|
|
35
38
|
}, customServer);
|
|
36
39
|
if (server) {
|
|
37
40
|
this.servers.set(id || "default", {
|
|
38
41
|
instance: server,
|
|
39
|
-
schema: settings.schema
|
|
40
|
-
typeDefs: settings.typeDefs,
|
|
41
|
-
resolvers: settings.resolvers
|
|
42
|
+
schema: settings.schema
|
|
42
43
|
});
|
|
43
44
|
await server.start();
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
...middlewareOptions,
|
|
50
|
-
context: contextHandler
|
|
51
|
-
}));
|
|
52
|
-
break;
|
|
53
|
-
case "koa":
|
|
54
|
-
const { koaMiddleware } = await import("@as-integrations/koa");
|
|
55
|
-
this.app.use(path, koaMiddleware(server, {
|
|
56
|
-
...middlewareOptions,
|
|
57
|
-
context: contextHandler
|
|
58
|
-
}));
|
|
59
|
-
break;
|
|
60
|
-
default:
|
|
61
|
-
this.logger.warn({
|
|
62
|
-
event: "APOLLO_UNKNOWN_PLATFORM",
|
|
63
|
-
message: "Platform not supported. Please use Ts.ED platform (express, koa)"
|
|
64
|
-
});
|
|
65
|
-
}
|
|
45
|
+
const middleware = server.getMiddleware({
|
|
46
|
+
path: settings.path,
|
|
47
|
+
...middlewareOptions
|
|
48
|
+
});
|
|
49
|
+
this.app.use(middleware);
|
|
66
50
|
}
|
|
67
51
|
}
|
|
68
52
|
catch (er) {
|
|
@@ -72,7 +56,8 @@ let ApolloService = class ApolloService {
|
|
|
72
56
|
message: er.message,
|
|
73
57
|
stack: er.stack
|
|
74
58
|
});
|
|
75
|
-
|
|
59
|
+
/* istanbul ignore next */
|
|
60
|
+
process.exit(-1);
|
|
76
61
|
}
|
|
77
62
|
}
|
|
78
63
|
return this.get(id);
|
|
@@ -85,21 +70,12 @@ let ApolloService = class ApolloService {
|
|
|
85
70
|
return this.servers.get(id)?.instance;
|
|
86
71
|
}
|
|
87
72
|
/**
|
|
88
|
-
* Get
|
|
73
|
+
* Get an instance of GraphQL schema from his id
|
|
89
74
|
* @returns GraphQLSchema
|
|
90
75
|
*/
|
|
91
76
|
getSchema(id = "default") {
|
|
92
77
|
return this.servers.get(id)?.schema;
|
|
93
78
|
}
|
|
94
|
-
/**
|
|
95
|
-
* Get TypeDefs of the ApolloServer from his id
|
|
96
|
-
*/
|
|
97
|
-
getTypeDefs(id = "default") {
|
|
98
|
-
return this.servers.get(id)?.typeDefs;
|
|
99
|
-
}
|
|
100
|
-
getResolvers(id = "default") {
|
|
101
|
-
return this.servers.get(id)?.resolvers;
|
|
102
|
-
}
|
|
103
79
|
/**
|
|
104
80
|
*
|
|
105
81
|
* @param {string} id
|
|
@@ -108,42 +84,47 @@ let ApolloService = class ApolloService {
|
|
|
108
84
|
has(id = "default") {
|
|
109
85
|
return this.servers.has(id);
|
|
110
86
|
}
|
|
87
|
+
async createInstance(options, server) {
|
|
88
|
+
if (server) {
|
|
89
|
+
return server(options);
|
|
90
|
+
}
|
|
91
|
+
const importServer = async () => {
|
|
92
|
+
switch (this.platformName) {
|
|
93
|
+
default:
|
|
94
|
+
this.logger.error(`Platform "${this.platformName}" not supported by @tsed/apollo`);
|
|
95
|
+
case "express":
|
|
96
|
+
return (await import("apollo-server-express")).ApolloServer;
|
|
97
|
+
case "koa":
|
|
98
|
+
return (await import("apollo-server-koa")).ApolloServer;
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
const Server = await importServer();
|
|
102
|
+
return new Server(options);
|
|
103
|
+
}
|
|
111
104
|
/**
|
|
112
105
|
* create a new dataSources function to use with apollo server config
|
|
106
|
+
* @param dataSources
|
|
113
107
|
*/
|
|
114
|
-
|
|
115
|
-
const
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
108
|
+
createDataSources(dataSources) {
|
|
109
|
+
const dataSourcesHash = this.dataSources.reduce((map, instance) => {
|
|
110
|
+
const klass = classOf(instance);
|
|
111
|
+
const store = Store.from(klass);
|
|
112
|
+
let { name } = store.get(DATASOURCES_PROVIDERS);
|
|
113
|
+
name = name || nameOf(klass);
|
|
119
114
|
const sourceName = `${name[0].toLowerCase()}${name.slice(1)}`;
|
|
120
|
-
map
|
|
115
|
+
map[sourceName] = instance;
|
|
121
116
|
return map;
|
|
122
|
-
},
|
|
123
|
-
return
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
dataSources: {
|
|
127
|
-
...(settings.dataSources?.() || {})
|
|
128
|
-
}
|
|
117
|
+
}, {});
|
|
118
|
+
return () => {
|
|
119
|
+
return {
|
|
120
|
+
...dataSourcesHash,
|
|
121
|
+
...(dataSources ? dataSources() : {})
|
|
129
122
|
};
|
|
130
|
-
const alteredContext = await this.injector.alterAsync("$alterApolloContext", context, $ctx);
|
|
131
|
-
$ctx.set(APOLLO_CONTEXT, alteredContext);
|
|
132
|
-
const locals = new LocalsContainer();
|
|
133
|
-
locals.set(APOLLO_CONTEXT, alteredContext);
|
|
134
|
-
locals.set(ApolloServer, server);
|
|
135
|
-
dataSourcesContainer.forEach((provider, key) => {
|
|
136
|
-
alteredContext.dataSources[key] = injector.invoke(provider.token, locals);
|
|
137
|
-
});
|
|
138
|
-
return alteredContext;
|
|
139
123
|
};
|
|
140
124
|
}
|
|
141
|
-
createInstance(options, server) {
|
|
142
|
-
return server ? server(options) : new ApolloServer(options);
|
|
143
|
-
}
|
|
144
125
|
async getPlugins(serverSettings) {
|
|
145
126
|
const playground = serverSettings.playground || (serverSettings.playground === undefined && process.env.NODE_ENV !== "production");
|
|
146
|
-
const result = await this.injector.
|
|
127
|
+
const result = await this.injector.alter("$alterApolloServerPlugins", [
|
|
147
128
|
this.httpServer &&
|
|
148
129
|
ApolloServerPluginDrainHttpServer({
|
|
149
130
|
httpServer: this.httpServer
|
|
@@ -184,7 +165,9 @@ __decorate([
|
|
|
184
165
|
__metadata("design:type", InjectorService)
|
|
185
166
|
], ApolloService.prototype, "injector", void 0);
|
|
186
167
|
ApolloService = __decorate([
|
|
187
|
-
Service()
|
|
168
|
+
Service(),
|
|
169
|
+
__param(0, Inject(DATASOURCES_PROVIDERS)),
|
|
170
|
+
__metadata("design:paramtypes", [Array])
|
|
188
171
|
], ApolloService);
|
|
189
172
|
export { ApolloService };
|
|
190
173
|
//# sourceMappingURL=ApolloService.js.map
|
|
@@ -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,eAAe,EAAE,mBAAmB,EAAC,MAAM,cAAc,CAAC;AAClE,OAAO,EAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAC,MAAM,YAAY,CAAC;AAClD,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,yCAAyC,EAC1C,MAAM,oBAAoB,CAAC;AAG5B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,qBAAqB,EAAC,MAAM,2BAA2B,CAAC;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,IA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C,CAAC,EAAC,KAAK,EAAE,IAAI,EAAC,CAAC,CAAC,CAAC,CAAC,qCAAqC,EAAE,CAAC,CAAC;aACzH,MAAM,CAAC,OAAO,CAAC,CAAC;IACrB,CAAC;CACF,CAAA;AAjLC;IAAC,QAAQ,CAAC,eAAe,CAAC;;mDACL;AAErB;IAAC,MAAM,EAAE;8BACS,MAAM;6CAAC;AAezB;IAAC,MAAM,EAAE;8BACI,mBAAmB;0CAAM;AAEtC;IAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC;;iDACmB;AAEvC;IAAC,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC;;kDACoB;AAEzC;IAAC,MAAM,EAAE;8BACS,eAAe;+CAAC;AA9BvB,aAAa;IADzB,OAAO,EAAE;IAiCK,WAAA,MAAM,CAAC,qBAAqB,CAAC,CAAA;;GAhC/B,aAAa,CAkLzB;SAlLY,aAAa"}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { AfterListen, Logger, OnRoutesInit } from "@tsed/common";
|
|
2
|
-
import { Configuration
|
|
2
|
+
import { Configuration } from "@tsed/di";
|
|
3
3
|
import { ApolloSettings } from "./interfaces/ApolloSettings.js";
|
|
4
4
|
import { ApolloService } from "./services/ApolloService.js";
|
|
5
5
|
export declare class ApolloModule implements OnRoutesInit, AfterListen {
|
|
6
6
|
protected logger: Logger;
|
|
7
7
|
protected service: ApolloService;
|
|
8
8
|
protected configuration: Configuration;
|
|
9
|
-
protected injector: InjectorService;
|
|
10
9
|
get settings(): {
|
|
11
10
|
[key: string]: ApolloSettings;
|
|
12
11
|
} | undefined;
|
|
13
|
-
$onRoutesInit(): Promise<void
|
|
12
|
+
$onRoutesInit(): Promise<any> | void;
|
|
14
13
|
$afterListen(): Promise<any> | void;
|
|
15
14
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* ```typescript
|
|
5
5
|
* import { DataSourceService } from "@tsed/graphql";
|
|
6
|
-
* import { RESTDataSource } from '
|
|
6
|
+
* import { RESTDataSource } from 'apollo-datasource-rest';
|
|
7
7
|
*
|
|
8
8
|
* @DataSource()
|
|
9
9
|
* export class MyDataSource extends RESTDataSource {
|
|
@@ -31,7 +31,7 @@ export declare function DataSource(name?: string): ClassDecorator;
|
|
|
31
31
|
*
|
|
32
32
|
* ```typescript
|
|
33
33
|
* import { DataSourceService } from "@tsed/graphql";
|
|
34
|
-
* import { RESTDataSource } from '
|
|
34
|
+
* import { RESTDataSource } from 'apollo-datasource-rest';
|
|
35
35
|
*
|
|
36
36
|
* @DataSource()
|
|
37
37
|
* export class MyDataSource extends RESTDataSource {
|
package/lib/types/index.d.ts
CHANGED
|
@@ -4,10 +4,5 @@
|
|
|
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";
|
|
@@ -1,32 +1,20 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { GatewayInterface } from "@apollo/server-gateway-interface";
|
|
3
|
-
import type { IExecutableSchemaDefinition } from "@graphql-tools/schema";
|
|
4
|
-
import type { GraphQLSchema } from "graphql/index";
|
|
5
|
-
import { ApolloContext } from "./ApolloContext";
|
|
1
|
+
import type { ApolloServerBase, ApolloServerPluginLandingPageGraphQLPlaygroundOptions, Config } from "apollo-server-core";
|
|
6
2
|
export type ApolloMiddlewareOptions = Record<string, any>;
|
|
7
|
-
export type
|
|
3
|
+
export type ApolloServer = ApolloServerBase & {
|
|
4
|
+
getMiddleware(settings: ApolloMiddlewareOptions): any;
|
|
5
|
+
};
|
|
6
|
+
export type ApolloCustomServerCB = (config: ApolloConfig) => ApolloServer;
|
|
7
|
+
export type ApolloConfig = Config;
|
|
8
8
|
declare global {
|
|
9
9
|
namespace TsED {
|
|
10
10
|
interface ApolloSettings {
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
export
|
|
15
|
-
export type ApolloSettings<TContext extends ApolloContext = ApolloContext> = ApolloServerOptionsBase<TContext> & TsED.ApolloSettings & {
|
|
14
|
+
export interface ApolloSettings extends ApolloConfig, TsED.ApolloSettings {
|
|
16
15
|
path: string;
|
|
17
|
-
server?: ApolloCustomServerCB
|
|
18
|
-
playground?: boolean;
|
|
16
|
+
server?: ApolloCustomServerCB;
|
|
17
|
+
playground?: boolean | ApolloServerPluginLandingPageGraphQLPlaygroundOptions;
|
|
19
18
|
serverRegistration?: ApolloMiddlewareOptions;
|
|
20
19
|
middlewareOptions?: ApolloMiddlewareOptions;
|
|
21
|
-
|
|
22
|
-
typeDefs?: IExecutableSchemaDefinition<TContext>["typeDefs"];
|
|
23
|
-
resolvers?: IExecutableSchemaDefinition<TContext>["resolvers"];
|
|
24
|
-
gateway?: GatewayInterface;
|
|
25
|
-
/**
|
|
26
|
-
* @deprecated use $alterApolloContext instead
|
|
27
|
-
*/
|
|
28
|
-
dataSources?: () => Record<string, unknown>;
|
|
29
|
-
};
|
|
30
|
-
export type ApolloSettingsWithID<TContext extends ApolloContext = ApolloContext> = ApolloSettings<TContext> & {
|
|
31
|
-
id: string;
|
|
32
|
-
};
|
|
20
|
+
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { ApolloServer, ApolloServerOptions } from "@apollo/server";
|
|
2
|
-
import type { IExecutableSchemaDefinition } from "@graphql-tools/schema";
|
|
3
1
|
import { Logger } from "@tsed/logger";
|
|
2
|
+
import type { Config } from "apollo-server-core";
|
|
3
|
+
import { ApolloServerBase } from "apollo-server-core";
|
|
4
4
|
import type { GraphQLSchema } from "graphql";
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
5
|
+
import type { ApolloServer, ApolloSettings } from "../interfaces/ApolloSettings.js";
|
|
6
|
+
import { ApolloCustomServerCB } from "../interfaces/ApolloSettings.js";
|
|
7
7
|
export declare class ApolloService {
|
|
8
|
+
protected dataSources: any[];
|
|
8
9
|
platformName: string;
|
|
9
10
|
protected logger: Logger;
|
|
10
11
|
/**
|
|
@@ -13,41 +14,36 @@ export declare class ApolloService {
|
|
|
13
14
|
* @private
|
|
14
15
|
*/
|
|
15
16
|
protected servers: Map<string, {
|
|
16
|
-
instance:
|
|
17
|
-
schema
|
|
18
|
-
typeDefs?: IExecutableSchemaDefinition<ApolloContext>["typeDefs"];
|
|
19
|
-
resolvers?: IExecutableSchemaDefinition<ApolloContext>["resolvers"];
|
|
17
|
+
instance: ApolloServerBase;
|
|
18
|
+
schema: GraphQLSchema | undefined;
|
|
20
19
|
}>;
|
|
21
20
|
private app;
|
|
22
21
|
private httpServer;
|
|
23
22
|
private httpsServer;
|
|
24
23
|
private injector;
|
|
25
|
-
|
|
24
|
+
constructor(dataSources: any[]);
|
|
25
|
+
createServer(id: string, settings: ApolloSettings): Promise<ApolloServer>;
|
|
26
26
|
/**
|
|
27
27
|
* Get an instance of ApolloServer from his id
|
|
28
28
|
* @returns ApolloServer
|
|
29
29
|
*/
|
|
30
|
-
get(id?: string):
|
|
30
|
+
get(id?: string): ApolloServerBase | undefined;
|
|
31
31
|
/**
|
|
32
|
-
* Get
|
|
32
|
+
* Get an instance of GraphQL schema from his id
|
|
33
33
|
* @returns GraphQLSchema
|
|
34
34
|
*/
|
|
35
35
|
getSchema(id?: string): GraphQLSchema | undefined;
|
|
36
|
-
/**
|
|
37
|
-
* Get TypeDefs of the ApolloServer from his id
|
|
38
|
-
*/
|
|
39
|
-
getTypeDefs(id?: string): import("@graphql-tools/utils").TypeSource | undefined;
|
|
40
|
-
getResolvers(id?: string): import("@graphql-tools/utils").IResolvers<any, ApolloContext, Record<string, any>, any> | import("@graphql-tools/utils").IResolvers<any, ApolloContext, Record<string, any>, any>[] | undefined;
|
|
41
36
|
/**
|
|
42
37
|
*
|
|
43
38
|
* @param {string} id
|
|
44
39
|
* @returns {boolean}
|
|
45
40
|
*/
|
|
46
41
|
has(id?: string): boolean;
|
|
42
|
+
protected createInstance(options: Config, server?: ApolloCustomServerCB): Promise<ApolloServer | undefined>;
|
|
47
43
|
/**
|
|
48
44
|
* create a new dataSources function to use with apollo server config
|
|
45
|
+
* @param dataSources
|
|
49
46
|
*/
|
|
50
|
-
|
|
51
|
-
protected createInstance(options: ApolloServerOptions<ApolloContext>, server?: ApolloCustomServerCB<ApolloContext>): ApolloServer<ApolloContext>;
|
|
47
|
+
protected createDataSources(dataSources: Function | undefined): () => any;
|
|
52
48
|
private getPlugins;
|
|
53
49
|
}
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { AfterListen, Logger, OnRoutesInit } from "@tsed/common";
|
|
2
|
-
import { Configuration
|
|
2
|
+
import { Configuration } from "@tsed/di";
|
|
3
3
|
import { ApolloSettings } from "./interfaces/ApolloSettings.js";
|
|
4
4
|
import { ApolloService } from "./services/ApolloService.js";
|
|
5
5
|
export declare class ApolloModule implements OnRoutesInit, AfterListen {
|
|
6
6
|
protected logger: Logger;
|
|
7
7
|
protected service: ApolloService;
|
|
8
8
|
protected configuration: Configuration;
|
|
9
|
-
protected injector: InjectorService;
|
|
10
9
|
get settings(): {
|
|
11
10
|
[key: string]: ApolloSettings;
|
|
12
11
|
} | undefined;
|
|
13
|
-
$onRoutesInit(): Promise<void
|
|
12
|
+
$onRoutesInit(): Promise<any> | void;
|
|
14
13
|
$afterListen(): Promise<any> | void;
|
|
15
14
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* ```typescript
|
|
5
5
|
* import { DataSourceService } from "@tsed/graphql";
|
|
6
|
-
* import { RESTDataSource } from '
|
|
6
|
+
* import { RESTDataSource } from 'apollo-datasource-rest';
|
|
7
7
|
*
|
|
8
8
|
* @DataSource()
|
|
9
9
|
* export class MyDataSource extends RESTDataSource {
|
|
@@ -31,7 +31,7 @@ export declare function DataSource(name?: string): ClassDecorator;
|
|
|
31
31
|
*
|
|
32
32
|
* ```typescript
|
|
33
33
|
* import { DataSourceService } from "@tsed/graphql";
|
|
34
|
-
* import { RESTDataSource } from '
|
|
34
|
+
* import { RESTDataSource } from 'apollo-datasource-rest';
|
|
35
35
|
*
|
|
36
36
|
* @DataSource()
|
|
37
37
|
* export class MyDataSource extends RESTDataSource {
|
package/lib/types-esm/index.d.ts
CHANGED
|
@@ -4,10 +4,5 @@
|
|
|
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";
|
|
@@ -1,32 +1,20 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { GatewayInterface } from "@apollo/server-gateway-interface";
|
|
3
|
-
import type { IExecutableSchemaDefinition } from "@graphql-tools/schema";
|
|
4
|
-
import type { GraphQLSchema } from "graphql/index";
|
|
5
|
-
import { ApolloContext } from "./ApolloContext";
|
|
1
|
+
import type { ApolloServerBase, ApolloServerPluginLandingPageGraphQLPlaygroundOptions, Config } from "apollo-server-core";
|
|
6
2
|
export type ApolloMiddlewareOptions = Record<string, any>;
|
|
7
|
-
export type
|
|
3
|
+
export type ApolloServer = ApolloServerBase & {
|
|
4
|
+
getMiddleware(settings: ApolloMiddlewareOptions): any;
|
|
5
|
+
};
|
|
6
|
+
export type ApolloCustomServerCB = (config: ApolloConfig) => ApolloServer;
|
|
7
|
+
export type ApolloConfig = Config;
|
|
8
8
|
declare global {
|
|
9
9
|
namespace TsED {
|
|
10
10
|
interface ApolloSettings {
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
|
-
export
|
|
15
|
-
export type ApolloSettings<TContext extends ApolloContext = ApolloContext> = ApolloServerOptionsBase<TContext> & TsED.ApolloSettings & {
|
|
14
|
+
export interface ApolloSettings extends ApolloConfig, TsED.ApolloSettings {
|
|
16
15
|
path: string;
|
|
17
|
-
server?: ApolloCustomServerCB
|
|
18
|
-
playground?: boolean;
|
|
16
|
+
server?: ApolloCustomServerCB;
|
|
17
|
+
playground?: boolean | ApolloServerPluginLandingPageGraphQLPlaygroundOptions;
|
|
19
18
|
serverRegistration?: ApolloMiddlewareOptions;
|
|
20
19
|
middlewareOptions?: ApolloMiddlewareOptions;
|
|
21
|
-
|
|
22
|
-
typeDefs?: IExecutableSchemaDefinition<TContext>["typeDefs"];
|
|
23
|
-
resolvers?: IExecutableSchemaDefinition<TContext>["resolvers"];
|
|
24
|
-
gateway?: GatewayInterface;
|
|
25
|
-
/**
|
|
26
|
-
* @deprecated use $alterApolloContext instead
|
|
27
|
-
*/
|
|
28
|
-
dataSources?: () => Record<string, unknown>;
|
|
29
|
-
};
|
|
30
|
-
export type ApolloSettingsWithID<TContext extends ApolloContext = ApolloContext> = ApolloSettings<TContext> & {
|
|
31
|
-
id: string;
|
|
32
|
-
};
|
|
20
|
+
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { ApolloServer, ApolloServerOptions } from "@apollo/server";
|
|
2
|
-
import type { IExecutableSchemaDefinition } from "@graphql-tools/schema";
|
|
3
1
|
import { Logger } from "@tsed/logger";
|
|
2
|
+
import type { Config } from "apollo-server-core";
|
|
3
|
+
import { ApolloServerBase } from "apollo-server-core";
|
|
4
4
|
import type { GraphQLSchema } from "graphql";
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
5
|
+
import type { ApolloServer, ApolloSettings } from "../interfaces/ApolloSettings.js";
|
|
6
|
+
import { ApolloCustomServerCB } from "../interfaces/ApolloSettings.js";
|
|
7
7
|
export declare class ApolloService {
|
|
8
|
+
protected dataSources: any[];
|
|
8
9
|
platformName: string;
|
|
9
10
|
protected logger: Logger;
|
|
10
11
|
/**
|
|
@@ -13,41 +14,36 @@ export declare class ApolloService {
|
|
|
13
14
|
* @private
|
|
14
15
|
*/
|
|
15
16
|
protected servers: Map<string, {
|
|
16
|
-
instance:
|
|
17
|
-
schema
|
|
18
|
-
typeDefs?: IExecutableSchemaDefinition<ApolloContext>["typeDefs"];
|
|
19
|
-
resolvers?: IExecutableSchemaDefinition<ApolloContext>["resolvers"];
|
|
17
|
+
instance: ApolloServerBase;
|
|
18
|
+
schema: GraphQLSchema | undefined;
|
|
20
19
|
}>;
|
|
21
20
|
private app;
|
|
22
21
|
private httpServer;
|
|
23
22
|
private httpsServer;
|
|
24
23
|
private injector;
|
|
25
|
-
|
|
24
|
+
constructor(dataSources: any[]);
|
|
25
|
+
createServer(id: string, settings: ApolloSettings): Promise<ApolloServer>;
|
|
26
26
|
/**
|
|
27
27
|
* Get an instance of ApolloServer from his id
|
|
28
28
|
* @returns ApolloServer
|
|
29
29
|
*/
|
|
30
|
-
get(id?: string):
|
|
30
|
+
get(id?: string): ApolloServerBase | undefined;
|
|
31
31
|
/**
|
|
32
|
-
* Get
|
|
32
|
+
* Get an instance of GraphQL schema from his id
|
|
33
33
|
* @returns GraphQLSchema
|
|
34
34
|
*/
|
|
35
35
|
getSchema(id?: string): GraphQLSchema | undefined;
|
|
36
|
-
/**
|
|
37
|
-
* Get TypeDefs of the ApolloServer from his id
|
|
38
|
-
*/
|
|
39
|
-
getTypeDefs(id?: string): import("@graphql-tools/utils").TypeSource | undefined;
|
|
40
|
-
getResolvers(id?: string): import("@graphql-tools/utils").IResolvers<any, ApolloContext, Record<string, any>, any> | import("@graphql-tools/utils").IResolvers<any, ApolloContext, Record<string, any>, any>[] | undefined;
|
|
41
36
|
/**
|
|
42
37
|
*
|
|
43
38
|
* @param {string} id
|
|
44
39
|
* @returns {boolean}
|
|
45
40
|
*/
|
|
46
41
|
has(id?: string): boolean;
|
|
42
|
+
protected createInstance(options: Config, server?: ApolloCustomServerCB): Promise<ApolloServer | undefined>;
|
|
47
43
|
/**
|
|
48
44
|
* create a new dataSources function to use with apollo server config
|
|
45
|
+
* @param dataSources
|
|
49
46
|
*/
|
|
50
|
-
|
|
51
|
-
protected createInstance(options: ApolloServerOptions<ApolloContext>, server?: ApolloCustomServerCB<ApolloContext>): ApolloServer<ApolloContext>;
|
|
47
|
+
protected createDataSources(dataSources: Function | undefined): () => any;
|
|
52
48
|
private getPlugins;
|
|
53
49
|
}
|
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": "commonjs",
|
|
5
|
-
"version": "7.81.
|
|
5
|
+
"version": "7.81.1",
|
|
6
6
|
"source": "./src/index.ts",
|
|
7
7
|
"main": "./lib/cjs/index.js",
|
|
8
8
|
"module": "./lib/esm/index.js",
|
|
@@ -26,31 +26,33 @@
|
|
|
26
26
|
"tslib": "2.6.1"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
-
"@
|
|
30
|
-
"@
|
|
31
|
-
"@
|
|
32
|
-
"@tsed/
|
|
33
|
-
"@tsed/common": "7.81.0-rc.1",
|
|
34
|
-
"@tsed/core": "7.81.0-rc.1",
|
|
35
|
-
"@tsed/di": "7.81.0-rc.1",
|
|
29
|
+
"@tsed/barrels": "7.81.1",
|
|
30
|
+
"@tsed/common": "7.81.1",
|
|
31
|
+
"@tsed/core": "7.81.1",
|
|
32
|
+
"@tsed/di": "7.81.1",
|
|
36
33
|
"@tsed/logger": ">=6.7.5",
|
|
37
|
-
"@tsed/typescript": "7.81.
|
|
38
|
-
"
|
|
39
|
-
"apollo-
|
|
34
|
+
"@tsed/typescript": "7.81.1",
|
|
35
|
+
"@types/graphql": "14.5.0",
|
|
36
|
+
"apollo-datasource": "^3.3.2",
|
|
37
|
+
"apollo-datasource-rest": "^3.7.0",
|
|
38
|
+
"apollo-server-core": "^3.13.0",
|
|
39
|
+
"apollo-server-express": "^3.13.0",
|
|
40
|
+
"apollo-server-koa": "^3.13.0",
|
|
41
|
+
"apollo-server-testing": "^2.26.2",
|
|
40
42
|
"eslint": "^8.57.0",
|
|
41
|
-
"graphql": "
|
|
43
|
+
"graphql": "15.8.0",
|
|
42
44
|
"typescript": "4.9.5",
|
|
43
45
|
"vitest": "2.0.4"
|
|
44
46
|
},
|
|
45
47
|
"peerDependencies": {
|
|
46
|
-
"@
|
|
47
|
-
"@
|
|
48
|
-
"@
|
|
49
|
-
"@tsed/common": "7.81.0-rc.1",
|
|
50
|
-
"@tsed/core": "7.81.0-rc.1",
|
|
51
|
-
"@tsed/di": "7.81.0-rc.1",
|
|
48
|
+
"@tsed/common": "7.81.1",
|
|
49
|
+
"@tsed/core": "7.81.1",
|
|
50
|
+
"@tsed/di": "7.81.1",
|
|
52
51
|
"@tsed/logger": ">=6.7.5",
|
|
53
|
-
"
|
|
52
|
+
"apollo-datasource": ">=3.0.0",
|
|
53
|
+
"apollo-datasource-rest": ">=3.0.0",
|
|
54
|
+
"apollo-server-core": ">=3.0.0",
|
|
55
|
+
"graphql": ">15.0.0"
|
|
54
56
|
},
|
|
55
57
|
"repository": "https://github.com/tsedio/tsed",
|
|
56
58
|
"bugs": {
|
|
@@ -58,8 +60,5 @@
|
|
|
58
60
|
},
|
|
59
61
|
"homepage": "https://github.com/tsedio/tsed/tree/production/packages/graphql/apollo",
|
|
60
62
|
"author": "Romain Lenzotti",
|
|
61
|
-
"license": "MIT"
|
|
62
|
-
"publishConfig": {
|
|
63
|
-
"tag": "rc"
|
|
64
|
-
}
|
|
63
|
+
"license": "MIT"
|
|
65
64
|
}
|