知识卡片
GraphQL聚合勿直连数据库
GraphQL 网关可按客户端需求聚合字段并减少往返,但 resolver 应调用服务契约,而非直接读写各领域数据库;还须审查聚合延迟、敏感数据和领域耦合。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
原书出处
参考来源
- 位置:《Principles of Software Architecture Modernization》第8章《Embracing New Technology》(源文件:`_epub-src/OPS/ch08.xhtml`,归一化正文 [84295:88664))
- 结论依据:原文列出 GraphQL 聚合优势和破坏隔离的风险,明确建议 resolver 只调用服务。
- 原始内容:Break isolation: You can be tempted to treat GraphQL like a proper service, thinking you can go straight to databases; this is a fast track to creating a distributed monolith. When you implement your resolvers, only call services. Now you need to wait: When you were doing multiple REST calls, you could launch some calls in parallel, but now you will need to wait for the whole aggregation to be done.