All files QueryRef.ts

91.43% Statements 32/35
0% Branches 0/4
93.33% Functions 14/15
91.18% Lines 31/34
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84                      4x   4x   4x     21x 21x         4x 1x     4x 1x     4x 1x     4x 1x     4x 1x     4x 4x     4x     1x     4x 1x   4x     1x     4x 1x     4x 1x     4x 2x     4x             4x  
import {
  ApolloQueryResult,
  ObservableQuery,
  ApolloError,
  FetchMoreQueryOptions,
  FetchMoreOptions,
  SubscribeToMoreOptions,
  UpdateQueryOptions,
} from 'apollo-client';
import {ApolloCurrentResult} from 'apollo-client/core/ObservableQuery';
import {Observable} from 'rxjs/Observable';
import {from} from 'rxjs/observable/from';
 
import {wrapWithZone} from './utils';
 
export class QueryRef<T> {
  public valueChanges: Observable<ApolloQueryResult<T>>;
 
  constructor(private obsQuery: ObservableQuery<T>) {
    this.valueChanges = wrapWithZone(from(this.obsQuery));
  }
 
  // ObservableQuery's methods
 
  public result(): Promise<ApolloQueryResult<T>> {
    return this.obsQuery.result();
  }
 
  public currentResult(): ApolloCurrentResult<T> {
    return this.obsQuery.currentResult();
  }
 
  public getLastResult(): ApolloQueryResult<T> {
    return this.obsQuery.getLastResult();
  }
 
  public getLastError(): ApolloError {
    return this.obsQuery.getLastError();
  }
 
  public resetLastResults(): void {
    return this.obsQuery.resetLastResults();
  }
 
  public refetch(variables?: any): Promise<ApolloQueryResult<T>> {
    return this.obsQuery.refetch(variables);
  }
 
  public fetchMore(
    fetchMoreOptions: FetchMoreQueryOptions & FetchMoreOptions,
  ): Promise<ApolloQueryResult<T>> {
    return this.obsQuery.fetchMore(fetchMoreOptions);
  }
 
  public subscribeToMore(options: SubscribeToMoreOptions): () => void {
    return this.obsQuery.subscribeToMore(options);
  }
  public updateQuery(
    mapFn: (previousQueryResult: any, options: UpdateQueryOptions) => any,
  ): void {
    return this.obsQuery.updateQuery(mapFn);
  }
 
  public stopPolling(): void {
    return this.obsQuery.stopPolling();
  }
 
  public startPolling(pollInterval: number): void {
    return this.obsQuery.startPolling(pollInterval);
  }
 
  public setOptions(opts: any): Promise<ApolloQueryResult<T>> {
    return this.obsQuery.setOptions(opts);
  }
 
  public setVariables(
    variables: any,
    tryFetch: boolean = false,
    fetchResults = true,
  ): Promise<ApolloQueryResult<T>> {
    return this.obsQuery.setVariables(variables, tryFetch, fetchResults);
  }
}