-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Open
Labels
🌹 has-reproduction🏓 awaiting-team-responserequires input from the apollo teamrequires input from the apollo team💸 caching
Description
I was using @apollo/client@3.3.19 with a custom type policy to do pagination merging based on what is described here:
My merge function looks as follows. It is intended to merge a connection-type entity with a nodes subkey, so something like:
query {
platform {
events {
nodes {
id
}
}
}
}
Here it is:
merge(existing: any, incoming: any, { args, readField }: any) {
const { nodes: incomingNodes, ...rest } = incoming || {};
let mergedNodes: Map<string, any>;
if (existing?.nodes) {
mergedNodes = new Map(existing.nodes);
} else {
mergedNodes = new Map();
}
incomingNodes?.forEach((item: any) => {
mergedNodes.set(readField("id", item), item);
});
return {...rest, nodes: mergedNodes};
},
This worked fine. After upgrading to @3.5.7 I see the following behaviour:
- The first time
useQuery()gets a result,readField("id", item)returnsundefined. Because of this, only a single node is actually stored in the cache. - On subsequent requests (say to load the second page),
readFieldworks 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 called Event, the nodes returned from the server are a concrete type implementing the interface (SaleEvent). I am defining possibleTypes in the cache (it implements both interfaces):
{
Event: ['SaleEvent'],
MarketplaceEvent: ['SaleEvent'],
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
🌹 has-reproduction🏓 awaiting-team-responserequires input from the apollo teamrequires input from the apollo team💸 caching