我有一个突变,可以改变外部系统中的数据(例如,posts)。
从我的UI中,在external-api上发布公共文章,并在此突变之后获取此api以进行刷新。
我希望保存使我的系统使用extenal-api的更改,但这并不是很重要,更重要的是在上瘾newPost之后立即在我的站点上更新posts,而不是等待将这些帖子保存在我的数据库中。
我原以为这段代码
.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}
});
}
})但是不幸的是,在解决了这个请求之后,tRPC杀死了Prisma,因为数据库中的保存数据需要等待Prisma,但是速度很慢
如何从tRPC返回响应,但继续执行其余的承诺?
发布于 2022-01-31 10:38:17
普莉丝玛不像我预料的那样工作
prisma.posts.create({
data: {postId, ...input}
});不要开始承诺,只在调用.then()之后才开始承诺
我不想使用await prisma.post.create(),但可以使用prisma.post.create().then()或prisma.$transaction(prisma.post.create())
初始代码的正确版本。
.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}
}).then();
}
})https://stackoverflow.com/questions/70912842
复制相似问题