From bd62c116d71c096a7f54ce77f996e4d39c1df250 Mon Sep 17 00:00:00 2001 From: Dhaivat Pandya Date: Thu, 7 Jul 2016 13:56:03 -0700 Subject: [PATCH 1/2] made sure queries are not merged when we have a single query --- src/networkInterface.ts | 8 ++++++++ test/networkInterface.ts | 28 ++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/networkInterface.ts b/src/networkInterface.ts index 5f513c2b8a5..62df02dbcd1 100644 --- a/src/networkInterface.ts +++ b/src/networkInterface.ts @@ -59,6 +59,14 @@ export interface RequestAndOptions { export function addQueryMerging(networkInterface: NetworkInterface): BatchedNetworkInterface { return assign(networkInterface, { batchQuery(requests: Request[]): Promise { + // 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); diff --git a/test/networkInterface.ts b/test/networkInterface.ts index 3005791352b..d2b04f650f2 100644 --- a/test/networkInterface.ts +++ b/test/networkInterface.ts @@ -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 { + 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 }); + }); + }); }); }); From 5e4220d817caf472fa09ad97273a11090e4edf28 Mon Sep 17 00:00:00 2001 From: Dhaivat Pandya Date: Thu, 7 Jul 2016 14:00:46 -0700 Subject: [PATCH 2/2] updated changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d43455be9b5..bc3393ebe10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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