I'm learning FQL and trying to do a mass update, but I can't figure out what I'm doing wrong, nor can I really figure out what the error is really pointing to.
Here is my code:
const updateResult = await serverClient.query(
q.Map(
guests,
q.Lambda(
"guest",
q.Update(q.Var("guest").id, {
data: {
emailSent: q.Var("guest").emailSent,
emailStatus: q.Var("guest").emailStatus,
emailRejectReason: q.Var("guest").emailRejectReason,
},
})
)
)
);
Here is the what the guests object is via console.log:
[ { email: 'myemail+bart72320@gmail.com',
emailStatus: 'sent',
emailRejectReason: null,
emailSent: true,
id: Ref(Collection("Guests"), "271884343706649107") } ]
Here is that same object with JSON.stringify:
[
{
"email": "myemail+bart72320@gmail.com",
"emailStatus": "sent",
"emailRejectReason": null,
"emailSent": true,
"id": {
"@ref": {
"id": "271884343706649107",
"collection": {
"@ref": {
"id": "Guests",
"collection": {
"@ref": {
"id": "collections"
}
}
}
}
}
}
}
]
Here is part of the error that is returned:
{ [BadRequest: invalid expression]
name: 'BadRequest',
message: 'invalid expression',
description:
'No form/function found, or invalid argument keys: { params }.',
requestResult:
RequestResult {
method: 'POST',
path: '',
query: null,
requestRaw:
'{"map":{"lambda":"guest","expr":{"params":{"object":{"data":{"object":{}}}}}},"collection":[{"object":{"email":"myemail+bart72320@gmail.com","emailStatus":"sent","emailRejectReason":null,"emailSent":true,"id":{"@ref":{"id":"271884343706649107","collection":{"@ref":{"id":"Guests","collection":{"@ref":{"id":"collections"}}}}}}}}]}',
requestContent: Expr { raw: [Object] },
responseRaw:
'{"errors":[{"position":["map","expr"],"code":"invalid expression","description":"No form/function found, or invalid argument keys: { params }."}]}',
I've gotten updates to work and lambdas to work, but not this one and maybe I'm just bad at reading very nested, functional looking error messages. What is a form and is it the same as a function, or am I missing keys: params? I don't know what to make of this.
Please help me understand what I'm doing wrong and if this error message is actually helpful and how to interpret it or if it's just a confusing catchall?
Thanks!
You are mixing Javascript syntax with FQL expressions.
Var("guest")
is a FQL expression, but
Var("guest").id
is a Javascript syntax. The equivalent of dot operator in FQL is
Select("id", Var("guest"))
Remember that FQL is not executed on Javascript, but is executed on server side.