-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
ReactRelayTypes.js
129 lines (115 loc) · 4.23 KB
/
ReactRelayTypes.js
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
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow strict-local
* @format
*/
// flowlint ambiguous-object-type:error
'use strict';
import type {
Disposable,
FragmentType,
GraphQLTaggedNode,
IEnvironment,
Observer,
Variables,
} from 'relay-runtime';
export type GeneratedNodeMap = {[key: string]: GraphQLTaggedNode, ...};
export type ObserverOrCallback = Observer<void> | ((error: ?Error) => mixed);
// NOTE: This is an inexact type in order to allow a RelayPaginationProp or
// RelayRefetchProp to flow into a RelayProp.
export type RelayProp = {+environment: IEnvironment, ...};
export type RelayPaginationProp = {|
+environment: IEnvironment,
+hasMore: () => boolean,
+isLoading: () => boolean,
+loadMore: (
pageSize: number,
observerOrCallback: ?ObserverOrCallback,
options?: RefetchOptions,
) => ?Disposable,
+refetchConnection: (
totalCount: number,
observerOrCallback: ?ObserverOrCallback,
refetchVariables: ?Variables,
) => ?Disposable,
|};
export type RelayRefetchProp = {|
+environment: IEnvironment,
+refetch: (
refetchVariables: Variables | ((fragmentVariables: Variables) => Variables),
renderVariables: ?Variables,
observerOrCallback: ?ObserverOrCallback,
options?: RefetchOptions,
) => Disposable,
|};
export type RefetchOptions = {|
+force?: boolean,
+fetchPolicy?: 'store-or-network' | 'network-only',
+metadata?: {[key: string]: mixed, ...},
|};
/**
* A utility type which takes the type of a fragment's data (typically found in
* a relay generated file) and returns a fragment reference type. This is used
* when the input to a Relay component needs to be explicitly typed:
*
* // ExampleComponent.js
* import type {ExampleComponent_data} from './generated/ExampleComponent_data.graphql';
* type Props = {
* title: string,
* data: ExampleComponent_data,
* };
*
* export default createFragmentContainer(
* (props: Props) => <div>{props.title}, {props.data.someField}</div>,
* graphql`
* fragment ExampleComponent_data on SomeType {
* someField
* }`
* );
*
* // ExampleUsage.js
* import type {ExampleComponent_data} from './generated/ExampleComponent_data.graphql';
* type Props = {
* title: string,
* data: $FragmentRef<ExampleComponent_data>,
* };
*
* export default function ExampleUsage(props: Props) {
* return <ExampleComponent {...props} />
* }
*
*/
export type $FragmentRef<T> = {
+$fragmentSpreads: T['$fragmentType'],
...
};
/**
* A utility type that takes the Props of a component and the type of
* `props.relay` and returns the props of the container.
*/
// prettier-ignore
export type $RelayProps<Props, RelayPropT = RelayProp> = $ObjMap<
$Diff<Props, { relay: RelayPropT | void, ... }>,
& (<T: { +$fragmentType: empty, ... }>( T) => T)
& (<T: { +$fragmentType: empty, ... }>(?T) => ?T)
& (<TFragmentType: FragmentType, T: { +$fragmentType: TFragmentType, ... }>( T ) => $FragmentRef<T> )
& (<TFragmentType: FragmentType, T: { +$fragmentType: TFragmentType, ... }>(? T ) => ? $FragmentRef<T> )
& (<TFragmentType: FragmentType, T: { +$fragmentType: TFragmentType, ... }>( $ReadOnlyArray< T>) => $ReadOnlyArray< $FragmentRef<T>>)
& (<TFragmentType: FragmentType, T: { +$fragmentType: TFragmentType, ... }>(?$ReadOnlyArray< T>) => ?$ReadOnlyArray< $FragmentRef<T>>)
& (<TFragmentType: FragmentType, T: { +$fragmentType: TFragmentType, ... }>( $ReadOnlyArray<?T>) => $ReadOnlyArray<?$FragmentRef<T>>)
& (<TFragmentType: FragmentType, T: { +$fragmentType: TFragmentType, ... }>(?$ReadOnlyArray<?T>) => ?$ReadOnlyArray<?$FragmentRef<T>>)
& (<T>(T) => T),
>;
export type RelayFragmentContainer<TComponent> = React$ComponentType<
$RelayProps<React$ElementConfig<TComponent>, RelayProp>,
>;
export type RelayPaginationContainer<TComponent> = React$ComponentType<
$RelayProps<React$ElementConfig<TComponent>, RelayPaginationProp>,
>;
export type RelayRefetchContainer<TComponent> = React$ComponentType<
$RelayProps<React$ElementConfig<TComponent>, RelayRefetchProp>,
>;