netlify-faunadb-example2/functions/todos-read-one.js
2018-06-11 16:39:45 -07:00

20 lines
551 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
});
exports.handler = (event, context, callback) => {
console.log(`readOne todo ${event.pathParameters.id}`);
return client.query(q.Get(q.Ref("classes/todos/"+event.pathParameters.id)))
.then((response) => {
console.log("success", response);
callback(false, response);
}).catch((error) => {
console.log("error", error);
callback(error)
})
};