简体   繁体   English

如何使用 Apollo Gateway 实现异步突变

[英]How to achieve Asynchronous mutations using Apollo Gateway

When using Apollo Gateway, the Gateway will forward mutations directly to the concerned implementing service.使用 Apollo Gateway 时,Gateway 会直接将变更转发给相关的实现服务。 Such requests are synchronous.此类请求是同步的。

Is there a way that Apollo Gateway can publish all mutations to a message broker like rabbitmq so that we can achieve asynchronous communication between the gateway and the implementing services?有没有一种方法可以让 Apollo Gateway 将所有突变发布到像 rabbitmq 这样的消息代理,以便我们可以在网关和实现服务之间实现异步通信?

As a clarification to your question: the requests are not synchronous, but serial.作为对您的问题的澄清:请求不是同步的,而是串行的。

Unlike Queries, which the GraphQL Specification leaves open to "allowing parallelization", mutations MUST run in a series.与 GraphQL 规范对“允许并行化”开放的查询不同,突变必须以一系列方式运行。

(Links to Query and Mutation spec 查询变异规范的链接

6.2.1 Query 6.2.1 查询

... ...

  1. Let data be the result of running ExecuteSelectionSet(selectionSet, queryType, initialValue, variableValues) normally (allowing parallelization).令 data 为正常运行 ExecuteSelectionSet(selectionSet, queryType, initialValue, variableValues) 的结果(允许并行化)。

6.2.2 Mutation 6.2.2 突变

... ...

  1. Let data be the result of running ExecuteSelectionSet(selectionSet, mutationType, initialValue, variableValues) serially.令 data 为连续运行 ExecuteSelectionSet(selectionSet, mutationType, initialValue, variableValues) 的结果。

The pattern that is widely adopted is that your mutation should "return when it's done, and wait until it has that data".广泛采用的模式是您的突变应该“在完成后返回,并等到它拥有该数据”。 Theoretically, however, you could make your mutation kick off some event and just respond saying it had.然而,理论上,你可以让你的突变开始一些事件,然后回应说它已经发生了。 You could then use a Subscription to identify when the response was ready.然后,您可以使用订阅来确定响应何时准备就绪。 Again, this isn't really "the way GraphQL is generally used", but theoretically, you could.同样,这并不是真正的“通常使用 GraphQL 的方式”,但从理论上讲,你可以。

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

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