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

Refactor custom field merge function processing. #5712

Merged
merged 2 commits into from
Dec 20, 2019

Conversation

benjamn
Copy link
Member

@benjamn benjamn commented Dec 19, 2019

Ever since implementing support for custom merge functions, I have been unsatisfied with the MergeOverrides concept, especially because a mistake in the processing of overrides recently resulted in a fairly significant bug, fixed by commit 8c58be5.

Instead of tracking MergeOverrides separately from the fields processed by processSelectionSet and processFieldValue (which is not only error-prone but also complicates the return values of those methods), we can embed the necessary FieldNode and __typename information within the field data returned by processSelectionSet, using recognizable FieldValueToBeMerged objects, which are safely removed by Policies#applyMerges before the fully processed fields are written into the EntityStore (which knows nothing about custom merge functions or FieldValueToBeMerged objects).

One small benefit of this refactoring is that we can call store.getFieldValue(dataId, name) instead of store.get(dataId) in Policies#applyMerges, which brings us a little closer to eliminating EntityStore#get once and for all.

Ever since implementing support for custom merge functions, I have been
unsatisfied with the MergeOverrides concept, especially because a mistake
in the processing of overrides recently resulted in a fairly significant
bug, fixed by commit 8c58be5.

Instead of tracking MergeOverrides separately from the fields processed by
processSelectionSet and processFieldValue (which is not only error-prone
but also complicates the return values of those methods), we can embed the
necessary FieldNode and __typename information within the field data
returned by processSelectionSet, using recognizeable FieldValueToBeMerged
objects, which are safely removed by Policies#applyMerges before the fully
processed fields are written into the EntityStore (which knows nothing
about custom merge functions or FieldValueToBeMerged objects).

One small benefit of this refactoring is that we can call
store.getFieldValue(dataId, name) instead of store.get(dataId) in
Policies#applyMerges, which brings us a little closer to eliminating
EntityStore#get once and for all.
Copy link
Member

@hwillson hwillson left a comment

Choose a reason for hiding this comment

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

Looks great @benjamn!

@benjamn
Copy link
Member Author

benjamn commented Dec 20, 2019

@hwillson Thanks for the review! I'm also pretty happy with the refactoring commit that I just pushed, in case you want to take a look (not vital).

@benjamn benjamn merged commit d16a4d2 into release-3.0 Dec 20, 2019
@benjamn benjamn mentioned this pull request Dec 20, 2019
31 tasks
@hwillson
Copy link
Member

29d4d10 also looks 👍 @benjamn - thanks!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants