-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (34 loc) · 824 Bytes
/
index.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
const {
processRequest,
renderGraphiQL
} = require('graphql-helix');
const { schema } = require("./schema");
module.exports.graphql = async (event, context) => {
let body = null
let isIql = event.queryStringParameters.type == 'iql'
if (isIql)
body = renderGraphiQL({
endpoint: '?type=graphql'
});
else {
const request = {
body: Buffer.from(event.body, event.isBase64Encoded ? 'base64' : 'ascii').toString('ascii'),
headers: event.headers,
method: event.httpMethod
};
const query = '{ alphabet }'
// Validate and execute the query
body = await processRequest({
query,
schema,
request,
});
}
return {
statusCode: 200,
headers: {
'Content-Type': isIql ? 'text/html' : 'application/json'
},
body: body
};
}