allen
allen•6mo ago

ctx.db.get() Always returning a Doc<'users'> typed doc

I have multiple queries for multiple documents structured like so:
export default query({
args: {
inviteId: v.id('invites'),
},
handler: async(ctx, args) {
return ctx.db.get(args.inviteId);
}
});
export default query({
args: {
inviteId: v.id('invites'),
},
handler: async(ctx, args) {
return ctx.db.get(args.inviteId);
}
});
The typed return of the ctx.db.get is a Doc<'users'> instead of a Doc<'invites'> (or the respective doc type to the provided arg type). If i inspect the type of the ID on the arg its showing as any. This problem emerged today after upgrade convex to latest and adding Convex Auth. This only seems to impact code where the ID is provided on query/mutation args.
6 Replies
ballingt
ballingt•6mo ago
When you type of Doc<" does anything autocomplete besides "users"? that's pretty wacky, I wonder if it's because convex auth augments your schema with users and something else is off
allen
allenOP•6mo ago
no that looks fine... and this might only be mutations, not queries.
No description
allen
allenOP•6mo ago
hmm actually the culprit may be my withUser wrapper not inheriting arg types correctly in a new version of something thinking its just queries/mutations that use that wrapper. Vanilla queries/mutations are ok. Is there a new/better pattern for asserting auth and injecting a user doc on the context these days?
allen
allenOP•6mo ago
found the customQuery blog entry. I'll investigate this. I'm only 7 months behind 😅 ... https://stack.convex.dev/custom-functions
Stack
Customizing serverless functions without middleware
Re-use code and centralize request handler definitions with discoverability and type safety and without the indirection of middleware or nesting of wr...
ballingt
ballingt•6mo ago
If you can post your custom withUser wrapper we can help update it too, the types for these have changed a little but yeah customQuery is the general pattern, also a lot of this now lives in the convex-helpers npm package, since when you were last active it might have been more copy and paste
allen
allenOP•6mo ago
The customQuery approach seems to take care of the ts issues, so i'll just cut over and get up to speed

Did you find this page helpful?