'Migrating from useQuery option in fetchMore to field level policy for nested queries
I have a question regarding this comment:
The updateQuery callback for fetchMore is deprecated, and will be removed
in the next major version of Apollo Client.
Please convert updateQuery functions to field policies with appropriate
read and merge functions, or use/adapt a helper function (such as
concatPagination, offsetLimitPagination, or relayStylePagination) from
@apollo/client/utilities.
The field policy system handles pagination more effectively than a
hand-written updateQuery function, and you only need to define the policy
once, rather than every time you call fetchMore.
I noticed when dealing with nested pagination - I had to provide:
- Field level policy to prevent additional network requests when performing the fetchMore request. The policy would result in something like the following in the cache:
parent: {
...,
child({"after":"" "first":100}): {
...,
},
child({"after":"MW" "first":100}): {
...,
}
}
- Also an
updateQueryoption, in order for the component to be remounted with the new data. Without providing an updateQuery function the react component did not seem to remount.
Is there an alternative way to remount the component after performing fetchMore?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
