@tsed/typegraphql 7.0.0-alpha.1 → 7.0.0-beta.3

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 (53) hide show
  1. package/.nycrc +1 -1
  2. package/lib/{TypeGraphQLModule.js → cjs/TypeGraphQLModule.js} +18 -16
  3. package/lib/cjs/TypeGraphQLModule.js.map +1 -0
  4. package/lib/{constants → cjs/constants}/index.js +0 -0
  5. package/lib/cjs/constants/index.js.map +1 -0
  6. package/lib/{decorators → cjs/decorators}/dataSourceService.js +3 -3
  7. package/lib/cjs/decorators/dataSourceService.js.map +1 -0
  8. package/lib/{decorators → cjs/decorators}/resolverService.js +1 -1
  9. package/lib/cjs/decorators/resolverService.js.map +1 -0
  10. package/lib/cjs/index.js +10 -0
  11. package/lib/cjs/index.js.map +1 -0
  12. package/lib/{interfaces → cjs/interfaces}/TypeGraphQLSettings.js +0 -0
  13. package/lib/cjs/interfaces/TypeGraphQLSettings.js.map +1 -0
  14. package/lib/{interfaces → cjs/interfaces}/index.js +1 -1
  15. package/lib/cjs/interfaces/index.js.map +1 -0
  16. package/lib/{services → cjs/services}/TypeGraphQLService.js +14 -14
  17. package/lib/cjs/services/TypeGraphQLService.js.map +1 -0
  18. package/lib/esm/TypeGraphQLModule.js +51 -0
  19. package/lib/esm/TypeGraphQLModule.js.map +1 -0
  20. package/lib/esm/constants/index.js +3 -0
  21. package/lib/esm/constants/index.js.map +1 -0
  22. package/lib/esm/decorators/dataSourceService.js +36 -0
  23. package/lib/esm/decorators/dataSourceService.js.map +1 -0
  24. package/lib/esm/decorators/resolverService.js +10 -0
  25. package/lib/esm/decorators/resolverService.js.map +1 -0
  26. package/lib/esm/index.js +7 -0
  27. package/lib/esm/index.js.map +1 -0
  28. package/lib/esm/interfaces/TypeGraphQLSettings.js +2 -0
  29. package/lib/esm/interfaces/TypeGraphQLSettings.js.map +1 -0
  30. package/lib/esm/interfaces/index.js +2 -0
  31. package/lib/esm/interfaces/index.js.map +1 -0
  32. package/lib/esm/services/TypeGraphQLService.js +129 -0
  33. package/lib/esm/services/TypeGraphQLService.js.map +1 -0
  34. package/lib/{TypeGraphQLModule.d.ts → types/TypeGraphQLModule.d.ts} +2 -2
  35. package/lib/{constants → types/constants}/index.d.ts +0 -0
  36. package/lib/{decorators → types/decorators}/dataSourceService.d.ts +0 -0
  37. package/lib/{decorators → types/decorators}/resolverService.d.ts +0 -0
  38. package/lib/{index.d.ts → types/index.d.ts} +0 -0
  39. package/lib/types/interfaces/TypeGraphQLSettings.d.ts +6 -0
  40. package/lib/{interfaces → types/interfaces}/index.d.ts +0 -0
  41. package/lib/{services → types/services}/TypeGraphQLService.d.ts +5 -6
  42. package/package.json +23 -19
  43. package/tsconfig.compile.esm.json +23 -0
  44. package/lib/TypeGraphQLModule.js.map +0 -1
  45. package/lib/constants/index.js.map +0 -1
  46. package/lib/decorators/dataSourceService.js.map +0 -1
  47. package/lib/decorators/resolverService.js.map +0 -1
  48. package/lib/index.js +0 -10
  49. package/lib/index.js.map +0 -1
  50. package/lib/interfaces/TypeGraphQLSettings.d.ts +0 -8
  51. package/lib/interfaces/TypeGraphQLSettings.js.map +0 -1
  52. package/lib/interfaces/index.js.map +0 -1
  53. package/lib/services/TypeGraphQLService.js.map +0 -1
package/.nycrc CHANGED
@@ -20,7 +20,7 @@
20
20
  "json"
21
21
  ],
22
22
  "check-coverage": true,
23
- "statements": 100,
23
+ "statements": 99.14,
24
24
  "branches": 70.45,
25
25
  "functions": 100,
26
26
  "lines": 100
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TypeGraphQLModule = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const common_1 = require("@tsed/common");
5
+ const di_1 = require("@tsed/di");
6
6
  const TypeGraphQLService_1 = require("./services/TypeGraphQLService");
7
7
  /**
8
8
  * @ignore
@@ -21,32 +21,34 @@ let TypeGraphQLModule = class TypeGraphQLModule {
21
21
  }
22
22
  }
23
23
  $afterListen() {
24
+ const host = this.configuration.getBestHost();
25
+ const displayLog = (key, path) => {
26
+ const url = typeof host.port === "number" ? `${host.protocol}://${host.address}:${host.port}` : "";
27
+ this.injector.logger.info(`[${key}] GraphQL server is available on ${url}/${path.replace(/^\//, "")}`);
28
+ };
24
29
  const { settings } = this;
25
30
  if (settings) {
26
- const httpHost = this.configuration.getHttpPort();
27
- const httpsHost = this.configuration.getHttpsPort();
28
- const host = httpsHost || httpHost;
29
31
  Object.entries(settings).map(async ([key, options]) => {
30
32
  const { path } = options;
31
- this.injector.logger.info(`[${key}] GraphQL server is available on http://${host.address}:${host.port}/${path.replace(/^\//, "")}`);
33
+ displayLog(key, path);
32
34
  });
33
35
  }
34
36
  }
35
37
  };
36
- tslib_1.__decorate([
37
- common_1.Inject(),
38
- tslib_1.__metadata("design:type", TypeGraphQLService_1.TypeGraphQLService)
38
+ (0, tslib_1.__decorate)([
39
+ (0, di_1.Inject)(),
40
+ (0, tslib_1.__metadata)("design:type", TypeGraphQLService_1.TypeGraphQLService)
39
41
  ], TypeGraphQLModule.prototype, "service", void 0);
40
- tslib_1.__decorate([
41
- common_1.Inject(),
42
- tslib_1.__metadata("design:type", common_1.InjectorService)
42
+ (0, tslib_1.__decorate)([
43
+ (0, di_1.Inject)(),
44
+ (0, tslib_1.__metadata)("design:type", di_1.InjectorService)
43
45
  ], TypeGraphQLModule.prototype, "injector", void 0);
44
- tslib_1.__decorate([
45
- common_1.Configuration(),
46
- tslib_1.__metadata("design:type", Object)
46
+ (0, tslib_1.__decorate)([
47
+ (0, di_1.Configuration)(),
48
+ (0, tslib_1.__metadata)("design:type", Object)
47
49
  ], TypeGraphQLModule.prototype, "configuration", void 0);
48
- TypeGraphQLModule = tslib_1.__decorate([
49
- common_1.Module()
50
+ TypeGraphQLModule = (0, tslib_1.__decorate)([
51
+ (0, di_1.Module)()
50
52
  ], TypeGraphQLModule);
51
53
  exports.TypeGraphQLModule = TypeGraphQLModule;
52
54
  //#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AAE,CAAC,CAAC;QACzG,CAAC,CAAC;QAEF,MAAM,EAAC,QAAQ,EAAC,GAAG,IAAI,CAAC;QAExB,IAAI,QAAQ,EAAE;YACZ,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE,EAAE;gBACpD,MAAM,EAAC,IAAI,EAAC,GAAG,OAAO,CAAC;gBAEvB,UAAU,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;YACxB,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;CACF,CAAA;AA1CC;IADC,IAAA,WAAM,GAAE;2CACU,uCAAkB;kDAAC;AAGtC;IADC,IAAA,WAAM,GAAE;2CACW,oBAAe;mDAAC;AAGpC;IADC,IAAA,kBAAa,GAAE;;wDACuB;AAR5B,iBAAiB;IAD7B,IAAA,WAAM,GAAE;GACI,iBAAiB,CA4C7B;AA5CY,8CAAiB","sourcesContent":["import {Configuration, Inject, InjectorService, Module} from \"@tsed/di\";\nimport {TypeGraphQLSettings} from \"./interfaces\";\nimport {TypeGraphQLService} from \"./services/TypeGraphQLService\";\n\n/**\n * @ignore\n */\n@Module()\nexport class TypeGraphQLModule {\n @Inject()\n protected service: TypeGraphQLService;\n\n @Inject()\n protected injector: InjectorService;\n\n @Configuration()\n protected configuration: Configuration;\n\n get settings(): {[key: string]: TypeGraphQLSettings} | undefined {\n return this.configuration.get(\"graphql\") || this.configuration.get(\"typegraphql\");\n }\n\n $onRoutesInit(): Promise<any> | void {\n const {settings} = this;\n if (settings) {\n const promises = Object.entries(settings).map(async ([key, options]) => {\n return this.service.createServer(key, options);\n });\n\n return Promise.all(promises);\n }\n }\n\n $afterListen(): Promise<any> | void {\n const host = this.configuration.getBestHost();\n\n const displayLog = (key: string, path: string) => {\n const url = typeof host.port === \"number\" ? `${host.protocol}://${host.address}:${host.port}` : \"\";\n\n this.injector.logger.info(`[${key}] GraphQL server is available on ${url}/${path.replace(/^\\//, \"\")}`);\n };\n\n const {settings} = this;\n\n if (settings) {\n Object.entries(settings).map(async ([key, options]) => {\n const {path} = options;\n\n displayLog(key, path);\n });\n }\n }\n}\n"]}
File without changes
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/constants/index.ts"],"names":[],"mappings":";;;AAAa,QAAA,gCAAgC,GAAG,0BAA0B,CAAC;AAC9D,QAAA,8BAA8B,GAAG,wBAAwB,CAAC","sourcesContent":["export const PROVIDER_TYPE_DATASOURCE_SERVICE = \"graphQLDataSourceService\";\nexport const PROVIDER_TYPE_RESOLVER_SERVICE = \"graphQLResolverService\";\n"]}
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DataSourceService = void 0;
4
- const common_1 = require("@tsed/common");
4
+ const di_1 = require("@tsed/di");
5
5
  const constants_1 = require("../constants");
