UNPKG

2.16 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const tslib_1 = require("tslib");
4const common_1 = require("@nestjs/common");
5const graphql_1 = require("@nestjs/graphql");
6const apollo_server_express_1 = require("apollo-server-express");
7const graphql_iso_date_1 = require("graphql-iso-date");
8const _ = require("lodash");
9const merge_graphql_schemas_1 = require("merge-graphql-schemas");
10const index_1 = require("../index");
11let GraphQLMiddleware = class GraphQLMiddleware {
12 constructor(graphqlFactory) {
13 this.graphqlFactory = graphqlFactory;
14 this.generateSchema = () => {
15 const appTypeDefs = merge_graphql_schemas_1.fileLoader('./src/**/*.graphqls');
16 const libTypeDefs = merge_graphql_schemas_1.fileLoader('./node_modules/@3wks/gae-node-nestjs/dist/**/*.graphqls');
17 const typeDefs = merge_graphql_schemas_1.mergeTypes([...appTypeDefs, ...libTypeDefs]);
18 return this.graphqlFactory.createSchema({
19 typeDefs,
20 resolvers: {
21 Time: graphql_iso_date_1.GraphQLTime,
22 DateAndTime: graphql_iso_date_1.GraphQLDateTime,
23 },
24 logger: {
25 log: payload => {
26 if (typeof payload === 'string') {
27 index_1.rootLogger.info(payload);
28 }
29 else {
30 index_1.rootLogger.warn(payload);
31 }
32 },
33 },
34 });
35 };
36 }
37 resolve(...args) {
38 const schema = this.generateSchema();
39 return apollo_server_express_1.graphqlExpress(async (req) => {
40 return {
41 schema,
42 rootValue: req,
43 context: _.get(req, 'context'),
44 };
45 });
46 }
47};
48GraphQLMiddleware = tslib_1.__decorate([
49 common_1.Injectable(),
50 tslib_1.__metadata("design:paramtypes", [graphql_1.GraphQLFactory])
51], GraphQLMiddleware);
52exports.GraphQLMiddleware = GraphQLMiddleware;
53//# sourceMappingURL=GraphQLMiddleware.js.map
\No newline at end of file