@tsed/apollo 7.83.3 → 8.0.0-alpha.10

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.
Files changed (55) hide show
  1. package/lib/esm/ApolloModule.js +13 -8
  2. package/lib/esm/ApolloModule.js.map +1 -1
  3. package/lib/esm/constants/constants.js +1 -0
  4. package/lib/esm/constants/constants.js.map +1 -1
  5. package/lib/esm/decorators/dataSource.js +2 -2
  6. package/lib/esm/decorators/dataSource.js.map +1 -1
  7. package/lib/esm/decorators/injectApolloContext.js +19 -0
  8. package/lib/esm/decorators/injectApolloContext.js.map +1 -0
  9. package/lib/esm/index.js +5 -0
  10. package/lib/esm/index.js.map +1 -1
  11. package/lib/esm/interfaces/AlterApolloContext.js +2 -0
  12. package/lib/esm/interfaces/AlterApolloContext.js.map +1 -0
  13. package/lib/esm/interfaces/AlterApolloServerPlugins.js +2 -0
  14. package/lib/esm/interfaces/AlterApolloServerPlugins.js.map +1 -0
  15. package/lib/esm/interfaces/AlterApolloSettings.js +2 -0
  16. package/lib/esm/interfaces/AlterApolloSettings.js.map +1 -0
  17. package/lib/esm/interfaces/ApolloContext.js +2 -0
  18. package/lib/esm/interfaces/ApolloContext.js.map +1 -0
  19. package/lib/esm/services/ApolloService.js +73 -53
  20. package/lib/esm/services/ApolloService.js.map +1 -1
  21. package/lib/types/ApolloModule.d.ts +3 -2
  22. package/lib/types/constants/constants.d.ts +1 -0
  23. package/lib/types/decorators/dataSource.d.ts +2 -2
  24. package/lib/types/decorators/injectApolloContext.d.ts +5 -0
  25. package/lib/types/index.d.ts +5 -0
  26. package/lib/types/interfaces/AlterApolloContext.d.ts +5 -0
  27. package/lib/types/interfaces/AlterApolloServerPlugins.d.ts +5 -0
  28. package/lib/types/interfaces/AlterApolloSettings.d.ts +7 -0
  29. package/lib/types/interfaces/ApolloContext.d.ts +4 -0
  30. package/lib/types/interfaces/ApolloSettings.d.ts +22 -10
  31. package/lib/types/services/ApolloService.d.ts +18 -14
  32. package/package.json +29 -31
  33. package/readme.md +1 -24
  34. package/vitest.config.mts +5 -5
  35. package/.nycrc +0 -26
  36. package/lib/cjs/ApolloModule.js +0 -52
  37. package/lib/cjs/ApolloModule.js.map +0 -1
  38. package/lib/cjs/constants/constants.js +0 -5
  39. package/lib/cjs/constants/constants.js.map +0 -1
  40. package/lib/cjs/decorators/dataSource.js +0 -69
  41. package/lib/cjs/decorators/dataSource.js.map +0 -1
  42. package/lib/cjs/index.js +0 -12
  43. package/lib/cjs/index.js.map +0 -1
  44. package/lib/cjs/interfaces/ApolloSettings.js +0 -3
  45. package/lib/cjs/interfaces/ApolloSettings.js.map +0 -1
  46. package/lib/cjs/package.json +0 -3
  47. package/lib/cjs/services/ApolloService.js +0 -169
  48. package/lib/cjs/services/ApolloService.js.map +0 -1
  49. package/lib/esm/package.json +0 -3
  50. package/lib/types-esm/ApolloModule.d.ts +0 -14
  51. package/lib/types-esm/constants/constants.d.ts +0 -1
  52. package/lib/types-esm/decorators/dataSource.d.ts +0 -56
  53. package/lib/types-esm/index.d.ts +0 -8
  54. package/lib/types-esm/interfaces/ApolloSettings.d.ts +0 -20
  55. package/lib/types-esm/services/ApolloService.d.ts +0 -49
