Skip to content

Commit 5e4d1ce

Browse files
arahansenJames Baxley
authored andcommitted
chore(flow): update flow types to [email protected] semantics (apollographql#1241)
1 parent 4546bca commit 5e4d1ce

File tree

2 files changed

+53
-62
lines changed

2 files changed

+53
-62
lines changed

src/index.js.flow

Lines changed: 51 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,24 @@ import gql from 'graphql-tag';
2424
export * from 'apollo-client';
2525
export { gql, compose };
2626

27-
declare type StatelessComponent<P> = (props: P) => ?React$Element<any>;
28-
2927
export interface ProviderProps {
30-
store?: Store<*, *>,
31-
client: ApolloClient,
28+
store?: Store<*, *>;
29+
client: ApolloClient;
3230
}
3331

34-
declare export class ApolloProvider extends React$Component {
35-
props: ProviderProps,
32+
declare export class ApolloProvider extends React$Component<ProviderProps> {
3633
childContextTypes: {
3734
store: Store<*, *>,
3835
client: ApolloClient,
39-
},
36+
};
4037
contextTypes: {
4138
store: Store<*, *>,
42-
},
39+
};
4340
getChildContext(): {
4441
store: Store<*, *>,
4542
client: ApolloClient,
46-
},
47-
render(): React$Element<*>,
43+
};
44+
render(): React$Element<*>;
4845
}
4946
export type MutationFunc<TResult> = (
5047
opts: MutationOpts,
@@ -59,42 +56,42 @@ export type ChildProps<P, R> = {
5956
export type DefaultChildProps<P, R> = ChildProps<P, R>;
6057

6158
export interface MutationOpts {
62-
variables?: Object,
63-
optimisticResponse?: Object,
64-
updateQueries?: MutationQueryReducersMap<*>,
65-
refetchQueries?: string[] | PureQueryOptions[],
66-
update?: MutationUpdaterFn<*>,
59+
variables?: Object;
60+
optimisticResponse?: Object;
61+
updateQueries?: MutationQueryReducersMap<*>;
62+
refetchQueries?: string[] | PureQueryOptions[];
63+
update?: MutationUpdaterFn<*>;
6764
}
6865

6966
export interface QueryOpts {
70-
ssr?: boolean,
71-
variables?: Object,
72-
fetchPolicy?: FetchPolicy,
73-
pollInterval?: number,
74-
skip?: boolean,
67+
ssr?: boolean;
68+
variables?: Object;
69+
fetchPolicy?: FetchPolicy;
70+
pollInterval?: number;
71+
skip?: boolean;
7572
}
7673

7774
export interface QueryProps {
78-
error?: ApolloError,
79-
networkStatus: number,
80-
loading: boolean,
81-
variables: Object,
75+
error?: ApolloError;
76+
networkStatus: number;
77+
loading: boolean;
78+
variables: Object;
8279
fetchMore: (
8380
fetchMoreOptions: FetchMoreQueryOptions & FetchMoreOptions,
84-
) => Promise<ApolloQueryResult<any>>,
85-
refetch: (variables?: Object) => Promise<ApolloQueryResult<any>>,
86-
startPolling: (pollInterval: number) => void,
87-
stopPolling: () => void,
88-
subscribeToMore: (options: SubscribeToMoreOptions) => () => void,
81+
) => Promise<ApolloQueryResult<any>>;
82+
refetch: (variables?: Object) => Promise<ApolloQueryResult<any>>;
83+
startPolling: (pollInterval: number) => void;
84+
stopPolling: () => void;
85+
subscribeToMore: (options: SubscribeToMoreOptions) => () => void;
8986
updateQuery: (
9087
mapFn: (previousQueryResult: any, options: UpdateQueryOptions) => any,
91-
) => void,
88+
) => void;
9289
}
9390

9491
export interface OptionProps<TProps, TResult> {
95-
ownProps: TProps,
96-
data: QueryProps & TResult,
97-
mutate: MutationFunc<TResult>,
92+
ownProps: TProps;
93+
data: QueryProps & TResult;
94+
mutate: MutationFunc<TResult>;
9895
}
9996

10097
export type OptionDescription<P> = (props: P) => QueryOpts | MutationOpts;
@@ -104,25 +101,21 @@ export type NamedProps<P, R> = P & {
104101
};
105102

106103
export interface OperationOption<TProps: {}, TResult: {}> {
107-
options?: OptionDescription<TProps>,
108-
props?: (props: OptionProps<TProps, TResult>) => any,
109-
+skip?: boolean | ((props: any) => boolean),
110-
name?: string,
111-
withRef?: boolean,
112-
shouldResubscribe?: (props: TProps, nextProps: TProps) => boolean,
113-
alias?: string,
104+
options?: OptionDescription<TProps>;
105+
props?: (props: OptionProps<TProps, TResult>) => any;
106+
+skip?: boolean | ((props: any) => boolean);
107+
name?: string;
108+
withRef?: boolean;
109+
shouldResubscribe?: (props: TProps, nextProps: TProps) => boolean;
110+
alias?: string;
114111
}
115112

116113
export interface OperationComponent<
117114
TResult: Object = {},
118115
TOwnProps: Object = {},
119116
TMergedProps = ChildProps<TOwnProps, TResult>,
120117
> {
121-
(
122-
component:
123-
| StatelessComponent<TMergedProps>
124-
| Class<React$Component<any, TMergedProps, any>>,
125-
): Class<React$Component<void, TOwnProps, void>>,
118+
(component: React$ComponentType<TOwnProps>): React$ComponentType<TOwnProps>;
126119
}
127120

128121
declare export function graphql<TResult, TProps, TChildProps>(
@@ -131,34 +124,32 @@ declare export function graphql<TResult, TProps, TChildProps>(
131124
): OperationComponent<TResult, TProps, TChildProps>;
132125

133126
declare export function withApollo<TProps>(
134-
component:
135-
| StatelessComponent<TProps & ApolloClient>
136-
| Class<React$Component<any, TProps & ApolloClient, any>>,
137-
): Class<React$Component<void, TProps & ApolloClient, void>>;
127+
component: React$ComponentType<TProps & ApolloClient>,
128+
): React$ComponentType<TProps & ApolloClient>;
138129

139130
export interface IDocumentDefinition {
140-
type: DocumentType,
141-
name: string,
142-
variables: VariableDefinitionNode[],
131+
type: DocumentType;
132+
name: string;
133+
variables: VariableDefinitionNode[];
143134
}
144135

145136
declare export function parser(document: DocumentNode): IDocumentDefinition;
146137

147138
export interface Context {
148-
client?: ApolloClient,
149-
store?: Store<*, *>,
150-
[key: string]: any,
139+
client?: ApolloClient;
140+
store?: Store<*, *>;
141+
[key: string]: any;
151142
}
152143

153144
export interface QueryTreeArgument {
154-
rootElement: React$Element<*>,
155-
rootContext?: Context,
145+
rootElement: React$Element<*>;
146+
rootContext?: Context;
156147
}
157148

158149
export interface QueryResult {
159-
query: Promise<ApolloQueryResult<mixed>>,
160-
element: React$Element<*>,
161-
context: Context,
150+
query: Promise<ApolloQueryResult<mixed>>;
151+
element: React$Element<*>;
152+
context: Context;
162153
}
163154

164155
declare export function walkTree(

test/flow.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*/
1111

1212
// @flow
13-
import { Component } from 'react';
13+
import React, { Component } from 'react';
1414
import {
1515
withApollo,
1616
compose,
@@ -102,7 +102,7 @@ export default withCharacter(({ loading, hero, error }) => {
102102
return null;
103103
});
104104

105-
export class Character extends Component {
105+
export class Character extends Component<*> {
106106
render() {
107107
const { loading, hero, error } = this.props;
108108
if (loading) return <div>Loading</div>;

0 commit comments

Comments
 (0)