6
6
  /**
7
7
  * Create a new DataSource binded with Tsed DI.
@@ -31,9 +31,9 @@ const constants_1 = require("../constants");
31
31
  * @graphql
32
32
  */
33
33
  function DataSourceService() {
34
- return common_1.Injectable({
34
+ return (0, di_1.Injectable)({
35
35
  type: constants_1.PROVIDER_TYPE_DATASOURCE_SERVICE,
36
- scope: common_1.ProviderScope.INSTANCE
36
+ scope: di_1.ProviderScope.INSTANCE
37
37
  });
38
38
  }
39
39
  exports.DataSourceService = DataSourceService;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dataSourceService.js","sourceRoot":"","sources":["../../../src/decorators/dataSourceService.ts"],"names":[],"mappings":";;;AAAA,iCAAmD;AACnD,4CAA8D;AAE9D;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,SAAgB,iBAAiB;IAC/B,OAAO,IAAA,eAAU,EAAC;QAChB,IAAI,EAAE,4CAAgC;QACtC,KAAK,EAAE,kBAAa,CAAC,QAAQ;KAC9B,CAAC,CAAC;AACL,CAAC;AALD,8CAKC","sourcesContent":["import {Injectable, ProviderScope} from \"@tsed/di\";\nimport {PROVIDER_TYPE_DATASOURCE_SERVICE} from \"../constants\";\n\n/**\n * Create a new DataSource binded with Tsed DI.\n *\n * ```typescript\n * import { DataSourceService } from \"@tsed/graphql\";\n * import { RESTDataSource } from 'apollo-datasource-rest';\n *\n * @DataSourceService()\n * export class MyDataSource extends RESTDataSource {\n * constructor() {\n * super();\n * this.baseURL = 'https://awesome-api.example.com';\n * }\n *\n * willSendRequest(request) {\n * request.headers.set('Authorization', this.context.token);\n * }\n *\n * getMyData(id: string) {\n * return this.get(`/v1/my_rest_data/${id}`);\n * }\n * }\n * ```\n *\n * @decorator\n * @graphql\n */\nexport function DataSourceService(): ClassDecorator {\n return Injectable({\n type: PROVIDER_TYPE_DATASOURCE_SERVICE,\n scope: ProviderScope.INSTANCE\n });\n}\n"]}
@@ -6,7 +6,7 @@ const di_1 = require("@tsed/di");
6
6
  const type_graphql_1 = require("type-graphql");
7
7
  const constants_1 = require("../constants");
8
8
  function ResolverService(...args) {
9
- return core_1.useDecorators(type_graphql_1.Resolver(...args), di_1.Injectable({
9
+ return (0, core_1.useDecorators)(type_graphql_1.Resolver(...args), (0, di_1.Injectable)({
10
10
  type: constants_1.PROVIDER_TYPE_RESOLVER_SERVICE
11
11
  }));
12
12
  }
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolverService.js","sourceRoot":"","sources":["../../../src/decorators/resolverService.ts"],"names":[],"mappings":";;;AAAA,qCAAyC;AACzC,iCAAoC;AACpC,+CAAiD;AAEjD,4CAA4D;AAM5D,SAAgB,eAAe,CAAC,GAAG,IAAW;IAC5C,OAAO,IAAA,oBAAa,EACjB,uBAAgB,CAAC,GAAG,IAAI,CAAC,EAC1B,IAAA,eAAU,EAAC;QACT,IAAI,EAAE,0CAA8B;KACrC,CAAC,CACH,CAAC;AACJ,CAAC;AAPD,0CAOC","sourcesContent":["import {useDecorators} from \"@tsed/core\";\nimport {Injectable} from \"@tsed/di\";\nimport {ClassType, Resolver} from \"type-graphql\";\nimport {AbstractClassOptions, ClassTypeResolver} from \"type-graphql/dist/decorators/types\";\nimport {PROVIDER_TYPE_RESOLVER_SERVICE} from \"../constants\";\n\nexport function ResolverService(): ClassDecorator;\nexport function ResolverService(options: AbstractClassOptions): ClassDecorator;\nexport function ResolverService(typeFunc: ClassTypeResolver, options?: AbstractClassOptions): ClassDecorator;\nexport function ResolverService(objectType: ClassType, options?: AbstractClassOptions): ClassDecorator;\nexport function ResolverService(...args: any[]): ClassDecorator {\n return useDecorators(\n (Resolver as any)(...args),\n Injectable({\n type: PROVIDER_TYPE_RESOLVER_SERVICE\n })\n );\n}\n"]}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const tslib_1 = require("tslib");
4
+ (0, tslib_1.__exportStar)(require("./interfaces"), exports);
5
+ (0, tslib_1.__exportStar)(require("./decorators/resolverService"), exports);
6
+ (0, tslib_1.__exportStar)(require("./decorators/dataSourceService"), exports);
7
+ (0, tslib_1.__exportStar)(require("./services/TypeGraphQLService"), exports);
8
+ (0, tslib_1.__exportStar)(require("./constants"), exports);
9
+ (0, tslib_1.__exportStar)(require("./TypeGraphQLModule"), exports);
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,4DAA6B;AAC7B,4EAA6C;AAC7C,8EAA+C;AAC/C,6EAA8C;AAC9C,2DAA4B;AAC5B,mEAAoC","sourcesContent":["export * from \"./interfaces\";\nexport * from \"./decorators/resolverService\";\nexport * from \"./decorators/dataSourceService\";\nexport * from \"./services/TypeGraphQLService\";\nexport * from \"./constants\";\nexport * from \"./TypeGraphQLModule\";\n"]}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TypeGraphQLSettings.js","sourceRoot":"","sources":["../../../src/interfaces/TypeGraphQLSettings.ts"],"names":[],"mappings":"","sourcesContent":["import {ApolloConfig, ApolloSettings} from \"@tsed/apollo\";\nimport {BuildSchemaOptions} from \"type-graphql\";\n\nexport interface TypeGraphQLSettings extends ApolloSettings {\n // TypeGraphQL options\n buildSchemaOptions?: Partial<BuildSchemaOptions>;\n // apollo-server-express options\n // See options descriptions on https://www.apollographql.com/docs/apollo-server/api/apollo-server.html\n serverConfig?: ApolloConfig;\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./TypeGraphQLSettings"), exports);
4
+ (0, tslib_1.__exportStar)(require("./TypeGraphQLSettings"), exports);
5
5
  //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/interfaces/index.ts"],"names":[],"mappings":";;;AAWA,qEAAsC","sourcesContent":["import {TypeGraphQLSettings} from \"./TypeGraphQLSettings\";\n\ndeclare global {\n namespace TsED {\n interface Configuration {\n graphql: {[key: string]: TypeGraphQLSettings};\n typegraphql: {[key: string]: TypeGraphQLSettings};\n }\n }\n}\n\nexport * from \"./TypeGraphQLSettings\";\n"]}
@@ -5,7 +5,7 @@ const tslib_1 = require("tslib");
5
5
  const apollo_1 = require("@tsed/apollo");
6
6
  const di_1 = require("@tsed/di");
7
7
  const logger_1 = require("@tsed/logger");
8
- const TypeGraphql = tslib_1.__importStar(require("type-graphql"));
8
+ const TypeGraphql = (0, tslib_1.__importStar)(require("type-graphql"));
9
9
  const type_graphql_1 = require("type-graphql");
10
10
  const constants_1 = require("../constants");
11
11
  const getKey = (id) => `typegraphql-${id}`;
