Comments (4)
The cache will cache all queries, but it will cache them together with the arguments for paging, and if you read only the first page, it will only return the first page.
But you can add configuration to merge all pages together, like described here:
https://ferrygraphql.com/docs/cache-configuration#the-fields-property
from ferry.
For this, you will have to use the 'read' parameter on the FieldPolicy in order to execute your query based on the variables passed to your query.
from ferry.
Looking at the code, I think the issue comes from the FetchPolicyTypedLink
that calls _writeToCache
/cache.writeQuery
which calls normalizeOperation
but never passes the requestId
.
@knaeckeKami do you think it'd be ok to pass the requestId
in the data of resolveDataId
? Then we could use the typePolicies
to group the requests together.
from ferry.
In my use case, I have a table view and i can go to the first page, next page, previous page and last page, also I can apply filters and sorting.
So based on this documentation, I should be setting my ['filter', 'sorting'] as keyArgs as I do not want results of queries with different filters/sorting to be merged together.
How to handle the fact that the user may navigate to the first page, then the last page, then press previous etc.
All the results will be added in some random order to my cache ?
Also I will need to not only merge the edges together in my result but also compute the pageInfo to get the startCursor, endCursor and hasNextPage.
query ProjectPhotos(
$filter: ProjectPhotoFilter!
$paging: CursorPaging!
$sorting: [ProjectPhotoSort!]
) {
projectPhotos(filter: $filter, paging: $paging, sorting: $sorting) {
edges {
node {
id
name
}
}
pageInfo {
startCursor
endCursor
hasNextPage
}
totalCount
}
}
'Query': TypePolicy(
fields: {
'projectPhotos': FieldPolicy(
keyArgs: const ['filter', 'sorting'],
merge: (existing, incoming, option) {
if (existing == null) return incoming;
final existingEdges = (existing['edges'] as List<dynamic>?) ?? [];
final incomingEdges = (incoming['edges'] as List<dynamic>?) ?? [];
final mergedEdges = (LinkedHashSet<dynamic>(equals: jsonMapEquals, hashCode: const DeepCollectionEquality().hash)
..addAll(existingEdges)
..addAll(incomingEdges))
.toList();
return incoming['edges'] = mergedEdges;
},
),
},
),
from ferry.
Related Issues (20)
- OfflineMutationTypedLink - Bad state: No serializer for '_Map<String, dynamic>'. HOT 6
- Delayed parsing HOT 3
- OfflineMutationTypedLink - How to pass same client to OfflineMutationTypedLink HOT 11
- FieldNode denormalization ignores HOT 4
- When evicting an entity from the cache, the list becomes empty when it is nested in an object. HOT 4
- When FetchPolicy is CacheAndNetwork and offline no response from cache HOT 2
- Sanity Portable Text Blocks HOT 1
- New way to refresh and pagination using StreamQueue HOT 2
- Question: is Discord still active? HOT 4
- Subscription challenges HOT 5
- Add field of custom data to local cache only
- How to add multiple schema.graphql files? HOT 3
- Using mixins for generating the fragments HOT 2
- Unable to use "Subscription" as a __typename value HOT 1
- Missing scalar JSON. Defaulting to String HOT 10
- Upgrade to gql 1.0 HOT 1
- Verbose, duplicated CHANGELOGS
- Could `FieldPolicy` and `TypePolicy` have a const constructor? HOT 1
- Add a way to generate classes for some types in the schema HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ferry.