winsoroaks
winsoroaks8mo ago

queryWithUser is not a function.

(not urgent) hi team! im working on some unit tests. the convex-test library is awesome and fun! however, im running into a weird scenario (not related to the lib perhaps).
// users.ts
import { LIMIT } from "./usage"

export const createUser = mutation({
...
await ctx.db.insert("usage", {
userId,
used: 0,
limit: LIMIT,
})

...

const addUser = customCtx(async (ctx: QueryCtx) => {
const userId = await getUserIdByTokenIdentifier(ctx)
if (!userId) {
throw new ConvexError("User ID not found")
}
return { userId }
})

export const queryWithUser = customQuery(query, addUser)
// users.ts
import { LIMIT } from "./usage"

export const createUser = mutation({
...
await ctx.db.insert("usage", {
userId,
used: 0,
limit: LIMIT,
})

...

const addUser = customCtx(async (ctx: QueryCtx) => {
const userId = await getUserIdByTokenIdentifier(ctx)
if (!userId) {
throw new ConvexError("User ID not found")
}
return { userId }
})

export const queryWithUser = customQuery(query, addUser)
and when i run vitest, im getting
TypeError: queryWithUser is not a function
convex/usage.ts:24:25
22| })
23|
24| export const getUsage = queryWithUser({
| ^
25| handler: async (ctx) => {
26| const usage = await ctx.db
TypeError: queryWithUser is not a function
convex/usage.ts:24:25
22| })
23|
24| export const getUsage = queryWithUser({
| ^
25| handler: async (ctx) => {
26| const usage = await ctx.db
but when i hard code the LIMIT to be 100, it works. any idea what's wrong? 🙏
1 Reply
Michal Srb
Michal Srb8mo ago
That's a circular import, and I guess Vite doesn't like it (browser probably wouldn't like it either, since those are consts). usage.ts imports queryWithUser from users.ts users.ts import LIMIT from usage.ts break the cycle

Did you find this page helpful?