apollographql / apollo-ios

📱  A strongly-typed, caching GraphQL client for iOS, written in Swift.
https://www.apollographql.com/docs/ios/
MIT License
3.87k stars 717 forks source link

When using apollo-ios-pagination, there is an issue where data is not accurately updated when mutations occur. #3331

Closed rlsmd9 closed 7 months ago

rlsmd9 commented 7 months ago

Question

When the cached value of a paginated query changes, the onFetch method of AsyncGraphQLQueryPager is invoked via a watcher. It seems that during this process, the variables are utilized as keys in the nextPageVarMap dictionary. If a key already exists, the data is updated; otherwise, a new page is added.

The issue lies in the fact that the Variables of a GraphQLOperation are represented as a dictionary, and the values of this dictionary are used as keys. For instance, with a query like:

Query(
    filter: .init(
        mine: true,
        query: query,
        orderType: latest
    ),
    first: 15,
    after: “123123”
)

the variables can result in various keys such as:

Converting the Variables dictionary of the Query into an array does not maintain consistent ordering, which leads to the inability to identify the same page consistently, thus resulting in the addition of new pages instead of updating existing ones.

If you are aware of a solution to this issue, please share!

Iron-Ham commented 7 months ago

Hi @ralph-101-dev! You're 100% correct. I'll open up a PR addressing that shortly. Thanks!