-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
readField() in type policy merge function returns undefined only on first query #9315
Comments
I'm experiencing the same issue on @apollo/client: 3.7.1 (latest release right now). |
Same here, with any fetchPolicy involving cache : 'cache-first', 'cache-and-network', 'cache-only'... |
Just adding that I'm experiencing the same issue, and is the same when setting 'network-only' as the fetchPolicy. It's not all queries and so I'm digging into specifically what in the graphql output that's causing it to occur. I suspect it's when fetching a connection that contains a field with another connection. |
It may be different for others but in my case I have the following graphQL structure:
If the top level User.id is the same as the User.post.edge.node.user.id then |
With this issue having been raised almost a year ago, has anyone found a work-around? |
I've reverted to version 3.3.21 which resolves the issue. 3.4.0 onwards re-introduces it. |
I can confirm that what @lprhodes suggested is correct. This issue only occurs when an object id reappears within the nested objects. It also has another side effect, the read function gets executed twice and the ObservableQuery also fires twice. |
Unfortunately version 3.3.21 that I downgraded to has an issue where it repeatedly performs queries created by the useQuery hook so I'll need to really dig into this issue. |
In case anyone's also working on the issue...I'm getting closer to locating the specific code causing the problem. It's related to how the |
Not a fix but I know specifically what's happening now. In the case of the following graphql, where the root
I'm unsure yet as to whether this is intentional to prevent an infinite loop, a missed requirement or an actual bug. I'll keep digging and see whether I can determine a fix for it but it'd be much appreciated if @benjamn could chime in please as the author of this piece of code. |
I've now found the specific code that's causing the issue: apollo-client/src/cache/inmemory/writeToStore.ts Lines 420 to 434 in 9134aaf
This code checks whether there's a previous entity and merges the two I believe this PR is the responsible: #8372 As a work-around, if you set I assume that by setting |
Having this issue too. |
Is there any chance the team can respond to this? This continues to be an issue in At the very least it would be nice if Our workaround has been to remove the |
I was using
@apollo/client@3.3.19
with a custom type policy to do pagination merging based on what is described here:https://www.apollographql.com/docs/react/caching/cache-field-behavior/#merging-non-normalized-objects
My merge function looks as follows. It is intended to merge a connection-type entity with a
nodes
subkey, so something like:Here it is:
This worked fine. After upgrading to @3.5.7 I see the following behaviour:
useQuery()
gets a result,readField("id", item)
returnsundefined
. Because of this, only a single node is actually stored in the cache.readField
works correctly.I don't have a repo, but wonder if it is related to https://github.com/apollographql/apollo-client/pull/8508/files
Note:
nodes
is an interface type calledEvent
, the nodes returned from the server are a concrete type implementing the interface (SaleEvent
). I am definingpossibleTypes
in the cache (it implements both interfaces):The text was updated successfully, but these errors were encountered: