forked from nikhilaravi/serverless-graphql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
14 lines (13 loc) · 583 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
'use strict';
require('env2')('.env');
var graphql = require('graphql');
var isEmpty = require('lodash.isempty');
var schema = require('./lib/schema');
exports.handler = function (event, context, callback) {
console.log('Incoming Event', event);
// In the introspection query from GraphiQL the variables key is not present in the event body
var variables = event.variables && !isEmpty(event.variables) ? JSON.parse(event.variables) : {};
graphql.graphql(schema.root, event.query, null, variables)
.then(data => callback(null, data))
.catch(err => callback(err));
};