1
1
import { OpaqueToken , Injectable , Inject } from '@angular/core' ;
2
2
import { rxify } from 'apollo-client-rxjs' ;
3
3
import { ApolloQueryResult } from 'apollo-client' ;
4
+ import { Observable } from 'rxjs/Observable' ;
4
5
5
6
import { ApolloQueryObservable } from './ApolloQueryObservable' ;
6
7
7
8
import ApolloClient from 'apollo-client' ;
8
9
9
- import 'rxjs/add/operator/switchMap ' ;
10
+ import 'rxjs/add/observable/from ' ;
10
11
11
12
export const angularApolloClient = new OpaqueToken ( 'AngularApolloClient' ) ;
12
13
export const defaultApolloClient = ( client : ApolloClient ) : any => {
@@ -22,15 +23,23 @@ export class Angular2Apollo {
22
23
@Inject ( angularApolloClient ) private client : any
23
24
) { }
24
25
25
- public watchQuery ( options ) : ApolloQueryObservable < ApolloQueryResult > {
26
+ public watchQuery ( options : any ) : ApolloQueryObservable < ApolloQueryResult > {
26
27
return new ApolloQueryObservable ( rxify ( this . client . watchQuery ) ( options ) ) ;
27
28
}
28
29
29
- public query ( options ) {
30
+ public query ( options : any ) {
30
31
return this . client . query ( options ) ;
31
32
}
32
33
33
- public mutate ( options ) {
34
+ public mutate ( options : any ) {
34
35
return this . client . mutate ( options ) ;
35
36
}
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
+ }
36
45
}
0 commit comments