1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const tslib_1 = require("tslib");
|
4 | const common_1 = require("@nestjs/common");
|
5 | const graphql_1 = require("@nestjs/graphql");
|
6 | const apollo_server_express_1 = require("apollo-server-express");
|
7 | const graphql_iso_date_1 = require("graphql-iso-date");
|
8 | const _ = require("lodash");
|
9 | const merge_graphql_schemas_1 = require("merge-graphql-schemas");
|
10 | const index_1 = require("../index");
|
11 | let 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 | };
|
48 | GraphQLMiddleware = tslib_1.__decorate([
|
49 | common_1.Injectable(),
|
50 | tslib_1.__metadata("design:paramtypes", [graphql_1.GraphQLFactory])
|
51 | ], GraphQLMiddleware);
|
52 | exports.GraphQLMiddleware = GraphQLMiddleware;
|
53 |
|
\ | No newline at end of file |