New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pagination with nested document returns same new data for both fetchMoreResultData and previousResultData #386
Comments
What problem are you facing when getting |
HI, now I am able to reproduce the issue. Flutter test page
Graphql Server Types
Graphql Server Resolvers
My environment
If you run this code, instead of getting new data attached to listview, you loose all the previous data and only get displayed new data. |
@mainawycliffe |
When you using final List<dynamic> repos =
queryResults.data['viewer']['repositories']['nodes'] as List<dynamic>; |
@mainawycliffe yea I know and I am using the normalization method as described in the example. Also, as you can see, casting is being implemented correctly. |
@mainawycliffe I can confirm that both What about just normal |
now I can confirm that this is problem with nested pagination. Pagination without nested object pagination works as expected but nested object pagination returns same data for both previous data and fetched data. #386 (comment) this is the code that fetches nested pagination data below is the code that fetches not nested pagination data.
Nested object pagination returns same data for both fetchMoreData and previousData ONLY when OptimisticCache or NormalizedInMemoryCache is used. If InMemoryCache is used, there's no problem with returned data. I feel like it's likely to be a problem with example normalization technique. Maybe the data is getting saved by the root object |
My guess was correct. If I tag the key of the cache with unique values for every iteration, the previousFetchData value does not get overwritten. We need to implement something like https://www.apollographql.com/docs/react/features/pagination/#the-connection-directive as presented in apollo-graphql. For those of you having same problem as I am, currently the only way to solve this problem is by providing an additional unique value to the cache key so that the data from fetchMore does not overwrite previousData. If you can point me to right direction, I could try to contribute to this feature. |
I am not well familiar with the caching part of this package, I would have to look into it to whether this is possible and how to do it. Maybe @micimize can help. |
If I understand your problem correctly, it seems due to the nested fields in your query, the normalization key is the same for the subsequent fetch more queries, hence they get overridden in the cache. So, am guessing here maybe you should look at your |
@mainawycliffe yes. The issue is exactly as you say. I have solved this issue by providing random uuid from the server and also including that as the cache key if I am calling nested pagination. But now the problem is that when Query and Mutation are in the same StatelessWidget, calling mutation causes query to re-run. Is this a known and intended behaviour? |
@mainawycliffe so say for example, if I make a query that retrieves posts (infinite scroll) and call mutation when likes are clicked on each post, query is run again and the list is reset to index 0 because original query does not provide the cursor, only fetchMore does. I have started another thread here #389 (comment) |
@serendipity1004 This is not intended behavior - we hadn't considered the case where A temporary workaround would be to paginateTestObject {
__typename
pageId: id
} That way the entity won't be picked up by the normalizer, and you can merge the results yourself. The correct solution is probably for us to run the |
I think it's best to run |
@serendipity1004 #394 should fix both your issues -You can test by overriding dependency_overrides:
graphql:
git:
url: git://github.com/micimize/graphql-flutter.git
ref: fetchmore_patch
path: packages/graphql Please give it a shot - I did some testing on #389 but not this issue. Also, worth noting that your first
|
@micimize I can confirm that it is working on both the example that I have provided and on my previous commit of my project. Great job and thank you. May I ask when this will be merged into the main branch? |
@micimize I have to investigate a little more but there's another problem when using |
FetchMore requests are never cached, the cache settings are purposefully ignored. We are working on improvements, tracked on this issue, but FetchMore is a complicated feature, as its uses are huge. |
@mainawycliffe fair enough. May I know why cache is purposefully ignored in fetchMore? Just wondering how it could be useful in some cases. |
The main reason is that it's the expected common use case. I can see the advantages of caching fetch more results, but it also brings up issues highlighted here like replacing the previous results during cache normalization. |
@mainawycliffe no, he's on my fork for #394 so the results of |
@HofmannZ why do we override the fetch policy if the default query option is used? Why not just change the default? |
Ok, well when I remove that block going back to the fetchmore query has no issues, so I'm leaving that for another (soon-to-be) PR |
closed by #394 |
I currently have settings like below
and I am updating cache like below
Cache is getting updated very nicely; however, the change is just not reflected on the screen. I am currently using this under statelesswidget.
Now, when I change the cache to
NormalizedCache
orOptimisticCache
, I can get the changes to be reflected on the screen; however, I encounter another problem where I just cannot get thepreviousResultData
properly (it is always same as thefetchMoreResultData
. This, for some reason I have not been able to reproduce so I will try to post more code on it when I can reproduce it. Meanwhile, how can I make InMemoryCache change get reflected throughout the widget enclosed by query?The text was updated successfully, but these errors were encountered: