我正在尝试从 netlify 函数运行查询。该功能非常简单,它只是“更新”一个帖子:
exports.handler = async function (event, context, callback) {
const faunadb = require('faunadb')
const headers = {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Headers': 'Content-Type',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE',
}
const q = faunadb.query
const adminClient = new faunadb.Client({
secret: process.env.FAUNADB_SERVER_SECRET,
})
const post = event.body
const queryResult = await adminClient.query(
q.If(
q.Exists(q.Match(q.Index('post_uuid'), post.uuid)),
q.Update(
q.Select(['ref'], q.Get(q.Match(q.Index('post_uuid'), post.uuid))),
{ data: post }
),
q.Create(q.Collection('posts'), { data: post })
)
)
callback(null, {
statusCode: 200,
headers,
body: '',
})
}
该查询使用 Fauna 的在线 shell 工作,脚本的所有其他部分似乎都在工作,但是当我运行查询时,我收到此错误并且 netlify CLI 崩溃:
Request from ::1: POST /.netlify/functions/savePost
{"level":"error","message":"End - Error:"}
{"errorMessage":"validation failed","errorType":"BadRequest","level":"error"}
TypeError: Cannot read property 'join' of undefined
at formatLambdaLocalError (C:\Users\Oliver\scoop\persist\nodejs\bin\node_modules\netlify-cli\src\utils\serve-functions.js:25:100)
at handleErr (C:\Users\Oliver\scoop\persist\nodejs\bin\node_modules\netlify-cli\src\utils\serve-functions.js:29:55)
at Context.callbackHandler [as callback] (C:\Users\Oliver\scoop\persist\nodejs\bin\node_modules\netlify-cli\src\utils\serve-functions.js:60:14)
at Context.done (C:\Users\Oliver\scoop\persist\nodejs\bin\node_modules\netlify-cli\node_modules\lambda-local\build\lib\context.js:204:14)
at Context.fail (C:\Users\Oliver\scoop\persist\nodejs\bin\node_modules\netlify-cli\node_modules\lambda-local\build\lib\context.js:211:10)
at processTicksAndRejections (node:internal/process/task_queues:93:5)
TypeError: Cannot read property 'join' of undefined
at formatLambdaLocalError (C:\Users\Oliver\scoop\persist\nodejs\bin\node_modules\netlify-cli\src\utils\serve-functions.js:25:100)
at handleErr (C:\Users\Oliver\scoop\persist\nodejs\bin\node_modules\netlify-cli\src\utils\serve-functions.js:29:55)
at Context.callbackHandler [as callback] (C:\Users\Oliver\scoop\persist\nodejs\bin\node_modules\netlify-cli\src\utils\serve-functions.js:60:14)
at Context.done (C:\Users\Oliver\scoop\persist\nodejs\bin\node_modules\netlify-cli\node_modules\lambda-local\build\lib\context.js:204:14)
at Context.fail (C:\Users\Oliver\scoop\persist\nodejs\bin\node_modules\netlify-cli\node_modules\lambda-local\build\lib\context.js:211:10)
at processTicksAndRejections (node:internal/process/task_queues:93:5)
C:\Users\Oliver\scoop\persist\nodejs\bin\node_modules\netlify-cli\node_modules\netlify-redirector\lib\redirects.js:116
throw ex;
^
abort({}) at Error
at jsStackTrace (C:\Users\Oliver\scoop\persist\nodejs\bin\node_modules\netlify-cli\node_modules\netlify-redirector\lib\redirects.js:1070:13)
at stackTrace (C:\Users\Oliver\scoop\persist\nodejs\bin\node_modules\netlify-cli\node_modules\netlify-redirector\lib\redirects.js:1087:12)
at process.abort (C:\Users\Oliver\scoop\persist\nodejs\bin\node_modules\netlify-cli\node_modules\netlify-redirector\lib\redirects.js:8502:44)
at process.emit (node:events:376:20)
at emit (node:internal/process/promises:202:22)
at processPromiseRejections (node:internal/process/promises:223:25)
at processTicksAndRejections (node:internal/process/task_queues:94:32)
(Use `node --trace-uncaught ...` to show where the exception was thrown)
我正在运行这个netlify dev
:
系统 Windows 10 节点:v15.4.0 netlify cli:v2.69.11