简体   繁体   English

Graphql - Apollo Server - 热门更新架构

[英]Graphql - Apollo Server - Hot update schema

I am looking to hot reload my GraphQL schema on my apollo-server-express server. 我期待在我的apollo-server-express服务器上热重新加载我的GraphQL架构。 Anyone would have any idea about how to do that? 任何人都会知道如何做到这一点?

I'm currently using schemas stitching to gather multiple API's schemas, however I do not want to have to restart my application every time one of these schema changes. 我目前正在使用模式拼接来收集多个API的模式,但是我不希望每次这些模式更改时都必须重新启动我的应用程序。

I've tried to look for the express route and remove it but that dit not work, I also tried to call graphQLExpress() again on the same route and that did not update it. 我试图寻找快速路线并删除它,但是dit不起作用,我也尝试在同一路线上再次调用graphQLExpress()并且没有更新它。

Thanks for your help! 谢谢你的帮助!

I dug into the graphqlExpress call a bit, it's fairly lightweight and just returns a middleware function using the provided schema. 我挖了一下graphqlExpress调用,它相当轻量级,只是使用提供的模式返回一个中间件函数。 I was able to ensure it's always using my latest schema by wrapping it: 我能够通过包装它来确保它始终使用我的最新模式:

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);
});

I'm working with local / static schema at the moment, so a file watcher allows me to update schema here as needed. 我目前正在使用本地/静态模式,因此文件监视器允许我根据需要更新schema

I managed to get it done by removing the express route and then re-creating it. 我设法通过删除快速路线然后重新创建它来完成它。 But actually I discovered that because makeRemoteExecutableSchema is sending the introspection query at every request, you actually don't need to update your schema, it gets updated by itself. 但实际上我发现因为makeRemoteExecutableSchema在每次请求时发送内省查询,实际上你不需要更新你的模式,它会自动更新。 That does not imply Graphiql though. 但这并不意味着Graphiql。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM