Skip to content

Commit

Permalink
Merge 6976546 into 56f9404
Browse files Browse the repository at this point in the history
  • Loading branch information
Problematic committed Oct 24, 2017
2 parents 56f9404 + 6976546 commit 5793e5c
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Expose `ClientMap`, `ClientMapWrapper`, `ClientWrapper` ([PR #360](https://github.com/apollographql/apollo-angular/pull/360))
- Allow to install the library directly from git (NPM v5+ required) ([PR #362](https://github.com/apollographql/apollo-angular/pull/362))
- Fix AoT issue in Angular 5 **(added InjectDecorator on ClientMap in Apollo)** ([PR #365](https://github.com/apollographql/apollo-angular/pull/365))
- Don't reuse options object for mutate and query ([PR #356](https://github.com/apollographql/apollo-angular/pull/356))

### v0.13.1

Expand Down
4 changes: 2 additions & 2 deletions src/Apollo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ export class ApolloBase {

public query<T>(options: WatchQueryOptions): Observable<ApolloQueryResult<T>> {
return wrapWithZone<ApolloQueryResult<T>>(
fromPromise<ApolloQueryResult<T>>(() => this.client.query<T>(options)),
fromPromise<ApolloQueryResult<T>>(() => this.client.query<T>({ ...options })),
);
}

public mutate<T>(options: MutationOptions): Observable<ApolloExecutionResult<T>> {
return wrapWithZone<ApolloExecutionResult<T>>(
fromPromise<ApolloExecutionResult<T>>(() => this.client.mutate<T>(options)),
fromPromise<ApolloExecutionResult<T>>(() => this.client.mutate<T>({ ...options })),
);
}

Expand Down
64 changes: 64 additions & 0 deletions tests/Apollo.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,38 @@ describe('Apollo', () => {
},
});
});

test('should not reuse options map', (done: jest.DoneCallback) => {
const client = {} as ApolloClient;
const apollo = createApollo({default: client});

client.query = jest.fn(options => {
if (options.used) {
throw new Error('options was reused');
}

options.used = true;

return Promise.resolve('query');
});

const obs = apollo.query({} as any);
const error = jest.fn(done.fail);

obs.subscribe({
complete: () => {
expect(client.query).toBeCalled();

obs.subscribe({
error,
complete: () => {
expect(error).not.toBeCalled();
done();
},
});
},
});
});
});

describe('mutate()', () => {
Expand Down Expand Up @@ -313,6 +345,38 @@ describe('Apollo', () => {
},
});
});

test('should not reuse options map', (done: jest.DoneCallback) => {
const client = {} as ApolloClient;
const apollo = createApollo({default: client});

client.mutate = jest.fn(options => {
if (options.used) {
throw new Error('options was reused');
}

options.used = true;

return Promise.resolve('mutation');
});

const obs = apollo.mutate({} as any);
const error = jest.fn(done.fail);

obs.subscribe({
complete: () => {
expect(client.mutate).toBeCalled();

obs.subscribe({
error,
complete: () => {
expect(error).not.toBeCalled();
done();
},
});
},
});
});
});

describe('subscribe', () => {
Expand Down

0 comments on commit 5793e5c

Please sign in to comment.