question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question: Graphcache multiple updates

See original GitHub issue

Hi all

Lets say i have a system with notifications and chat

notification {
 user {
  id,
  name
 }
 content:String
}

chatmessage {
 user {
  id
  name
 }
 message:string
}

I first execute a query to get the list of all notifications and then i subscribe to get subsequent updates. Subsequent updates are merged with the original array using updateQuery

Second i have a chat system in which from the beginning i subscribe to receive new chat messages

The problem is the following If the notifications array contains 100 entities. 95 of them are from the same user and then that same user sends a chat message

Graphcache will update the user in the cache that will result in the notification query to be reloaded thus resulting in the whole notifications component to be rerendered

If the chat system is very busy with many users chatting at the same time then the notifications component will rerender any time a chat arrives which contains a user that also has a notification

I am using react.memo to avoid rerendering each notificatio but the loop on all the notifications will be executed since the notifications array will be refreshed (due to the new chat message)

How should someone handle this kind of situations?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:19 (7 by maintainers)

github_iconTop GitHub Comments

3reactions
zenioscommented, Mar 20, 2020

Thanks a lot

0reactions
zenioscommented, Mar 20, 2020

Some more information.

If i have maskTypeName to true then the objects do come back with a prototype I assume its because its doing something to hide __typename

Read more comments on GitHub >

github_iconTop Results From Across the Web

Question: Graphcache multiple updates · Issue #648 - GitHub
I first execute a query to get the list of all notifications and then i subscribe to get subsequent updates. Subsequent updates are...
Read more >
Normalized Caching | urql Documentation
When multiple optimistic updates are made at the same time, we never allow these layers to be deleted separately. Instead Graphcache waits for...
Read more >
Mutation not updating Graphcache cache entry in urql
So in this case, your routines isn't updating any fields, since you're just fetching a list of them. But if that's intended, then...
Read more >
Pagination and Cache Updates with GraphQL, React & urql ...
Pagination and Cache Updates with GraphQL, React & urql Tutorial. ... a list separated into multiple pages that the user can navigate through....
Read more >
Phil @philpl@toot.cafe on Twitter: "Working on urql's ...
This lead to a problem with Apollo's optimistic updates though. ... so suddenly, sending two messages would quickly display three 2/.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found