package/package.json CHANGED
@@ -1,18 +1,17 @@
1
1
  {
2
2
  "name": "@tsed/apollo",
3
3
  "description": "Apollo package for Ts.ED framework",
4
- "type": "commonjs",
5
- "version": "7.83.3",
4
+ "type": "module",
5
+ "version": "8.0.0-alpha.10",
6
6
  "source": "./src/index.ts",
7
- "main": "./lib/cjs/index.js",
7
+ "main": "./lib/esm/index.js",
8
8
  "module": "./lib/esm/index.js",
9
9
  "typings": "./lib/types/index.d.ts",
10
10
  "exports": {
11
11
  ".": {
12
12
  "types": "./lib/types/index.d.ts",
13
13
  "import": "./lib/esm/index.js",
14
- "require": "./lib/cjs/index.js",
15
- "default": "./lib/cjs/index.js"
14
+ "default": "./lib/esm/index.js"
16
15
  }
17
16
  },
18
17
  "scripts": {
@@ -23,36 +22,32 @@
23
22
  "test:ci": "vitest run --coverage.thresholds.autoUpdate=true"
24
23
  },
25
24
  "dependencies": {
26
- "tslib": "2.6.1"
25
+ "tslib": "2.7.0"
27
26
  },
28
27
  "devDependencies": {
29
- "@tsed/barrels": "7.83.3",
30
- "@tsed/common": "7.83.3",
31
- "@tsed/core": "7.83.3",
32
- "@tsed/di": "7.83.3",
33
- "@tsed/logger": ">=6.7.5",
34
- "@tsed/typescript": "7.83.3",
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",
42
- "eslint": "^8.57.0",
43
- "graphql": "15.8.0",
44
- "typescript": "4.9.5",
45
- "vitest": "2.0.4"
28
+ "@apollo/datasource-rest": "6.3.0",
29
+ "@apollo/server": "^4.11.0",
30
+ "@as-integrations/koa": "1.1.1",
31
+ "@tsed/barrels": "8.0.0-alpha.10",
32
+ "@tsed/common": "8.0.0-alpha.10",
33
+ "@tsed/core": "8.0.0-alpha.10",
34
+ "@tsed/di": "8.0.0-alpha.10",
35
+ "@tsed/logger": "^6.7.8",
36
+ "@tsed/typescript": "8.0.0-alpha.10",
37
+ "apollo-datasource-http": "0.21.0",
38
+ "apollo-server-testing": "2.26.2",
39
+ "eslint": "9.12.0",
40
+ "graphql": "16.9.0",
41
+ "typescript": "5.4.5",
42
+ "vitest": "2.1.2"
46
43
  },
47
44
  "peerDependencies": {
48
- "@tsed/common": "7.83.3",
49
- "@tsed/core": "7.83.3",
50
- "@tsed/di": "7.83.3",
45
+ "@apollo/server": ">=4.10.4",
46
+ "@tsed/common": "8.0.0-alpha.10",
47
+ "@tsed/core": "8.0.0-alpha.10",
48
+ "@tsed/di": "8.0.0-alpha.10",
51
49
  "@tsed/logger": ">=6.7.5",
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"
50
+ "graphql": ">16.0.0"
56
51
  },
57
52
  "repository": "https://github.com/tsedio/tsed",
58
53
  "bugs": {
@@ -60,5 +55,8 @@
60
55
  },
61
56
  "homepage": "https://github.com/tsedio/tsed/tree/production/packages/graphql/apollo",
62
57
  "author": "Romain Lenzotti",
63
- "license": "MIT"
58
+ "license": "MIT",
59
+ "publishConfig": {
60
+ "tag": "alpha"
61
+ }
64
62
  }
package/readme.md CHANGED
@@ -45,8 +45,7 @@ If you're looking for integration with TypeGraphQL see the [`@tsed/typegraphql`]
45
45
  To begin, install the Apollo module for TS.ED:
46
46
 
47
47
  ```bash
48
- npm install --save @tsed/apollo graphql@15
49
- npm install --save apollo-datasource apollo-datasource-rest apollo-server-express
48
+ npm install --save @tsed/apollo graphql@15 @apollo/server apollo/datasource-rest
50
49
  npm install --save-dev apollo-server-testing
51
50
  ```
52
51
 
@@ -68,28 +67,6 @@ import "@tsed/apollo";
68
67
  export class Server {}
69
68
  ```
70
69
 
71
- ## ApolloService
72
-
73
- ApolloService let you to retrieve an instance of ApolloServer.
74
-
75
- ```typescript
76
- import {Injectable, AfterRoutesInit} from "@tsed/common";
77
- import {graphQLService} from "@tsed/apollo";
78
- import {ApolloServer} from "apollo-server-express";
79
-
80
- @Injectable()
81
- export class UsersService implements AfterRoutesInit {
82
- @Injec()
83
- apolloService: ApolloService;
84
-
85
- private server: ApolloServer;
86
-
87
- $afterRoutesInit() {
88
- this.server = this.apolloService.get("server1");
89
- }
90
- }
91
- ```
92
-
93
70
  For more information about ApolloServer look his documentation [here](https://www.apollographql.com/docs/apollo-server/api/apollo-server.html);
94
71
 
95
72
  ## Contributors
package/vitest.config.mts CHANGED
@@ -10,12 +10,12 @@ export default defineConfig(
10
10
  coverage: {
11
11
  ...presets.test.coverage,
12
12
  thresholds: {
13
- statements: 0,
14
- branches: 0,
15
- functions: 0,
16
- lines: 0
13
+ statements: 83.48,
14
+ branches: 87.17,
15
+ functions: 94.11,
16
+ lines: 83.48
17
17
  }
18
18
  }
19
19
  }
20
20
  }
21
- );
21
+ );
package/.nycrc DELETED
@@ -1,26 +0,0 @@
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
- }
@@ -1,52 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApolloModule = void 0;
4
- const tslib_1 = require("tslib");
5
- const common_1 = require("@tsed/common");
6
- const di_1 = require("@tsed/di");
7
- const ApolloService_js_1 = require("./services/ApolloService.js");
8
- let ApolloModule = class ApolloModule {
9
- get settings() {
10
- return this.configuration.get("apollo");
11
- }
12
- $onRoutesInit() {
13
- const { settings } = this;
14
- if (settings) {
15
- const promises = Object.entries(settings).map(([key, options]) => {
16
- return this.service.createServer(key, options);
17
- });
18
- return Promise.all(promises);
19
- }
20
- }
21
- $afterListen() {
22
- const host = this.configuration.getBestHost();
23
- const displayLog = (key, path) => {
24
- const url = typeof host.port === "number" ? `${host.protocol}://${host.address}:${host.port}` : "";
25
- this.logger.info(`[${key}] Apollo server is available on ${url}${path.replace(/^\//, "")}`);
26
- };
27
- const { settings } = this;
28
- if (settings) {
29
- Object.entries(settings).map(([key, options]) => {
30
- const { path } = options;
31
- displayLog(key, path);
32
- });
33
- }
34
- }
35
- };
36
- tslib_1.__decorate([
37
- (0, di_1.Inject)(),
38
- tslib_1.__metadata("design:type", common_1.Logger)
39
- ], ApolloModule.prototype, "logger", void 0);
40
- tslib_1.__decorate([
41
- (0, di_1.Inject)(),
42
- tslib_1.__metadata("design:type", ApolloService_js_1.ApolloService)
43
- ], ApolloModule.prototype, "service", void 0);
44
- tslib_1.__decorate([
45
- (0, di_1.Configuration)(),
46
- tslib_1.__metadata("design:type", Object)
47
- ], ApolloModule.prototype, "configuration", void 0);
48
- ApolloModule = tslib_1.__decorate([
49
- (0, di_1.Module)()
50
- ], ApolloModule);
51
- exports.ApolloModule = ApolloModule;
52
- //# sourceMappingURL=ApolloModule.js.map
@@ -1 +0,0 @@
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;IAUvB,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,5 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DATASOURCES_PROVIDERS = void 0;
4
- exports.DATASOURCES_PROVIDERS = "graphql:datasources";
5
- //# sourceMappingURL=constants.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/constants/constants.ts"],"names":[],"mappings":";;;AAAa,QAAA,qBAAqB,GAAG,qBAAqB,CAAC"}
@@ -1,69 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DataSourceService = exports.DataSource = void 0;
4
- const core_1 = require("@tsed/core");
5
- const di_1 = require("@tsed/di");
6
- const constants_js_1 = require("../constants/constants.js");
7
- /**
8
- * Create a new injectable DataSource.
9
- *
10
- * ```typescript
11
- * import { DataSourceService } from "@tsed/graphql";
12
- * import { RESTDataSource } from 'apollo-datasource-rest';
13
- *
14
- * @DataSource()
15
- * export class MyDataSource extends RESTDataSource {
16
- * constructor() {
17
- * super();
18
- * this.baseURL = 'https://awesome-api.example.com';
19
- * }
20
- *
21
- * willSendRequest(request) {
22
- * request.headers.set('Authorization', this.context.token);
23
- * }
24
- *
25
- * getMyData(id: string) {
26
- * return this.get(`/v1/my_rest_data/${id}`);
27
- * }
28
- * }
29
- * ```
30
- *
31
- * @decorator
32
- * @graphql
33
- */
34
- function DataSource(name) {
35
- return (0, core_1.useDecorators)((0, di_1.Injectable)({
36
- type: constants_js_1.DATASOURCES_PROVIDERS,
37
- scope: di_1.ProviderScope.INSTANCE
38
- }), (0, core_1.StoreSet)(constants_js_1.DATASOURCES_PROVIDERS, { name }));
39
- }
40
- exports.DataSource = DataSource;
41
- /**
42
- * Create a new injectable DataSource.
43
- *
44
- * ```typescript
45
- * import { DataSourceService } from "@tsed/graphql";
46
- * import { RESTDataSource } from 'apollo-datasource-rest';
47
- *
48
- * @DataSource()
49
- * export class MyDataSource extends RESTDataSource {
50
- * constructor() {
51
- * super();
52
- * this.baseURL = 'https://awesome-api.example.com';
53
- * }
54
- *
55
- * willSendRequest(request) {
56
- * request.headers.set('Authorization', this.context.token);
57
- * }
58
- *
59
- * getMyData(id: string) {
60
- * return this.get(`/v1/my_rest_data/${id}`);
61
- * }
62
- * }
63
- * ```
64
- *
65
- * @decorator
66
- * @graphql
67
- */
68
- exports.DataSourceService = DataSource;
69
- //# sourceMappingURL=dataSource.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"dataSource.js","sourceRoot":"","sources":["../../../src/decorators/dataSource.ts"],"names":[],"mappings":";;;AAAA,qCAAmD;AACnD,iCAAmD;AACnD,4DAAgE;AAEhE;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,SAAgB,UAAU,CAAC,IAAa;IACtC,OAAO,IAAA,oBAAa,EAClB,IAAA,eAAU,EAAC;QACT,IAAI,EAAE,oCAAqB;QAC3B,KAAK,EAAE,kBAAa,CAAC,QAAQ;KAC9B,CAAC,EACF,IAAA,eAAQ,EAAC,oCAAqB,EAAE,EAAC,IAAI,EAAC,CAAC,CACxC,CAAC;AACJ,CAAC;AARD,gCAQC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACU,QAAA,iBAAiB,GAAG,UAAU,CAAC"}
package/lib/cjs/index.js DELETED
@@ -1,12 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- /**
5
- * @file Automatically generated by @tsed/barrels.
6
- */
7
- tslib_1.__exportStar(require("./ApolloModule.js"), exports);
8
- tslib_1.__exportStar(require("./constants/constants.js"), exports);
9
- tslib_1.__exportStar(require("./decorators/dataSource.js"), exports);
10
- tslib_1.__exportStar(require("./interfaces/ApolloSettings.js"), exports);
11
- tslib_1.__exportStar(require("./services/ApolloService.js"), exports);
12
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
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"}
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=ApolloSettings.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ApolloSettings.js","sourceRoot":"","sources":["../../../src/interfaces/ApolloSettings.ts"],"names":[],"mappings":""}
@@ -1,3 +0,0 @@
1
- {
2
- "type": "commonjs"
3
- }
@@ -1,169 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ApolloService = void 0;
4
- const tslib_1 = require("tslib");
5
- const common_1 = require("@tsed/common");
6
- const core_1 = require("@tsed/core");
7
- const di_1 = require("@tsed/di");
8
- const logger_1 = require("@tsed/logger");
9
- const apollo_server_core_1 = require("apollo-server-core");
10
- const http_1 = tslib_1.__importDefault(require("http"));
11
- const https_1 = tslib_1.__importDefault(require("https"));
12
- const constants_js_1 = require("../constants/constants.js");
13
- let ApolloService = class ApolloService {
14
- constructor(dataSources) {
15
- this.dataSources = dataSources;
16
- /**
17
- *
18
- * @type {Map<any, any>}
19
- * @private
20
- */
21
- this.servers = new Map();
22
- }
23
- async createServer(id, settings) {
24
- if (!this.has(id)) {
25
- try {
26
- const { dataSources, path, middlewareOptions = {}, server: customServer, ...config } = settings;
27
- this.logger.info(`Create server with Apollo for: ${id}`);
28
- this.logger.debug(`options: ${JSON.stringify({ path })}`);
29
- const plugins = await this.getPlugins(settings);
30
- const server = await this.createInstance({
31
- ...config,
32
- plugins,
33
- dataSources: this.createDataSources(dataSources)
34
- }, customServer);
35
- if (server) {
36
- this.servers.set(id || "default", {
37
- instance: server,
38
- schema: settings.schema
39
- });
40
- await server.start();
41
- const middleware = server.getMiddleware({
42
- path: settings.path,
43
- ...middlewareOptions
44
- });
45
- this.app.use(middleware);
46
- }
47
- }
48
- catch (er) {
49
- this.logger.error({
50
- event: "APOLLO_BOOTSTRAP_ERROR",
51
- error_name: er.name,
52
- message: er.message,
53
- stack: er.stack
54
- });
55
- /* istanbul ignore next */
56
- process.exit(-1);
57
- }
58
- }
59
- return this.get(id);
60
- }
61
- /**
62
- * Get an instance of ApolloServer from his id
63
- * @returns ApolloServer
64
- */
65
- get(id = "default") {
66
- return this.servers.get(id)?.instance;
67
- }
68
- /**
69
- * Get an instance of GraphQL schema from his id
70
- * @returns GraphQLSchema
71
- */
72
- getSchema(id = "default") {
73
- return this.servers.get(id)?.schema;
74
- }
75
- /**
76
- *
77
- * @param {string} id
78
- * @returns {boolean}
79
- */
80
- has(id = "default") {
81
- return this.servers.has(id);
82
- }
83
- async createInstance(options, server) {
84
- if (server) {
85
- return server(options);
86
- }
87
- const importServer = async () => {
88
- switch (this.platformName) {
89
- default:
90
- this.logger.error(`Platform "${this.platformName}" not supported by @tsed/apollo`);
91
- case "express":
92
- return (await import("apollo-server-express")).ApolloServer;
93
- case "koa":
94
- return (await import("apollo-server-koa")).ApolloServer;
95
- }
96
- };
97
- const Server = await importServer();
98
- return new Server(options);
99
- }
100
- /**
101
- * create a new dataSources function to use with apollo server config
102
- * @param dataSources
103
- */
104
- createDataSources(dataSources) {
105
- const dataSourcesHash = this.dataSources.reduce((map, instance) => {
106
- const klass = (0, core_1.classOf)(instance);
107
- const store = core_1.Store.from(klass);
108
- let { name } = store.get(constants_js_1.DATASOURCES_PROVIDERS);
109
- name = name || (0, core_1.nameOf)(klass);
110
- const sourceName = `${name[0].toLowerCase()}${name.slice(1)}`;
111
- map[sourceName] = instance;
112
- return map;
113
- }, {});
114
- return () => {
115
- return {
116
- ...dataSourcesHash,
117
- ...(dataSources ? dataSources() : {})
118
- };
119
- };
120
- }
121
- async getPlugins(serverSettings) {
122
- const playground = serverSettings.playground || (serverSettings.playground === undefined && process.env.NODE_ENV !== "production");
123
- const result = await this.injector.alter("$alterApolloServerPlugins", [
124
- this.httpServer &&
125
- (0, apollo_server_core_1.ApolloServerPluginDrainHttpServer)({
126
- httpServer: this.httpServer
127
- }),
128
- this.httpsServer &&
129
- (0, apollo_server_core_1.ApolloServerPluginDrainHttpServer)({
130
- httpServer: this.httpsServer
131
- }),
132
- ...(serverSettings.plugins || [])
133
- ].filter(Boolean), serverSettings);
134
- return result
135
- .concat([playground ? (0, apollo_server_core_1.ApolloServerPluginLandingPageLocalDefault)({ embed: true }) : (0, apollo_server_core_1.ApolloServerPluginLandingPageDisabled)()])
136
- .filter(Boolean);
137
- }
138
- };
139
- tslib_1.__decorate([
140
- (0, di_1.Constant)("PLATFORM_NAME"),
141
- tslib_1.__metadata("design:type", String)
142
- ], ApolloService.prototype, "platformName", void 0);
143
- tslib_1.__decorate([
144
- (0, di_1.Inject)(),
145
- tslib_1.__metadata("design:type", logger_1.Logger)
146
- ], ApolloService.prototype, "logger", void 0);
147
- tslib_1.__decorate([
148
- (0, di_1.Inject)(),
149
- tslib_1.__metadata("design:type", common_1.PlatformApplication)
150
- ], ApolloService.prototype, "app", void 0);
151
- tslib_1.__decorate([
152
- (0, di_1.Inject)(http_1.default.Server),
153
- tslib_1.__metadata("design:type", Object)
154
- ], ApolloService.prototype, "httpServer", void 0);
155
- tslib_1.__decorate([
156
- (0, di_1.Inject)(https_1.default.Server),
157
- tslib_1.__metadata("design:type", Object)
158
- ], ApolloService.prototype, "httpsServer", void 0);
159
- tslib_1.__decorate([
160
- (0, di_1.Inject)(),
161
- tslib_1.__metadata("design:type", common_1.InjectorService)
162
- ], ApolloService.prototype, "injector", void 0);
163
- ApolloService = tslib_1.__decorate([
164
- (0, di_1.Service)(),
165
- tslib_1.__param(0, (0, di_1.Inject)(constants_js_1.DATASOURCES_PROVIDERS)),
166
- tslib_1.__metadata("design:paramtypes", [Array])
167
- ], ApolloService);
168
- exports.ApolloService = ApolloService;
169
- //# sourceMappingURL=ApolloService.js.map
@@ -1 +0,0 @@
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;IAgCxB,YAAqD,WAAkB;QAAlB,gBAAW,GAAX,WAAW,CAAO;QAzBvE;;;;WAIG;QACO,YAAO,GAMb,IAAI,GAAG,EAAE,CAAC;IAc4D,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,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C,EACjB,cAAc,CACf,CAAC;QAEF,OAAO,MAAM;aACV,MAAM,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,IAAA,8DAAyC,EAAC,EAAC,KAAK,EAAE,IAAI,EAAC,CAAC,CAAC,CAAC,CAAC,IAAA,0DAAqC,GAAE,CAAC,CAAC;aACzH,MAAM,CAAC,OAAO,CAAC,CAAC;IACrB,CAAC;CACF,CAAA;AAjLC;IAAC,IAAA,aAAQ,EAAC,eAAe,CAAC;;mDACL;AAErB;IAAC,IAAA,WAAM,GAAE;sCACS,eAAM;6CAAC;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"}
@@ -1,3 +0,0 @@
1
- {
2
- "type": "module"
3
- }
@@ -1,14 +0,0 @@
1
- import { AfterListen, Logger, OnRoutesInit } from "@tsed/common";
2
- import { Configuration } from "@tsed/di";
3
- import { ApolloSettings } from "./interfaces/ApolloSettings.js";
4
- import { ApolloService } from "./services/ApolloService.js";
5
- export declare class ApolloModule implements OnRoutesInit, AfterListen {
6
- protected logger: Logger;
7
- protected service: ApolloService;
8
- protected configuration: Configuration;
9
- get settings(): {
10
- [key: string]: ApolloSettings;
11
- } | undefined;
12
- $onRoutesInit(): Promise<any> | void;
13
- $afterListen(): Promise<any> | void;
14
- }
@@ -1 +0,0 @@
1
- export declare const DATASOURCES_PROVIDERS = "graphql:datasources";
@@ -1,56 +0,0 @@
1
- /**
2
- * Create a new injectable DataSource.
3
- *
4
- * ```typescript
5
- * import { DataSourceService } from "@tsed/graphql";
6
- * import { RESTDataSource } from 'apollo-datasource-rest';
7
- *
8
- * @DataSource()
9
- * export class MyDataSource extends RESTDataSource {
10
- * constructor() {
11
- * super();
12
- * this.baseURL = 'https://awesome-api.example.com';
13
- * }
14
- *
15
- * willSendRequest(request) {
16
- * request.headers.set('Authorization', this.context.token);
17
- * }
18
- *
19
- * getMyData(id: string) {
20
- * return this.get(`/v1/my_rest_data/${id}`);
21
- * }
22
- * }
23
- * ```
24
- *
25
- * @decorator
26
- * @graphql
27
- */
28
- export declare function DataSource(name?: string): ClassDecorator;
29
- /**
30
- * Create a new injectable DataSource.
31
- *
32
- * ```typescript
33
- * import { DataSourceService } from "@tsed/graphql";
34
- * import { RESTDataSource } from 'apollo-datasource-rest';
35
- *
36
- * @DataSource()
37
- * export class MyDataSource extends RESTDataSource {
38
- * constructor() {
39
- * super();
40
- * this.baseURL = 'https://awesome-api.example.com';
41
- * }
42
- *
43
- * willSendRequest(request) {
44
- * request.headers.set('Authorization', this.context.token);
45
- * }
46
- *
47
- * getMyData(id: string) {
48
- * return this.get(`/v1/my_rest_data/${id}`);
49
- * }
50
- * }
51
- * ```
52
- *
53
- * @decorator
54
- * @graphql
55
- */
56
- export declare const DataSourceService: typeof DataSource;
@@ -1,8 +0,0 @@
1
- /**
2
- * @file Automatically generated by @tsed/barrels.
3
- */
4
- export * from "./ApolloModule.js";
5
- export * from "./constants/constants.js";
6
- export * from "./decorators/dataSource.js";
7
- export * from "./interfaces/ApolloSettings.js";
8
- export * from "./services/ApolloService.js";
@@ -1,20 +0,0 @@
1
- import type { ApolloServerBase, ApolloServerPluginLandingPageGraphQLPlaygroundOptions, Config } from "apollo-server-core";
2
- export type ApolloMiddlewareOptions = Record<string, any>;
3
- export type ApolloServer = ApolloServerBase & {
4
- getMiddleware(settings: ApolloMiddlewareOptions): any;
5
- };
6
- export type ApolloCustomServerCB = (config: ApolloConfig) => ApolloServer;
7
- export type ApolloConfig = Config;
8
- declare global {
9
- namespace TsED {
10
- interface ApolloSettings {
11
- }
12
- }
13
- }
14
- export interface ApolloSettings extends ApolloConfig, TsED.ApolloSettings {
15
- path: string;
16
- server?: ApolloCustomServerCB;
17
- playground?: boolean | ApolloServerPluginLandingPageGraphQLPlaygroundOptions;
18
- serverRegistration?: ApolloMiddlewareOptions;
19
- middlewareOptions?: ApolloMiddlewareOptions;
20
- }