-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler.js
59 lines (53 loc) · 1.5 KB
/
handler.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
'use strict';
const fs = require('fs')
const {introspectionQuery, graphqlRequest} = require('./gql-interface')
module.exports.index = (event, context, callback) => {
let html = fs.readFileSync('index.html', 'utf8')
let index = fs.readFileSync('index.js', 'utf8')
let renderHelpers = fs.readFileSync('renderHelpers.js', 'utf8')
html = html.replace("{{ index.js }}", index)
html = html.replace("{{ renderHelpers.js }}", renderHelpers);
const response = {
statusCode: 200,
headers: {
'Content-Type': 'text/html',
},
body: html,
};
callback(null, response);
};
module.exports.introspectionQuery = async (event, context, callback) => {
let body = JSON.parse(event.body)
let endpoint = body['endpoint']
let resp = await introspectionQuery(endpoint)
let response = {
statusCode: 200,
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(resp),
};
callback(null, response);
};
module.exports.graphqlRequest = async (event, context, callback) => {
let body = JSON.parse(event.body)
let query = body['query']
let token = body['token']
let endpoint = body['endpoint']
let variables = body['variables']
let resp = {}
try {
resp = await graphqlRequest(endpoint, token, query, variables)
}
catch (e) {
resp = {status: 'ERROR', message: e.message}
}
let response = {
statusCode: 200,
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(resp),
};
callback(null, response);
};