I’m attempting to use paging in a query such that I request first 5 items (starting with item 0) and then 10 items (also starting from item 0.)
I originally expected that Apollo would first fetch the first 5 items over the network but for the second query (requesting the first 10) it would manage to pull the first 5 items from cache and fulfill the remaining with a network request for items 5-9
What I expected:
query 1 - snowRegionPagedConnection(5) → Network { Regions[0-4] }
query 2 - snowRegionPagedConnection(10) → Cache{ Regions[0-4] } ] + Network { Regions[5-9] }
Actual:
query 1 - snowRegionPagedConnection(5) → Network { Regions[0-4] }
query 2 - snowRegionPagedConnection(10) → Network { Regions[0-9] }
Can a paged query work this way at all, or are the page result bound in the cache to the query paramters?
After snowRegionPagedConnection(5) the cache has indexed entries corresponding to each item:
"snowRegionsConnection({"after":null,"filter":null,"limit":5}).edges.0" : {
"cursor" : ChEKDw0wQmVydGhvdWQgUGFzcwoDEKMC
"node" : CacheKey(SnowRegion:15x36wk86ykm)
}
After snowRegionPagedConnection(10) the cache has new entries for those same items:
"snowRegionsConnection({"after":null,"filter":null,"limit":10}).edges.0" : {
"cursor" : ChEKDw0wQmVydGhvdWQgUGFzcwoDEKMC
"node" : CacheKey(SnowRegion:15x36wk86ykm)
}
Same items, but keyed to different query parameters.
Additional info about my setup if it matters:
query snowRegionPagedConnection($filter: SnowRegionFilter, $limit: Int, $after: String) {
snowRegionsConnection(filter: $filter, limit: $limit, after: $after) {
edges {
cursor
node {
...snowRegionModel
}
}
pageInfo {
hasPreviousPage
hasNextPage
startCursor
endCursor
}
}
}
fragment snowRegionModel on SnowRegion{
id
}
extend type SnowRegion @typePolicy(keyFields: "id")