typegraphql-nestjs
Version:
Basic integration of TypeGraphQL in NestJS. Allows to use TypeGraphQL features while integrating with NestJS modules system and dependency injector.
49 lines (48 loc) • 2.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const common_1 = require("@nestjs/common");
const type_graphql_1 = require("type-graphql");
const lodash_merge_1 = tslib_1.__importDefault(require("lodash.merge"));
const subgraph_1 = require("@apollo/subgraph");
const graphql_tag_1 = tslib_1.__importDefault(require("graphql-tag"));
const constants_1 = require("./constants");
const prepare_options_service_1 = tslib_1.__importDefault(require("./prepare-options.service"));
const helpers_1 = require("./helpers");
let TypeGraphQLOptionsFactory = class TypeGraphQLOptionsFactory {
constructor(rootModuleOptions, optionsPreparatorService) {
this.rootModuleOptions = rootModuleOptions;
this.optionsPreparatorService = optionsPreparatorService;
}
async createGqlOptions() {
const { federationVersion } = this.rootModuleOptions;
const { resolversClasses, container, orphanedTypes, referenceResolvers } = this.optionsPreparatorService.prepareOptions(constants_1.TYPEGRAPHQL_FEATURE_MODULE_OPTIONS);
const isFederatedModule = federationVersion === 1 || federationVersion === 2;
let schema = await (0, type_graphql_1.buildSchema)({
...this.rootModuleOptions,
resolvers: resolversClasses,
orphanedTypes,
container,
});
if (isFederatedModule) {
const federatedSchema = (0, subgraph_1.buildSubgraphSchema)({
typeDefs: (0, graphql_tag_1.default)((0, helpers_1.printSubgraphSchema)(schema, federationVersion)),
resolvers: (0, lodash_merge_1.default)((0, type_graphql_1.createResolversMap)(schema), referenceResolvers),
});
return {
...this.rootModuleOptions,
schema: federatedSchema,
};
}
return {
...this.rootModuleOptions,
schema,
};
}
};
TypeGraphQLOptionsFactory = tslib_1.__decorate([
(0, common_1.Injectable)(),
tslib_1.__param(0, (0, common_1.Inject)(constants_1.TYPEGRAPHQL_ROOT_MODULE_OPTIONS)),
tslib_1.__metadata("design:paramtypes", [Object, prepare_options_service_1.default])
], TypeGraphQLOptionsFactory);
exports.default = TypeGraphQLOptionsFactory;