userQuery is not a function
I created a convex custom helper, but whenever I try to use it, it returns this error in the image:
Here is my code for the custom Helper:
export const userQuery = customQuery(
query,
customCtx(async (ctx) => {
return {
userId: await getUserId(ctx)
};
})
);
And where I use it:
export const getUser = userQuery({
args: {},
async handler(ctx) {
return await ctx.db.get(ctx.userId as Id<'users'>);
}
});
here is the github repo where the issue is:
https://github.com/Cyberverse2/squid
GitHub
GitHub - CyberVerse2/squid
Contribute to CyberVerse2/squid development by creating an account on GitHub.
6 Replies
I would remove "use node" from the top of user.ts. I'm not sure why it would cause this error message, but convex files that use node cannot define queries, mutations, or http actions, and the bundler is probably unhappy with it
Do you mean I should remove it where I'm using the custom query?
I removed use node, but it's still not working
It might be bc you have a circular dependency: user imports userQuery from utils which imports getUserId from user. When it’s parsing the circular dependency, it is null on the first pass
Please, how can I solve the issue, as I saw this customQuery in the notesGPT sample app and tried to use it.
you should remove the cycle, for example move
getUserId
into utils.tsOk, lemme try that
Suprisingly worked after that, thanks @lee