netlify-faunadb-example/functions/todos-create.js
2018-06-11 16:15:03 -07:00

21 lines
544 B
JavaScript

'use strict';
import faunadb from 'faunadb'
// const faunadb = require('faunadb');
const q = faunadb.query;
const client = new faunadb.Client({
secret: process.env.FAUNADB_SECRET
});
module.exports = (event, callback) => {
const data = JSON.parse(event.body);
console.log("create todo", data);
return client.query(q.Create(q.Ref("classes/todos"), {data}))
.then((response) => {
console.log("success", response);
callback(false, response);
}).catch((error) => {
console.log("error", error);
callback(error)
})
};