react-relay 14.1.0 → 15.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/ReactRelayContainerUtils.js.flow +1 -0
- package/ReactRelayContext.js +1 -1
- package/ReactRelayContext.js.flow +1 -0
- package/ReactRelayFragmentContainer.js.flow +6 -2
- package/ReactRelayFragmentMockRenderer.js.flow +1 -0
- package/ReactRelayLocalQueryRenderer.js.flow +5 -3
- package/ReactRelayPaginationContainer.js.flow +21 -12
- package/ReactRelayQueryFetcher.js.flow +19 -5
- package/ReactRelayQueryRenderer.js.flow +32 -1
- package/ReactRelayQueryRendererContext.js.flow +1 -0
- package/ReactRelayRefetchContainer.js.flow +9 -5
- package/ReactRelayTestMocker.js.flow +3 -1
- package/ReactRelayTypes.js.flow +1 -0
- package/RelayContext.js.flow +1 -0
- package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +2 -1
- package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +1 -0
- package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +1 -0
- package/__flowtests__/RelayModern-flowtest.js.flow +1 -0
- package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +1 -0
- package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +1 -0
- package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +1 -0
- package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +1 -0
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +3 -1
- package/assertFragmentMap.js.flow +1 -0
- package/buildReactRelayContainer.js.flow +7 -5
- package/getRootVariablesForFragments.js.flow +1 -1
- package/hooks.js +1 -1
- package/hooks.js.flow +4 -0
- package/index.js +1 -1
- package/index.js.flow +4 -0
- package/isRelayEnvironment.js.flow +1 -0
- package/jest-react/enqueueTask.js.flow +1 -1
- package/jest-react/index.js.flow +1 -1
- package/jest-react/internalAct.js.flow +1 -1
- package/legacy.js +1 -1
- package/legacy.js.flow +1 -0
- package/lib/ReactRelayContainerUtils.js +2 -2
- package/lib/ReactRelayContext.js +3 -3
- package/lib/ReactRelayFragmentContainer.js +39 -66
- package/lib/ReactRelayFragmentMockRenderer.js +2 -3
- package/lib/ReactRelayLocalQueryRenderer.js +18 -30
- package/lib/ReactRelayPaginationContainer.js +66 -159
- package/lib/ReactRelayQueryFetcher.js +48 -74
- package/lib/ReactRelayQueryRenderer.js +62 -82
- package/lib/ReactRelayQueryRendererContext.js +2 -1
- package/lib/ReactRelayRefetchContainer.js +52 -99
- package/lib/ReactRelayTestMocker.js +32 -66
- package/lib/ReactRelayTypes.js +2 -0
- package/lib/RelayContext.js +4 -6
- package/lib/assertFragmentMap.js +3 -4
- package/lib/buildReactRelayContainer.js +10 -25
- package/lib/getRootVariablesForFragments.js +5 -8
- package/lib/hooks.js +5 -17
- package/lib/index.js +5 -24
- package/lib/isRelayEnvironment.js +5 -3
- package/lib/jest-react/enqueueTask.js +5 -9
- package/lib/jest-react/index.js +0 -1
- package/lib/jest-react/internalAct.js +9 -20
- package/lib/legacy.js +2 -7
- package/lib/multi-actor/ActorChange.js +2 -5
- package/lib/multi-actor/index.js +2 -1
- package/lib/multi-actor/useRelayActorEnvironment.js +4 -7
- package/lib/relay-hooks/EntryPointContainer.react.js +9 -14
- package/lib/relay-hooks/EntryPointTypes.flow.js +5 -2
- package/lib/relay-hooks/FragmentResource.js +102 -196
- package/lib/relay-hooks/HooksImplementation.js +2 -5
- package/lib/relay-hooks/InternalLogger.js +2 -2
- package/lib/relay-hooks/LRUCache.js +2 -19
- package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +33 -53
- package/lib/relay-hooks/MatchContainer.js +14 -22
- package/lib/relay-hooks/ProfilerContext.js +3 -2
- package/lib/relay-hooks/QueryResource.js +30 -99
- package/lib/relay-hooks/RelayEnvironmentProvider.js +5 -8
- package/lib/relay-hooks/SuspenseResource.js +8 -31
- package/lib/relay-hooks/loadEntryPoint.js +19 -31
- package/lib/relay-hooks/loadQuery.js +41 -77
- package/lib/relay-hooks/preloadQuery_DEPRECATED.js +10 -35
- package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +9 -14
- package/lib/relay-hooks/react-cache/RelayReactCache.js +7 -11
- package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +24 -78
- package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +23 -56
- package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +65 -143
- package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +5 -14
- package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +17 -23
- package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +73 -74
- package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +24 -38
- package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +60 -102
- package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +7 -15
- package/lib/relay-hooks/useBlockingPaginationFragment.js +71 -92
- package/lib/relay-hooks/useClientQuery.js +3 -6
- package/lib/relay-hooks/useEntryPointLoader.js +17 -36
- package/lib/relay-hooks/useFetchTrackingRef.js +10 -11
- package/lib/relay-hooks/useFragment.js +8 -18
- package/lib/relay-hooks/useFragmentNode.js +20 -31
- package/lib/relay-hooks/useIsMountedRef.js +4 -5
- package/lib/relay-hooks/useIsOperationNodeActive.js +8 -20
- package/lib/relay-hooks/useIsParentQueryActive.js +3 -6
- package/lib/relay-hooks/useLazyLoadQuery.js +6 -9
- package/lib/relay-hooks/useLazyLoadQueryNode.js +23 -33
- package/lib/relay-hooks/useLoadMoreFunction.js +45 -76
- package/lib/relay-hooks/useMemoOperationDescriptor.js +6 -14
- package/lib/relay-hooks/useMemoVariables.js +15 -33
- package/lib/relay-hooks/useMutation.js +8 -25
- package/lib/relay-hooks/usePaginationFragment.js +61 -76
- package/lib/relay-hooks/usePreloadedQuery.js +12 -29
- package/lib/relay-hooks/useQueryLoader.js +23 -47
- package/lib/relay-hooks/useRefetchableFragment.js +8 -18
- package/lib/relay-hooks/useRefetchableFragmentNode.js +64 -107
- package/lib/relay-hooks/useRelayEnvironment.js +4 -7
- package/lib/relay-hooks/useStaticFragmentNodeWarning.js +4 -7
- package/lib/relay-hooks/useSubscribeToInvalidationState.js +8 -8
- package/lib/relay-hooks/useSubscription.js +5 -9
- package/lib/relay-hooks/useUnsafeRef_DEPRECATED.js +29 -0
- package/multi-actor/ActorChange.js.flow +1 -1
- package/multi-actor/index.js.flow +1 -1
- package/multi-actor/useRelayActorEnvironment.js.flow +2 -2
- package/package.json +2 -2
- package/react-relay-hooks.js +2 -2
- package/react-relay-hooks.min.js +2 -2
- package/react-relay-legacy.js +2 -2
- package/react-relay-legacy.min.js +2 -2
- package/react-relay.js +2 -2
- package/react-relay.min.js +2 -2
- package/relay-hooks/EntryPointContainer.react.js.flow +1 -1
- package/relay-hooks/EntryPointTypes.flow.js.flow +7 -5
- package/relay-hooks/FragmentResource.js.flow +34 -8
- package/relay-hooks/HooksImplementation.js.flow +1 -1
- package/relay-hooks/InternalLogger.js.flow +1 -1
- package/relay-hooks/LRUCache.js.flow +1 -1
- package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +15 -8
- package/relay-hooks/MatchContainer.js.flow +1 -1
- package/relay-hooks/ProfilerContext.js.flow +1 -1
- package/relay-hooks/QueryResource.js.flow +25 -5
- package/relay-hooks/RelayEnvironmentProvider.js.flow +2 -2
- package/relay-hooks/SuspenseResource.js.flow +1 -1
- package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +3 -1
- package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +2 -2
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +3 -1
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +3 -1
- package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +35 -33
- package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +1 -1
- package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +33 -32
- package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +18 -18
- package/relay-hooks/__flowtests__/utils.js.flow +13 -2
- package/relay-hooks/loadEntryPoint.js.flow +11 -6
- package/relay-hooks/loadQuery.js.flow +11 -7
- package/relay-hooks/preloadQuery_DEPRECATED.js.flow +5 -6
- package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +13 -8
- package/relay-hooks/react-cache/RelayReactCache.js.flow +1 -1
- package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +4 -4
- package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +3 -3
- package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +4 -4
- package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +1 -1
- package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +1 -1
- package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +41 -22
- package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +1 -2
- package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +11 -5
- package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +2 -2
- package/relay-hooks/useBlockingPaginationFragment.js.flow +85 -56
- package/relay-hooks/useClientQuery.js.flow +1 -1
- package/relay-hooks/useEntryPointLoader.js.flow +10 -6
- package/relay-hooks/useFetchTrackingRef.js.flow +5 -4
- package/relay-hooks/useFragment.js.flow +2 -2
- package/relay-hooks/useFragmentNode.js.flow +5 -4
- package/relay-hooks/useIsMountedRef.js.flow +1 -1
- package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
- package/relay-hooks/useIsParentQueryActive.js.flow +1 -1
- package/relay-hooks/useLazyLoadQuery.js.flow +2 -2
- package/relay-hooks/useLazyLoadQueryNode.js.flow +2 -2
- package/relay-hooks/useLoadMoreFunction.js.flow +14 -9
- package/relay-hooks/useMemoOperationDescriptor.js.flow +3 -3
- package/relay-hooks/useMemoVariables.js.flow +13 -29
- package/relay-hooks/useMutation.js.flow +4 -4
- package/relay-hooks/usePaginationFragment.js.flow +53 -46
- package/relay-hooks/usePreloadedQuery.js.flow +47 -22
- package/relay-hooks/useQueryLoader.js.flow +85 -22
- package/relay-hooks/useRefetchableFragment.js.flow +64 -33
- package/relay-hooks/useRefetchableFragmentNode.js.flow +10 -4
- package/relay-hooks/useRelayEnvironment.js.flow +2 -2
- package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -3
- package/relay-hooks/useSubscribeToInvalidationState.js.flow +2 -2
- package/relay-hooks/useSubscription.js.flow +1 -1
- package/relay-hooks/useUnsafeRef_DEPRECATED.js.flow +25 -0
- package/lib/readContext.js +0 -27
- package/readContext.js.flow +0 -29
@@ -4,21 +4,22 @@
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*
|
7
|
-
* @emails oncall+relay
|
8
7
|
* @flow strict-local
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
11
|
|
12
12
|
'use strict';
|
13
13
|
|
14
|
+
import type {RefetchableFragment} from '../../relay-runtime/util/RelayRuntimeTypes';
|
14
15
|
import type {LoadMoreFn, UseLoadMoreFunctionArgs} from './useLoadMoreFunction';
|
15
|
-
import type {
|
16
|
+
import type {Options} from './useRefetchableFragmentNode';
|
16
17
|
import type {
|
18
|
+
Disposable,
|
17
19
|
FragmentType,
|
18
20
|
GraphQLResponse,
|
19
|
-
GraphQLTaggedNode,
|
20
21
|
Observer,
|
21
|
-
|
22
|
+
Variables,
|
22
23
|
} from 'relay-runtime';
|
23
24
|
|
24
25
|
const useLoadMoreFunction = require('./useLoadMoreFunction');
|
@@ -32,35 +33,54 @@ const {
|
|
32
33
|
getPaginationMetadata,
|
33
34
|
} = require('relay-runtime');
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
type RefetchVariables<TVariables, TKey> =
|
37
|
+
// NOTE: This $Call ensures that the type of the variables is either:
|
38
|
+
// - nullable if the provided ref type is non-nullable
|
39
|
+
// - non-nullable if the provided ref type is nullable, and the caller need to provide the full set of variables
|
40
|
+
// prettier-ignore
|
41
|
+
$Call<
|
42
|
+
& (<TFragmentType>( { +$fragmentSpreads: TFragmentType, ... }) => $Shape<TVariables>)
|
43
|
+
& (<TFragmentType>(?{ +$fragmentSpreads: TFragmentType, ... }) => TVariables),
|
44
|
+
TKey,
|
45
|
+
>;
|
46
|
+
|
47
|
+
type RefetchFnBase<TVars, TOptions> = (
|
48
|
+
vars: TVars,
|
49
|
+
options?: TOptions,
|
50
|
+
) => Disposable;
|
51
|
+
|
52
|
+
type RefetchFn<TVariables, TKey, TOptions = Options> = RefetchFnBase<
|
53
|
+
RefetchVariables<TVariables, TKey>,
|
54
|
+
TOptions,
|
55
|
+
>;
|
56
|
+
|
57
|
+
type ReturnType<TVariables, TData, TKey> = {
|
58
|
+
// NOTE: This $Call ensures that the type of the returned data is either:
|
59
|
+
// - nullable if the provided ref type is nullable
|
60
|
+
// - non-nullable if the provided ref type is non-nullable
|
61
|
+
// prettier-ignore
|
62
|
+
data: $Call<
|
63
|
+
& (<TFragmentType>( { +$fragmentSpreads: TFragmentType, ... }) => TData)
|
64
|
+
& (<TFragmentType>(?{ +$fragmentSpreads: TFragmentType, ... }) => ?TData),
|
65
|
+
TKey,
|
66
|
+
>,
|
67
|
+
loadNext: LoadMoreFn<TVariables>,
|
68
|
+
loadPrevious: LoadMoreFn<TVariables>,
|
39
69
|
hasNext: boolean,
|
40
70
|
hasPrevious: boolean,
|
41
|
-
refetch:
|
71
|
+
refetch: RefetchFn<TVariables, TKey>,
|
42
72
|
};
|
43
73
|
|
44
74
|
function useBlockingPaginationFragment<
|
45
|
-
|
46
|
-
|
75
|
+
TFragmentType: FragmentType,
|
76
|
+
TVariables: Variables,
|
77
|
+
TData,
|
78
|
+
TKey: ?{+$fragmentSpreads: TFragmentType, ...},
|
47
79
|
>(
|
48
|
-
fragmentInput:
|
80
|
+
fragmentInput: RefetchableFragment<TFragmentType, TData, TVariables>,
|
49
81
|
parentFragmentRef: TKey,
|
50
82
|
componentDisplayName: string = 'useBlockingPaginationFragment()',
|
51
|
-
): ReturnType<
|
52
|
-
TQuery,
|
53
|
-
TKey,
|
54
|
-
// NOTE: This $Call ensures that the type of the returned data is either:
|
55
|
-
// - nullable if the provided ref type is nullable
|
56
|
-
// - non-nullable if the provided ref type is non-nullable
|
57
|
-
// prettier-ignore
|
58
|
-
$Call<
|
59
|
-
& (<TFragmentData>( { +$data?: TFragmentData, ... }) => TFragmentData)
|
60
|
-
& (<TFragmentData>(?{ +$data?: TFragmentData, ... }) => ?TFragmentData),
|
61
|
-
TKey,
|
62
|
-
>,
|
63
|
-
> {
|
83
|
+
): ReturnType<TVariables, TData, TKey> {
|
64
84
|
const fragmentNode = getFragment(fragmentInput);
|
65
85
|
useStaticFragmentNodeWarning(
|
66
86
|
fragmentNode,
|
@@ -86,33 +106,39 @@ function useBlockingPaginationFragment<
|
|
86
106
|
refetch,
|
87
107
|
disableStoreUpdates,
|
88
108
|
enableStoreUpdates,
|
89
|
-
} = useRefetchableFragmentNode<
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
109
|
+
} = useRefetchableFragmentNode<
|
110
|
+
{
|
111
|
+
response: TData,
|
112
|
+
variables: TVariables,
|
113
|
+
},
|
114
|
+
{
|
115
|
+
+$data: mixed,
|
116
|
+
...
|
117
|
+
},
|
118
|
+
>(fragmentNode, parentFragmentRef, componentDisplayName);
|
94
119
|
const fragmentIdentifier = getFragmentIdentifier(fragmentNode, fragmentRef);
|
95
120
|
|
96
121
|
// Backward pagination
|
97
|
-
const [loadPrevious, hasPrevious, disposeFetchPrevious] = useLoadMore<
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
122
|
+
const [loadPrevious, hasPrevious, disposeFetchPrevious] = useLoadMore<
|
123
|
+
TVariables,
|
124
|
+
TData,
|
125
|
+
>({
|
126
|
+
componentDisplayName,
|
127
|
+
connectionPathInFragmentData,
|
128
|
+
direction: 'backward',
|
129
|
+
disableStoreUpdates,
|
130
|
+
enableStoreUpdates,
|
131
|
+
fragmentData,
|
132
|
+
fragmentIdentifier,
|
133
|
+
fragmentNode,
|
134
|
+
fragmentRef,
|
135
|
+
identifierField,
|
136
|
+
paginationMetadata,
|
137
|
+
paginationRequest,
|
138
|
+
});
|
113
139
|
|
114
140
|
// Forward pagination
|
115
|
-
const [loadNext, hasNext, disposeFetchNext] = useLoadMore<
|
141
|
+
const [loadNext, hasNext, disposeFetchNext] = useLoadMore<TVariables, TData>({
|
116
142
|
componentDisplayName,
|
117
143
|
connectionPathInFragmentData,
|
118
144
|
direction: 'forward',
|
@@ -127,8 +153,8 @@ function useBlockingPaginationFragment<
|
|
127
153
|
paginationRequest,
|
128
154
|
});
|
129
155
|
|
130
|
-
const refetchPagination:
|
131
|
-
(variables, options) => {
|
156
|
+
const refetchPagination: RefetchFn<TVariables, TKey> = useCallback(
|
157
|
+
(variables: TVariables, options: void | Options) => {
|
132
158
|
disposeFetchNext();
|
133
159
|
disposeFetchPrevious();
|
134
160
|
return refetch(variables, {...options, __environment: undefined});
|
@@ -137,7 +163,8 @@ function useBlockingPaginationFragment<
|
|
137
163
|
);
|
138
164
|
|
139
165
|
return {
|
140
|
-
|
166
|
+
// $FlowFixMe[incompatible-cast]
|
167
|
+
data: (fragmentData: TData),
|
141
168
|
loadNext,
|
142
169
|
loadPrevious,
|
143
170
|
hasNext,
|
@@ -146,7 +173,7 @@ function useBlockingPaginationFragment<
|
|
146
173
|
};
|
147
174
|
}
|
148
175
|
|
149
|
-
function useLoadMore<
|
176
|
+
function useLoadMore<TVariables: Variables>(args: {
|
150
177
|
disableStoreUpdates: () => void,
|
151
178
|
enableStoreUpdates: () => void,
|
152
179
|
...$Exact<
|
@@ -159,11 +186,13 @@ function useLoadMore<TQuery: OperationType>(args: {
|
|
159
186
|
},
|
160
187
|
>,
|
161
188
|
>,
|
162
|
-
}): [LoadMoreFn<
|
189
|
+
}): [LoadMoreFn<TVariables>, boolean, () => void] {
|
163
190
|
const {disableStoreUpdates, enableStoreUpdates, ...loadMoreArgs} = args;
|
164
|
-
const [requestPromise, setRequestPromise] = useState(
|
165
|
-
|
166
|
-
|
191
|
+
const [requestPromise, setRequestPromise] = useState<null | Promise<mixed>>(
|
192
|
+
null,
|
193
|
+
);
|
194
|
+
const requestPromiseRef = useRef<null | Promise<mixed>>(null);
|
195
|
+
const promiseResolveRef = useRef<null | (() => void)>(null);
|
167
196
|
|
168
197
|
const promiseResolve = () => {
|
169
198
|
if (promiseResolveRef.current != null) {
|
@@ -208,7 +237,7 @@ function useLoadMore<TQuery: OperationType>(args: {
|
|
208
237
|
// and blow away the whole list of items.
|
209
238
|
error: promiseResolve,
|
210
239
|
};
|
211
|
-
const [loadMore, hasMore, disposeFetch] = useLoadMoreFunction<
|
240
|
+
const [loadMore, hasMore, disposeFetch] = useLoadMoreFunction<TVariables>({
|
212
241
|
...loadMoreArgs,
|
213
242
|
observer,
|
214
243
|
onReset: handleReset,
|
@@ -4,9 +4,9 @@
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*
|
7
|
-
* @emails oncall+relay
|
8
7
|
* @flow strict-local
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
11
|
|
12
12
|
'use strict';
|
@@ -134,11 +134,15 @@ function useLoadEntryPoint<
|
|
134
134
|
const entryPointLoaderCallback = useCallback(
|
135
135
|
(params: TEntryPointParams) => {
|
136
136
|
if (isMountedRef.current) {
|
137
|
-
const updatedEntryPointReference = loadEntryPoint
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
137
|
+
const updatedEntryPointReference = loadEntryPoint<
|
138
|
+
TEntryPointParams,
|
139
|
+
TPreloadedQueries,
|
140
|
+
TPreloadedEntryPoints,
|
141
|
+
TRuntimeProps,
|
142
|
+
TExtraProps,
|
143
|
+
TEntryPointComponent,
|
144
|
+
TEntryPoint,
|
145
|
+
>(environmentProvider, entryPoint, params);
|
142
146
|
undisposedEntryPointReferencesRef.current.add(
|
143
147
|
updatedEntryPointReference,
|
144
148
|
);
|
@@ -4,16 +4,17 @@
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*
|
7
|
-
* @emails oncall+relay
|
8
7
|
* @flow strict-local
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
11
|
|
12
12
|
'use strict';
|
13
13
|
|
14
14
|
import type {Subscription} from 'relay-runtime';
|
15
15
|
|
16
|
-
const
|
16
|
+
const useUnsafeRef_DEPRECATED = require('./useUnsafeRef_DEPRECATED');
|
17
|
+
const {useCallback, useEffect} = require('react');
|
17
18
|
|
18
19
|
/**
|
19
20
|
* This hook returns a mutable React ref that holds the value of whether a
|
@@ -33,8 +34,8 @@ function useFetchTrackingRef(): {
|
|
33
34
|
disposeFetch: () => void,
|
34
35
|
completeFetch: () => void,
|
35
36
|
} {
|
36
|
-
const subscriptionRef =
|
37
|
-
const isFetchingRef =
|
37
|
+
const subscriptionRef = useUnsafeRef_DEPRECATED<?Subscription>(null);
|
38
|
+
const isFetchingRef = useUnsafeRef_DEPRECATED<?boolean>(false);
|
38
39
|
|
39
40
|
const disposeFetch = useCallback(() => {
|
40
41
|
if (subscriptionRef.current != null) {
|
@@ -4,9 +4,9 @@
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*
|
7
|
-
* @emails oncall+relay
|
8
7
|
* @flow strict-local
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
11
|
|
12
12
|
'use strict';
|
@@ -50,7 +50,7 @@ function useFragment_LEGACY(fragment: GraphQLTaggedNode, key: mixed): mixed {
|
|
50
50
|
|
51
51
|
const fragmentNode = getFragment(fragment);
|
52
52
|
useStaticFragmentNodeWarning(fragmentNode, 'first argument of useFragment()');
|
53
|
-
const {data} = useFragmentNode<
|
53
|
+
const {data} = useFragmentNode<mixed>(fragmentNode, key, 'useFragment()');
|
54
54
|
if (__DEV__) {
|
55
55
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
56
56
|
useDebugValue({fragment: fragmentNode.name, data});
|
@@ -4,9 +4,9 @@
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*
|
7
|
-
* @emails oncall+relay
|
8
7
|
* @flow strict-local
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
11
|
|
12
12
|
'use strict';
|
@@ -15,7 +15,8 @@ import type {ReaderFragment} from 'relay-runtime';
|
|
15
15
|
|
16
16
|
const {getFragmentResourceForEnvironment} = require('./FragmentResource');
|
17
17
|
const useRelayEnvironment = require('./useRelayEnvironment');
|
18
|
-
const
|
18
|
+
const useUnsafeRef_DEPRECATED = require('./useUnsafeRef_DEPRECATED');
|
19
|
+
const {useEffect, useState} = require('react');
|
19
20
|
const {getFragmentIdentifier} = require('relay-runtime');
|
20
21
|
const warning = require('warning');
|
21
22
|
|
@@ -33,7 +34,7 @@ function useFragmentNode<TFragmentData: mixed>(
|
|
33
34
|
const environment = useRelayEnvironment();
|
34
35
|
const FragmentResource = getFragmentResourceForEnvironment(environment);
|
35
36
|
|
36
|
-
const isMountedRef =
|
37
|
+
const isMountedRef = useUnsafeRef_DEPRECATED(false);
|
37
38
|
const [, forceUpdate] = useState(0);
|
38
39
|
const fragmentIdentifier = getFragmentIdentifier(fragmentNode, fragmentRef);
|
39
40
|
|
@@ -45,7 +46,7 @@ function useFragmentNode<TFragmentData: mixed>(
|
|
45
46
|
componentDisplayName,
|
46
47
|
);
|
47
48
|
|
48
|
-
const isListeningForUpdatesRef =
|
49
|
+
const isListeningForUpdatesRef = useUnsafeRef_DEPRECATED(true);
|
49
50
|
function enableStoreUpdates() {
|
50
51
|
isListeningForUpdatesRef.current = true;
|
51
52
|
const didMissUpdates =
|
@@ -4,9 +4,9 @@
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*
|
7
|
-
* @emails oncall+relay
|
8
7
|
* @flow strict-local
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
11
|
|
12
12
|
'use strict';
|
@@ -64,7 +64,7 @@ function useLazyLoadQuery<TVariables: Variables, TData>(
|
|
64
64
|
? options.networkCacheConfig
|
65
65
|
: {force: true},
|
66
66
|
);
|
67
|
-
const data = useLazyLoadQueryNode({
|
67
|
+
const data = useLazyLoadQueryNode<$FlowFixMe>({
|
68
68
|
componentDisplayName: 'useLazyLoadQuery()',
|
69
69
|
fetchKey: options?.fetchKey,
|
70
70
|
fetchObservable: fetchQuery(environment, query),
|
@@ -4,9 +4,9 @@
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*
|
7
|
-
* @emails oncall+relay
|
8
7
|
* @flow strict-local
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
11
|
|
12
12
|
'use strict';
|
@@ -125,7 +125,7 @@ function useLazyLoadQueryNode<TQuery: OperationType>({
|
|
125
125
|
});
|
126
126
|
|
127
127
|
const {fragmentNode, fragmentRef} = preparedQueryResult;
|
128
|
-
const {data} = useFragmentNode(
|
128
|
+
const {data} = useFragmentNode<$FlowFixMe>(
|
129
129
|
fragmentNode,
|
130
130
|
fragmentRef,
|
131
131
|
componentDisplayName,
|
@@ -4,9 +4,9 @@
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*
|
7
|
-
* @emails oncall+relay
|
8
7
|
* @flow strict-local
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
11
|
|
12
12
|
'use strict';
|
@@ -17,10 +17,9 @@ import type {
|
|
17
17
|
Disposable,
|
18
18
|
GraphQLResponse,
|
19
19
|
Observer,
|
20
|
-
OperationType,
|
21
20
|
ReaderFragment,
|
22
21
|
ReaderPaginationMetadata,
|
23
|
-
|
22
|
+
Variables,
|
24
23
|
} from 'relay-runtime';
|
25
24
|
|
26
25
|
const useFetchTrackingRef = require('./useFetchTrackingRef');
|
@@ -30,8 +29,8 @@ const useRelayEnvironment = require('./useRelayEnvironment');
|
|
30
29
|
const invariant = require('invariant');
|
31
30
|
const {useCallback, useEffect, useState} = require('react');
|
32
31
|
const {
|
33
|
-
ConnectionInterface,
|
34
32
|
__internal: {fetchQuery},
|
33
|
+
ConnectionInterface,
|
35
34
|
createOperationDescriptor,
|
36
35
|
getPaginationVariables,
|
37
36
|
getSelector,
|
@@ -39,11 +38,11 @@ const {
|
|
39
38
|
} = require('relay-runtime');
|
40
39
|
const warning = require('warning');
|
41
40
|
|
42
|
-
export type LoadMoreFn<
|
41
|
+
export type LoadMoreFn<TVariables: Variables> = (
|
43
42
|
count: number,
|
44
43
|
options?: {
|
45
44
|
onComplete?: (Error | null) => void,
|
46
|
-
UNSTABLE_extraVariables?: $Shape<
|
45
|
+
UNSTABLE_extraVariables?: $Shape<TVariables>,
|
47
46
|
},
|
48
47
|
) => Disposable;
|
49
48
|
|
@@ -62,9 +61,9 @@ export type UseLoadMoreFunctionArgs = {
|
|
62
61
|
onReset: () => void,
|
63
62
|
};
|
64
63
|
|
65
|
-
function useLoadMoreFunction<
|
64
|
+
function useLoadMoreFunction<TVariables: Variables>(
|
66
65
|
args: UseLoadMoreFunctionArgs,
|
67
|
-
): [LoadMoreFn<
|
66
|
+
): [LoadMoreFn<TVariables>, boolean, () => void] {
|
68
67
|
const {
|
69
68
|
direction,
|
70
69
|
fragmentNode,
|
@@ -123,7 +122,13 @@ function useLoadMoreFunction<TQuery: OperationType>(
|
|
123
122
|
}, [disposeFetch]);
|
124
123
|
|
125
124
|
const loadMore = useCallback(
|
126
|
-
(
|
125
|
+
(
|
126
|
+
count: number,
|
127
|
+
options: void | {
|
128
|
+
UNSTABLE_extraVariables?: $Shape<TVariables>,
|
129
|
+
onComplete?: (Error | null) => void,
|
130
|
+
},
|
131
|
+
) => {
|
127
132
|
// TODO(T41131846): Fetch/Caching policies for loadMore
|
128
133
|
|
129
134
|
const onComplete = options?.onComplete;
|
@@ -4,9 +4,9 @@
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*
|
7
|
-
* @emails oncall+relay
|
8
7
|
* @flow strict-local
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
11
|
|
12
12
|
'use strict';
|
@@ -29,8 +29,8 @@ function useMemoOperationDescriptor(
|
|
29
29
|
variables: Variables,
|
30
30
|
cacheConfig?: ?CacheConfig,
|
31
31
|
): OperationDescriptor {
|
32
|
-
const
|
33
|
-
const
|
32
|
+
const memoVariables = useMemoVariables(variables);
|
33
|
+
const memoCacheConfig = useMemoVariables(cacheConfig || {});
|
34
34
|
return useMemo(
|
35
35
|
() =>
|
36
36
|
createOperationDescriptor(
|
@@ -4,9 +4,9 @@
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*
|
7
|
-
* @emails oncall+relay
|
8
7
|
* @flow strict-local
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
11
|
|
12
12
|
'use strict';
|
@@ -14,39 +14,23 @@
|
|
14
14
|
import type {Variables} from 'relay-runtime';
|
15
15
|
|
16
16
|
const areEqual = require('areEqual');
|
17
|
-
const
|
18
|
-
|
19
|
-
const {useMemo, useRef, useState} = React;
|
17
|
+
const {useState} = require('react');
|
20
18
|
|
19
|
+
/**
|
20
|
+
* Memoizes the passed in `variables` object based on `areEqual` equality.
|
21
|
+
* This is useful when a `variables` object is used as a value in a depencency
|
22
|
+
* array as it might often be constructed during render.
|
23
|
+
*/
|
21
24
|
function useMemoVariables<TVariables: Variables | null>(
|
22
25
|
variables: TVariables,
|
23
|
-
):
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
const variablesChangedGenerationRef = useRef(0);
|
29
|
-
|
30
|
-
// We mirror the variables to check if they have changed between renders
|
31
|
-
const [mirroredVariables, setMirroredVariables] = useState<Variables | null>(
|
32
|
-
variables,
|
33
|
-
);
|
34
|
-
|
35
|
-
const variablesChanged = !areEqual(variables, mirroredVariables);
|
36
|
-
if (variablesChanged) {
|
37
|
-
variablesChangedGenerationRef.current =
|
38
|
-
(variablesChangedGenerationRef.current ?? 0) + 1;
|
26
|
+
): TVariables {
|
27
|
+
const [mirroredVariables, setMirroredVariables] = useState(variables);
|
28
|
+
if (areEqual(variables, mirroredVariables)) {
|
29
|
+
return mirroredVariables;
|
30
|
+
} else {
|
39
31
|
setMirroredVariables(variables);
|
32
|
+
return variables;
|
40
33
|
}
|
41
|
-
|
42
|
-
// NOTE: We disable react-hooks-deps warning because we explicitly
|
43
|
-
// don't want to memoize on object identity
|
44
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
45
|
-
const memoVariables = useMemo(
|
46
|
-
() => variables,
|
47
|
-
[variablesChangedGenerationRef.current],
|
48
|
-
);
|
49
|
-
return [memoVariables, variablesChangedGenerationRef.current ?? 0];
|
50
34
|
}
|
51
35
|
|
52
36
|
module.exports = useMemoVariables;
|
@@ -4,9 +4,9 @@
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*
|
7
|
-
* @emails oncall+relay
|
8
7
|
* @flow strict-local
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
11
|
|
12
12
|
'use strict';
|
@@ -61,11 +61,11 @@ function useMutation<TMutation: MutationParameters>(
|
|
61
61
|
const isMountedRef = useIsMountedRef();
|
62
62
|
const environmentRef = useRef(environment);
|
63
63
|
const mutationRef = useRef(mutation);
|
64
|
-
const inFlightMutationsRef = useRef(new Set());
|
64
|
+
const inFlightMutationsRef = useRef(new Set<Disposable>());
|
65
65
|
const [isMutationInFlight, setMutationInFlight] = useState(false);
|
66
66
|
|
67
67
|
const cleanup = useCallback(
|
68
|
-
disposable => {
|
68
|
+
(disposable: Disposable) => {
|
69
69
|
if (
|
70
70
|
environmentRef.current === environment &&
|
71
71
|
mutationRef.current === mutation
|
@@ -98,7 +98,7 @@ function useMutation<TMutation: MutationParameters>(
|
|
98
98
|
if (isMountedRef.current) {
|
99
99
|
setMutationInFlight(true);
|
100
100
|
}
|
101
|
-
const disposable = commitMutationFn(environment, {
|
101
|
+
const disposable: Disposable = commitMutationFn(environment, {
|
102
102
|
...config,
|
103
103
|
mutation,
|
104
104
|
onCompleted: (response, errors) => {
|