@tsed/typegraphql 7.0.0-alpha.1 → 7.0.0-beta.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 (57) hide show
  1. package/.mocharc.js +2 -2
  2. package/.nycrc +1 -1
  3. package/lib/{TypeGraphQLModule.js → cjs/TypeGraphQLModule.js} +12 -10
  4. package/lib/cjs/TypeGraphQLModule.js.map +1 -0
  5. package/lib/{constants/index.js → cjs/constants/constants.js} +1 -1
  6. package/lib/cjs/constants/constants.js.map +1 -0
  7. package/lib/{decorators → cjs/decorators}/dataSourceService.js +4 -4
  8. package/lib/cjs/decorators/dataSourceService.js.map +1 -0
  9. package/lib/{decorators → cjs/decorators}/resolverService.js +2 -2
  10. package/lib/cjs/decorators/resolverService.js.map +1 -0
  11. package/lib/{index.js → cjs/index.js} +8 -4
  12. package/lib/cjs/index.js.map +1 -0
  13. package/lib/{interfaces → cjs/interfaces}/TypeGraphQLSettings.js +0 -0
  14. package/lib/cjs/interfaces/TypeGraphQLSettings.js.map +1 -0
  15. package/lib/{interfaces/index.js → cjs/interfaces/interfaces.js} +1 -1
  16. package/lib/cjs/interfaces/interfaces.js.map +1 -0
  17. package/lib/cjs/package.json +3 -0
  18. package/lib/{services → cjs/services}/TypeGraphQLService.js +7 -7
  19. package/lib/cjs/services/TypeGraphQLService.js.map +1 -0
  20. package/lib/esm/TypeGraphQLModule.js +51 -0
  21. package/lib/esm/TypeGraphQLModule.js.map +1 -0
  22. package/lib/esm/constants/constants.js +3 -0
  23. package/lib/esm/constants/constants.js.map +1 -0
  24. package/lib/esm/decorators/dataSourceService.js +36 -0
  25. package/lib/esm/decorators/dataSourceService.js.map +1 -0
  26. package/lib/esm/decorators/resolverService.js +10 -0
  27. package/lib/esm/decorators/resolverService.js.map +1 -0
  28. package/lib/esm/index.js +11 -0
  29. package/lib/esm/index.js.map +1 -0
  30. package/lib/esm/interfaces/TypeGraphQLSettings.js +2 -0
  31. package/lib/esm/interfaces/TypeGraphQLSettings.js.map +1 -0
  32. package/lib/esm/interfaces/interfaces.js +2 -0
  33. package/lib/esm/interfaces/interfaces.js.map +1 -0
  34. package/lib/esm/package.json +3 -0
  35. package/lib/esm/services/TypeGraphQLService.js +129 -0
  36. package/lib/esm/services/TypeGraphQLService.js.map +1 -0
  37. package/lib/{TypeGraphQLModule.d.ts → types/TypeGraphQLModule.d.ts} +3 -3
  38. package/lib/{constants/index.d.ts → types/constants/constants.d.ts} +0 -0
  39. package/lib/{decorators → types/decorators}/dataSourceService.d.ts +0 -0
  40. package/lib/{decorators → types/decorators}/resolverService.d.ts +0 -0
  41. package/lib/types/index.d.ts +10 -0
  42. package/lib/types/interfaces/TypeGraphQLSettings.d.ts +6 -0
  43. package/lib/{interfaces/index.d.ts → types/interfaces/interfaces.d.ts} +0 -0
  44. package/lib/{services → types/services}/TypeGraphQLService.d.ts +6 -7
  45. package/package.json +28 -21
  46. package/readme.md +22 -20
  47. package/tsconfig.compile.esm.json +12 -0
  48. package/lib/TypeGraphQLModule.js.map +0 -1
  49. package/lib/constants/index.js.map +0 -1
  50. package/lib/decorators/dataSourceService.js.map +0 -1
  51. package/lib/decorators/resolverService.js.map +0 -1
  52. package/lib/index.d.ts +0 -6
  53. package/lib/index.js.map +0 -1
  54. package/lib/interfaces/TypeGraphQLSettings.d.ts +0 -8
  55. package/lib/interfaces/TypeGraphQLSettings.js.map +0 -1
  56. package/lib/interfaces/index.js.map +0 -1
  57. package/lib/services/TypeGraphQLService.js.map +0 -1
package/.mocharc.js CHANGED
@@ -1,5 +1,5 @@
1
1
  module.exports = {
2
- ...require('@tsed/mocha-config')(),
2
+ ...require("@tsed/mocha-config")(),
3
3
  spec: ["{src,test}/**/*.spec.ts"],
4
- exclude: [],
4
+ exclude: []
5
5
  };
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
38
  tslib_1.__decorate([
37
- common_1.Inject(),
39
+ (0, di_1.Inject)(),
38
40
  tslib_1.__metadata("design:type", TypeGraphQLService_1.TypeGraphQLService)
39
41
  ], TypeGraphQLModule.prototype, "service", void 0);
40
42
  tslib_1.__decorate([
41
- common_1.Inject(),
42
- tslib_1.__metadata("design:type", common_1.InjectorService)
43
+ (0, di_1.Inject)(),
44
+ tslib_1.__metadata("design:type", di_1.InjectorService)
43
45
  ], TypeGraphQLModule.prototype, "injector", void 0);
44
46
  tslib_1.__decorate([
45
- common_1.Configuration(),
47
+ (0, di_1.Configuration)(),
46
48
  tslib_1.__metadata("design:type", Object)
47
49
  ], TypeGraphQLModule.prototype, "configuration", void 0);
48
50
  TypeGraphQLModule = tslib_1.__decorate([
49
- common_1.Module()
51
+ (0, di_1.Module)()
50
52
  ], TypeGraphQLModule);
51
53
  exports.TypeGraphQLModule = TypeGraphQLModule;
52
54
  //# sourceMappingURL=TypeGraphQLModule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TypeGraphQLModule.js","sourceRoot":"","sources":["../../src/TypeGraphQLModule.ts"],"names":[],"mappings":";;;;AAAA,iCAAwE;AAExE,sEAAiE;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,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,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,GAAG,oCAAoC,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,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;sCACU,uCAAkB;kDAAC;AAGtC;IADC,IAAA,WAAM,GAAE;sCACW,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/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"]}
@@ -3,4 +3,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PROVIDER_TYPE_RESOLVER_SERVICE = exports.PROVIDER_TYPE_DATASOURCE_SERVICE = void 0;
4
4
  exports.PROVIDER_TYPE_DATASOURCE_SERVICE = "graphQLDataSourceService";
5
5
  exports.PROVIDER_TYPE_RESOLVER_SERVICE = "graphQLResolverService";
6
- //# sourceMappingURL=index.js.map
6
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/constants/constants.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,8 +1,8 @@
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");
5
- const constants_1 = require("../constants");
4
+ const di_1 = require("@tsed/di");
5
+ const constants_1 = require("../constants/constants");
6
6
  /**
7
7
  * Create a new DataSource binded with Tsed DI.
8
8
  *
@@ -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,sDAAwE;AAExE;;;;;;;;;;;;;;;;;;;;;;;;;;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/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"]}
@@ -4,9 +4,9 @@ exports.ResolverService = void 0;
4
4
  const core_1 = require("@tsed/core");
5
5
  const di_1 = require("@tsed/di");
6
6
  const type_graphql_1 = require("type-graphql");
7
- const constants_1 = require("../constants");
7
+ const constants_1 = require("../constants/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,sDAAsE;AAMtE,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/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"]}
@@ -1,10 +1,14 @@
1
1
  "use strict";
2
+ /**
3
+ * @file Automatically generated by barrelsby.
4
+ */
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  const tslib_1 = require("tslib");
4
- tslib_1.__exportStar(require("./interfaces"), exports);
5
- tslib_1.__exportStar(require("./decorators/resolverService"), exports);
7
+ tslib_1.__exportStar(require("./TypeGraphQLModule"), exports);
8
+ tslib_1.__exportStar(require("./constants/constants"), exports);
6
9
  tslib_1.__exportStar(require("./decorators/dataSourceService"), exports);
10
+ tslib_1.__exportStar(require("./decorators/resolverService"), exports);
11
+ tslib_1.__exportStar(require("./interfaces/TypeGraphQLSettings"), exports);
12
+ tslib_1.__exportStar(require("./interfaces/interfaces"), exports);
7
13
  tslib_1.__exportStar(require("./services/TypeGraphQLService"), exports);
8
- tslib_1.__exportStar(require("./constants"), exports);
9
- tslib_1.__exportStar(require("./TypeGraphQLModule"), exports);
10
14
  //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,8DAAoC;AACpC,gEAAsC;AACtC,yEAA+C;AAC/C,uEAA6C;AAC7C,2EAAiD;AACjD,kEAAwC;AACxC,wEAA8C","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./TypeGraphQLModule\";\nexport * from \"./constants/constants\";\nexport * from \"./decorators/dataSourceService\";\nexport * from \"./decorators/resolverService\";\nexport * from \"./interfaces/TypeGraphQLSettings\";\nexport * from \"./interfaces/interfaces\";\nexport * from \"./services/TypeGraphQLService\";\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"]}
@@ -2,4 +2,4 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  tslib_1.__exportStar(require("./TypeGraphQLSettings"), exports);
5
- //# sourceMappingURL=index.js.map
5
+ //# sourceMappingURL=interfaces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/interfaces/interfaces.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"]}
@@ -0,0 +1,3 @@
1
+ {
2
+ "type": "commonjs"
3
+ }
@@ -7,7 +7,7 @@ const di_1 = require("@tsed/di");
7
7
  const logger_1 = require("@tsed/logger");
8
8
  const TypeGraphql = tslib_1.__importStar(require("type-graphql"));
9
9
  const type_graphql_1 = require("type-graphql");
10
- const constants_1 = require("../constants");
10
+ const constants_1 = require("../constants/constants");
11
11
  const getKey = (id) => `typegraphql-${id}`;
12
12
  let TypeGraphQLService = class TypeGraphQLService {
13
13
  /**
@@ -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
@@ -114,19 +114,19 @@ let TypeGraphQLService = class TypeGraphQLService {
114
114
  }
115
115
  };
116
116
  tslib_1.__decorate([
117
- di_1.Inject(),
117
+ (0, di_1.Inject)(),
118
118
  tslib_1.__metadata("design:type", di_1.InjectorService)
119
119
  ], TypeGraphQLService.prototype, "injector", void 0);
120
120
  tslib_1.__decorate([
121
- di_1.Inject(),
121
+ (0, di_1.Inject)(),
122
122
  tslib_1.__metadata("design:type", apollo_1.ApolloService)
123
123
  ], TypeGraphQLService.prototype, "apolloService", void 0);
124
124
  tslib_1.__decorate([
125
- di_1.Inject(),
125
+ (0, di_1.Inject)(),
126
126
  tslib_1.__metadata("design:type", logger_1.Logger)
127
127
  ], TypeGraphQLService.prototype, "logger", void 0);
128
128
  TypeGraphQLService = tslib_1.__decorate([
129
- di_1.Injectable()
129
+ (0, di_1.Injectable)()
130
130
  ], TypeGraphQLService);
131
131
  exports.TypeGraphQLService = TypeGraphQLService;
132
132
  //# sourceMappingURL=TypeGraphQLService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TypeGraphQLService.js","sourceRoot":"","sources":["../../../src/services/TypeGraphQLService.ts"],"names":[],"mappings":";;;;AAAA,yCAAyD;AAEzD,iCAAuE;AACvE,yCAAoC;AAGpC,kEAA4C;AAC5C,+CAA6D;AAE7D,sDAAwG;AAGxG,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,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;IAC5C,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,YAAY,C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aAAa;YACb,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;SAChD;IACH,CAAC;CACF,CAAA;AA5HC;IADC,IAAA,WAAM,GAAE;sCACW,oBAAe;oDAAC;AAGpC;IADC,IAAA,WAAM,GAAE;sCACgB,sBAAa;yDAAC;AAGvC;IADC,IAAA,WAAM,GAAE;sCACS,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/constants\";\nimport {TypeGraphQLSettings} from \"../interfaces/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.js";
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":";A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C,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,MAAM,EAAE;8BACU,kBAAkB;kDAAC;AAGtC;IADC,MAAM,EAAE;8BACW,eAAe;mDAAC;AAGpC;IADC,aAAa,EAAE;;wDACuB;AAR5B,iBAAiB;IAD7B,MAAM,EAAE;GACI,iBAAiB,CA4C7B;SA5CY,iBAAiB","sourcesContent":["import {Configuration, Inject, InjectorService, Module} from \"@tsed/di\";\nimport {TypeGraphQLSettings} from \"./interfaces/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"]}
@@ -0,0 +1,3 @@
1
+ export const PROVIDER_TYPE_DATASOURCE_SERVICE = "graphQLDataSourceService";
2
+ export const PROVIDER_TYPE_RESOLVER_SERVICE = "graphQLResolverService";
3
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../src/constants/constants.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/constants.js";
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,wBAAwB,CAAC;AAExE;;;;;;;;;;;;;;;;;;;;;;;;;;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/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/constants.js";
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,wBAAwB,CAAC;AAMtE,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/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,11 @@
1
+ /**
2
+ * @file Automatically generated by barrelsby.
3
+ */
4
+ export * from "./TypeGraphQLModule.js";
5
+ export * from "./constants/constants.js";
6
+ export * from "./decorators/dataSourceService.js";
7
+ export * from "./decorators/resolverService.js";
8
+ export * from "./interfaces/TypeGraphQLSettings.js";
9
+ export * from "./interfaces/interfaces.js";
10
+ export * from "./services/TypeGraphQLService.js";
11
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,8BAA8B,CAAC;AAC7C,cAAc,kCAAkC,CAAC;AACjD,cAAc,yBAAyB,CAAC;AACxC,cAAc,+BAA+B,CAAC","sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from \"./TypeGraphQLModule\";\nexport * from \"./constants/constants\";\nexport * from \"./decorators/dataSourceService\";\nexport * from \"./decorators/resolverService\";\nexport * from \"./interfaces/TypeGraphQLSettings\";\nexport * from \"./interfaces/interfaces\";\nexport * from \"./services/TypeGraphQLService\";\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.js";
2
+ //# sourceMappingURL=interfaces.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interfaces.js","sourceRoot":"","sources":["../../../src/interfaces/interfaces.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,3 @@
1
+ {
2
+ "type": "module"
3
+ }
@@ -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/constants.js";
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,wBAAwB,CAAC;AAGxG,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,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;IAC5C,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,YAAY,CAAC,EAAU,EAAE,QAA6B;QAC1D,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;YAChB,OAAO,IAAI,CAAC,GAAG,CAAC,EAAE,CAAE,CAAC;SACtB;QAED,IAAI;YACF,MAAM,EAAC,WAAW,EAAE,SAAS,EAAE,gBA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E;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/constants\";\nimport {TypeGraphQLSettings} from \"../interfaces/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";
2
- import { TypeGraphQLSettings } from "./interfaces";
1
+ import { Configuration, InjectorService } from "@tsed/di";
2
+ import { TypeGraphQLSettings } from "./interfaces/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;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * @file Automatically generated by barrelsby.
3
+ */
4
+ export * from "./TypeGraphQLModule";
5
+ export * from "./constants/constants";
6
+ export * from "./decorators/dataSourceService";
7
+ export * from "./decorators/resolverService";
8
+ export * from "./interfaces/TypeGraphQLSettings";
9
+ export * from "./interfaces/interfaces";
10
+ export * from "./services/TypeGraphQLService";
@@ -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
+ }
@@ -1,11 +1,12 @@
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 { TypeGraphQLSettings } from "../interfaces";
8
+ import { ApolloServerBase } from "apollo-server-core";
9
+ import { TypeGraphQLSettings } from "../interfaces/interfaces";
9
10
  export declare class TypeGraphQLService {
10
11
  protected injector: InjectorService;
11
12
  protected apolloService: ApolloService;
@@ -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,51 @@
1
1
  {
2
2
  "name": "@tsed/typegraphql",
3
- "version": "7.0.0-alpha.1",
3
+ "version": "7.0.0-beta.10",
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
+ "module": "./lib/esm/index.js",
9
+ "typings": "./lib/types/index.d.ts",
10
+ "exports": {
11
+ "types": "./lib/types/index.d.ts",
12
+ "import": "./lib/esm/index.js",
13
+ "require": "./lib/cjs/index.js",
14
+ "default": "./lib/esm/index.js"
15
+ },
8
16
  "scripts": {
9
- "build": "tsc --build tsconfig.compile.json",
10
- "start": "ts-node -r tsconfig-paths/register test/app/index.ts",
17
+ "build": "yarn barrels && yarn run build:esm && yarn run build:cjs",
18
+ "build:cjs": "tsc --build tsconfig.compile.json",
19
+ "build:esm": "tsc --build tsconfig.compile.esm.json",
20
+ "barrels": "yarn barrelsby --delete -d ./src -e \"\\.spec\\.ts\" -e \"__mock__\" -e \".benchmark.ts\"",
21
+ "start:express": "ts-node -r tsconfig-paths/register test/app/index.express.ts",
22
+ "start:koa": "ts-node -r tsconfig-paths/register test/app/index.koa.ts",
11
23
  "test": "cross-env NODE_ENV=test nyc mocha"
12
24
  },
13
25
  "dependencies": {
14
- "@tsed/apollo": "7.0.0-alpha.1",
15
- "tslib": "2.2.0"
26
+ "@tsed/apollo": "7.0.0-beta.10",
27
+ "tslib": "2.3.1"
16
28
  },
17
29
  "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",
30
+ "@tsed/common": "7.0.0-beta.10",
31
+ "@tsed/core": "7.0.0-beta.10",
32
+ "@types/graphql": "^14.5.0",
25
33
  "class-validator": "~0.13.1",
26
- "graphql": "15.5.1",
27
34
  "graphql-passport": "0.6.3",
28
35
  "type-graphql": "^1.1.1"
29
36
  },
30
37
  "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"
38
+ "apollo-datasource": ">=3.0.0",
39
+ "apollo-datasource-rest": ">=3.0.0",
40
+ "class-validator": ">=0.13.1",
41
+ "graphql": ">=15.0.0",
42
+ "type-graphql": ">=1.0.0"
36
43
  },
37
44
  "repository": "https://github.com/tsedio/tsed",
38
45
  "bugs": {
39
46
  "url": "https://github.com/tsedio/tsed/issues"
40
47
  },
41
- "homepage": "https://github.com/tsedio/tsed/tree/alpha/packages/graphql/typegraphql",
48
+ "homepage": "https://github.com/tsedio/tsed/tree/beta/packages/graphql/typegraphql",
42
49
  "author": "Romain Lenzotti",
43
50
  "license": "MIT"
44
51
  }
package/readme.md CHANGED
@@ -39,6 +39,7 @@ for the decorators.
39
39
  ## Installation
40
40
 
41
41
  To begin, install the TypeGraphQL module for TS.ED:
42
+
42
43
  ```bash
43
44
  npm install --save @tsed/typegraphql type-graphql graphql@15
44
45
  npm install --save apollo-datasource apollo-datasource-rest apollo-server-express
@@ -49,12 +50,12 @@ Now, we can configure the Ts.ED server by importing `@tsed/typegraphql` in your
49
50
 
50
51
  ```typescript
51
52
  import {Configuration} from "@tsed/common";
52
- import "@tsed/typegraphql";
53
+ import "@tsed/typegraphql";
53
54
 
54
55
  @Configuration({
55
- graphql: {
56
- 'server1': {
57
- resolvers:[]
56
+ graphql: {
57
+ server1: {
58
+ resolvers: []
58
59
  }
59
60
  }
60
61
  })
@@ -73,12 +74,12 @@ import {ApolloServer} from "apollo-server-express";
73
74
  @Service()
74
75
  export class UsersService implements AfterRoutesInit {
75
76
  private server: ApolloServer;
76
-
77
+
77
78
  @Inject()
78
- typeGraphQLService: TypeGraphQLService
79
-
79
+ typeGraphQLService: TypeGraphQLService;
80
+
80
81
  $afterRoutesInit() {
81
- this.server = this.typeGraphQLService.get("server1");
82
+ this.server = this.typeGraphQLService.get("server1");
82
83
  }
83
84
  }
84
85
  ```
@@ -86,6 +87,7 @@ export class UsersService implements AfterRoutesInit {
86
87
  For more information about ApolloServer look his documentation [here](https://www.apollographql.com/docs/apollo-server/api/apollo-server.html);
87
88
 
88
89
  ## Type-graphql
90
+
89
91
  ### Types
90
92
 
91
93
  We want to get equivalent of this type described in SDL:
@@ -115,35 +117,36 @@ class Recipe {
115
117
  Then we decorate the class and it properties with decorators:
116
118
 
117
119
  ```typescript
118
- import {ObjectType, ID, Field} from "type-graphql"
120
+ import {ObjectType, ID, Field} from "type-graphql";
119
121
 
120
122
  @ObjectType()
121
123
  export class Recipe {
122
- @Field(type => ID)
124
+ @Field((type) => ID)
123
125
  id: string;
124
126
 
125
127
  @Field()
126
128
  title: string;
127
129
 
128
- @Field({ nullable: true })
130
+ @Field({nullable: true})
129
131
  description?: string;
130
132
 
131
133
  @Field()
132
134
  creationDate: Date;
133
135
 
134
- @Field(type => [String])
136
+ @Field((type) => [String])
135
137
  ingredients: string[];
136
138
  }
137
139
  ```
140
+
138
141
  The detailed rules when to use nullable, array and others are described in [fields and types docs](https://19majkel94.github.io/type-graphql/docs/types-and-fields.html).
139
142
 
140
- ### Resolvers
143
+ ### Resolvers
141
144
 
142
145
  After that we want to create typical crud queries and mutation. To do that we create the resolver (controller) class that will have injected RecipeService in constructor:
143
146
 
144
147
  ```typescript
145
148
  import {Resolver, Query, Arg, Args, Mutation, Authorized, Ctx} from "type-graphql";
146
- import {ResolverService} from "@tsed/typegraphql"
149
+ import {ResolverService} from "@tsed/typegraphql";
147
150
  import {Recipe} from "../types/Recipe";
148
151
  import {RecipeService} from "../services/RecipeService";
149
152
  import {RecipeNotFoundError} from "../errors/RecipeNotFoundError";
@@ -152,7 +155,7 @@ import {RecipeNotFoundError} from "../errors/RecipeNotFoundError";
152
155
  export class RecipeResolver {
153
156
  constructor(private recipeService: RecipeService) {}
154
157
 
155
- @Query(returns => Recipe)
158
+ @Query((returns) => Recipe)
156
159
  async recipe(@Arg("id") id: string) {
157
160
  const recipe = await this.recipeService.findById(id);
158
161
  if (recipe === undefined) {
@@ -161,26 +164,25 @@ export class RecipeResolver {
161
164
  return recipe;
162
165
  }
163
166
 
164
- @Query(returns => [Recipe])
165
- recipes(@Args() { skip, take }: RecipesArgs) {
166
- return this.recipeService.findAll({ skip, take });
167
+ @Query((returns) => [Recipe])
168
+ recipes(@Args() {skip, take}: RecipesArgs) {
169
+ return this.recipeService.findAll({skip, take});
167
170
  }
168
171
  }
169
172
  ```
170
173
 
171
174
  ## Contributors
175
+
172
176
  Please read [contributing guidelines here](https://tsed.io/CONTRIBUTING.html)
173
177
 
174
178
  <a href="https://github.com/tsedio/ts-express-decorators/graphs/contributors"><img src="https://opencollective.com/tsed/contributors.svg?width=890" /></a>
175
179
 
176
-
177
180
  ## Backers
178
181
 
179
182
  Thank you to all our backers! 🙏 [[Become a backer](https://opencollective.com/tsed#backer)]
180
183
 
181
184
  <a href="https://opencollective.com/tsed#backers" target="_blank"><img src="https://opencollective.com/tsed/backers.svg?width=890"></a>
182
185
 
183
-
184
186
  ## Sponsors
185
187
 
186
188
  Support this project by becoming a sponsor. Your logo will show up here with a link to your website. [[Become a sponsor](https://opencollective.com/tsed#sponsor)]
@@ -0,0 +1,12 @@
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": ["node_modules", "test", "lib", "benchmark", "coverage", "spec", "**/*.benchmark.ts", "**/*.spec.ts", "keys", "jest.config.js"]
12
+ }
@@ -1 +0,0 @@
1
- {"version":3,"file":"TypeGraphQLModule.js","sourceRoot":"","sources":["../src/TypeGraphQLModule.ts"],"names":[],"mappings":";;;;AAAA,yCAAuG;AAEvG,sEAAiE;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,OAAO,CAAC,CAAC;YACjD,CAAC,CAAC,CAAC;YAEH,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;SAC9B;IACH,CAAC;IAED,YAAY;QACV,MAAM,EAAC,QAAQ,EAAC,GAAG,IAAI,CAAC;QAExB,IAAI,QAAQ,EAAE;YACZ,MAAM,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,WAAW,EAAE,CAAC;YAClD,MAAM,SAAS,GAAG,IAAI,CAAC,aAAa,CAAC,YAAY,EAAE,CAAC;YACpD,MAAM,IAAI,GAAG,SAAS,IAAI,QAAQ,CAAC;YAEnC,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;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.d.ts DELETED
@@ -1,6 +0,0 @@
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";
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,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,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;IAC5C,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,YAAY,CAAC,EAAU,EAAE,QAA6B;QAC1D,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE;YAChB,OAAO,IAAI,CAAC,GAAG,CAAC,EAAE,CAAE,CAAC;SACtB;QAED,IAAI;YACF,MAAM,EAAC,WAAW,EAAE,SAAS,EAAE,gBAAgB,GAAG,EAAE,EAAE,kBAAkB,GAAG,EAAE,EAAE,YAAY,GAAG,EAAE,EAAE,GAAG,aAAa,EAAC,GAAG,QAAQ,CAAC;YAE/H,IAAI,CAAC,sBAAsB,EAAE,CAAC;YAE9B,MAAM,SAAS,GAAQ,CAAC,GAAG,IAAI,CAAC,YAAY,EAAE,EAAE,GAAI,gBAA0B,CAAC,CAAC;YAChF,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,YAAY,CAAC;gBACrC,SAAS,EAAE,IAAI,CAAC,QAAQ;gBACxB,GAAG,k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,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC;YACjF,GAAG,CAAC,UAAU,CAAC,GAAG,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,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"]}