-
-
Notifications
You must be signed in to change notification settings - Fork 454
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
Cache update and invalidation in same transaction voids the update #3618
Comments
This is indeed intended behavior, basically what you're doing is not marking it for a "refetch" but removing the whole connection. Marking it for a refetch would be that you invalidate a nullable part of the operation and that triggers a refetch while displaying stale data. What you are doing here is that you add an entity to your |
Thanks for the quick answer. How come when I invalidate data, it is still displayed in the UI until the refetch returns a new result? Is there any way to achieve the desired result (mark for refetch) with graphcache? |
Scrap that, even that won't work 😅 I don't think there's currently a way to observe that, all though in theory subscriptions were created for things like this... Or you can try polling... |
We were able to fix our problem by manually refetching the query in the component when an event gets created. |
You might be better off splitting this result up or modelling your mutation differently. Basically, updating is an all or nothing approach unless you trigger query updates in another way. That means that updates are intended to fully reflect either invalidations or updates. You basically need a signal at the query end. There's several ways though of achieving what you're looking for:
Basically, the reason why you're running into trouble is because this case is fighting the cache in a way. Personally, I'd try to model this as an optimistic and non-optimistic update, since this gives the user immediate feedback. Re. the flashing of UI, this really depends on how you treat refetches. This basically doesn't have much to do with the updated but with how you treat these refetches. If you hide the UI while a refetches occurs with |
Describe the bug
I am executing a query that updates creates a calendar event. As a result I am getting back that event instance and adding it to the list via an updater. This far everything works great.
However, creating a event may also add other events in the background that are not immediately returned (think recurring events). So what I want to do is:
Now I have the following updater:
As soon as I add the invalidate in the updater, the manual updates are no longer visible and the event does not get added until the refetch completes resulting in flashing of the UI.
In my opinion this should work but if that behaviour is on purpose please advice on how else this should be solved.
(I wanted to create a repro but the Postgres db for https://trygql.formidable.dev/ is down. If needed I can provide one later when its up again)
Reproduction
See description
Urql version
"urql": "^4.0.7"
"@urql/exchange-graphcache": "^7.0.2",
Validations
The text was updated successfully, but these errors were encountered: