graphql - 在阿波罗 2 中更新 graphql 模式而不重新启动服务器
问题描述
我的项目有一种定义模式和解析器的声明方式,它在单独的存储库中维护。我的 graphql 服务器轮询此结果以查找对模式的更新。
使用 apollo-server-express@1,我可以直接访问 graphqlExpress 中间件,因此当架构更改时,我可以构建它的新实例并丢弃旧实例,就像这样
const { graphqlExpress } = require('apollo-server-express');
let api;
const constructAPI = () => {
try {
const newSchema = createSchema();
api = graphqlExpress(({ headers }) => ({
schema: newSchema,
}));
logger.info({ event: 'GRAPHQL_SCHEMA_UPDATED' });
};
schemaPoller.on('change', constructAPI);
module.exports = router => {
// Note that we wrap the api controller in a function that passes
// the original args through because a new api controller is generated
// every time the schema changes. We can't pass express a direct
// reference to the api controller on startup, or it will
// never update the reference to point at the latest version of the
// controller using the latest schema
router
.route('/')
.get((...args) => api(...args))
.post((...args) => api(...args));
return router;
};
在 apollo-server-express@2 中,对中间件的访问被隐藏了,并且有 2 种新的、更具声明性的方式使用该库,乍一看,这两种方式都不兼容在不停止服务器的情况下更新模式,获取新模式并从新数据重新开始,这是我想避免的停机时间。
任何人都可以建议一种让这个设置与 apollo@2 一起使用的方法吗?
解决方案
推荐阅读
- graphql - 将 graphql 解析器文件拆分为单独的文件
- ruby-on-rails - nginx 上的乘客没有在 rails 上重新加载我的更改 ruby
- c - 如何在 C 中释放 2D 数组内存
- java - 对象动画只会为对象设置一次动画
- python - 无法使用 python 创建文本文件
- elixir - Ecto.Queryable 未针对用户/凤凰错误实现
- c#-4.0 - Entity Framework Core 2.1:在实体类型“BarCodeDevice”上找不到属性“模型”的指定字段“模型”
- symfony - 驱动程序发生异常:SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known
- vagrant - “mount.nfs:连接超时”在 Ubuntu 18.04 上安装 open edX 时出错
- python - 无法保存和加载经过训练的 CNN 模型以进行二值图像分类