Home How to handle async mutations in GraphQL Apollo client
Reply: 0

How to handle async mutations in GraphQL Apollo client

user1339
1#
user1339 Published in July 18, 2018, 4:52 am

Structure

This is a question how to best use Apollo Client 2 in our current infrastructure. We have one Graphql server (Apollo server 2) which connects to multiple other endpoints. Mutations are send via RabbitMQ and our Graphql also listens to RabbitMQ which then are pushed to the client via subscriptions.

Implementation

We have a Apollo server which we send mutations, these always give a null because they are async. Results will be send back via a subscription. I have currently implemented it like this.

  • Send mutation.
  • Create a optimisticResponse.
  • Update the state optimistically via writeQuery in the update function.
  • When the real response comes (which is null) use the optimisticResponse again in the update method.
  • Wait for the subscription to come back with the response.
  • Then refresh the the state/component with the actual data.

As you can see.. not the most ideal way, and a lot of complexity in the client.

Would love to keep the client as dumb as possible and reduce complexity. Seems Apollo is mostly designed for sync mutations (which is logical).

What are your thoughts on a better way to implement this?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.305506 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO