@tsed/typegraphql 7.0.0-beta.3 → 7.0.0-beta.6
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/.mocharc.js +2 -2
- package/lib/cjs/TypeGraphQLModule.js +7 -7
- package/lib/cjs/TypeGraphQLModule.js.map +1 -1
- package/lib/cjs/constants/{index.js → constants.js} +1 -1
- package/lib/cjs/constants/constants.js.map +1 -0
- package/lib/cjs/decorators/dataSourceService.js +1 -1
- package/lib/cjs/decorators/dataSourceService.js.map +1 -1
- package/lib/cjs/decorators/resolverService.js +1 -1
- package/lib/cjs/decorators/resolverService.js.map +1 -1
- package/lib/cjs/index.js +10 -6
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/interfaces/{index.js → interfaces.js} +2 -2
- package/lib/cjs/interfaces/interfaces.js.map +1 -0
- package/lib/cjs/package.json +3 -0
- package/lib/cjs/services/TypeGraphQLService.js +9 -9
- package/lib/cjs/services/TypeGraphQLService.js.map +1 -1
- package/lib/esm/TypeGraphQLModule.js +1 -1
- package/lib/esm/TypeGraphQLModule.js.map +1 -1
- package/lib/esm/constants/{index.js → constants.js} +1 -1
- package/lib/esm/constants/constants.js.map +1 -0
- package/lib/esm/decorators/dataSourceService.js +1 -1
- package/lib/esm/decorators/dataSourceService.js.map +1 -1
- package/lib/esm/decorators/resolverService.js +1 -1
- package/lib/esm/decorators/resolverService.js.map +1 -1
- package/lib/esm/index.js +10 -6
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/interfaces/interfaces.js +2 -0
- package/lib/esm/interfaces/interfaces.js.map +1 -0
- package/lib/esm/package.json +3 -0
- package/lib/esm/services/TypeGraphQLService.js +1 -1
- package/lib/esm/services/TypeGraphQLService.js.map +1 -1
- package/lib/types/TypeGraphQLModule.d.ts +1 -1
- package/lib/types/constants/{index.d.ts → constants.d.ts} +0 -0
- package/lib/types/index.d.ts +8 -4
- package/lib/types/interfaces/{index.d.ts → interfaces.d.ts} +0 -0
- package/lib/types/services/TypeGraphQLService.d.ts +1 -1
- package/package.json +11 -8
- package/readme.md +22 -20
- package/tsconfig.compile.esm.json +1 -12
- package/lib/cjs/constants/index.js.map +0 -1
- package/lib/cjs/interfaces/index.js.map +0 -1
- package/lib/esm/constants/index.js.map +0 -1
- package/lib/esm/interfaces/index.js +0 -2
- package/lib/esm/interfaces/index.js.map +0 -1
package/.mocharc.js
CHANGED
|
@@ -35,19 +35,19 @@ let TypeGraphQLModule = class TypeGraphQLModule {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
-
|
|
38
|
+
tslib_1.__decorate([
|
|
39
39
|
(0, di_1.Inject)(),
|
|
40
|
-
|
|
40
|
+
tslib_1.__metadata("design:type", TypeGraphQLService_1.TypeGraphQLService)
|
|
41
41
|
], TypeGraphQLModule.prototype, "service", void 0);
|
|
42
|
-
|
|
42
|
+
tslib_1.__decorate([
|
|
43
43
|
(0, di_1.Inject)(),
|
|
44
|
-
|
|
44
|
+
tslib_1.__metadata("design:type", di_1.InjectorService)
|
|
45
45
|
], TypeGraphQLModule.prototype, "injector", void 0);
|
|
46
|
-
|
|
46
|
+
tslib_1.__decorate([
|
|
47
47
|
(0, di_1.Configuration)(),
|
|
48
|
-
|
|
48
|
+
tslib_1.__metadata("design:type", Object)
|
|
49
49
|
], TypeGraphQLModule.prototype, "configuration", void 0);
|
|
50
|
-
TypeGraphQLModule =
|
|
50
|
+
TypeGraphQLModule = tslib_1.__decorate([
|
|
51
51
|
(0, di_1.Module)()
|
|
52
52
|
], TypeGraphQLModule);
|
|
53
53
|
exports.TypeGraphQLModule = TypeGraphQLModule;
|
|
@@ -1 +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;IAU5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,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=
|
|
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"]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.DataSourceService = void 0;
|
|
4
4
|
const di_1 = require("@tsed/di");
|
|
5
|
-
const constants_1 = require("../constants");
|
|
5
|
+
const constants_1 = require("../constants/constants");
|
|
6
6
|
/**
|
|
7
7
|
* Create a new DataSource binded with Tsed DI.
|
|
8
8
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dataSourceService.js","sourceRoot":"","sources":["../../../src/decorators/dataSourceService.ts"],"names":[],"mappings":";;;AAAA,iCAAmD;AACnD,
|
|
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,7 +4,7 @@ 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
9
|
return (0, core_1.useDecorators)(type_graphql_1.Resolver(...args), (0, di_1.Injectable)({
|
|
10
10
|
type: constants_1.PROVIDER_TYPE_RESOLVER_SERVICE
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolverService.js","sourceRoot":"","sources":["../../../src/decorators/resolverService.ts"],"names":[],"mappings":";;;AAAA,qCAAyC;AACzC,iCAAoC;AACpC,+CAAiD;AAEjD,
|
|
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"]}
|
package/lib/cjs/index.js
CHANGED
|
@@ -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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
tslib_1.__exportStar(require("./TypeGraphQLModule"), exports);
|
|
8
|
+
tslib_1.__exportStar(require("./constants/constants"), exports);
|
|
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);
|
|
13
|
+
tslib_1.__exportStar(require("./services/TypeGraphQLService"), exports);
|
|
10
14
|
//# sourceMappingURL=index.js.map
|
package/lib/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;
|
|
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"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
|
|
5
|
-
//# sourceMappingURL=
|
|
4
|
+
tslib_1.__exportStar(require("./TypeGraphQLSettings"), exports);
|
|
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"]}
|
|
@@ -5,9 +5,9 @@ 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 =
|
|
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
|
/**
|
|
@@ -113,19 +113,19 @@ let TypeGraphQLService = class TypeGraphQLService {
|
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
};
|
|
116
|
-
|
|
116
|
+
tslib_1.__decorate([
|
|
117
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
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
125
|
(0, di_1.Inject)(),
|
|
126
|
-
|
|
126
|
+
tslib_1.__metadata("design:type", logger_1.Logger)
|
|
127
127
|
], TypeGraphQLService.prototype, "logger", void 0);
|
|
128
|
-
TypeGraphQLService =
|
|
128
|
+
TypeGraphQLService = tslib_1.__decorate([
|
|
129
129
|
(0, di_1.Injectable)()
|
|
130
130
|
], TypeGraphQLService);
|
|
131
131
|
exports.TypeGraphQLService = TypeGraphQLService;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypeGraphQLService.js","sourceRoot":"","sources":["../../../src/services/TypeGraphQLService.ts"],"names":[],"mappings":";;;;AAAA,yCAAyD;AAEzD,iCAAuE;AACvE,yCAAoC;AAGpC,
|
|
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,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,EAA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AM,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"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { __decorate, __metadata } from "tslib";
|
|
2
2
|
import { Configuration, Inject, InjectorService, Module } from "@tsed/di";
|
|
3
|
-
import { TypeGraphQLService } from "./services/TypeGraphQLService";
|
|
3
|
+
import { TypeGraphQLService } from "./services/TypeGraphQLService.js";
|
|
4
4
|
/**
|
|
5
5
|
* @ignore
|
|
6
6
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TypeGraphQLModule.js","sourceRoot":"","sources":["../../src/TypeGraphQLModule.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,aAAa,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EAAC,MAAM,UAAU,CAAC;AAExE,OAAO,EAAC,kBAAkB,EAAC,MAAM,+BAA+B,CAAC;AAEjE;;GAEG;AAEH,IAAa,iBAAiB,GAA9B,MAAa,iBAAiB;IAU5B,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IACpF,CAAC;IAED,aAAa;QACX,MAAM,EAAC,QAAQ,EAAC,GAAG,IAAI,CAAC;QACxB,IAAI,QAAQ,EAAE;YACZ,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE,EAAE;gBACrE,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,GAAG,EAAE,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,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\";\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"]}
|
|
1
|
+
{"version":3,"file":"TypeGraphQLModule.js","sourceRoot":"","sources":["../../src/TypeGraphQLModule.ts"],"names":[],"mappings":";AAAA,OAAO,EAAC,aAAa,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EAAC,MAAM,UAAU,CAAC;AAExE,OAAO,EAAC,kBAAkB,EAAC,MAAM,+BAA+B,CAAC;AAEjE;;GAEG;AAEH,IAAa,iBAAiB,GAA9B,MAAa,iBAAiB;IAU5B,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IACpF,CAAC;IAED,aAAa;QACX,MAAM,EAAC,QAAQ,EAAC,GAAG,IAAI,CAAC;QACxB,IAAI,QAAQ,EAAE;YACZ,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE,EAAE;gBACrE,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,GAAG,EAAE,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,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 @@
|
|
|
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"]}
|
|
@@ -1 +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,
|
|
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"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useDecorators } from "@tsed/core";
|
|
2
2
|
import { Injectable } from "@tsed/di";
|
|
3
3
|
import { Resolver } from "type-graphql";
|
|
4
|
-
import { PROVIDER_TYPE_RESOLVER_SERVICE } from "../constants";
|
|
4
|
+
import { PROVIDER_TYPE_RESOLVER_SERVICE } from "../constants/constants.js";
|
|
5
5
|
export function ResolverService(...args) {
|
|
6
6
|
return useDecorators(Resolver(...args), Injectable({
|
|
7
7
|
type: PROVIDER_TYPE_RESOLVER_SERVICE
|
|
@@ -1 +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,
|
|
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"]}
|
package/lib/esm/index.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export * from "./
|
|
5
|
-
export * from "./constants";
|
|
6
|
-
export * from "./
|
|
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";
|
|
7
11
|
//# sourceMappingURL=index.js.map
|
package/lib/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
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 @@
|
|
|
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"]}
|
|
@@ -4,7 +4,7 @@ import { Inject, Injectable, InjectorService } from "@tsed/di";
|
|
|
4
4
|
import { Logger } from "@tsed/logger";
|
|
5
5
|
import * as TypeGraphql from "type-graphql";
|
|
6
6
|
import { buildSchema } from "type-graphql";
|
|
7
|
-
import { PROVIDER_TYPE_DATASOURCE_SERVICE, PROVIDER_TYPE_RESOLVER_SERVICE } from "../constants";
|
|
7
|
+
import { PROVIDER_TYPE_DATASOURCE_SERVICE, PROVIDER_TYPE_RESOLVER_SERVICE } from "../constants/constants.js";
|
|
8
8
|
const getKey = (id) => `typegraphql-${id}`;
|
|
9
9
|
let TypeGraphQLService = class TypeGraphQLService {
|
|
10
10
|
/**
|
|
@@ -1 +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,
|
|
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,E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ED;;;;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,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/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"]}
|
|
File without changes
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* @file Automatically generated by barrelsby.
|
|
3
|
+
*/
|
|
4
|
+
export * from "./TypeGraphQLModule";
|
|
5
|
+
export * from "./constants/constants";
|
|
3
6
|
export * from "./decorators/dataSourceService";
|
|
7
|
+
export * from "./decorators/resolverService";
|
|
8
|
+
export * from "./interfaces/TypeGraphQLSettings";
|
|
9
|
+
export * from "./interfaces/interfaces";
|
|
4
10
|
export * from "./services/TypeGraphQLService";
|
|
5
|
-
export * from "./constants";
|
|
6
|
-
export * from "./TypeGraphQLModule";
|
|
File without changes
|
|
@@ -6,7 +6,7 @@ import { DataSource } from "apollo-datasource";
|
|
|
6
6
|
import { GraphQLSchema } from "graphql";
|
|
7
7
|
import { BuildSchemaOptions } from "type-graphql";
|
|
8
8
|
import { ApolloServerBase } from "apollo-server-core";
|
|
9
|
-
import { TypeGraphQLSettings } from "../interfaces";
|
|
9
|
+
import { TypeGraphQLSettings } from "../interfaces/interfaces";
|
|
10
10
|
export declare class TypeGraphQLService {
|
|
11
11
|
protected injector: InjectorService;
|
|
12
12
|
protected apolloService: ApolloService;
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tsed/typegraphql",
|
|
3
|
-
"version": "7.0.0-beta.
|
|
3
|
+
"version": "7.0.0-beta.6",
|
|
4
4
|
"description": "TypeGraphQL package for Ts.ED framework, based on Apollo-server-core and Type-graphql",
|
|
5
5
|
"private": false,
|
|
6
6
|
"source": "./src/index.ts",
|
|
7
7
|
"main": "./lib/cjs/index.js",
|
|
8
|
+
"module": "./lib/esm/index.js",
|
|
8
9
|
"typings": "./lib/types/index.d.ts",
|
|
9
10
|
"exports": {
|
|
10
11
|
"types": "./lib/types/index.d.ts",
|
|
@@ -13,19 +14,21 @@
|
|
|
13
14
|
"default": "./lib/esm/index.js"
|
|
14
15
|
},
|
|
15
16
|
"scripts": {
|
|
16
|
-
"build": "yarn run build:esm && yarn run build:cjs",
|
|
17
|
+
"build": "yarn barrels && yarn run build:esm && yarn run build:cjs",
|
|
17
18
|
"build:cjs": "tsc --build tsconfig.compile.json",
|
|
18
19
|
"build:esm": "tsc --build tsconfig.compile.esm.json",
|
|
19
|
-
"
|
|
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",
|
|
20
23
|
"test": "cross-env NODE_ENV=test nyc mocha"
|
|
21
24
|
},
|
|
22
25
|
"dependencies": {
|
|
23
|
-
"@tsed/apollo": "7.0.0-beta.
|
|
24
|
-
"tslib": "2.
|
|
26
|
+
"@tsed/apollo": "7.0.0-beta.6",
|
|
27
|
+
"tslib": "2.3.1"
|
|
25
28
|
},
|
|
26
29
|
"devDependencies": {
|
|
27
|
-
"@tsed/common": "7.0.0-beta.
|
|
28
|
-
"@tsed/core": "7.0.0-beta.
|
|
30
|
+
"@tsed/common": "7.0.0-beta.6",
|
|
31
|
+
"@tsed/core": "7.0.0-beta.6",
|
|
29
32
|
"@types/graphql": "^14.5.0",
|
|
30
33
|
"class-validator": "~0.13.1",
|
|
31
34
|
"graphql-passport": "0.6.3",
|
|
@@ -42,7 +45,7 @@
|
|
|
42
45
|
"bugs": {
|
|
43
46
|
"url": "https://github.com/tsedio/tsed/issues"
|
|
44
47
|
},
|
|
45
|
-
"homepage": "https://github.com/tsedio/tsed/tree/
|
|
48
|
+
"homepage": "https://github.com/tsedio/tsed/tree/production/packages/graphql/typegraphql",
|
|
46
49
|
"author": "Romain Lenzotti",
|
|
47
50
|
"license": "MIT"
|
|
48
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
|
-
|
|
56
|
-
|
|
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
|
-
|
|
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({
|
|
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
|
-
###
|
|
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() {
|
|
166
|
-
return this.recipeService.findAll({
|
|
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)]
|
|
@@ -8,16 +8,5 @@
|
|
|
8
8
|
"declaration": true,
|
|
9
9
|
"declarationDir": "./lib/types"
|
|
10
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
|
-
]
|
|
11
|
+
"exclude": ["node_modules", "test", "lib", "benchmark", "coverage", "spec", "**/*.benchmark.ts", "**/*.spec.ts", "keys", "jest.config.js"]
|
|
23
12
|
}
|
|
@@ -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":"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"]}
|
|
@@ -1 +0,0 @@
|
|
|
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"]}
|
|
@@ -1 +0,0 @@
|
|
|
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"]}
|