forked from apollographql/react-apollo
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js.flow
166 lines (145 loc) · 4.35 KB
/
index.js.flow
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import type {
ApolloClient,
MutationQueryReducersMap,
ApolloQueryResult,
ApolloError,
FetchPolicy,
FetchMoreOptions,
UpdateQueryOptions,
FetchMoreQueryOptions,
SubscribeToMoreOptions,
PureQueryOptions,
MutationUpdaterFn,
} from "apollo-client";
import type { Store } from "redux";
import type { DocumentNode, VariableDefinitionNode } from "graphql";
declare module "react-apollo" {
import type { Component } from "react";
declare type StatelessComponent<P> = (props: P) => ?React$Element<any>;
declare export interface ProviderProps {
store?: Store<any>,
client: ApolloClient,
}
declare export class ApolloProvider extends React$Component {
props: ProviderProps,
childContextTypes: {
store: Store,
client: ApolloClient,
},
contextTypes: {
store: Store,
},
getChildContext(): {
store: Store,
client: ApolloClient,
},
render(): React$Element<*>,
}
declare export type MutationFunc<TResult> = (
opts: MutationOpts
) => Promise<ApolloQueryResult<TResult>>;
declare export type DefaultChildProps<P, R> = {
data: QueryProps & R,
mutate: MutationFunc<R>,
} & P;
declare export interface MutationOpts {
variables?: Object,
optimisticResponse?: Object,
updateQueries?: MutationQueryReducersMap,
refetchQueries?: string[] | PureQueryOptions[];
update?: MutationUpdaterFn;
}
declare export interface QueryOpts {
ssr?: boolean,
variables?: Object,
fetchPolicy?: FetchPolicy,
pollInterval?: number,
skip?: boolean,
}
declare export interface QueryProps {
error?: ApolloError,
networkStatus: number,
loading: boolean,
variables: Object,
fetchMore: (
fetchMoreOptions: FetchMoreQueryOptions & FetchMoreOptions
) => Promise<ApolloQueryResult<any>>,
refetch: (variables?: Object) => Promise<ApolloQueryResult<any>>,
startPolling: (pollInterval: number) => void,
stopPolling: () => void,
subscribeToMore: (options: SubscribeToMoreOptions) => () => void,
updateQuery: (
mapFn: (previousQueryResult: any, options: UpdateQueryOptions) => any
) => void,
}
declare export interface OptionProps<TProps, TResult> {
ownProps: TProps,
data?: QueryProps & TResult,
mutate?: MutationFunc<TResult>,
}
declare export type OptionDescription<P> = (
props: P
) => QueryOpts | MutationOpts;
declare export interface OperationOption<TProps: {}, TResult: {}> {
options?: OptionDescription<TProps>,
props?: (props: OptionProps<TProps, TResult>) => any,
skip?: boolean | ((props: any) => boolean),
name?: string,
withRef?: boolean,
shouldResubscribe?: (props: TProps, nextProps: TProps) => boolean,
alias?: string,
}
declare export interface OperationComponent<
TResult: Object = {},
TOwnProps: Object = {},
TMergedProps = DefaultChildProps<TOwnProps, TResult>
> {
(
component:
| StatelessComponent<TMergedProps>
| React$Component<void, TMergedProps, void>
): Class<React$Component<void, TOwnProps, void>>,
}
declare export function graphql<TResult, TProps, TChildProps>(
document: DocumentNode,
operationOptions?: OperationOption<TProps, TResult>
): OperationComponent<TResult, TProps, TChildProps>;
declare export interface IDocumentDefinition {
type: DocumentType,
name: string,
variables: VariableDefinitionNode[],
}
declare export function parser(document: DocumentNode): IDocumentDefinition;
declare export interface Context {
client?: ApolloClient,
store?: Store,
[key: string]: any
}
declare export interface QueryTreeArgument {
rootElement: React$Element<*>,
rootContext?: Context
}
declare export interface QueryResult {
query: Promise<ApolloQueryResult<mixed>>,
element: React$Element<*>,
context: Context
}
declare export function walkTree(
element: React$Element<*>,
context: Context,
visitor: (
element: React$Element<*>,
instance: any,
context: Context
) => boolean | void
): void;
declare export function getDataFromTree(
rootElement: React$Element<*>,
rootContext?: any,
fetchRoot?: boolean
): Promise<void>;
declare export function renderToStringWithData(
component: React$Element<*>
): Promise<string>;
declare export function cleanupApolloState(apolloState: any): void;
}