Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing the cache update logic #647

Closed
cihadturhan opened this issue May 20, 2020 · 1 comment
Closed

Fixing the cache update logic #647

cihadturhan opened this issue May 20, 2020 · 1 comment

Comments

@cihadturhan
Copy link

Hello,
First of all, I've used this library extensively for last week and I want to thank for your hard work. It works great!

Secondly, I've used apollo client with react, react native and vue so I'd like to ask about cache update logic OR report a bug if it's a design flow. Here is an example:

  • Page A
    -- Query (messages)

  • Page B
    -- Mutation (addMessage)
    --- Use update() callback in Mutation widget. Update "messages" cache and run cache.save()

This scenario works fine 👍 Let's skip to second scenario

  • Page A
    -- Query (messages)

  • Page B
    -- receive an event (e.g. push notification with data)
    -- Update "messages" cache and run cache.save()

In this case, I would expect the Query in "Page A" to be updated but it's not. 👎 I've spent almost two days to understand what's wrong.

After digging code, it turns out there is also a local snapshot for every Query widget.
If I change the cache externally, a local snapshot from AsyncSnapshot will not be updated.
I realized snapshot is only updated with Mutation callbacks: update, onError and onCompleted

If I want to update a Query snapshot externally, I manually force cache update with
client.queryManager.rebroadcastQueries()
This was my aha moment.

Is this a design choice? I believe, rebroadcastQueries should run after ever cache.write().
Correct?

@micimize
Copy link
Collaborator

Consolidating into #728

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants