Skip to content

Commit

Permalink
Add possibility to skip the queue
Browse files Browse the repository at this point in the history
  • Loading branch information
sync authored and helfer committed Jul 11, 2018
1 parent 0850ef9 commit 4583b2f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/QueueLink.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,27 @@ describe('OnOffLink', () => {
jest.runAllTimers();
});
});
it('skips the queue when asked to', () => {
const opWithSkipQueue: GraphQLRequest = {
query: gql`{ hello }`,
context: {
skipQueue: true,
},
};
onOffLink.close();
return new Promise((resolve, reject) => {
execute(link, opWithSkipQueue).subscribe({
next: (data) => undefined,
error: (error) => reject(error),
complete: () => {
expect(testLink.operations.length).toBe(1);
expect(testLink.operations[0].query).toEqual(op.query);
resolve();
},
});
jest.runAllTimers();
});
});
it('passes through errors', () => {
const testError = new Error('Hello darkness my old friend');
const opWithError: GraphQLRequest = {
Expand Down
3 changes: 3 additions & 0 deletions src/QueueLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export default class QueueLink extends ApolloLink {
if (this.isOpen) {
return forward(operation);
}
if (operation.getContext().skipQueue) {
return forward(operation);
}
return new Observable(observer => {
const operationEntry = { operation, forward, observer };
this.enqueue(operationEntry);
Expand Down

0 comments on commit 4583b2f

Please sign in to comment.