I have a paginated list of photos (by groups of 50) that I fetch via a graphql query through ferry:
query Photos(
$paging: CursorPaging!
) {
photos(paging: $paging) {
edges {
cursor
node {
id
name
}
}
pageInfo {
startCursor
endCursor
hasNextPage
}
totalCount
}
}
I've set a requestID such as 'AllMyPhotos' not dependant on the cursor and have checked that that requestID is used everywhere.
When I want to load more data, I use the updateResult function:
fetchMore: (_) {
if (data == null) return;
final endCursor = data!.photos.pageInfo.endCursor?.value;
if (endCursor == null) return;
final client = locator<Client>();
final request = ref.read(photosReqProvider);
client.requestController.add(request.rebuild((req) {
print('reqID in fetchMore: ${req.requestId}');
req.vars.paging.after.value = endCursor;
req.updateResult = combinePhotos;
}));
},
GPhotosData? combinePhotos(GPhotosData? prev, GPhotosData? next) {
if (prev == null) return next;
return next?.rebuild((data) {
data.photos.edges.insertAll(0, prev.photos.edges);
});
}
I manage to get all the data in data.photos
correctly.
But when I want to read the cache I only have the first 50 items inside and not all the items I have loaded so far.
final cache = locator<Client>().cache;
final photosData = cache.readQuery(photosReq);
if (photosData == null) return;
final photoIDs = photosData.projectPhotos.edges.map((edge) => edge.node.id).toList();
// photosIDs is always 50, even when the data previously contained 100,150, etc when fetchingMore
Does updateResult
not update the cache for that requestID ?