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

Fix deduplicator #1481

Merged
merged 4 commits into from
Mar 23, 2017
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
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
- Fix `cachePolicy: cache-and-network` queries never dispatching `APOLLO_QUERY_RESULT_CLIENT` [PR #1463](https://github.com/apollographql/apollo-client/pull/1463)
- Fix: `cachePolicy: cache-and-network` queries now dispatch `APOLLO_QUERY_RESULT_CLIENT` [PR #1463](https://github.com/apollographql/apollo-client/pull/1463)
- Fix: query deduplication no longer causes query errors to prevent subsequent successful execution of the same query [PR #1481](https://github.com/apollographql/apollo-client/pull/1481)


### 1.0.0-rc.6
Expand Down
4 changes: 4 additions & 0 deletions src/transport/Deduplicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ export class Deduplicator {
.then( res => {
delete this.inFlightRequestPromises[key];
return res;
})
.catch( err => {
delete this.inFlightRequestPromises[key];
throw err;
});
}

Expand Down
41 changes: 41 additions & 0 deletions test/deduplicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,47 @@ describe('query deduplication', () => {

});

it(`will not deduplicate requests following an errored query`, () => {

const document: DocumentNode = gql`query test1($x: String){
test(x: $x)
}`;
const variables = { x: 'Hello World' };

const request: Request = {
query: document,
variables: variables,
operationName: getOperationName(document),
};

let called = 0;
const deduper = new Deduplicator({
query: () => {
called += 1;
switch (called) {
case 1:
return new Promise((resolve, reject) => {
setTimeout(reject);
});
case 2:
return new Promise((resolve, reject) => {
setTimeout(resolve);
});
default:
return assert(false, 'Should not have been called more than twice');
}

},
} as any );

return deduper.query(request)
.catch( () => {
deduper.query(request);
return assert.equal(called, 2);
});

});

it(`deduplicates identical queries`, () => {

const document: DocumentNode = gql`query test1($x: String){
Expand Down
4 changes: 2 additions & 2 deletions test/fetchMore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ describe('updateQuery on a simple query', () => {
},
});

return new Promise((resolve) => setTimeout(resolve))
return new Promise((resolve) => setTimeout(resolve, 5))
.then(() => obsHandle)
.then((watchedQuery: ObservableQuery<any>) => {
assert.equal(latestResult.data.entry.value, 1);
Expand Down Expand Up @@ -119,7 +119,7 @@ describe('updateQuery on a query with required and optional variables', () => {
},
});

return new Promise((resolve) => setTimeout(resolve))
return new Promise((resolve) => setTimeout(resolve, 5))
.then(() => obsHandle)
.then((watchedQuery: ObservableQuery<any>) => {
assert.equal(latestResult.data.entry.value, 1);
Expand Down