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

Made sure single queries are not merged together #369

Merged
merged 2 commits into from
Jul 8, 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Expect active development and potentially significant breaking changes in the `0.x` track. We'll try to be diligent about releasing a `1.0` version in a timely fashion (ideally within 3 to 6 months), to signal the start of a more stable API.

### vNEXT
- Made sure that query merging is only applied when we have more than one query in the batcher's queue [Issue #308](https://github.com/apollostack/apollo-client/issues/308) and [PR #369](https://github.com/apollostack/apollo-client/pull/369).

### v0.3.28

Expand Down
8 changes: 8 additions & 0 deletions src/networkInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@ export interface RequestAndOptions {
export function addQueryMerging(networkInterface: NetworkInterface): BatchedNetworkInterface {
return assign(networkInterface, {
batchQuery(requests: Request[]): Promise<GraphQLResult[]> {
// If we a have a single request, there is no point doing any merging
// at all.
if (requests.length === 1) {
return this.query(requests[0]).then((result) => {
return Promise.resolve([result]);
});
}

const composedRequest = mergeRequests(requests);
return this.query(composedRequest).then((composedResult) => {
return unpackMergedResult(composedResult, requests);
Expand Down
28 changes: 28 additions & 0 deletions test/networkInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,34 @@ describe('network interface', () => {
done();
});
});

it('should not merge queries when batchQuery is passed a single query', () => {
const query = gql`
query {
author {
firstName
lastName
}
}`;
const data = {
author: {
firstName: 'John',
lastName: 'Smith',
},
};
const request = { query: query };
const myNetworkInterface: NetworkInterface = {
query(requestReceived: Request): Promise<GraphQLResult> {
assert.equal(print(requestReceived.query), print(query));
return Promise.resolve({ data });
},
};
const mergingNetworkInterface = addQueryMerging(myNetworkInterface);
mergingNetworkInterface.batchQuery([request]).then((results) => {
assert.equal(results.length[0], 1);
assert.deepEqual(results[0], { data });
});
});
});
});

Expand Down