AmohPrince
AmohPrince17mo ago

are internalMutations only callable from actions?.

From the docs i got this message Internal functions can be called from other functions using the internal object. but the runMutation function is only available in the ctx object of the action handler. Is it supposed to be this way or im i doing something wrong here is a code snippet.
7 Replies
ballingt
ballingt17mo ago
You're doing this right, internal mutations can only be - called in actions with ctx.runMutation(internal.file.addNewUserMessage) - scheduled from actions and mutations with ctx.scheduler.runAfter(internal.file.addNewUserMessage) - scheduled as cron jobs - run from the command line with npx convex run file:addNewUserMessage
AmohPrince
AmohPrinceOP17mo ago
Thanks mahn. While you are here im running into a tiny bug. Im trying to run an internal mutation when a user signs into my app for the first time. My logic following the docs was to check if a user exists then if not running the internal mutation to the messages table. This logic was working yesterday but right now it isnt. I cant figure it out. Even if the users table is clean it seems the user object is always defined. why is that? here is my logic.
AmohPrince
AmohPrinceOP17mo ago
im saving the user by an effect in a react hook.
AmohPrince
AmohPrinceOP17mo ago
Would you mind helping me figure why the internalMutation is not running @Web Dev Cody 😁
Michal Srb
Michal Srb17mo ago
@AmohPrince Doesn't seem like you need to use an action, you can expose the mutation directly (use mutation instead of internalMutation). Then make sure that your client code (api.users.storeUser) matches the name of that mutation.
AmohPrince
AmohPrinceOP17mo ago
but its an internal mutation dont you think its a bad practice?
Michal Srb
Michal Srb17mo ago
Mutations are intended to be exposed as public API to the client. The Convex approach is: 1. Most things can be accomplished with query and mutation. 2. Only if you need to do something that these can't do (for example, call fetch to fetch from a third-party API) you reach for action 3. If you need to use a Node package that doesn't work in the default query/mutation/action environment, you use action with "use node"

Did you find this page helpful?