Help, I can’t figure out what went wrong.
Netlify Function with FaunaDB Query failed: Ref refers to undefined index
The outcome of deployed function is different to the outcome of localhost.
Test site: https://1028--droplets.netlify.app/.netlify/functions/getUser?id=nik
Outcome: /getUser?id=nik
{"build":1028,"message":"Query failed: Ref refers to undefined index 'users_id'"}
locahost: /getUser?id=nik
{"build":1028,"response":{"ref":{"@ref":{"id":"315756321428210252","collection":{"@ref":{"id":"users","collection":{"@ref":{"id":"collections"}}}}}},"ts":1637387544000000,"data":{"id":"nik"}}}
getUser.js
"use strict";
const { handle, json, message } = require('./utils/main');
const { q, client, getFaunaErrorMessage } = require('./utils/fauna');
const { env } = process, e=env;
const build=1028;
exports.handler = handle(async function(event,context) {
const
{ id } = event.queryStringParameters;
return client(
q.Get(q.Match(q.Index("users_id"), id||'' ))
)
.then(response=>json(200,
{
build:build,
response:response,
}
))
.catch(error=>{
return json(500,{
build:build,
message:'Query failed: '+getFaunaErrorMessage(error)
})
})
})
Deployment
>netlify deploy --alias=1028
Deploy path: \_site
Functions path: \_functions
Configuration path: \netlify.toml
Deploying to draft URL...
√ No cached functions were found
√ Finished hashing 10 files and 2 functions
√ CDN requesting 0 files and 2 functions
√ Finished uploading 2 assets
√ Deploy is live!
Logs: https://app.netlify.com/sites/droplets/deploys/619c4c6cb61e243bc617c82e
Website Draft URL: https://1028--droplets.netlify.app
FaunaDB: Running Shell Query with Server key
Outcome just fine.
Paginate(Collections())
Paginate(Indexes())
Get(Match(Index("users_id"), "nik"))
[
{
data: [Collection("users")]
},
{
data: [Index("users_id")]
},
{
ref: Ref(Collection("users"), "315756321428210252"),
ts: 1637387544000000,
data: {
id: "nik"
}
}
]
I wonder what went wrong?
The better the post - the faster the answer.