在 GraphQL 解析器中返回后继续运行其他函数

问题描述 投票:0回答:1

如何在 GraphQL 解析器中返回后保持其他操作运行。

套餐

import { ApolloServer } from "@apollo/server";
import { typeDefs } from "./definitions";
import { resolvers } from "./resolvers";
import { makeExecutableSchema } from "graphql-tools";
import { applyMiddleware } from "graphql-middleware";
import { shield, allow } from "graphql-shield";
import { permissions } from "./shield/permissions";

代码

createOrder: async (_: any, args: MutationCreateOrderArgs, ctx: IContext) => {

const sendToGoogleSheetsPromise....
const sendToConversionApiPrmise....

return ctx.order.create()
}

承诺在返回后以某种方式被取消,我不想等待所有承诺或使用 Promise.all。

服务人员中有类似

waitUntil()
的东西吗?

node.js graphql apollo-server
1个回答
0
投票

您确定 Promise 被取消,还是只是您丢失了对 Promise 的引用,从而丢失了已解决的结果??

可能的解决方案是返回已解决的订单创建并返回其他函数调用的未解决的承诺。

createOrder: async (_: any, args: MutationCreateOrderArgs, ctx: IContext) => {

    const sendToGoogleSheetsPromise....
    const sendToConversionApiPrmise....
    const order = await ctx.order.create();
    return {
       order,
       sendToGoogleSheetsPromise,
       sendToConversionApiPrmise
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.