Custom functions <> return validators
If I have something like this:
How do I update it so that I don't get errors when doing this:
8 Replies
@ian I was using your blogpost as reference: 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...
follow up question about custom functions: what's the recommended way to export a custom Context type that replaces MutationCtx and QueryCtx?
something like this?
If you're getting type errors, (1) make sure you're using the latest version of convex-helpers + convex (in particular, convex 1.13 requires a newer version of convex-helpers) (2) sharing the error here would be helpful
updating convex-helpers fixed it, thanks @sshader !
Related to the above context, where I have a custom query (
authenticatedQuery
), which takes in an additional argument, I was wondering if there's a recommended way to extend the useQuery
hook to do avoid having to do something like this on every component that uses useQuery
You can either wrap
useQuery
like I do for useSessionQuery, or more simply wrap the args, so you could have
where useOrgId
is like useSessionIdArgthese examples are just what I needed, thank you!! 👌
do you have similar examples for fetchSessionQuery, etc? @ian
ideally there's also a nice way to inject the token inside the
fetchAuthQuery
function...
Related: any guides on extending useQueryWithStatus and the useQuery from the caching library with similar purpose?Yeah as the combinatorial matrix grows, the most reliable wrapper is going to be at the parameter level, such as the
useSessionIdArg
function linked above. Then you can use it anywhere. Or write a single custom wrapper yourself that picks the behavior and return values. I made the makeUseQueryWithStatus
so at least you can combine it with the caching library by passing in the caching library's useQueries
. What I need to do is sit down and write a post on how to work with the types to write your own wrappers - mostly walking through how some existing wrappers work - pure wrapping like the cache, adding args like sessions, changing return types like useQueryWithStatus