UNPKG

2.6 kBTypeScriptView Raw
1import { NgZone } from '@angular/core';
2import { ApolloClient, QueryOptions, MutationOptions, ApolloQueryResult, SubscriptionOptions, ApolloClientOptions } from 'apollo-client';
3import { FetchResult } from 'apollo-link';
4import { Observable } from 'rxjs';
5import { QueryRef } from './QueryRef';
6import { WatchQueryOptions, ExtraSubscriptionOptions, R } from './types';
7export declare class ApolloBase<TCacheShape = any> {
8 protected ngZone: NgZone;
9 protected _client?: ApolloClient<TCacheShape>;
10 constructor(ngZone: NgZone, _client?: ApolloClient<TCacheShape>);
11 watchQuery<T, V = R>(options: WatchQueryOptions<V>): QueryRef<T, V>;
12 query<T, V = R>(options: QueryOptions<V>): Observable<ApolloQueryResult<T>>;
13 mutate<T, V = R>(options: MutationOptions<T, V>): Observable<FetchResult<T>>;
14 subscribe<T, V = R>(options: SubscriptionOptions<V>, extra?: ExtraSubscriptionOptions): Observable<FetchResult<T>>;
15 /**
16 * Get an access to an instance of ApolloClient
17 */
18 getClient(): ApolloClient<TCacheShape>;
19 /**
20 * Set a new instance of ApolloClient
21 * Remember to clean up the store before setting a new client.
22 *
23 * @param client ApolloClient instance
24 */
25 setClient(client: ApolloClient<TCacheShape>): void;
26 private readonly client;
27 private beforeEach;
28 private checkInstance;
29}
30export declare class Apollo extends ApolloBase<any> {
31 private _ngZone;
32 private map;
33 constructor(_ngZone: NgZone, apolloOptions?: ApolloClientOptions<any>);
34 /**
35 * Create an instance of ApolloClient
36 * @param options Options required to create ApolloClient
37 * @param name client's name
38 */
39 create<TCacheShape>(options: ApolloClientOptions<TCacheShape>, name?: string): void;
40 /**
41 * Use a default ApolloClient
42 */
43 default(): ApolloBase<any>;
44 /**
45 * Use a named ApolloClient
46 * @param name client's name
47 */
48 use(name: string): ApolloBase<any>;
49 /**
50 * Create a default ApolloClient, same as `apollo.create(options)`
51 * @param options ApolloClient's options
52 */
53 createDefault<TCacheShape>(options: ApolloClientOptions<TCacheShape>): void;
54 /**
55 * Create a named ApolloClient, same as `apollo.create(options, name)`
56 * @param name client's name
57 * @param options ApolloClient's options
58 */
59 createNamed<TCacheShape>(name: string, options: ApolloClientOptions<TCacheShape>): void;
60 /**
61 * Remember to clean up the store before removing a client
62 * @param name client's name
63 */
64 removeClient(name?: string): void;
65}