1- import { from , Observable } from 'rxjs' ;
1+ import { Observable } from 'rxjs' ;
22import { Inject , Injectable , NgZone , Optional } from '@angular/core' ;
33import type {
44 ApolloClientOptions ,
@@ -23,18 +23,16 @@ import type {
2323 WatchFragmentOptions ,
2424 WatchQueryOptions ,
2525} from './types' ;
26- import { fixObservable , fromPromise , useMutationLoading , wrapWithZone } from './utils' ;
26+ import { fromLazyPromise , useMutationLoading , wrapWithZone } from './utils' ;
2727
2828export class ApolloBase < TCacheShape = any > {
29- private useInitialLoading : boolean ;
3029 private useMutationLoading : boolean ;
3130
3231 constructor (
3332 protected readonly ngZone : NgZone ,
3433 protected readonly flags ?: Flags ,
3534 protected _client ?: ApolloClient < TCacheShape > ,
3635 ) {
37- this . useInitialLoading = flags ?. useInitialLoading ?? false ;
3836 this . useMutationLoading = flags ?. useMutationLoading ?? false ;
3937 }
4038
@@ -46,24 +44,22 @@ export class ApolloBase<TCacheShape = any> {
4644 ...options ,
4745 } ) as ObservableQuery < TData , TVariables > ,
4846 this . ngZone ,
49- {
50- useInitialLoading : this . useInitialLoading ,
51- ...options ,
52- } ,
5347 ) ;
5448 }
5549
5650 public query < T , V extends OperationVariables = EmptyObject > (
5751 options : QueryOptions < V , T > ,
5852 ) : Observable < ApolloQueryResult < T > > {
59- return fromPromise < ApolloQueryResult < T > > ( ( ) => this . ensureClient ( ) . query < T , V > ( { ...options } ) ) ;
53+ return fromLazyPromise < ApolloQueryResult < T > > ( ( ) =>
54+ this . ensureClient ( ) . query < T , V > ( { ...options } ) ,
55+ ) ;
6056 }
6157
6258 public mutate < T , V extends OperationVariables = EmptyObject > (
6359 options : MutationOptions < T , V > ,
6460 ) : Observable < MutationResult < T > > {
6561 return useMutationLoading (
66- fromPromise ( ( ) => this . ensureClient ( ) . mutate < T , V > ( { ...options } ) ) ,
62+ fromLazyPromise ( ( ) => this . ensureClient ( ) . mutate < T , V > ( { ...options } ) ) ,
6763 options . useMutationLoading ?? this . useMutationLoading ,
6864 ) ;
6965 }
@@ -75,9 +71,7 @@ export class ApolloBase<TCacheShape = any> {
7571 options : WatchFragmentOptions < TFragmentData , TVariables > ,
7672 extra ?: ExtraSubscriptionOptions ,
7773 ) : Observable < WatchFragmentResult < TFragmentData > > {
78- const obs = from (
79- fixObservable ( this . ensureClient ( ) . watchFragment < TFragmentData , TVariables > ( { ...options } ) ) ,
80- ) ;
74+ const obs = this . ensureClient ( ) . watchFragment < TFragmentData , TVariables > ( { ...options } ) ;
8175
8276 return extra && extra . useZone !== true ? obs : wrapWithZone ( obs , this . ngZone ) ;
8377 }
@@ -86,7 +80,7 @@ export class ApolloBase<TCacheShape = any> {
8680 options : SubscriptionOptions < V , T > ,
8781 extra ?: ExtraSubscriptionOptions ,
8882 ) : Observable < FetchResult < T > > {
89- const obs = from ( fixObservable ( this . ensureClient ( ) . subscribe < T , V > ( { ...options } ) ) ) ;
83+ const obs = this . ensureClient ( ) . subscribe < T , V > ( { ...options } ) ;
9084
9185 return extra && extra . useZone !== true ? obs : wrapWithZone ( obs , this . ngZone ) ;
9286 }
0 commit comments