ctx.db.get() Always returning a Doc<'users'> typed doc
I have multiple queries for multiple documents structured like so:
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
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 offno that looks fine... and this might only be mutations, not queries.
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?found the
customQuery
blog entry. I'll investigate this. I'm only 7 months behind 😅 ...
https://stack.convex.dev/custom-functionsStack
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...
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 pasteThe
customQuery
approach seems to take care of the ts issues, so i'll just cut over and get up to speed