【问题标题】:How to close graphql-yoga server?如何关闭graphql-yoga服务器?
【发布时间】:2019-11-25 04:33:59
【问题描述】:

对于快递的描述在

how to properly close node-express server?

但在瑜伽文档中

https://github.com/prisma/graphql-yoga

没有关于close 方法的信息。


更新

@perdox 的解决方案解决了我的问题,正确答案是:

const gqlServer = new GraphQLServer({ typeDefs, resolvers });
const server = gqlServer.start(() => console.log('Server is running on localhost:4000'));
(async function f() {
    (await server).close();
})();

【问题讨论】:

    标签: express graphql-js prisma-graphql


    【解决方案1】:

    GraphQLYoga 是一个工具集合,使用/包装了 express 服务器。

    见:https://github.com/prisma/graphql-yoga/blob/master/src/index.ts

    正如您在源代码中看到的,GraphQLServer 包装了 express 服务器,并且 start 方法返回一个 HttpServer Promise。所以你应该可以通过在 HttpServer 上调用 close 方法来关闭服务器:

    const gqlServer = new GraphQLServer({ typeDefs, resolvers })
    const server = gqlServer.start(() => console.log('Server is running on localhost:4000'))
    server.close()
    

    【讨论】:

      猜你喜欢
      • 2019-05-30
      • 2020-01-10
      • 2019-08-03
      • 1970-01-01
      • 2019-09-06
      • 2021-01-31
      • 2017-08-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多