fix(graphql): ensure readNormalized correctly merges Map<String, dynamic> patches #1474
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Thank you for the awesome package!!
This PR aims to resolve the issue in
readNormalized
function.The detail is described below.
Let me know if any additional tests or changes are needed. 🚀
Thank you!
Steps to reproduce
In certain cases, patchData from
optimisticResult
containsObject?
data, which is parsed asMap<String, dynamic>
:Under these conditions, the patchData ends up replacing the normalized value that should be merged from the store data.
The type check value is
Map<String, Object>
and patchData isMap<String, Object>
fails to account forMap<String, dynamic>
. This causes the merge to be skipped, and the existing store value is replaced instead of being merged, which results in inconsistency.The
deeplyMergeLeft
function already acceptsMap<String, dynamic>
:Additionally, both
value
fromstore.get(rootId)
andpatchData
frompatch.data[rootId]
areMap<String, dynamic>?
.Thus, it would be safe and appropriate to update the type check as follows:
Expected behavior
The
readNormalized
function should correctly merge the optimistic patch into the existing cached data.Actual behavior
Currently, the
readNormalized
function replaces the stored existing data instead of merging it.System configuration
Dart version:
Dart SDK version: 3.5.2 (stable) (Wed Aug 28 10:01:20 2024 +0000) on "macos_arm64"
Flutter version:
Package version:
graphql_flutter 5.2.0-beta.8
graphql 5.2.0-beta.9