I have a mutation that changes data in the extern system (for example posts).
From my UI I public post on external-api
and fetch this api for refresh posts after this mutation
I want save changes that make my system in extenal-api, but it is not very important, more important is to update posts on my site immediately after addiction newPost, without awaiting save these posts in my database
I expected that this code makes it
.mutation('post.add', {
input: z.object({ title: z.string(), text: z.string() }),
async resolve({ input }) {
const postId = await useExternApiForPublicThisPost(input);
// save change in my database, but not await response
prisma.posts.create({
data: {postId, ...input}
});
}
})
but unfortunately, after resolving this request, tRPC kill Prisma, for save data in the database need await Prisma, but it's is slow
How can return response from tRPC, but continue to execute remaining promises?