-
-
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
Problem: @urql/exchange-graphcache updateCacheWithResult reads null after writing link in cache updater. #3526
Comments
There's basically some very specific conditions here — as you say — which make this a bit tricky and this "outcome" can only occur when these are true. Let me list them to make this a little clearer for future reference:
This is kind of expected behaviour because this breaks several assumptions that we're making:
I might be forgetting a couple of things here but to keep it short, this condition is kind of meant to prevent cache misses after writes. After writes, when a layer is still commutative, we read from layers in a very specific manner because we value data integrity above all else. Cache updaters for result data has come as a feature afterwards, so it can lead to some unexpected cases as you're seeing. Unless I'm misunderstanding where you've placed your updater in the cache config |
is this during the first or second write? |
I will try to explain timeline one more time.
|
Hm, I think the main thing I'm struggling with here is the inherent inconsistency of trying to link data from In other words, the problem kind of stems from It does seem like in the schema design there's a missing edge here potentially, but that could be one way of solving this. Other than that and ignoring the above, this kind of creates an awkward situation, as this behaves “as expected” as per the all the pre-conditions we assume, namely:
|
I think I hit same issue in out project. Running two queries in paralell, both fetches some (different) attributes on same entity. On network layer I can see all data are returned from server correctly but quiery.subscribie never emit them (instead null data is emitted once) Some observations: |
Do either of you have a way for us to reproduce this, that would make this easier to debug |
I spent some time and eventually isolated my error to simple example repo I am going to create regular issue ticket, I am still not 100% sure if it is same bug as described here. |
This is not a bug, because I cannot create reproduce link. Problem is very complicated to create small example and i am not able to share whole project.
Context
We have entities linked with Foreign Keys in schema.
Execution -> Question looks like:
We load this entities separately, and then combine it (add link to real Question instead of IdOfEntity) using URQL "cache updaters" feature. Like this:
Problem
Everything works fine, but we met very specific case when we load all data at same time:
updateCacheWithResult
, which:initDataState
for 'write' (create new layer)executionQuestionUpdater
(see details above)cache.resolve(entityLink, '_id')
CAN find record in previous commutative layer because it hascurrentOperation === 'write'
, according skip condition in functiongetNode
:cache.link
has been called and we updated the linkinitDataState
for 'read'_query
->readSelection
->readLink
->getNode
.My solution
I decided to use temporary solution - read record from commutative layer if it not found in other layers or data.base:
It will work fine in our application, but I am not sure, that it is correct solution for everyone, because possible it can break invalidation logic.
Urql version
urql 4.0.6
@urql/core 4.3.0
exchange-graphcache 6.5.0
The text was updated successfully, but these errors were encountered: