0

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?

subhrob
  • 1
  • 1
  • 2

1 Answers1

0

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.

Dan Crews
  • 3,067
  • 17
  • 20
  • I guess I'm not really sure if you're asking about running multiple mutations or if you're specifically asking about not using HTTP. If the former, this is the answer. If the latter, I have a different answer, which changes from `CachedRemoteGraphQLDataSource` to a custom event-driven one. – Dan Crews Jul 12 '20 at 01:22
  • i am trying not to use HTTP between the gateway and the other implementing services. (only for mutations). The gateway should publish the mutation to a message broker rather than send the mutation directly to the implementing service via HTTP. The services would in turn be listening for any message in the message broker. In this way, even when a service is down, the mutation will not be lost and can be consumed once the service is up. How can this be achieved using Apollo Gateway – subhrob Jul 12 '20 at 06:35