How do I get my mutation to return a value?

Im trying to get my mutation to return the object after its been created. My router code is
createAnswerCollection: publicProcedure
.input(
z.object({
userId: z.string(),
})
)
.mutation(async ({ ctx, input }) => {
const answerCollectionObject = await ctx.prisma.answerCollection.create({
data: {
userId: input?.userId,
},
});
return answerCollectionObject;
}),
createAnswerCollection: publicProcedure
.input(
z.object({
userId: z.string(),
})
)
.mutation(async ({ ctx, input }) => {
const answerCollectionObject = await ctx.prisma.answerCollection.create({
data: {
userId: input?.userId,
},
});
return answerCollectionObject;
}),
And my front end code is
const getAnswerCollection = answerCollectionMutation.mutate({ userId });
console.log(`getAnswerCollection`, getAnswerCollection)
const getAnswerCollection = answerCollectionMutation.mutate({ userId });
console.log(`getAnswerCollection`, getAnswerCollection)
the console log keeps returning undefined. How do I get it to return the object? when I look at getAnswerCollection it says void
2 Replies
.improb
.improbOP2y ago
okay I actually answered this myself by using mutateAsync on the frontend
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server