Skip to content

Commit c51b27f

Browse files
committed
feat: Add Angular2Apollo.subscribe and ApolloQueryObservable.updateQuery
1 parent f2b7e88 commit c51b27f

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
### vNEXT
44

5+
- Added `subscribe` method to `Angular2Apollo` service ([PR #113](https://github.com/apollostack/angular2-apollo/pull/113))
6+
- Added `updateQuery` to `ApolloQueryObservable` ([PR #113](https://github.com/apollostack/angular2-apollo/pull/113))
7+
58
### v0.4.6
69

710
- Moved to Angular 2 final and updated RxJS to the latest version ([PR #96](https://github.com/apollostack/angular2-apollo/pull/96))

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
"rxjs": "^5.0.0-beta.12"
3535
},
3636
"dependencies": {
37-
"apollo-client-rxjs": "^0.0.1",
37+
"apollo-client-rxjs": "^0.1.0",
3838
"lodash.assign": "^4.0.9",
3939
"lodash.forin": "^4.2.0",
4040
"lodash.isequal": "^4.2.0"

src/Angular2Apollo.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { OpaqueToken, Injectable, Inject } from '@angular/core';
22
import { rxify } from 'apollo-client-rxjs';
33
import { ApolloQueryResult } from 'apollo-client';
4+
import { Observable } from 'rxjs/Observable';
45

56
import { ApolloQueryObservable } from './ApolloQueryObservable';
67

78
import ApolloClient from 'apollo-client';
89

9-
import 'rxjs/add/operator/switchMap';
10+
import 'rxjs/add/observable/from';
1011

1112
export const angularApolloClient = new OpaqueToken('AngularApolloClient');
1213
export const defaultApolloClient = (client: ApolloClient): any => {
@@ -22,15 +23,23 @@ export class Angular2Apollo {
2223
@Inject(angularApolloClient) private client: any
2324
) {}
2425

25-
public watchQuery(options): ApolloQueryObservable<ApolloQueryResult> {
26+
public watchQuery(options: any): ApolloQueryObservable<ApolloQueryResult> {
2627
return new ApolloQueryObservable(rxify(this.client.watchQuery)(options));
2728
}
2829

29-
public query(options) {
30+
public query(options: any) {
3031
return this.client.query(options);
3132
}
3233

33-
public mutate(options) {
34+
public mutate(options: any) {
3435
return this.client.mutate(options);
3536
}
37+
38+
public subscribe(options: any): Observable<any> {
39+
if (typeof this.client.subscribe === 'undefined') {
40+
throw new Error(`Your version of ApolloClient doesn't support subscriptions`);
41+
}
42+
43+
return Observable.from(this.client.subscribe(options));
44+
}
3645
}

0 commit comments

Comments
 (0)