Trying to update all code base to FQL10 I found very difficult to rebuild a simple function called getByRef accepting a collectionName and ID, which is currently used by hundred of routes and functions in the app. The collectionName is never defined by the user, so no security issues are involved related to potential extraction of data from unintended collections. Not having that function would require rewriting almost all routes requiring specific documents and repeating al the fql query too much times.
Following the fixes in some posts here I found the use of new Module as a workaround, but it still does not work. The passed collection name is “invoicing”.
_.getByRef = async function (collection, ref) {
const mod = new Module(collection)
const query = fql`
let coll = ${mod}
coll.byId(${ref})
`
const resp = await client.query(query)
return resp.data
}
The error obtained is:
httpStatus: 400,
code: 'invalid_query',
queryInfo: {
txn_ts: 1722574494812618,
summary: 'error: Type `invoicingCollection` does not have field `byId`\n' +
'at *query*:3:12\n' +
' |\n' +
'3 | coll.byId(<value>)\n' +
' | ^^^^\n' +
' |\n' +
'hint: Type `invoicingCollection` inferred here\n' +
'at *query*:2:18\n' +
' |\n' +
'2 | let coll = <value>\n' +
' | ^^^^^^^\n' +
' |'
}
Why does it add “Collection” to the end of the collection name and yet is not working.