I have a ReactJSNextJSweb-app . The following code outputs the correct values to the terminal however it fails to update the database at all. As such, I think that the faunaDBUpdate function is incorrectly specified. All 4console.log calls are outputting the correct values.
You cannot include console.log as arguments to a query.
You can see in the JS driver docs that client.query expects as arguments:
expression: your FQL expression
options: query options which can include a bunch of things (check the driver docs for more info)
console.log doesn’t return anything (or consider that it returns undefined). client.query doesn’t accept a third argument. So you are essentially calling
client.query(undefined, undefined)
More tips for debugging
I find it useful to log the entire error object to see what fauna sends back.
client
.query(undefined, undefined)
.then((res) => console.log(res))
.catch((e) => console.error(JSON.stringify(e, null, 2)))
// console result:
{
"name": "BadRequest",
"message": "invalid expression",
"description": "Request body is not valid JSON.",
"requestResult": {
"method": "POST",
"path": "",
"query": null,
"responseRaw": "{\"errors\":[{\"position\":[],\"code\":\"invalid expression\",\"description\":\"Request body is not valid JSON.\"}]}",
"responseContent": {
"errors": [
{
"position": [],
"code": "invalid expression",
"description": "Request body is not valid JSON."
}
]
},
"statusCode": 400,
/* ... */
}
}