How to achieve Asynchronous mutations using Apollo Gateway

815 views Asked by At

When using Apollo Gateway, the Gateway will forward mutations directly to the concerned implementing service. 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?

1

There are 1 answers

2
Dan Crews On

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.

(Links to Query and Mutation spec

6.2.1 Query

...

  1. Let data be the result of running ExecuteSelectionSet(selectionSet, queryType, initialValue, variableValues) normally (allowing parallelization).

6.2.2 Mutation

...

  1. Let data be the result of running ExecuteSelectionSet(selectionSet, mutationType, initialValue, variableValues) serially.

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.