1 | ;
|
2 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
3 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
4 | };
|
5 | Object.defineProperty(exports, "__esModule", { value: true });
|
6 | // this must be imported to allow async-functions within an AWS lambda environment
|
7 | // see: https://github.com/babel/babel/issues/5085
|
8 | require("@babel/polyfill");
|
9 | const graphql_1 = require("graphql");
|
10 | const types_1 = __importDefault(require("../types"));
|
11 | const loader_1 = require("../libs/loader");
|
12 | //const awsServerlessExpress = require('aws-serverless-express');
|
13 | /**
|
14 | * Handler-Function
|
15 | *
|
16 | * @param event of the http-request (POST). The event.body must be json-formatted and must contain
|
17 | * `query` as a GraphQl-Query object
|
18 | *
|
19 | * @param context
|
20 | * @param callback
|
21 | *
|
22 | async function query (event, context, callback) {
|
23 |
|
24 | console.log("event: ", event);
|
25 | const parsedBody = JSON.parse(event.body);
|
26 | console.log("parsedBody: ", parsedBody);
|
27 |
|
28 | console.log("context: ", context);
|
29 |
|
30 |
|
31 | // load the IsomorphicComponent
|
32 | // we must load it directly from the module here, to enable the aliad of the config_file_path
|
33 | const isoConfig = loadConfigurationFromModule(require('__CONFIG_FILE_PATH__'), INFRASTRUCTURE_MODES.RUNTIME);
|
34 |
|
35 | // let's extract it from the root configuration
|
36 | const dataLayer = extractObject(
|
37 | isoConfig,
|
38 | Types.INFRASTRUCTURE_TYPE_COMPONENT,
|
39 | __DATALAYER_ID__
|
40 | );
|
41 |
|
42 | /**
|
43 | * The schema specifies the queries that the user can run. It also connects to implementation of the DynamoDb-connection
|
44 | * through the resolve-functions!
|
45 | * /
|
46 | const schema = new GraphQLSchema({
|
47 | query: new GraphQLObjectType({
|
48 | name: 'RootQueryType', // an arbitrary name
|
49 | fields: dataLayer.queries
|
50 | }), mutation: new GraphQLObjectType({
|
51 | name: 'RootMutationType', // an arbitrary name
|
52 | fields: dataLayer.mutations
|
53 | })
|
54 | });
|
55 |
|
56 | await graphql(schema, parsedBody.query)
|
57 | .then(
|
58 | result => callback(null, {
|
59 | statusCode: 200,
|
60 | headers: {
|
61 | "Access-Control-Allow-Origin" : "*", // Required for CORS support to work
|
62 | "Access-Control-Allow-Credentials" : true // Required for cookies, authorization headers with HTTPS
|
63 | },
|
64 | body: JSON.stringify(result)
|
65 | }),
|
66 | err => callback(err)
|
67 | );
|
68 | }*/
|
69 | const universal_cookie_express_1 = __importDefault(require("universal-cookie-express"));
|
70 | const query = () => {
|
71 | const express = require('express');
|
72 | //const graphqlHTTP = require('express-graphql');
|
73 | const app = express();
|
74 | // load the IsomorphicComponent
|
75 | // we must load it directly from the module here, to enable the aliad of the config_file_path
|
76 | const isoConfig = loader_1.loadConfigurationFromModule(require('__CONFIG_FILE_PATH__'), loader_1.INFRASTRUCTURE_MODES.RUNTIME);
|
77 | // let's extract it from the root configuration
|
78 | const dataLayer = loader_1.extractObject(isoConfig, types_1.default.INFRASTRUCTURE_TYPE_COMPONENT, __DATALAYER_ID__);
|
79 | app.use(universal_cookie_express_1.default());
|
80 | /*
|
81 | app.use((req, res, next) => {
|
82 |
|
83 | console.log("this it the datalayer-mw: ", req);
|
84 |
|
85 | const { body} = req;
|
86 | console.log("body: ", body);
|
87 | return next();
|
88 | });*/
|
89 | console.log("DataLayer -- queries: ", dataLayer.queries);
|
90 | console.log("DataLayer -- mutations: ", dataLayer.mutations);
|
91 | /**
|
92 | * The schema specifies the queries that the user can run. It also connects to implementation of the DynamoDb-connection
|
93 | * through the resolve-functions!
|
94 | */
|
95 | const schema = new graphql_1.GraphQLSchema({
|
96 | query: new graphql_1.GraphQLObjectType({
|
97 | name: 'RootQueryType',
|
98 | fields: dataLayer.queries
|
99 | }), mutation: new graphql_1.GraphQLObjectType({
|
100 | name: 'RootMutationType',
|
101 | fields: dataLayer.mutations
|
102 | })
|
103 | });
|
104 | /*app.use('/query', graphqlHTTP({
|
105 | schema: schema,
|
106 | graphiql: false
|
107 | }));*/
|
108 | app.use('/query', (req, res, next) => {
|
109 | console.log("I should not be called...", req);
|
110 | });
|
111 | return app;
|
112 | };
|
113 | function default_1(event, context) {
|
114 | //return awsServerlessExpress.proxy(query(), event, context);
|
115 | }
|
116 | exports.default = default_1;
|
117 | //# sourceMappingURL=data-layer.js.map |
\ | No newline at end of file |