Hey, is there a way to pass custom info
Hey, is there a way to pass custom info to mutation context? I'd like to return localised error messages in my mutations, but for this I need to know the current locale. What's the best way to do it?
6 Replies
I pass that sort of info directly into args. There are helpers for custom mutation context that might help, haven't tried it for this.
thanks, guess I'll probably also pass it in args
regarding those helpers, do you have any links or info on this?
The closest I've seen is
makeUseQueryWithStatus
- I suspect you could use that as an example for making your own custom useQuery that includes some default args: https://github.com/get-convex/convex-helpers/blob/16014342c4baa666483359139b9e40f67bfcbe70/packages/convex-helpers/react.ts#L88
To pair with that, assuming you can find a way to add default args to a custom useQuery, you can try making custom convex query/mutation/action where those args are moved to ctx
: https://github.com/get-convex/convex-helpers/blob/16014342c4baa666483359139b9e40f67bfcbe70/packages/convex-helpers/README.md#custom-functions
This is just the direction I'd look first, again, haven't actually tried myself. cc/ @ian in case there's some glaring opportunity I'm missing herethose custom functions actually look like something I might need!
I'll take a closer look, thanks
just tried, works like a charm
Nice! Feel free to drop some code here in case anyone else is curious, I might use it myself 😅
as another example, here's a hook and custom function that implicitly pass up a session argument https://www.npmjs.com/package/convex-helpers#session-tracking-via-client-side-sessionid-storage
npm
convex-helpers
A collection of useful code to complement the official convex package.. Latest version: 0.1.65, last published: 6 days ago. Start using convex-helpers in your project by running
npm i convex-helpers
. There are 3 other projects in the npm registry using convex-helpers.