import { Observable } from 'rxjs/Observable' ; import { Subscriber } from 'rxjs/Subscriber' ; import { Subscription } from 'rxjs/Subscription' ; import { Operator } from 'rxjs/Operator' ; import { $$observable } from 'rxjs/symbol/observable' ; import { ApolloQueryResult , ObservableQuery } from 'apollo-client' ; import { ObservableQueryRef } from './utils/ObservableQueryRef' ; export class RxObservableQuery < T > extends Observable < ApolloQueryResult < T > > { constructor ( public apollo , subscribe ? ) { super ( null ) ; if ( subscribe ) { this . _subscribe = subscribe ; } } public lift < R > ( operator ) { const observable = new RxObservableQuery < R > ( this . apollo ) ; observable . source = this ; observable . operator = operator as any ; return observable as any ; } public refetch ( variables ? ) { return this . getObservableQuery ( ) . refetch ( variables ) ; } public stopPolling ( ) { return this . getObservableQuery ( ) . stopPolling ( ) ; } public startPolling ( p ) { return this . getObservableQuery ( ) . startPolling ( p ) ; } public fetchMore ( options ) { return this . getObservableQuery ( ) . fetchMore ( options ) ; } public updateQuery ( mapFn ) { this . getObservableQuery ( ) . updateQuery ( mapFn ) ; } public subscribeToMore ( options ) { return this . getObservableQuery ( ) . subscribeToMore ( options ) ; } public result ( ) { return this . getObservableQuery ( ) . result ( ) ; } public currentResult ( ) { return this . getObservableQuery ( ) . currentResult ( ) ; } public get variables ( ) : { [ key ] : any ; } { return this . getObservableQuery ( ) . variables ; } public setOptions ( opts ) { return this . getObservableQuery ( ) . setOptions ( opts ) ; } public setVariables ( variables , tryFetch = false ) { return this . getObservableQuery ( ) . setVariables ( variables , tryFetch ) ; } public _subscribe ( subscriber ) { if ( this . source ) { return this . source [ '_subscribe' ] ( subscriber ) ; } const obs = this . getObservableQuery ( ) ; return obs [ $$observable ] ( ) . subscribe ( subscriber ) ; } private getObservableQuery ( ) { if ( this . apollo instanceof ObservableQueryRef ) { const ref = this . apollo as ObservableQueryRef ; return ref . getRef ( ) ; } return this . apollo as ObservableQuery < T > ; } }