Skip to content
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

[ApolloPagination] Update variable mapping logic to use a Set instead of an Array #260

Merged
merged 3 commits into from
Feb 9, 2024

Conversation

Iron-Ham
Copy link
Contributor

@Iron-Ham Iron-Ham commented Feb 9, 2024

A special thank you to @ralph-101-dev for finding this issue in a pre-release build of ApolloPagination.

Closes apollographql/apollo-ios#3331


This pull request primarily focuses on modifying how variables are handled in AsyncGraphQLQueryPagerCoordinator.swift. The changes involve altering the data types of variables from arrays to sets, which should eliminate the possibility of a mismatch between mis-ordered array outputs. This is especially needed, because the underlying values being pulled from are an unordered dictionary, so multiple invocations of the same function can result in a key-miss.

The change to production code is a one-liner: We've updated the value of the variables variable – which houses the input variables of a given GraphQLQuery – from an Array<JSONValue to a Set<JSONValue.

The tests were updated to unwrap the AnyHashable key-value of the nextPageVarMap property as a Set instead of as an Array. Notably, the tests were masking this error, as they were previously taking the Array outputs, wrapping them in a Set, and then comparing the sets!

@Iron-Ham Iron-Ham requested a review from a team as a code owner February 9, 2024 19:43
Copy link

netlify bot commented Feb 9, 2024

👷 Deploy request for eclectic-pie-88a2ba pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 91e2190

@Iron-Ham Iron-Ham changed the title Update variable mapping logic to use a Set instead of an Array [ApolloPagination] Update variable mapping logic to use a Set instead of an Array Feb 9, 2024
@AnthonyMDev
Copy link
Contributor

Notably, the tests were masking this error, as they were previously taking the Array outputs, wrapping them in a Set, and then comparing the sets!

🤣 Amazing

Copy link
Contributor

@AnthonyMDev AnthonyMDev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. Only question I have is this:

nextPageVarMap is currently an OrderedDictionary<AnyHashable, PaginatedQuery.Data>. But the keys should be these sets of variables. And the line in this PR is the only place we are adding data to that variable.

Shouldn't we change this property to the type OrderedDictionary<Set<JSONValue>, PaginatedQuery.Data>. This would prevent us from making any mistakes with this in the future (forgetting to wrap variables in a Set). Is there anything that needs this to be AnyHashable?

If so, we also should change previousPageVarMap.

@Iron-Ham
Copy link
Contributor Author

Iron-Ham commented Feb 9, 2024

@AnthonyMDev That sounds right – Updating this PR.

@AnthonyMDev AnthonyMDev merged commit 25f4292 into apollographql:main Feb 9, 2024
7 checks passed
BobaFetters pushed a commit that referenced this pull request Feb 9, 2024
BobaFetters pushed a commit to apollographql/apollo-ios-pagination that referenced this pull request Feb 9, 2024
BobaFetters pushed a commit that referenced this pull request Feb 9, 2024
7182da31 [ApolloPagination] Update variable mapping logic to use a Set instead of an Array (#260)

git-subtree-dir: apollo-ios-pagination
git-subtree-split: 7182da3193a3263e3522e7a0f04d670ffc081625
BobaFetters pushed a commit that referenced this pull request Feb 9, 2024
…riable mapping logic to use a Set instead of an Array

git-subtree-dir: apollo-ios-pagination
git-subtree-mainline: 67e512a
git-subtree-split: 7182da3193a3263e3522e7a0f04d670ffc081625
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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