-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathindex.d.ts
79 lines (67 loc) · 2.57 KB
/
index.d.ts
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
import React, { StatelessComponent, ComponentClass, ClassicComponentClass, Children } from "react";
type MutationSubscription = {
when: string | RegExp;
run: (payload: MutationHandlerPayload, resp: any, variables: any) => any;
};
type MutationHandlerPayload = {
currentResults: any;
cache: Cache;
softReset: (newResults: any) => void;
hardReset: () => void;
refresh: () => void;
};
export type QueryPayload<TResults = any> = {
loading: boolean;
loaded: boolean;
data: TResults;
error: any;
currentQuery: string;
reload: () => void;
clearCache: () => void;
clearCacheAndReload: () => void;
softReset: (newResults?: any) => void;
};
export type MutationPayload<TResults = any> = {
running: boolean;
finished: boolean;
runMutation: (variables: any) => Promise<TResults>;
};
export class Cache {
constructor(cacheSize?: number);
entries: [string, any][];
get(key: string): any;
set(key: string, results: any): void;
delete(key: string): void;
clearCache(): void;
}
export class Client {
constructor(options: { endpoint: string; cacheSize?: number; fetchOptions?: any });
runQuery(query: string, variables?: any): Promise<any>;
getGraphqlQuery({ query, variables }: { query: string; variables: any }): string;
processMutation(mutation: string, variables?: any): Promise<any>;
runMutation(mutation: string, variables?: any): Promise<any>;
getCache(query: string): Cache;
newCacheForQuery(query: string): Cache;
setCache(query: string, cache: Cache): void;
subscribeMutation(subscription: any, options?: any): () => void;
forceUpdate(query: string): void;
preload(query: string, variables: any): Promise<any>;
read<TResults = unknown>(query: string, variables: any): { data: TResults; error: any };
}
type BuildQueryOptions = {
onMutation?: MutationSubscription | MutationSubscription[];
client?: Client;
cache?: Cache;
active?: boolean;
preloadOnly?: boolean;
};
type BuildMutationOptions = {
client?: Client;
};
type IReactComponent<P = any> = StatelessComponent<P> | ComponentClass<P> | ClassicComponentClass<P>;
export const compress: any;
export const setDefaultClient: (client: Client) => void;
export const getDefaultClient: () => Client;
export function useQuery<TResults = any>(queryText: string, variables?: any, options?: BuildQueryOptions): QueryPayload<TResults>;
export function useSuspenseQuery<TResults = any>(queryText: string, variables?: any, options?: BuildQueryOptions): QueryPayload<TResults>;
export function useMutation<TResults = any>(mutationText: string, options?: BuildQueryOptions): MutationPayload<TResults>;