Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
Edvin Erikson committed Sep 9, 2016
1 parent 2e575a8 commit 195c1ed
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ delianides <drew@delianides.com>
greenkeeperio-bot <support@greenkeeper.io>
hammadj <jutt@ualberta.ca>
matt debergalis <matt@meteor.com>
Edvin Eriksson <edvinerikson@gmail.com>
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Expect active development and potentially significant breaking changes in the `0

- Options set in middleware can override the fetch query in the network layer. [Issue #627](https://github.com/apollostack/apollo-client/issues/627) and [PR #628](https://github.com/apollostack/apollo-client/pull/628).
- Make `returnPartialData` work better with fragments. [PR #580](https://github.com/apollostack/apollo-client/pull/580)
- Fixed issue with nested fragments overriding each other.

### v0.4.14

Expand Down
32 changes: 25 additions & 7 deletions src/data/diffAgainstStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,16 @@ export function diffSelectionSetAgainstStore({
}

if (isObject(fieldResult)) {
for (const key in fieldResult) {
if (
(fieldResult.hasOwnProperty(key) && result.hasOwnProperty(key)) && (isObject(fieldResult[key]) && isObject(result[key]))) {
assign(result[key], fieldResult[key]);
Object.keys(fieldResult).forEach(key => {
if (shouldDeepMerge(key, result, fieldResult)) {
assign(
(result as { [key: string]: Object })[key],
(fieldResult as { [key: string]: Object })[key]
);
} else {
assign(result, fieldResult);
}
}

});
}
if (!fragmentErrors[typename]) {
fragmentErrors[typename] = null;
Expand Down Expand Up @@ -268,7 +269,16 @@ export function diffSelectionSetAgainstStore({
pushMissingField(selection);
}
if (isObject(fieldResult)) {
assign(result, fieldResult);
Object.keys(fieldResult).forEach(key => {
if (shouldDeepMerge(key, result, fieldResult)) {
assign(
(result as { [key: string]: Object })[key],
(fieldResult as { [key: string]: Object })[key]
);
} else {
assign(result, fieldResult);
}
});
}

if (!fragmentErrors[typename]) {
Expand Down Expand Up @@ -322,6 +332,14 @@ export function diffSelectionSetAgainstStore({
};
}

function shouldDeepMerge(
key: string,
result: { [key: string]: any },
fieldResult: { [key: string]: any }
): boolean {
return isObject(fieldResult[key]) && isObject(result[key]);
}

function diffFieldAgainstStore({
field,
throwOnMissingField,
Expand Down

0 comments on commit 195c1ed

Please sign in to comment.