For express it is described in
how to properly close node-express server?
but in documentation of yoga
https://github.com/prisma/graphql-yoga
there is not info about close
method.
Solution of @perdox solves my problem, correct answer is:
const gqlServer = new GraphQLServer({ typeDefs, resolvers });
const server = gqlServer.start(() => console.log('Server is running on localhost:4000'));
(async function f() {
(await server).close();
})();
GraphQLYoga is a collection of tools and uses / wraps the express server.
See: https://github.com/prisma/graphql-yoga/blob/master/src/index.ts
So as you can see in the source code the GraphQLServer wraps the express server and the start method returns a HttpServer Promise. So you should be able to close the server by invoking the close method on the HttpServer:
const gqlServer = new GraphQLServer({ typeDefs, resolvers })
const server = gqlServer.start(() => console.log('Server is running on localhost:4000'))
server.close()