gpt4 book ai didi

node.js - Graphql - Apollo 服务器 - 热更新模式

转载 作者:搜寻专家 更新时间:2023-10-31 22:33:49 24 4
gpt4 key购买 nike

我希望在我的 apollo-server-express 服务器上热重载我的 GraphQL 模式。任何人都知道如何做到这一点?

我目前正在使用模式拼接来收集多个 API 的模式,但是我不想每次这些模式之一发生更改时都必须重新启动我的应用程序。

我试图寻找快速路线并将其删除,但那行不通,我还尝试在同一路线上再次调用 graphQLEExpress() 但没有更新它。

感谢您的帮助!

最佳答案

我深入研究了 graphqlExpress 调用,它相当轻量级,仅使用提供的模式返回中间件函数。我能够通过包装它来确保它始终使用我的最新架构:

let schema = createSchema();
app.use('/graphql', bodyParser.json(), function(req, res, next) {
// ensure latest schema is always passed in, we'll reload it automatically
const graphql = graphqlExpress({ schema });
graphql(req, res, next);
});

我目前正在使用本地/静态架构,因此文件观察器允许我根据需要在此处更新架构

关于node.js - Graphql - Apollo 服务器 - 热更新模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48261057/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com