3

我正在寻找优化在graphql-java和上运行的 GraphQL 端点graphql-java-tools

我有以下架构:

{
  product(id: String) {
    id
    title
    offer {
      price
    }
  }
}

id并且title来自服务A,价格来自服务B。

现在,我有一个GraphQLQueryResolver返回CompletableFuture<ProductResponse>where ProductResponsecontains idand的 a title,还有一个返回 aGraphQLResolver<ProductResponse>的方法。offer(ProductResponse productResponse)CompletableFuture<OfferResponse>

但是,这意味着我必须等待服务 A 返回 aProductResponse才能开始向服务 B 查询 a OfferResponse。这两个服务只需要 ID 作为输入,因此可以并行执行。有没有办法在不调整架构的情况下并行执行两个服务调用?

4

1 回答 1

-2

我认为您可以考虑使用 Apollo federation,它以一种通用的方式解决它,但仍然以一种优雅的方式。

尝试通过这个 - https://github.com/apollographql/federation-demo

于 2019-08-14T20:01:02.317 回答