Hi,
for some reason i am unable to deploy a fairly simple function to netlify… it runs on my machine but does not work when deployed to netlify.
const groq = require('groq-js');
// Docs on event and context https://www.netlify.com/docs/functions/#the-handler-method
exports.handler = async (event, context) => {
try {
// const subject = event.queryStringParameters.name || 'World';
const input = '*[_type == "user"]{name}';
// Returns an ESTree-inspired syntax tree
const tree = groq.parse(input);
const dataset = [
{ _type: 'user', name: 'Michael' },
{ _type: 'company', name: 'Bluth Company' },
];
// Evaluate a tree against a dataset
const value = await groq.evaluate(tree, { dataset });
// Gather everything into one JavaScript object
const result = await value.get();
return {
statusCode: 200,
body: JSON.stringify(result),
};
} catch (err) {
return { statusCode: 500, body: err.toString() };
}
};
do you have any idea why? the following error was thrown when the function was called
{"errorMessage":"Unexpected token *","errorType":"SyntaxError","stackTrace":["SyntaxError: Unexpected token *","createScript (vm.js:80:10)","Object.runInThisContext (vm.js:139:10)","Module._compile (module.js:616:28)","Object.Module._extensions..js (module.js:663:10)","Module.load (module.js:565:32)","tryModuleLoad (module.js:505:12)","Function.Module._load (module.js:497:3)","Module.require (module.js:596:17)","require (internal/module.js:11:18)","Object.<anonymous>(/var/task/src/node_modules/groq-js/src/index.js:6:20)"]}
expected result:
[{"name":"Michael"}]
i find it rather difficult to debug netlify functions and was hoping netlify dev would at least mirror the above behaviour, which it does not…