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 theupdate
function. - When the real response comes (which is null) use the
optimisticResponse
again in theupdate
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?