mocking - 是否可以在网关级别模拟 GraphQL 服务?
问题描述
想象一下下面的 Node(简化)模块。它使用底层 Apollo 联合网关定义了一个 Hapi 服务器。服务器有一个/graphql
能够接受 GraphQL 请求并聚合来自多个联合 GraphQL 服务器的数据的路由。
const Hapi = require("hapi");
const { ApolloServer } = require("apollo-server-hapi");
const initGateway = require("./init-gateway"); // Apollo Gateway
const context = require("./some-context-getter");
module.exports = async ({ config, plugins, routes }) => {
const gateway = initGateway();
const hapiServer = new Hapi.Server(config);
const apolloServer = new ApolloServer({
gateway,
context,
// mocks: true, doesn't work
subscriptions: false
});
await hapiServer.register(plugins);
hapiServer.route(routes);
await apolloServer.applyMiddleware({
app: hapiServer
});
return hapiServer;
};
我想模拟 GraphQL 响应以进行测试。我的猜测是,根据我从文档中得到的信息,不能在这个级别使用普通的 Apollo 或 GraphQL 模拟策略,主要是因为我读到的模拟策略依赖于手头的模式(使用graphql-tools
mockServer
, for例子)。
我的假设是否正确,我是否需要在服务器级别模拟单个服务?这是否意味着可以认为没有必要使用模拟服务测试 Apollo 网关?
解决方案
推荐阅读
- java - 将 GUI 链接到逻辑
- php - 如何使用 Laravel 隐藏未经身份验证的用户的字段?
- postgresql - 转置具有未知行数/列数的结果
- postgresql - npgsql 使用 SSL 连接到 AWS RDS PostgreSQL
- python - 通过“不在”列表中的 Python Turtle 碰撞检测。为什么它不起作用?
- javascript - 如何在javascript中获取窗口宽度以匹配css媒体?
- c++ - 默认构造函数没有被调用?
- python - 在每个数据框 hhid 中以不同名称合并列上的多个面板数据框
- python - 使用 ratemyprofessor 的加载更多按钮刮取数据
- java - 如何将缓冲写入器加入我的随机猜谜游戏?