@@ -62,7 +62,7 @@ let TypeGraphQLService = class TypeGraphQLService {
62
62
  * @param buildSchemaOptions
63
63
  */
64
64
  async createSchema(buildSchemaOptions) {
65
- return type_graphql_1.buildSchema(buildSchemaOptions);
65
+ return (0, type_graphql_1.buildSchema)(buildSchemaOptions);
66
66
  }
67
67
  /**
68
68
  * Get an instance of GraphQL schema from his id
@@ -79,7 +79,7 @@ let TypeGraphQLService = class TypeGraphQLService {
79
79
  return this.injector.getProviders(constants_1.PROVIDER_TYPE_RESOLVER_SERVICE).map((provider) => provider.useClass);
80
80
  }
81
81
  getDataSources() {
82
- const providers = Array.from(this.injector.getProviders(constants_1.PROVIDER_TYPE_DATASOURCE_SERVICE));
82
+ const providers = this.injector.getProviders(constants_1.PROVIDER_TYPE_DATASOURCE_SERVICE);
83
83
  return providers.reduce((map, provider) => {
84
84
  // set the first letter of the class lowercase to follow proper conventions during access
85
85
  // i.e. this.context.dataSources.userService
@@ -113,20 +113,20 @@ let TypeGraphQLService = class TypeGraphQLService {
113
113
  }
114
114
  }
115
115
  };
116
- tslib_1.__decorate([
117
- di_1.Inject(),
118
- tslib_1.__metadata("design:type", di_1.InjectorService)
116
+ (0, tslib_1.__decorate)([
117
+ (0, di_1.Inject)(),
118
+ (0, tslib_1.__metadata)("design:type", di_1.InjectorService)
119
119
  ], TypeGraphQLService.prototype, "injector", void 0);
120
- tslib_1.__decorate([
121
- di_1.Inject(),
122
- tslib_1.__metadata("design:type", apollo_1.ApolloService)
120
+ (0, tslib_1.__decorate)([
121
+ (0, di_1.Inject)(),
122
+ (0, tslib_1.__metadata)("design:type", apollo_1.ApolloService)
123
123
  ], TypeGraphQLService.prototype, "apolloService", void 0);
124
- tslib_1.__decorate([
125
- di_1.Inject(),
126
- tslib_1.__metadata("design:type", logger_1.Logger)
124
+ (0, tslib_1.__decorate)([
125
+ (0, di_1.Inject)(),
126
+ (0, tslib_1.__metadata)("design:type", logger_1.Logger)
127
127
  ], TypeGraphQLService.prototype, "logger", void 0);
128
- TypeGraphQLService = tslib_1.__decorate([
129
- di_1.Injectable()
128
+ TypeGraphQLService = (0, tslib_1.__decorate)([
129
+ (0, di_1.Injectable)()
130
130
  ], TypeGraphQLService);
131
131
  exports.TypeGraphQLService = TypeGraphQLService;
132
132
  //# sourceMappingURL=TypeGraphQLService.js.map
@@ -0,0 +1 @@
1
+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,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;YAEzD,OAAO,GAAG,CAAC;QACb,CAAC,EAAE,EAAE,CAAC,CAAC;IACT,CAAC;IAED;;;;OAIG;IACO,iBAAiB,CAAC,WAAiC,EAAE,mBAAyC;QACtG,OAAO,GAAG,EAAE;YACV,MAAM,OAAO,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;YAEtC,OAAO;gBACL,GAAG,OAAO;gBACV,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACrC,GAAG,CAAC,mBAAmB,CAAC,CAAC,CAAC,mBAAmB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACtD,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC;IAES,sBAAsB;QAC9B,uBAAuB;QACvB,aAAa;QACb,IAAI,WAAW,CAAC,YAAY,EAAE;YAC5B,mDAAmD;YACnD,aAAa;YACb,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;SAChD;IACH,CAAC;CACF,CAAA;AA5HC;IADC,IAAA,WAAM,GAAE;2CACW,oBAAe;oDAAC;AAGpC;IADC,IAAA,WAAM,GAAE;2CACgB,sBAAa;yDAAC;AAGvC;IADC,IAAA,WAAM,GAAE;2CACS,eAAM;kDAAC;AARd,kBAAkB;IAD9B,IAAA,eAAU,GAAE;GACA,kBAAkB,CA8H9B;AA9HY,gDAAkB","sourcesContent":["import {ApolloServer, ApolloService} from \"@tsed/apollo\";\nimport {Type} from \"@tsed/core\";\nimport {Inject, Injectable, InjectorService, Provider} from \"@tsed/di\";\nimport {Logger} from \"@tsed/logger\";\nimport {DataSource} from \"apollo-datasource\";\nimport {GraphQLSchema} from \"graphql\";\nimport * as TypeGraphql from \"type-graphql\";\nimport {buildSchema, BuildSchemaOptions} from \"type-graphql\";\nimport {ApolloServerBase} from \"apollo-server-core\";\nimport {PROVIDER_TYPE_DATASOURCE_SERVICE, PROVIDER_TYPE_RESOLVER_SERVICE} from \"../constants\";\nimport {TypeGraphQLSettings} from \"../interfaces\";\n\nconst getKey = (id: string) => `typegraphql-${id}`;\n\n@Injectable()\nexport class TypeGraphQLService {\n @Inject()\n protected injector: InjectorService;\n\n @Inject()\n protected apolloService: ApolloService;\n\n @Inject()\n protected logger: Logger;\n\n /**\n * Get an instance of ApolloServer from his id\n * @returns ApolloServer\n */\n get(id: string = \"default\"): ApolloServerBase | undefined {\n return this.apolloService.get(getKey(id));\n }\n\n /**\n *\n * @param {string} id\n * @returns {boolean}\n */\n has(id: string = \"default\"): boolean {\n return this.apolloService.has(getKey(id));\n }\n\n /**\n *\n * @returns {Promise<ApolloServer>}\n */\n async createServer(id: string, settings: TypeGraphQLSettings): Promise<any> {\n if (this.has(id)) {\n return this.get(id)!;\n }\n\n try {\n const {dataSources, resolvers: initialResolvers = [], buildSchemaOptions = {}, serverConfig = {}, ...serverOptions} = settings;\n\n this.configureTypeGraphQLDI();\n\n const resolvers: any = [...this.getResolvers(), ...(initialResolvers as any[])];\n const schema = await this.createSchema({\n container: this.injector,\n ...buildSchemaOptions,\n resolvers\n });\n\n return await this.apolloService.createServer(getKey(id), {\n ...serverOptions,\n ...serverConfig,\n resolvers,\n dataSources: this.createDataSources(dataSources, serverConfig.dataSources),\n schema\n });\n } catch (err) {\n /* istanbul ignore next */\n this.logger.error(err);\n /* istanbul ignore next */\n process.exit(-1);\n }\n }\n\n /**\n * Create a new type-graphql Schema and bind it with Ts.ED injector.\n * @param buildSchemaOptions\n */\n async createSchema(buildSchemaOptions: BuildSchemaOptions) {\n return buildSchema(buildSchemaOptions);\n }\n\n /**\n * Get an instance of GraphQL schema from his id\n * @returns GraphQLSchema\n */\n getSchema(id: string = \"default\"): GraphQLSchema | undefined {\n return this.apolloService.getSchema(getKey(id));\n }\n\n /**\n *\n * @returns {Provider<any>[]}\n */\n protected getResolvers(): Type<any>[] {\n return this.injector.getProviders(PROVIDER_TYPE_RESOLVER_SERVICE).map((provider) => provider.useClass);\n }\n\n protected getDataSources(): Record<string, DataSource> {\n const providers = this.injector.getProviders(PROVIDER_TYPE_DATASOURCE_SERVICE);\n\n return providers.reduce<Record<string, DataSource>>((map, provider) => {\n // set the first letter of the class lowercase to follow proper conventions during access\n // i.e. this.context.dataSources.userService\n const sourceName = `${provider.name[0].toLowerCase()}${provider.name.substr(1)}`;\n map[sourceName] = this.injector.invoke(provider.provide);\n\n return map;\n }, {});\n }\n\n /**\n * create a new dataSources function to use with apollo server config\n * @param dataSources\n * @param serverConfigSources\n */\n protected createDataSources(dataSources: Function | undefined, serverConfigSources: Function | undefined) {\n return () => {\n const sources = this.getDataSources();\n\n return {\n ...sources,\n ...(dataSources ? dataSources() : {}),\n ...(serverConfigSources ? serverConfigSources() : {})\n };\n };\n }\n\n protected configureTypeGraphQLDI() {\n // istanbul ignore next\n // @ts-ignore\n if (TypeGraphql.useContainer) {\n // support old version of type-graphql under @v0.17\n // @ts-ignore\n TypeGraphql.useContainer(this.injectorService);\n }\n }\n}\n"]}
@@ -0,0 +1,51 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import { Configuration, Inject, InjectorService, Module } from "@tsed/di";
3
+ import { TypeGraphQLService } from "./services/TypeGraphQLService";
4
+ /**
5
+ * @ignore
6
+ */
7
+ let TypeGraphQLModule = class TypeGraphQLModule {
8
+ get settings() {
9
+ return this.configuration.get("graphql") || this.configuration.get("typegraphql");
10
+ }
11
+ $onRoutesInit() {
12
+ const { settings } = this;
13
+ if (settings) {
14
+ const promises = Object.entries(settings).map(async ([key, options]) => {
15
+ return this.service.createServer(key, options);
16
+ });
17
+ return Promise.all(promises);
18
+ }
19
+ }
20
+ $afterListen() {
21
+ const host = this.configuration.getBestHost();
22
+ const displayLog = (key, path) => {
23
+ const url = typeof host.port === "number" ? `${host.protocol}://${host.address}:${host.port}` : "";
24
+ this.injector.logger.info(`[${key}] GraphQL server is available on ${url}/${path.replace(/^\//, "")}`);
25
+ };
26
+ const { settings } = this;
27
+ if (settings) {
28
+ Object.entries(settings).map(async ([key, options]) => {
29
+ const { path } = options;
30
+ displayLog(key, path);
31
+ });
32
+ }
33
+ }
34
+ };
35
+ __decorate([
36
+ Inject(),
37
+ __metadata("design:type", TypeGraphQLService)
38
+ ], TypeGraphQLModule.prototype, "service", void 0);
39
+ __decorate([
40
+ Inject(),
41
+ __metadata("design:type", InjectorService)
42
+ ], TypeGraphQLModule.prototype, "injector", void 0);
43
+ __decorate([
44
+ Configuration(),
45
+ __metadata("design:type", Object)
46
+ ], TypeGraphQLModule.prototype, "configuration", void 0);
47
+ TypeGraphQLModule = __decorate([
48
+ Module()
49
+ ], TypeGraphQLModule);
50
+ export { TypeGraphQLModule };
51
+ //# sourceMappingURL=TypeGraphQLModule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TypeGraphQLModule.js","sourceRoot":"","sources":["../../src/TypeGraphQLModule.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,aAAa,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EAAC,MAAM,UAAU,CAAC;AAExE,OAAO,EAAC,kBAAkB,EAAC,MAAM,+BAA+B,CAAC;AAEjE;;GAEG;AAEH,IAAa,iBAAiB,GAA9B,MAAa,iBAAiB;IAU5B,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IACpF,CAAC;IAED,aAAa;QACX,MAAM,EAAC,QAAQ,EAAC,GAAG,IAAI,CAAC;QACxB,IAAI,QAAQ,EAAE;YACZ,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE,EAAE;gBACrE,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,GAAG,EAAE,O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import {TypeGraphQLService} from \"./services/TypeGraphQLService\";\n\n/**\n * @ignore\n */\n@Module()\nexport class TypeGraphQLModule {\n @Inject()\n protected service: TypeGraphQLService;\n\n @Inject()\n protected injector: InjectorService;\n\n @Configuration()\n protected configuration: Configuration;\n\n get settings(): {[key: string]: TypeGraphQLSettings} | undefined {\n return this.configuration.get(\"graphql\") || this.configuration.get(\"typegraphql\");\n }\n\n $onRoutesInit(): Promise<any> | void {\n const {settings} = this;\n if (settings) {\n const promises = Object.entries(settings).map(async ([key, options]) => {\n return this.service.createServer(key, options);\n });\n\n return Promise.all(promises);\n }\n }\n\n $afterListen(): Promise<any> | void {\n const host = this.configuration.getBestHost();\n\n const displayLog = (key: string, path: string) => {\n const url = typeof host.port === \"number\" ? `${host.protocol}://${host.address}:${host.port}` : \"\";\n\n this.injector.logger.info(`[${key}] GraphQL server is available on ${url}/${path.replace(/^\\//, \"\")}`);\n };\n\n const {settings} = this;\n\n if (settings) {\n Object.entries(settings).map(async ([key, options]) => {\n const {path} = options;\n\n displayLog(key, path);\n });\n }\n }\n}\n"]}
@@ -0,0 +1,3 @@
1
+ export const PROVIDER_TYPE_DATASOURCE_SERVICE = "graphQLDataSourceService";
2
+ export const PROVIDER_TYPE_RESOLVER_SERVICE = "graphQLResolverService";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/constants/index.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,gCAAgC,GAAG,0BAA0B,CAAC;AAC3E,MAAM,CAAC,MAAM,8BAA8B,GAAG,wBAAwB,CAAC","sourcesContent":["export const PROVIDER_TYPE_DATASOURCE_SERVICE = \"graphQLDataSourceService\";\nexport const PROVIDER_TYPE_RESOLVER_SERVICE = \"graphQLResolverService\";\n"]}
@@ -0,0 +1,36 @@
1
+ import { Injectable, ProviderScope } from "@tsed/di";
2
+ import { PROVIDER_TYPE_DATASOURCE_SERVICE } from "../constants";
3
+ /**
4
+ * Create a new DataSource binded with Tsed DI.
5
+ *
6
+ * ```typescript
7
+ * import { DataSourceService } from "@tsed/graphql";
8
+ * import { RESTDataSource } from 'apollo-datasource-rest';
9
+ *
10
+ * @DataSourceService()
11
+ * export class MyDataSource extends RESTDataSource {
12
+ * constructor() {
13
+ * super();
14
+ * this.baseURL = 'https://awesome-api.example.com';
15
+ * }
16
+ *
17
+ * willSendRequest(request) {
18
+ * request.headers.set('Authorization', this.context.token);
19
+ * }
20
+ *
21
+ * getMyData(id: string) {
22
+ * return this.get(`/v1/my_rest_data/${id}`);
23
+ * }
24
+ * }
25
+ * ```
26
+ *
27
+ * @decorator
28
+ * @graphql
29
+ */
30
+ export function DataSourceService() {
31
+ return Injectable({
32
+ type: PROVIDER_TYPE_DATASOURCE_SERVICE,
33
+ scope: ProviderScope.INSTANCE
34
+ });
35
+ }
36
+ //# sourceMappingURL=dataSourceService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dataSourceService.js","sourceRoot":"","sources":["../../../src/decorators/dataSourceService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,aAAa,EAAC,MAAM,UAAU,CAAC;AACnD,OAAO,EAAC,gCAAgC,EAAC,MAAM,cAAc,CAAC;AAE9D;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,iBAAiB;IAC/B,OAAO,UAAU,CAAC;QAChB,IAAI,EAAE,gCAAgC;QACtC,KAAK,EAAE,aAAa,CAAC,QAAQ;KAC9B,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {Injectable, ProviderScope} from \"@tsed/di\";\nimport {PROVIDER_TYPE_DATASOURCE_SERVICE} from \"../constants\";\n\n/**\n * Create a new DataSource binded with Tsed DI.\n *\n * ```typescript\n * import { DataSourceService } from \"@tsed/graphql\";\n * import { RESTDataSource } from 'apollo-datasource-rest';\n *\n * @DataSourceService()\n * export class MyDataSource extends RESTDataSource {\n * constructor() {\n * super();\n * this.baseURL = 'https://awesome-api.example.com';\n * }\n *\n * willSendRequest(request) {\n * request.headers.set('Authorization', this.context.token);\n * }\n *\n * getMyData(id: string) {\n * return this.get(`/v1/my_rest_data/${id}`);\n * }\n * }\n * ```\n *\n * @decorator\n * @graphql\n */\nexport function DataSourceService(): ClassDecorator {\n return Injectable({\n type: PROVIDER_TYPE_DATASOURCE_SERVICE,\n scope: ProviderScope.INSTANCE\n });\n}\n"]}
@@ -0,0 +1,10 @@
1
+ import { useDecorators } from "@tsed/core";
2
+ import { Injectable } from "@tsed/di";
3
+ import { Resolver } from "type-graphql";
4
+ import { PROVIDER_TYPE_RESOLVER_SERVICE } from "../constants";
5
+ export function ResolverService(...args) {
6
+ return useDecorators(Resolver(...args), Injectable({
7
+ type: PROVIDER_TYPE_RESOLVER_SERVICE
8
+ }));
9
+ }
10
+ //# sourceMappingURL=resolverService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolverService.js","sourceRoot":"","sources":["../../../src/decorators/resolverService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,aAAa,EAAC,MAAM,YAAY,CAAC;AACzC,OAAO,EAAC,UAAU,EAAC,MAAM,UAAU,CAAC;AACpC,OAAO,EAAY,QAAQ,EAAC,MAAM,cAAc,CAAC;AAEjD,OAAO,EAAC,8BAA8B,EAAC,MAAM,cAAc,CAAC;AAM5D,MAAM,UAAU,eAAe,CAAC,GAAG,IAAW;IAC5C,OAAO,aAAa,CACjB,QAAgB,CAAC,GAAG,IAAI,CAAC,EAC1B,UAAU,CAAC;QACT,IAAI,EAAE,8BAA8B;KACrC,CAAC,CACH,CAAC;AACJ,CAAC","sourcesContent":["import {useDecorators} from \"@tsed/core\";\nimport {Injectable} from \"@tsed/di\";\nimport {ClassType, Resolver} from \"type-graphql\";\nimport {AbstractClassOptions, ClassTypeResolver} from \"type-graphql/dist/decorators/types\";\nimport {PROVIDER_TYPE_RESOLVER_SERVICE} from \"../constants\";\n\nexport function ResolverService(): ClassDecorator;\nexport function ResolverService(options: AbstractClassOptions): ClassDecorator;\nexport function ResolverService(typeFunc: ClassTypeResolver, options?: AbstractClassOptions): ClassDecorator;\nexport function ResolverService(objectType: ClassType, options?: AbstractClassOptions): ClassDecorator;\nexport function ResolverService(...args: any[]): ClassDecorator {\n return useDecorators(\n (Resolver as any)(...args),\n Injectable({\n type: PROVIDER_TYPE_RESOLVER_SERVICE\n })\n );\n}\n"]}
@@ -0,0 +1,7 @@
1
+ export * from "./interfaces";
2
+ export * from "./decorators/resolverService";
3
+ export * from "./decorators/dataSourceService";
4
+ export * from "./services/TypeGraphQLService";
5
+ export * from "./constants";
6
+ export * from "./TypeGraphQLModule";
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,aAAa,CAAC;AAC5B,cAAc,qBAAqB,CAAC","sourcesContent":["export * from \"./interfaces\";\nexport * from \"./decorators/resolverService\";\nexport * from \"./decorators/dataSourceService\";\nexport * from \"./services/TypeGraphQLService\";\nexport * from \"./constants\";\nexport * from \"./TypeGraphQLModule\";\n"]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=TypeGraphQLSettings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TypeGraphQLSettings.js","sourceRoot":"","sources":["../../../src/interfaces/TypeGraphQLSettings.ts"],"names":[],"mappings":"","sourcesContent":["import {ApolloConfig, ApolloSettings} from \"@tsed/apollo\";\nimport {BuildSchemaOptions} from \"type-graphql\";\n\nexport interface TypeGraphQLSettings extends ApolloSettings {\n // TypeGraphQL options\n buildSchemaOptions?: Partial<BuildSchemaOptions>;\n // apollo-server-express options\n // See options descriptions on https://www.apollographql.com/docs/apollo-server/api/apollo-server.html\n serverConfig?: ApolloConfig;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export * from "./TypeGraphQLSettings";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/interfaces/index.ts"],"names":[],"mappings":"AAWA,cAAc,uBAAuB,CAAC","sourcesContent":["import {TypeGraphQLSettings} from \"./TypeGraphQLSettings\";\n\ndeclare global {\n namespace TsED {\n interface Configuration {\n graphql: {[key: string]: TypeGraphQLSettings};\n typegraphql: {[key: string]: TypeGraphQLSettings};\n }\n }\n}\n\nexport * from \"./TypeGraphQLSettings\";\n"]}
@@ -0,0 +1,129 @@
1
+ import { __decorate, __metadata } from "tslib";
2
+ import { ApolloService } from "@tsed/apollo";
3
+ import { Inject, Injectable, InjectorService } from "@tsed/di";
4
+ import { Logger } from "@tsed/logger";
5
+ import * as TypeGraphql from "type-graphql";
6
+ import { buildSchema } from "type-graphql";
7
+ import { PROVIDER_TYPE_DATASOURCE_SERVICE, PROVIDER_TYPE_RESOLVER_SERVICE } from "../constants";
8
+ const getKey = (id) => `typegraphql-${id}`;
9
+ let TypeGraphQLService = class TypeGraphQLService {
10
+ /**
11
+ * Get an instance of ApolloServer from his id
12
+ * @returns ApolloServer
13
+ */
14
+ get(id = "default") {
15
+ return this.apolloService.get(getKey(id));
16
+ }
17
+ /**
18
+ *
19
+ * @param {string} id
20
+ * @returns {boolean}
21
+ */
22
+ has(id = "default") {
23
+ return this.apolloService.has(getKey(id));
24
+ }
25
+ /**
26
+ *
27
+ * @returns {Promise<ApolloServer>}
28
+ */
29
+ async createServer(id, settings) {
30
+ if (this.has(id)) {
31
+ return this.get(id);
32
+ }
33
+ try {
34
+ const { dataSources, resolvers: initialResolvers = [], buildSchemaOptions = {}, serverConfig = {}, ...serverOptions } = settings;
35
+ this.configureTypeGraphQLDI();
36
+ const resolvers = [...this.getResolvers(), ...initialResolvers];
37
+ const schema = await this.createSchema({
38
+ container: this.injector,
39
+ ...buildSchemaOptions,
40
+ resolvers
41
+ });
42
+ return await this.apolloService.createServer(getKey(id), {
43
+ ...serverOptions,
44
+ ...serverConfig,
45
+ resolvers,
46
+ dataSources: this.createDataSources(dataSources, serverConfig.dataSources),
47
+ schema
48
+ });
49
+ }
50
+ catch (err) {
51
+ /* istanbul ignore next */
52
+ this.logger.error(err);
53
+ /* istanbul ignore next */
54
+ process.exit(-1);
55
+ }
56
+ }
57
+ /**
58
+ * Create a new type-graphql Schema and bind it with Ts.ED injector.
59
+ * @param buildSchemaOptions
60
+ */
61
+ async createSchema(buildSchemaOptions) {
62
+ return buildSchema(buildSchemaOptions);
63
+ }
64
+ /**
65
+ * Get an instance of GraphQL schema from his id
66
+ * @returns GraphQLSchema
67
+ */
68
+ getSchema(id = "default") {
69
+ return this.apolloService.getSchema(getKey(id));
70
+ }
71
+ /**
72
+ *
73
+ * @returns {Provider<any>[]}
74
+ */
75
+ getResolvers() {
76
+ return this.injector.getProviders(PROVIDER_TYPE_RESOLVER_SERVICE).map((provider) => provider.useClass);
77
+ }
78
+ getDataSources() {
79
+ const providers = this.injector.getProviders(PROVIDER_TYPE_DATASOURCE_SERVICE);
80
+ return providers.reduce((map, provider) => {
81
+ // set the first letter of the class lowercase to follow proper conventions during access
82
+ // i.e. this.context.dataSources.userService
83
+ const sourceName = `${provider.name[0].toLowerCase()}${provider.name.substr(1)}`;
84
+ map[sourceName] = this.injector.invoke(provider.provide);
85
+ return map;
86
+ }, {});
87
+ }
88
+ /**
89
+ * create a new dataSources function to use with apollo server config
90
+ * @param dataSources
91
+ * @param serverConfigSources
92
+ */
93
+ createDataSources(dataSources, serverConfigSources) {
94
+ return () => {
95
+ const sources = this.getDataSources();
96
+ return {
97
+ ...sources,
98
+ ...(dataSources ? dataSources() : {}),
99
+ ...(serverConfigSources ? serverConfigSources() : {})
100
+ };
101
+ };
102
+ }
103
+ configureTypeGraphQLDI() {
104
+ // istanbul ignore next
105
+ // @ts-ignore
106
+ if (TypeGraphql.useContainer) {
107
+ // support old version of type-graphql under @v0.17
108
+ // @ts-ignore
109
+ TypeGraphql.useContainer(this.injectorService);
110
+ }
111
+ }
112
+ };
113
+ __decorate([
114
+ Inject(),
115
+ __metadata("design:type", InjectorService)
116
+ ], TypeGraphQLService.prototype, "injector", void 0);
117
+ __decorate([
118
+ Inject(),
119
+ __metadata("design:type", ApolloService)
120
+ ], TypeGraphQLService.prototype, "apolloService", void 0);
121
+ __decorate([
122
+ Inject(),
123
+ __metadata("design:type", Logger)
124
+ ], TypeGraphQLService.prototype, "logger", void 0);
125
+ TypeGraphQLService = __decorate([
126
+ Injectable()
127
+ ], TypeGraphQLService);
128
+ export { TypeGraphQLService };
129
+ //# sourceMappingURL=TypeGraphQLService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TypeGraphQLService.js","sourceRoot":"","sources":["../../../src/services/TypeGraphQLService.ts"],"names":[],"mappings":";AAAA,OAAO,EAAe,aAAa,EAAC,MAAM,cAAc,CAAC;AAEzD,OAAO,EAAC,MAAM,EAAE,UAAU,EAAE,eAAe,EAAW,MAAM,UAAU,CAAC;AACvE,OAAO,EAAC,MAAM,EAAC,MAAM,cAAc,CAAC;AAGpC,OAAO,KAAK,WAAW,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAC,WAAW,EAAqB,MAAM,cAAc,CAAC;AAE7D,OAAO,EAAC,gCAAgC,EAAE,8BAA8B,EAAC,MAAM,cAAc,CAAC;AAG9F,MAAM,MAAM,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,eAAe,EAAE,EAAE,CAAC;AAGnD,IAAa,kBAAkB,GAA/B,MAAa,kBAAkB;IAU7B;;;OAGG;IACH,GAAG,CAAC,KAAa,SAAS;QACxB,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;IAC5C,CAAC;IAED;;;;OAIG;IACH,GAAG,CAAC,KAAa,SAAS;QACxB,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG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B;QAC9B,uBAAuB;QACvB,aAAa;QACb,IAAI,WAAW,CAAC,YAAY,EAAE;YAC5B,mDAAmD;YACnD,aAAa;YACb,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;SAChD;IACH,CAAC;CACF,CAAA;AA5HC;IADC,MAAM,EAAE;8BACW,eAAe;oDAAC;AAGpC;IADC,MAAM,EAAE;8BACgB,aAAa;yDAAC;AAGvC;IADC,MAAM,EAAE;8BACS,MAAM;kDAAC;AARd,kBAAkB;IAD9B,UAAU,EAAE;GACA,kBAAkB,CA8H9B;SA9HY,kBAAkB","sourcesContent":["import {ApolloServer, ApolloService} from \"@tsed/apollo\";\nimport {Type} from \"@tsed/core\";\nimport {Inject, Injectable, InjectorService, Provider} from \"@tsed/di\";\nimport {Logger} from \"@tsed/logger\";\nimport {DataSource} from \"apollo-datasource\";\nimport {GraphQLSchema} from \"graphql\";\nimport * as TypeGraphql from \"type-graphql\";\nimport {buildSchema, BuildSchemaOptions} from \"type-graphql\";\nimport {ApolloServerBase} from \"apollo-server-core\";\nimport {PROVIDER_TYPE_DATASOURCE_SERVICE, PROVIDER_TYPE_RESOLVER_SERVICE} from \"../constants\";\nimport {TypeGraphQLSettings} from \"../interfaces\";\n\nconst getKey = (id: string) => `typegraphql-${id}`;\n\n@Injectable()\nexport class TypeGraphQLService {\n @Inject()\n protected injector: InjectorService;\n\n @Inject()\n protected apolloService: ApolloService;\n\n @Inject()\n protected logger: Logger;\n\n /**\n * Get an instance of ApolloServer from his id\n * @returns ApolloServer\n */\n get(id: string = \"default\"): ApolloServerBase | undefined {\n return this.apolloService.get(getKey(id));\n }\n\n /**\n *\n * @param {string} id\n * @returns {boolean}\n */\n has(id: string = \"default\"): boolean {\n return this.apolloService.has(getKey(id));\n }\n\n /**\n *\n * @returns {Promise<ApolloServer>}\n */\n async createServer(id: string, settings: TypeGraphQLSettings): Promise<any> {\n if (this.has(id)) {\n return this.get(id)!;\n }\n\n try {\n const {dataSources, resolvers: initialResolvers = [], buildSchemaOptions = {}, serverConfig = {}, ...serverOptions} = settings;\n\n this.configureTypeGraphQLDI();\n\n const resolvers: any = [...this.getResolvers(), ...(initialResolvers as any[])];\n const schema = await this.createSchema({\n container: this.injector,\n ...buildSchemaOptions,\n resolvers\n });\n\n return await this.apolloService.createServer(getKey(id), {\n ...serverOptions,\n ...serverConfig,\n resolvers,\n dataSources: this.createDataSources(dataSources, serverConfig.dataSources),\n schema\n });\n } catch (err) {\n /* istanbul ignore next */\n this.logger.error(err);\n /* istanbul ignore next */\n process.exit(-1);\n }\n }\n\n /**\n * Create a new type-graphql Schema and bind it with Ts.ED injector.\n * @param buildSchemaOptions\n */\n async createSchema(buildSchemaOptions: BuildSchemaOptions) {\n return buildSchema(buildSchemaOptions);\n }\n\n /**\n * Get an instance of GraphQL schema from his id\n * @returns GraphQLSchema\n */\n getSchema(id: string = \"default\"): GraphQLSchema | undefined {\n return this.apolloService.getSchema(getKey(id));\n }\n\n /**\n *\n * @returns {Provider<any>[]}\n */\n protected getResolvers(): Type<any>[] {\n return this.injector.getProviders(PROVIDER_TYPE_RESOLVER_SERVICE).map((provider) => provider.useClass);\n }\n\n protected getDataSources(): Record<string, DataSource> {\n const providers = this.injector.getProviders(PROVIDER_TYPE_DATASOURCE_SERVICE);\n\n return providers.reduce<Record<string, DataSource>>((map, provider) => {\n // set the first letter of the class lowercase to follow proper conventions during access\n // i.e. this.context.dataSources.userService\n const sourceName = `${provider.name[0].toLowerCase()}${provider.name.substr(1)}`;\n map[sourceName] = this.injector.invoke(provider.provide);\n\n return map;\n }, {});\n }\n\n /**\n * create a new dataSources function to use with apollo server config\n * @param dataSources\n * @param serverConfigSources\n */\n protected createDataSources(dataSources: Function | undefined, serverConfigSources: Function | undefined) {\n return () => {\n const sources = this.getDataSources();\n\n return {\n ...sources,\n ...(dataSources ? dataSources() : {}),\n ...(serverConfigSources ? serverConfigSources() : {})\n };\n };\n }\n\n protected configureTypeGraphQLDI() {\n // istanbul ignore next\n // @ts-ignore\n if (TypeGraphql.useContainer) {\n // support old version of type-graphql under @v0.17\n // @ts-ignore\n TypeGraphql.useContainer(this.injectorService);\n }\n }\n}\n"]}
@@ -1,10 +1,10 @@
1
- import { AfterListen, Configuration, InjectorService, OnRoutesInit } from "@tsed/common";
1
+ import { Configuration, InjectorService } from "@tsed/di";
2
2
  import { TypeGraphQLSettings } from "./interfaces";
3
3
  import { TypeGraphQLService } from "./services/TypeGraphQLService";
4
4
  /**
5
5
  * @ignore
6
6
  */
7
- export declare class TypeGraphQLModule implements OnRoutesInit, AfterListen {
7
+ export declare class TypeGraphQLModule {
8
8
  protected service: TypeGraphQLService;
9
9
  protected injector: InjectorService;
10
10
  protected configuration: Configuration;
File without changes
File without changes
@@ -0,0 +1,6 @@
1
+ import { ApolloConfig, ApolloSettings } from "@tsed/apollo";
2
+ import { BuildSchemaOptions } from "type-graphql";
3
+ export interface TypeGraphQLSettings extends ApolloSettings {
4
+ buildSchemaOptions?: Partial<BuildSchemaOptions>;
5
+ serverConfig?: ApolloConfig;
6
+ }
File without changes
@@ -1,10 +1,11 @@
1
- import { ApolloServer, ApolloService } from "@tsed/apollo";
1
+ import { ApolloService } from "@tsed/apollo";
2
2
  import { Type } from "@tsed/core";
3
3
  import { InjectorService } from "@tsed/di";
4
4
  import { Logger } from "@tsed/logger";
5
5
  import { DataSource } from "apollo-datasource";
6
6
  import { GraphQLSchema } from "graphql";
7
7
  import { BuildSchemaOptions } from "type-graphql";
8
+ import { ApolloServerBase } from "apollo-server-core";
8
9
  import { TypeGraphQLSettings } from "../interfaces";
9
10
  export declare class TypeGraphQLService {
10
11
  protected injector: InjectorService;
@@ -14,7 +15,7 @@ export declare class TypeGraphQLService {
14
15
  * Get an instance of ApolloServer from his id
15
16
  * @returns ApolloServer
16
17
  */
17
- get(id?: string): ApolloServer | undefined;
18
+ get(id?: string): ApolloServerBase | undefined;
18
19
  /**
19
20
  *
20
21
  * @param {string} id
@@ -30,7 +31,7 @@ export declare class TypeGraphQLService {
30
31
  * Create a new type-graphql Schema and bind it with Ts.ED injector.
31
32
  * @param buildSchemaOptions
32
33
  */
33
- createSchema(buildSchemaOptions: BuildSchemaOptions): Promise<import("graphql").GraphQLSchema>;
34
+ createSchema(buildSchemaOptions: BuildSchemaOptions): Promise<GraphQLSchema>;
34
35
  /**
35
36
  * Get an instance of GraphQL schema from his id
36
37
  * @returns GraphQLSchema
@@ -41,9 +42,7 @@ export declare class TypeGraphQLService {
41
42
  * @returns {Provider<any>[]}
42
43
  */
43
44
  protected getResolvers(): Type<any>[];
44
- protected getDataSources(): {
45
- [serviceName: string]: DataSource;
46
- };
45
+ protected getDataSources(): Record<string, DataSource>;
47
46
  /**
48
47
  * create a new dataSources function to use with apollo server config
49
48
  * @param dataSources
package/package.json CHANGED
@@ -1,44 +1,48 @@
1
1
  {
2
2
  "name": "@tsed/typegraphql",
3
- "version": "7.0.0-alpha.1",
3
+ "version": "7.0.0-beta.3",
4
4
  "description": "TypeGraphQL package for Ts.ED framework, based on Apollo-server-core and Type-graphql",
5
5
  "private": false,
6
- "main": "./lib/index.js",
7
- "typings": "./lib/index.d.ts",
6
+ "source": "./src/index.ts",
7
+ "main": "./lib/cjs/index.js",
8
+ "typings": "./lib/types/index.d.ts",
9
+ "exports": {
10
+ "types": "./lib/types/index.d.ts",
11
+ "import": "./lib/esm/index.js",
12
+ "require": "./lib/cjs/index.js",
13
+ "default": "./lib/esm/index.js"
14
+ },
8
15
  "scripts": {
9
- "build": "tsc --build tsconfig.compile.json",
16
+ "build": "yarn run build:esm && yarn run build:cjs",
17
+ "build:cjs": "tsc --build tsconfig.compile.json",
18
+ "build:esm": "tsc --build tsconfig.compile.esm.json",
10
19
  "start": "ts-node -r tsconfig-paths/register test/app/index.ts",
11
20
  "test": "cross-env NODE_ENV=test nyc mocha"
12
21
  },
13
22
  "dependencies": {
14
- "@tsed/apollo": "7.0.0-alpha.1",
23
+ "@tsed/apollo": "7.0.0-beta.3",
15
24
  "tslib": "2.2.0"
16
25
  },
17
26
  "devDependencies": {
18
- "@tsed/common": "7.0.0-alpha.1",
19
- "@tsed/core": "7.0.0-alpha.1",
20
- "@types/graphql": "14.5.0",
21
- "apollo-datasource": "^0.7.2",
22
- "apollo-datasource-rest": "^0.9.3",
23
- "apollo-server-express": "^2.16.1",
24
- "apollo-server-testing": "2.18.2",
27
+ "@tsed/common": "7.0.0-beta.3",
28
+ "@tsed/core": "7.0.0-beta.3",
29
+ "@types/graphql": "^14.5.0",
25
30
  "class-validator": "~0.13.1",
26
- "graphql": "15.5.1",
27
31
  "graphql-passport": "0.6.3",
28
32
  "type-graphql": "^1.1.1"
29
33
  },
30
34
  "peerDependencies": {
31
- "apollo-datasource": "^0.7.3",
32
- "apollo-datasource-rest": "^0.10.0",
33
- "apollo-server-express": "^2.21.0",
34
- "graphql": "^15.5.0 | 14.7.0",
35
- "type-graphql": "^1.1.1 | ^0.17.6"
35
+ "apollo-datasource": ">=3.0.0",
36
+ "apollo-datasource-rest": ">=3.0.0",
37
+ "class-validator": ">=0.13.1",
38
+ "graphql": ">=15.0.0",
39
+ "type-graphql": ">=1.0.0"
36
40
  },
37
41
  "repository": "https://github.com/tsedio/tsed",
38
42
  "bugs": {
39
43
  "url": "https://github.com/tsedio/tsed/issues"
40
44
  },
41
- "homepage": "https://github.com/tsedio/tsed/tree/alpha/packages/graphql/typegraphql",
45
+ "homepage": "https://github.com/tsedio/tsed/tree/beta/packages/graphql/typegraphql",
42
46
  "author": "Romain Lenzotti",
43
47
  "license": "MIT"
44
48
  }
@@ -0,0 +1,23 @@
1
+ {
2
+ "extends": "./tsconfig.compile.json",
3
+ "compilerOptions": {
4
+ "baseUrl": ".",
5
+ "module": "ES2020",
6
+ "rootDir": "src",
7
+ "outDir": "./lib/esm",
8
+ "declaration": true,
9
+ "declarationDir": "./lib/types"
10
+ },
11
+ "exclude": [
12
+ "node_modules",
13
+ "test",
14
+ "lib",
15
+ "benchmark",
16
+ "coverage",
17
+ "spec",
18
+ "**/*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AAO,CAAC;gBACvB,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,GAAG,2CAA2C,IAAI,CAAC,OAAO,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC,CAAC;YACtI,CAAC,CAAC,CAAC;SACJ;IACH,CAAC;CACF,CAAA;AArCC;IADC,eAAM,EAAE;sCACU,uCAAkB;kDAAC;AAGtC;IADC,eAAM,EAAE;sCACW,wBAAe;mDAAC;AAGpC;IADC,sBAAa,EAAE;;wDACuB;AAR5B,iBAAiB;IAD7B,eAAM,EAAE;GACI,iBAAiB,CAuC7B;AAvCY,8CAAiB","sourcesContent":["import {AfterListen, Configuration, Inject, InjectorService, Module, OnRoutesInit} from \"@tsed/common\";\nimport {TypeGraphQLSettings} from \"./interfaces\";\nimport {TypeGraphQLService} from \"./services/TypeGraphQLService\";\n\n/**\n * @ignore\n */\n@Module()\nexport class TypeGraphQLModule implements OnRoutesInit, AfterListen {\n @Inject()\n protected service: TypeGraphQLService;\n\n @Inject()\n protected injector: InjectorService;\n\n @Configuration()\n protected configuration: Configuration;\n\n get settings(): {[key: string]: TypeGraphQLSettings} | undefined {\n return this.configuration.get(\"graphql\") || this.configuration.get(\"typegraphql\");\n }\n\n $onRoutesInit(): Promise<any> | void {\n const {settings} = this;\n if (settings) {\n const promises = Object.entries(settings).map(async ([key, options]) => {\n return this.service.createServer(key, options);\n });\n\n return Promise.all(promises);\n }\n }\n\n $afterListen(): Promise<any> | void {\n const {settings} = this;\n\n if (settings) {\n const httpHost = this.configuration.getHttpPort();\n const httpsHost = this.configuration.getHttpsPort();\n const host = httpsHost || httpHost;\n\n Object.entries(settings).map(async ([key, options]) => {\n const {path} = options;\n this.injector.logger.info(`[${key}] GraphQL server is available on http://${host.address}:${host.port}/${path.replace(/^\\//, \"\")}`);\n });\n }\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/constants/index.ts"],"names":[],"mappings":";;;AAAa,QAAA,gCAAgC,GAAG,0BAA0B,CAAC;AAC9D,QAAA,8BAA8B,GAAG,wBAAwB,CAAC","sourcesContent":["export const PROVIDER_TYPE_DATASOURCE_SERVICE = \"graphQLDataSourceService\";\nexport const PROVIDER_TYPE_RESOLVER_SERVICE = \"graphQLResolverService\";\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"dataSourceService.js","sourceRoot":"","sources":["../../src/decorators/dataSourceService.ts"],"names":[],"mappings":";;;AAAA,yCAAuD;AACvD,4CAA8D;AAE9D;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,SAAgB,iBAAiB;IAC/B,OAAO,mBAAU,CAAC;QAChB,IAAI,EAAE,4CAAgC;QACtC,KAAK,EAAE,sBAAa,CAAC,QAAQ;KAC9B,CAAC,CAAC;AACL,CAAC;AALD,8CAKC","sourcesContent":["import {Injectable, ProviderScope} from \"@tsed/common\";\nimport {PROVIDER_TYPE_DATASOURCE_SERVICE} from \"../constants\";\n\n/**\n * Create a new DataSource binded with Tsed DI.\n *\n * ```typescript\n * import { DataSourceService } from \"@tsed/graphql\";\n * import { RESTDataSource } from 'apollo-datasource-rest';\n *\n * @DataSourceService()\n * export class MyDataSource extends RESTDataSource {\n * constructor() {\n * super();\n * this.baseURL = 'https://awesome-api.example.com';\n * }\n *\n * willSendRequest(request) {\n * request.headers.set('Authorization', this.context.token);\n * }\n *\n * getMyData(id: string) {\n * return this.get(`/v1/my_rest_data/${id}`);\n * }\n * }\n * ```\n *\n * @decorator\n * @graphql\n */\nexport function DataSourceService(): ClassDecorator {\n return Injectable({\n type: PROVIDER_TYPE_DATASOURCE_SERVICE,\n scope: ProviderScope.INSTANCE\n });\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolverService.js","sourceRoot":"","sources":["../../src/decorators/resolverService.ts"],"names":[],"mappings":";;;AAAA,qCAAyC;AACzC,iCAAoC;AACpC,+CAAiD;AAEjD,4CAA4D;AAM5D,SAAgB,eAAe,CAAC,GAAG,IAAW;IAC5C,OAAO,oBAAa,CACjB,uBAAgB,CAAC,GAAG,IAAI,CAAC,EAC1B,eAAU,CAAC;QACT,IAAI,EAAE,0CAA8B;KACrC,CAAC,CACH,CAAC;AACJ,CAAC;AAPD,0CAOC","sourcesContent":["import {useDecorators} from \"@tsed/core\";\nimport {Injectable} from \"@tsed/di\";\nimport {ClassType, Resolver} from \"type-graphql\";\nimport {AbstractClassOptions, ClassTypeResolver} from \"type-graphql/dist/decorators/types\";\nimport {PROVIDER_TYPE_RESOLVER_SERVICE} from \"../constants\";\n\nexport function ResolverService(): ClassDecorator;\nexport function ResolverService(options: AbstractClassOptions): ClassDecorator;\nexport function ResolverService(typeFunc: ClassTypeResolver, options?: AbstractClassOptions): ClassDecorator;\nexport function ResolverService(objectType: ClassType, options?: AbstractClassOptions): ClassDecorator;\nexport function ResolverService(...args: any[]): ClassDecorator {\n return useDecorators(\n (Resolver as any)(...args),\n Injectable({\n type: PROVIDER_TYPE_RESOLVER_SERVICE\n })\n );\n}\n"]}
package/lib/index.js DELETED
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./interfaces"), exports);
5
- tslib_1.__exportStar(require("./decorators/resolverService"), exports);
6
- tslib_1.__exportStar(require("./decorators/dataSourceService"), exports);
7
- tslib_1.__exportStar(require("./services/TypeGraphQLService"), exports);
8
- tslib_1.__exportStar(require("./constants"), exports);
9
- tslib_1.__exportStar(require("./TypeGraphQLModule"), exports);
10
- //# sourceMappingURL=index.js.map
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,uDAA6B;AAC7B,uEAA6C;AAC7C,yEAA+C;AAC/C,wEAA8C;AAC9C,sDAA4B;AAC5B,8DAAoC","sourcesContent":["export * from \"./interfaces\";\nexport * from \"./decorators/resolverService\";\nexport * from \"./decorators/dataSourceService\";\nexport * from \"./services/TypeGraphQLService\";\nexport * from \"./constants\";\nexport * from \"./TypeGraphQLModule\";\n"]}
@@ -1,8 +0,0 @@
1
- import { ApolloSettings } from "@tsed/apollo";
2
- import { Config } from "apollo-server-core";
3
- import { BuildSchemaOptions } from "type-graphql";
4
- export interface TypeGraphQLSettings extends ApolloSettings {
5
- path: string;
6
- buildSchemaOptions?: BuildSchemaOptions;
7
- serverConfig?: Config;
8
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"TypeGraphQLSettings.js","sourceRoot":"","sources":["../../src/interfaces/TypeGraphQLSettings.ts"],"names":[],"mappings":"","sourcesContent":["import {ApolloSettings} from \"@tsed/apollo\";\nimport {Config} from \"apollo-server-core\";\nimport {BuildSchemaOptions} from \"type-graphql\";\n\nexport interface TypeGraphQLSettings extends ApolloSettings {\n // Basic options\n path: string;\n // TypeGraphQL options\n buildSchemaOptions?: BuildSchemaOptions;\n // apollo-server-express options\n // See options descriptions on https://www.apollographql.com/docs/apollo-server/api/apollo-server.html\n serverConfig?: Config;\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/interfaces/index.ts"],"names":[],"mappings":";;;AAWA,gEAAsC","sourcesContent":["import {TypeGraphQLSettings} from \"./TypeGraphQLSettings\";\n\ndeclare global {\n namespace TsED {\n interface Configuration {\n graphql: {[key: string]: TypeGraphQLSettings};\n typegraphql: {[key: string]: TypeGraphQLSettings};\n }\n }\n}\n\nexport * from \"./TypeGraphQLSettings\";\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"TypeGraphQLService.js","sourceRoot":"","sources":["../../src/services/TypeGraphQLService.ts"],"names":[],"mappings":";;;;AAAA,yCAAyD;AAEzD,iCAAyF;AACzF,yCAAoC;AAGpC,kEAA4C;AAC5C,+CAA6D;AAC7D,4CAA8F;AAG9F,MAAM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AAiB,CAAC,WAAiC,EAAE,mBAAyC;QACtG,OAAO,GAAG,EAAE;YACV,MAAM,OAAO,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;YAEtC,OAAO;gBACL,GAAG,OAAO;gBACV,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACrC,GAAG,CAAC,mBAAmB,CAAC,CAAC,CAAC,mBAAmB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACtD,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC;IAES,sBAAsB;QAC9B,uBAAuB;QACvB,aAAa;QACb,IAAI,WAAW,CAAC,YAAY,EAAE;YAC5B,mDAAmD;YACnD,aAAa;YACb,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;SAChD;IACH,CAAC;CACF,CAAA;AA5HC;IADC,WAAM,EAAE;sCACW,oBAAe;oDAAC;AAGpC;IADC,WAAM,EAAE;sCACgB,sBAAa;yDAAC;AAGvC;IADC,WAAM,EAAE;sCACS,eAAM;kDAAC;AARd,kBAAkB;IAD9B,eAAU,EAAE;GACA,kBAAkB,CA8H9B;AA9HY,gDAAkB","sourcesContent":["import {ApolloServer, ApolloService} from \"@tsed/apollo\";\nimport {Type} from \"@tsed/core\";\nimport {Inject, Injectable, InjectorService, Provider, registerProvider} from \"@tsed/di\";\nimport {Logger} from \"@tsed/logger\";\nimport {DataSource} from \"apollo-datasource\";\nimport {GraphQLSchema} from \"graphql\";\nimport * as TypeGraphql from \"type-graphql\";\nimport {buildSchema, BuildSchemaOptions} from \"type-graphql\";\nimport {PROVIDER_TYPE_DATASOURCE_SERVICE, PROVIDER_TYPE_RESOLVER_SERVICE} from \"../constants\";\nimport {TypeGraphQLSettings} from \"../interfaces\";\n\nconst getKey = (id: string) => `typegraphql-${id}`;\n\n@Injectable()\nexport class TypeGraphQLService {\n @Inject()\n protected injector: InjectorService;\n\n @Inject()\n protected apolloService: ApolloService;\n\n @Inject()\n protected logger: Logger;\n\n /**\n * Get an instance of ApolloServer from his id\n * @returns ApolloServer\n */\n get(id: string = \"default\"): ApolloServer | undefined {\n return this.apolloService.get(getKey(id));\n }\n\n /**\n *\n * @param {string} id\n * @returns {boolean}\n */\n has(id: string = \"default\"): boolean {\n return this.apolloService.has(getKey(id));\n }\n\n /**\n *\n * @returns {Promise<ApolloServer>}\n */\n async createServer(id: string, settings: TypeGraphQLSettings): Promise<any> {\n if (this.has(id)) {\n return this.get(id)!;\n }\n\n try {\n const {dataSources, resolvers: initialResolvers = [], buildSchemaOptions = {}, serverConfig = {}, ...serverOptions} = settings;\n\n this.configureTypeGraphQLDI();\n\n const resolvers: any = [...this.getResolvers(), ...(initialResolvers as any[])];\n const schema = await this.createSchema({\n container: this.injector,\n ...buildSchemaOptions,\n resolvers\n });\n\n return await this.apolloService.createServer(getKey(id), {\n ...serverOptions,\n ...serverConfig,\n resolvers,\n dataSources: this.createDataSources(dataSources, serverConfig.dataSources),\n schema\n });\n } catch (err) {\n /* istanbul ignore next */\n this.logger.error(err);\n /* istanbul ignore next */\n process.exit(-1);\n }\n }\n\n /**\n * Create a new type-graphql Schema and bind it with Ts.ED injector.\n * @param buildSchemaOptions\n */\n async createSchema(buildSchemaOptions: BuildSchemaOptions) {\n return buildSchema(buildSchemaOptions);\n }\n\n /**\n * Get an instance of GraphQL schema from his id\n * @returns GraphQLSchema\n */\n getSchema(id: string = \"default\"): GraphQLSchema | undefined {\n return this.apolloService.getSchema(getKey(id));\n }\n\n /**\n *\n * @returns {Provider<any>[]}\n */\n protected getResolvers(): Type<any>[] {\n return this.injector.getProviders(PROVIDER_TYPE_RESOLVER_SERVICE).map((provider) => provider.useClass);\n }\n\n protected getDataSources(): {[serviceName: string]: DataSource} {\n const providers = Array.from(this.injector.getProviders(PROVIDER_TYPE_DATASOURCE_SERVICE));\n\n return providers.reduce<{[serviceName: string]: DataSource}>((map, provider) => {\n // set the first letter of the class lowercase to follow proper conventions during access\n // i.e. this.context.dataSources.userService\n const sourceName = `${provider.name[0].toLowerCase()}${provider.name.substr(1)}`;\n map[sourceName] = this.injector.invoke(provider.provide);\n\n return map;\n }, {});\n }\n\n /**\n * create a new dataSources function to use with apollo server config\n * @param dataSources\n * @param serverConfigSources\n */\n protected createDataSources(dataSources: Function | undefined, serverConfigSources: Function | undefined) {\n return () => {\n const sources = this.getDataSources();\n\n return {\n ...sources,\n ...(dataSources ? dataSources() : {}),\n ...(serverConfigSources ? serverConfigSources() : {})\n };\n };\n }\n\n protected configureTypeGraphQLDI() {\n // istanbul ignore next\n // @ts-ignore\n if (TypeGraphql.useContainer) {\n // support old version of type-graphql under @v0.17\n // @ts-ignore\n TypeGraphql.useContainer(this.injectorService);\n }\n }\n}\n"]}