node.jsgraphqlapollo-server

Keep running other functions after return in GraphQL resolvers


How can I keep other operation running after return in GraphQL resolvers.

packages

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";

Code

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

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

return ctx.order.create()
}

Promises somehow got cancelled after return, I don't want to wait all of them or using Promise.all.

Is there something like waitUntil() in service workers?


Solution

  • After investigating many days about how to make this done, I will write some solutions that may help.