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

Fixed the error passing situation with query merging #589

Merged
merged 2 commits into from
Aug 30, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Expect active development and potentially significant breaking changes in the `0
### vNEXT

- Avoid extra `assign` when there are no optimistic updates present. [PR #597]((https://github.com/apollostack/apollo-client/pull/597)
- ...
- Fixed issue with error passing with query merging. [PR #589](https://github.com/apollostack/apollo-client/pull/589) and [Issue #551](https://github.com/apollostack/apollo-client/issues/551).

### v0.4.13

Expand Down
2 changes: 1 addition & 1 deletion src/batching/queryMerging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export function unpackMergedResult(
topLevel: true,
});

return { data: unpackedData };
return assign({}, result, { data: unpackedData });
});

return resultArray;
Expand Down
34 changes: 34 additions & 0 deletions test/queryMerging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,39 @@ describe('Query merging', () => {
assert.deepEqual(unpackedResults[1], { data: secondResult });
});

it('should unpack with errors in the result', () => {
const query = gql`
query authorNames {
author {
firstName
lastName
}
}`;
const graphQLError = new Error('This is some kind of graphql error.');
const result = {
data: {
author: {
firstName: 'Dhaivat',
lastName: 'Pandya',
},
},
errors: [ graphQLError ],
};
const composedResult = {
data: {
___authorNames___requestIndex_0___fieldIndex_0: {
firstName: 'Dhaivat',
lastName: 'Pandya',
},
},
errors: [ graphQLError ],
};
const requests = [{ query }];
const unpackedResults = unpackMergedResult(composedResult, requests);
assert.equal(unpackedResults.length, 1);
assert.deepEqual(unpackedResults[0], result);
});

describe('unpackDataForRequest', () => {
const unpackQueryResult = (query: Document, data: Object) => {
return unpackDataForRequest({
Expand Down Expand Up @@ -1210,5 +1243,6 @@ describe('Query merging', () => {
});
assert.deepEqual(unpackedData, result);
});

});
});