-
Notifications
You must be signed in to change notification settings - Fork 3k
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
fix(siblings) Combine siblings data but remove duplicate data #5337
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import merge from 'deepmerge'; | ||
import { unionBy } from 'lodash'; | ||
import { Entity, MatchedField, Maybe, SiblingProperties } from '../../../types.generated'; | ||
|
||
function cleanHelper(obj, visited) { | ||
|
@@ -41,6 +42,31 @@ const combineMerge = (target, source, options) => { | |
return destination; | ||
}; | ||
|
||
const mergeTags = (destinationArray, sourceArray, _options) => { | ||
return unionBy(destinationArray, sourceArray, 'tag.urn'); | ||
}; | ||
|
||
const mergeTerms = (destinationArray, sourceArray, _options) => { | ||
return unionBy(destinationArray, sourceArray, 'term.urn'); | ||
}; | ||
|
||
const mergeAssertions = (destinationArray, sourceArray, _options) => { | ||
return unionBy(destinationArray, sourceArray, 'urn'); | ||
}; | ||
|
||
function getArrayMergeFunction(key) { | ||
switch (key) { | ||
case 'tags': | ||
return mergeTags; | ||
case 'terms': | ||
return mergeTerms; | ||
case 'assertions': | ||
return mergeAssertions; | ||
default: | ||
return undefined; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this cause any runtime issues when we add new arrays to our objects? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no sir - originally we weren't even setting |
||
} | ||
} | ||
|
||
const customMerge = (isPrimary, key) => { | ||
if (key === 'upstream' || key === 'downstream') { | ||
return (_secondary, primary) => primary; | ||
|
@@ -51,6 +77,7 @@ const customMerge = (isPrimary, key) => { | |
if (key === 'tags' || key === 'terms' || key === 'assertions') { | ||
return (secondary, primary) => { | ||
return merge(secondary, primary, { | ||
arrayMerge: getArrayMergeFunction(key), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice! |
||
customMerge: customMerge.bind({}, isPrimary), | ||
}); | ||
}; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need assertion.urn or something here, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nope! the
assertions
array simply returns assertion objects with theurn
exposed right there. on the other hand, thetags
andterms
array both have the shape:terms: [{term: {urn ...}}, ...]