It's complex when used with apollo


For example, the updateTopics mutation.

And I want to update apollo cache when send this mutation to graphql server.

Here is my code:

Why do I say update cache is complex?

Because this mutation is updateTopics, not removeTopic + addTopic.

Take a notice about the if...else... statement.

Is there any better solution for updating apollo cache when use updateTopics mutation?


Hi @mrdulin!

As you said, this is not removeTopic + addTopic, it’s a single updateTopics mutation.

However, the updateTopics mutation is idempotent and replaces the whole set of topics in a repository. This means your cache should be as simple as replacing the entire set in cache when this mutation is called.

So I’m not totally certain why you need an if...else... statement in there, could you maybe clarify?