@tsed/typegraphql 6.88.1 → 6.89.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/{TypeGraphQLModule.d.ts → cjs/TypeGraphQLModule.d.ts} +0 -0
- package/lib/{TypeGraphQLModule.js → cjs/TypeGraphQLModule.js} +11 -11
- package/lib/cjs/TypeGraphQLModule.js.map +1 -0
- package/lib/{constants → cjs/constants}/index.d.ts +0 -0
- package/lib/{constants → cjs/constants}/index.js +0 -0
- package/lib/cjs/constants/index.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/dataSourceService.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/dataSourceService.js +1 -1
- package/lib/cjs/decorators/dataSourceService.js.map +1 -0
- package/lib/{decorators → cjs/decorators}/resolverService.d.ts +0 -0
- package/lib/{decorators → cjs/decorators}/resolverService.js +1 -1
- package/lib/cjs/decorators/resolverService.js.map +1 -0
- package/lib/{index.d.ts → cjs/index.d.ts} +0 -0
- package/lib/cjs/index.js +10 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/{interfaces → cjs/interfaces}/TypeGraphQLSettings.d.ts +0 -0
- package/lib/{interfaces → cjs/interfaces}/TypeGraphQLSettings.js +0 -0
- package/lib/cjs/interfaces/TypeGraphQLSettings.js.map +1 -0
- package/lib/{interfaces → cjs/interfaces}/index.d.ts +0 -0
- package/lib/{interfaces → cjs/interfaces}/index.js +1 -1
- package/lib/cjs/interfaces/index.js.map +1 -0
- package/lib/{services → cjs/services}/TypeGraphQLService.d.ts +0 -0
- package/lib/{services → cjs/services}/TypeGraphQLService.js +13 -13
- package/lib/cjs/services/TypeGraphQLService.js.map +1 -0
- package/lib/esm/TypeGraphQLModule.js +51 -0
- package/lib/esm/TypeGraphQLModule.js.map +1 -0
- package/lib/esm/constants/index.js +3 -0
- package/lib/esm/constants/index.js.map +1 -0
- package/lib/esm/decorators/dataSourceService.js +36 -0
- package/lib/esm/decorators/dataSourceService.js.map +1 -0
- package/lib/esm/decorators/resolverService.js +10 -0
- package/lib/esm/decorators/resolverService.js.map +1 -0
- package/lib/esm/index.js +7 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/interfaces/TypeGraphQLSettings.js +2 -0
- package/lib/esm/interfaces/TypeGraphQLSettings.js.map +1 -0
- package/lib/esm/interfaces/index.js +2 -0
- package/lib/esm/interfaces/index.js.map +1 -0
- package/lib/esm/services/TypeGraphQLService.js +129 -0
- package/lib/esm/services/TypeGraphQLService.js.map +1 -0
- package/lib/types/TypeGraphQLModule.d.ts +16 -0
- package/lib/types/constants/index.d.ts +2 -0
- package/lib/types/decorators/dataSourceService.d.ts +28 -0
- package/lib/types/decorators/resolverService.d.ts +6 -0
- package/lib/types/index.d.ts +6 -0
- package/lib/types/interfaces/TypeGraphQLSettings.d.ts +6 -0
- package/lib/types/interfaces/index.d.ts +14 -0
- package/lib/types/services/TypeGraphQLService.d.ts +53 -0
- package/package.json +16 -7
- package/tsconfig.compile.esm.json +23 -0
- package/lib/TypeGraphQLModule.js.map +0 -1
- package/lib/constants/index.js.map +0 -1
- package/lib/decorators/dataSourceService.js.map +0 -1
- package/lib/decorators/resolverService.js.map +0 -1
- package/lib/index.js +0 -10
- package/lib/index.js.map +0 -1
- package/lib/interfaces/TypeGraphQLSettings.js.map +0 -1
- package/lib/interfaces/index.js.map +0 -1
- package/lib/services/TypeGraphQLService.js.map +0 -1
|
File without changes
|
|
@@ -35,20 +35,20 @@ let TypeGraphQLModule = class TypeGraphQLModule {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
-
tslib_1.__decorate([
|
|
39
|
-
common_1.Inject(),
|
|
40
|
-
tslib_1.__metadata("design:type", TypeGraphQLService_1.TypeGraphQLService)
|
|
38
|
+
(0, tslib_1.__decorate)([
|
|
39
|
+
(0, common_1.Inject)(),
|
|
40
|
+
(0, tslib_1.__metadata)("design:type", TypeGraphQLService_1.TypeGraphQLService)
|
|
41
41
|
], TypeGraphQLModule.prototype, "service", void 0);
|
|
42
|
-
tslib_1.__decorate([
|
|
43
|
-
common_1.Inject(),
|
|
44
|
-
tslib_1.__metadata("design:type", common_1.InjectorService)
|
|
42
|
+
(0, tslib_1.__decorate)([
|
|
43
|
+
(0, common_1.Inject)(),
|
|
44
|
+
(0, tslib_1.__metadata)("design:type", common_1.InjectorService)
|
|
45
45
|
], TypeGraphQLModule.prototype, "injector", void 0);
|
|
46
|
-
tslib_1.__decorate([
|
|
47
|
-
common_1.Configuration(),
|
|
48
|
-
tslib_1.__metadata("design:type", Object)
|
|
46
|
+
(0, tslib_1.__decorate)([
|
|
47
|
+
(0, common_1.Configuration)(),
|
|
48
|
+
(0, tslib_1.__metadata)("design:type", Object)
|
|
49
49
|
], TypeGraphQLModule.prototype, "configuration", void 0);
|
|
50
|
-
TypeGraphQLModule = tslib_1.__decorate([
|
|
51
|
-
common_1.Module()
|
|
50
|
+
TypeGraphQLModule = (0, tslib_1.__decorate)([
|
|
51
|
+
(0, common_1.Module)()
|
|
52
52
|
], TypeGraphQLModule);
|
|
53
53
|
exports.TypeGraphQLModule = TypeGraphQLModule;
|
|
54
54
|
//# sourceMappingURL=TypeGraphQLModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,O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AA,sBAAa,GAAE;;wDACuB;AAR5B,iBAAiB;IAD7B,IAAA,eAAM,GAAE;GACI,iBAAiB,CA4C7B;AA5CY,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 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
|
|
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"]}
|
|
File without changes
|
|
@@ -31,7 +31,7 @@ const constants_1 = require("../constants");
|
|
|
31
31
|
* @graphql
|
|
32
32
|
*/
|
|
33
33
|
function DataSourceService() {
|
|
34
|
-
return common_1.Injectable({
|
|
34
|
+
return (0, common_1.Injectable)({
|
|
35
35
|
type: constants_1.PROVIDER_TYPE_DATASOURCE_SERVICE,
|
|
36
36
|
scope: common_1.ProviderScope.INSTANCE
|
|
37
37
|
});
|
|
@@ -0,0 +1 @@
|
|
|
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,IAAA,mBAAU,EAAC;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"]}
|
|
File without changes
|
|
@@ -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"]}
|
|
File without changes
|
package/lib/cjs/index.js
ADDED
|
@@ -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"]}
|
|
File without changes
|
|
File without changes
|
|
@@ -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"]}
|
|
File without changes
|
|
@@ -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"]}
|
|
File without changes
|
|
@@ -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
|
|
@@ -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
|
+
{"version":3,"file":"TypeGraphQLService.js","sourceRoot":"","sources":["../../../src/services/TypeGraphQLService.ts"],"names":[],"mappings":";;;;AAAA,yCAAyD;AAEzD,iCAAuE;AACvE,yCAAoC;AAGpC,uEAA4C;AAC5C,+CAA6D;AAE7D,4CAA8F;AAG9F,MAAM,MAAM,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,eAAe,EAAE,EAAE,CAAC;AAGnD,IAAa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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/common";
|
|
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,EAAe,MAAM,cAAc,CAAC;AAEvG,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,CA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;GACI,iBAAiB,CA4C7B;SA5CY,iBAAiB","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 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 @@
|
|
|
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/common";
|
|
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,cAAc,CAAC;AACvD,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/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"]}
|
|
@@ -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"]}
|
package/lib/esm/index.js
ADDED
|
@@ -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 @@
|
|
|
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 @@
|
|
|
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,CA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AC,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,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"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { AfterListen, Configuration, InjectorService, OnRoutesInit } from "@tsed/common";
|
|
2
|
+
import { TypeGraphQLSettings } from "./interfaces";
|
|
3
|
+
import { TypeGraphQLService } from "./services/TypeGraphQLService";
|
|
4
|
+
/**
|
|
5
|
+
* @ignore
|
|
6
|
+
*/
|
|
7
|
+
export declare class TypeGraphQLModule implements OnRoutesInit, AfterListen {
|
|
8
|
+
protected service: TypeGraphQLService;
|
|
9
|
+
protected injector: InjectorService;
|
|
10
|
+
protected configuration: Configuration;
|
|
11
|
+
get settings(): {
|
|
12
|
+
[key: string]: TypeGraphQLSettings;
|
|
13
|
+
} | undefined;
|
|
14
|
+
$onRoutesInit(): Promise<any> | void;
|
|
15
|
+
$afterListen(): Promise<any> | void;
|
|
16
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a new DataSource binded with Tsed DI.
|
|
3
|
+
*
|
|
4
|
+
* ```typescript
|
|
5
|
+
* import { DataSourceService } from "@tsed/graphql";
|
|
6
|
+
* import { RESTDataSource } from 'apollo-datasource-rest';
|
|
7
|
+
*
|
|
8
|
+
* @DataSourceService()
|
|
9
|
+
* export class MyDataSource extends RESTDataSource {
|
|
10
|
+
* constructor() {
|
|
11
|
+
* super();
|
|
12
|
+
* this.baseURL = 'https://awesome-api.example.com';
|
|
13
|
+
* }
|
|
14
|
+
*
|
|
15
|
+
* willSendRequest(request) {
|
|
16
|
+
* request.headers.set('Authorization', this.context.token);
|
|
17
|
+
* }
|
|
18
|
+
*
|
|
19
|
+
* getMyData(id: string) {
|
|
20
|
+
* return this.get(`/v1/my_rest_data/${id}`);
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* @decorator
|
|
26
|
+
* @graphql
|
|
27
|
+
*/
|
|
28
|
+
export declare function DataSourceService(): ClassDecorator;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { ClassType } from "type-graphql";
|
|
2
|
+
import { AbstractClassOptions, ClassTypeResolver } from "type-graphql/dist/decorators/types";
|
|
3
|
+
export declare function ResolverService(): ClassDecorator;
|
|
4
|
+
export declare function ResolverService(options: AbstractClassOptions): ClassDecorator;
|
|
5
|
+
export declare function ResolverService(typeFunc: ClassTypeResolver, options?: AbstractClassOptions): ClassDecorator;
|
|
6
|
+
export declare function ResolverService(objectType: ClassType, options?: AbstractClassOptions): ClassDecorator;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { TypeGraphQLSettings } from "./TypeGraphQLSettings";
|
|
2
|
+
declare global {
|
|
3
|
+
namespace TsED {
|
|
4
|
+
interface Configuration {
|
|
5
|
+
graphql: {
|
|
6
|
+
[key: string]: TypeGraphQLSettings;
|
|
7
|
+
};
|
|
8
|
+
typegraphql: {
|
|
9
|
+
[key: string]: TypeGraphQLSettings;
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export * from "./TypeGraphQLSettings";
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { ApolloService } from "@tsed/apollo";
|
|
2
|
+
import { Type } from "@tsed/core";
|
|
3
|
+
import { InjectorService } from "@tsed/di";
|
|
4
|
+
import { Logger } from "@tsed/logger";
|
|
5
|
+
import { DataSource } from "apollo-datasource";
|
|
6
|
+
import { GraphQLSchema } from "graphql";
|
|
7
|
+
import { BuildSchemaOptions } from "type-graphql";
|
|
8
|
+
import { ApolloServerBase } from "apollo-server-core";
|
|
9
|
+
import { TypeGraphQLSettings } from "../interfaces";
|
|
10
|
+
export declare class TypeGraphQLService {
|
|
11
|
+
protected injector: InjectorService;
|
|
12
|
+
protected apolloService: ApolloService;
|
|
13
|
+
protected logger: Logger;
|
|
14
|
+
/**
|
|
15
|
+
* Get an instance of ApolloServer from his id
|
|
16
|
+
* @returns ApolloServer
|
|
17
|
+
*/
|
|
18
|
+
get(id?: string): ApolloServerBase | undefined;
|
|
19
|
+
/**
|
|
20
|
+
*
|
|
21
|
+
* @param {string} id
|
|
22
|
+
* @returns {boolean}
|
|
23
|
+
*/
|
|
24
|
+
has(id?: string): boolean;
|
|
25
|
+
/**
|
|
26
|
+
*
|
|
27
|
+
* @returns {Promise<ApolloServer>}
|
|
28
|
+
*/
|
|
29
|
+
createServer(id: string, settings: TypeGraphQLSettings): Promise<any>;
|
|
30
|
+
/**
|
|
31
|
+
* Create a new type-graphql Schema and bind it with Ts.ED injector.
|
|
32
|
+
* @param buildSchemaOptions
|
|
33
|
+
*/
|
|
34
|
+
createSchema(buildSchemaOptions: BuildSchemaOptions): Promise<GraphQLSchema>;
|
|
35
|
+
/**
|
|
36
|
+
* Get an instance of GraphQL schema from his id
|
|
37
|
+
* @returns GraphQLSchema
|
|
38
|
+
*/
|
|
39
|
+
getSchema(id?: string): GraphQLSchema | undefined;
|
|
40
|
+
/**
|
|
41
|
+
*
|
|
42
|
+
* @returns {Provider<any>[]}
|
|
43
|
+
*/
|
|
44
|
+
protected getResolvers(): Type<any>[];
|
|
45
|
+
protected getDataSources(): Record<string, DataSource>;
|
|
46
|
+
/**
|
|
47
|
+
* create a new dataSources function to use with apollo server config
|
|
48
|
+
* @param dataSources
|
|
49
|
+
* @param serverConfigSources
|
|
50
|
+
*/
|
|
51
|
+
protected createDataSources(dataSources: Function | undefined, serverConfigSources: Function | undefined): () => any;
|
|
52
|
+
protected configureTypeGraphQLDI(): void;
|
|
53
|
+
}
|
package/package.json
CHANGED
|
@@ -1,22 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/typegraphql",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.89.0",
|
|
4
4
|
"description": "TypeGraphQL package for Ts.ED framework, based on Apollo-server-core and Type-graphql",
|
|
5
5
|
"private": false,
|
|
6
|
-
"
|
|
7
|
-
"
|
|
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": "
|
|
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": "6.
|
|
23
|
+
"@tsed/apollo": "6.89.0",
|
|
15
24
|
"tslib": "2.2.0"
|
|
16
25
|
},
|
|
17
26
|
"devDependencies": {
|
|
18
|
-
"@tsed/common": "6.
|
|
19
|
-
"@tsed/core": "6.
|
|
27
|
+
"@tsed/common": "6.89.0",
|
|
28
|
+
"@tsed/core": "6.89.0",
|
|
20
29
|
"@types/graphql": "^14.5.0",
|
|
21
30
|
"class-validator": "~0.13.1",
|
|
22
31
|
"graphql-passport": "0.6.3",
|
|
@@ -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
|
+
"**/*.benchmark.ts",
|
|
19
|
+
"**/*.spec.ts",
|
|
20
|
+
"keys",
|
|
21
|
+
"jest.config.js"
|
|
22
|
+
]
|
|
23
|
+
}
|
|
@@ -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,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,eAAM,EAAE;sCACU,uCAAkB;kDAAC;AAGtC;IADC,eAAM,EAAE;sCACW,wBAAe;mDAAC;AAGpC;IADC,sBAAa,EAAE;;wDACuB;AAR5B,iBAAiB;IAD7B,eAAM,EAAE;GACI,iBAAiB,CA4C7B;AA5CY,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 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"]}
|
|
@@ -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 +0,0 @@
|
|
|
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 +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,iCAAuE;AACvE,yCAAoC;AAGpC,kEAA4C;AAC5C,+CAA6D;AAE7D,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,CAA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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"]}
|