json
json11mo ago

can i call mutations inside mutations?

can i call mutations inside mutations? is this... recommended?
4 Replies
erquhart
erquhart11mo ago
If you want two different mutations to both include the same behavior, create a separate plain function to execute the shared behavior and call that function from both mutations. You'll generally pass the ctx into the function so it can execute the mutation. This is less likely, but if you really do specifically have a need to call one mutation from another, you can use ctx.scheduler to schedule the mutation from within another mutation.
json
jsonOP11mo ago
thanks, the scheduler is what I'm looking for
erquhart
erquhart11mo ago
Note that you won't be able to await the scheduled mutation, the returned promise only resolves to indicate that the function was successfully scheduled.
lee
lee11mo ago
the main difference is calling a js function would run it in the same transaction while scheduling it will run a separate transaction

Did you find this page helpful?