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
14
|
import type {LoadMoreFn, UseLoadMoreFunctionArgs} from './useLoadMoreFunction';
|
15
|
-
import type {
|
15
|
+
import type {RefetchFn} from './useRefetchableFragment';
|
16
|
+
import type {Options} from './useRefetchableFragmentNode';
|
16
17
|
import type {
|
17
18
|
FragmentType,
|
18
19
|
GraphQLResponse,
|
19
|
-
GraphQLTaggedNode,
|
20
20
|
Observer,
|
21
|
-
|
21
|
+
RefetchableFragment,
|
22
|
+
Variables,
|
22
23
|
} from 'relay-runtime';
|
23
24
|
|
24
25
|
const HooksImplementation = require('./HooksImplementation');
|
@@ -32,43 +33,28 @@ const {
|
|
32
33
|
getPaginationMetadata,
|
33
34
|
} = require('relay-runtime');
|
34
35
|
|
35
|
-
export type ReturnType<TQuery: OperationType, TKey> = {
|
36
|
-
// NOTE: This $Call ensures that the type of the returned data is either:
|
37
|
-
// - nullable if the provided ref type is nullable
|
38
|
-
// - non-nullable if the provided ref type is non-nullable
|
39
|
-
// prettier-ignore
|
40
|
-
data: $Call<
|
41
|
-
& (<TFragmentData>( { +$data?: TFragmentData, ... }) => TFragmentData)
|
42
|
-
& (<TFragmentData>(?{ +$data?: TFragmentData, ... }) => ?TFragmentData),
|
43
|
-
TKey,
|
44
|
-
>,
|
45
|
-
loadNext: LoadMoreFn<TQuery>,
|
46
|
-
loadPrevious: LoadMoreFn<TQuery>,
|
47
|
-
hasNext: boolean,
|
48
|
-
hasPrevious: boolean,
|
49
|
-
isLoadingNext: boolean,
|
50
|
-
isLoadingPrevious: boolean,
|
51
|
-
refetch: RefetchFnDynamic<TQuery, TKey>,
|
52
|
-
};
|
53
|
-
|
54
36
|
// This separate type export is only needed as long as we are injecting
|
55
37
|
// a separate hooks implementation in ./HooksImplementation -- it can
|
56
38
|
// be removed after we stop doing that.
|
57
39
|
export type UsePaginationFragmentType = <
|
58
|
-
|
59
|
-
|
40
|
+
TFragmentType: FragmentType,
|
41
|
+
TVariables: Variables,
|
42
|
+
TData,
|
43
|
+
TKey: ?{+$fragmentSpreads: TFragmentType, ...},
|
60
44
|
>(
|
61
|
-
fragmentInput:
|
45
|
+
fragmentInput: RefetchableFragment<TFragmentType, TData, TVariables>,
|
62
46
|
parentFragmentRef: TKey,
|
63
|
-
) => ReturnType<
|
47
|
+
) => ReturnType<TVariables, TData, TKey>;
|
64
48
|
|
65
49
|
function usePaginationFragment_LEGACY<
|
66
|
-
|
67
|
-
|
50
|
+
TFragmentType: FragmentType,
|
51
|
+
TVariables: Variables,
|
52
|
+
TData,
|
53
|
+
TKey: ?{+$fragmentSpreads: TFragmentType, ...},
|
68
54
|
>(
|
69
|
-
fragmentInput:
|
55
|
+
fragmentInput: RefetchableFragment<TFragmentType, TData, TVariables>,
|
70
56
|
parentFragmentRef: TKey,
|
71
|
-
): ReturnType<
|
57
|
+
): ReturnType<TVariables, TData, TKey> {
|
72
58
|
const fragmentNode = getFragment(fragmentInput);
|
73
59
|
useStaticFragmentNodeWarning(
|
74
60
|
fragmentNode,
|
@@ -84,14 +70,14 @@ function usePaginationFragment_LEGACY<
|
|
84
70
|
} = getPaginationMetadata(fragmentNode, componentDisplayName);
|
85
71
|
|
86
72
|
const {fragmentData, fragmentRef, refetch} = useRefetchableFragmentNode<
|
87
|
-
|
88
|
-
|
73
|
+
$FlowFixMe,
|
74
|
+
$FlowFixMe,
|
89
75
|
>(fragmentNode, parentFragmentRef, componentDisplayName);
|
90
76
|
const fragmentIdentifier = getFragmentIdentifier(fragmentNode, fragmentRef);
|
91
77
|
|
92
78
|
// Backward pagination
|
93
79
|
const [loadPrevious, hasPrevious, isLoadingPrevious, disposeFetchPrevious] =
|
94
|
-
useLoadMore<
|
80
|
+
useLoadMore<TVariables>({
|
95
81
|
componentDisplayName,
|
96
82
|
connectionPathInFragmentData,
|
97
83
|
direction: 'backward',
|
@@ -106,7 +92,7 @@ function usePaginationFragment_LEGACY<
|
|
106
92
|
|
107
93
|
// Forward pagination
|
108
94
|
const [loadNext, hasNext, isLoadingNext, disposeFetchNext] =
|
109
|
-
useLoadMore<
|
95
|
+
useLoadMore<TVariables>({
|
110
96
|
componentDisplayName,
|
111
97
|
connectionPathInFragmentData,
|
112
98
|
direction: 'forward',
|
@@ -119,8 +105,8 @@ function usePaginationFragment_LEGACY<
|
|
119
105
|
paginationRequest,
|
120
106
|
});
|
121
107
|
|
122
|
-
const refetchPagination:
|
123
|
-
(variables, options) => {
|
108
|
+
const refetchPagination: RefetchFn<TVariables, TKey> = useCallback(
|
109
|
+
(variables: TVariables, options: void | Options) => {
|
124
110
|
disposeFetchNext();
|
125
111
|
disposeFetchPrevious();
|
126
112
|
return refetch(variables, {...options, __environment: undefined});
|
@@ -140,7 +126,7 @@ function usePaginationFragment_LEGACY<
|
|
140
126
|
});
|
141
127
|
}
|
142
128
|
return {
|
143
|
-
data: fragmentData,
|
129
|
+
data: (fragmentData: $FlowFixMe),
|
144
130
|
loadNext,
|
145
131
|
loadPrevious,
|
146
132
|
hasNext,
|
@@ -151,7 +137,7 @@ function usePaginationFragment_LEGACY<
|
|
151
137
|
};
|
152
138
|
}
|
153
139
|
|
154
|
-
function useLoadMore<
|
140
|
+
function useLoadMore<TVariables: Variables>(
|
155
141
|
args: $Diff<
|
156
142
|
UseLoadMoreFunctionArgs,
|
157
143
|
{
|
@@ -160,7 +146,7 @@ function useLoadMore<TQuery: OperationType>(
|
|
160
146
|
...
|
161
147
|
},
|
162
148
|
>,
|
163
|
-
): [LoadMoreFn<
|
149
|
+
): [LoadMoreFn<TVariables>, boolean, boolean, () => void] {
|
164
150
|
const [isLoadingMore, setIsLoadingMore] = useState(false);
|
165
151
|
const observer = {
|
166
152
|
start: () => setIsLoadingMore(true),
|
@@ -168,7 +154,7 @@ function useLoadMore<TQuery: OperationType>(
|
|
168
154
|
error: () => setIsLoadingMore(false),
|
169
155
|
};
|
170
156
|
const handleReset = () => setIsLoadingMore(false);
|
171
|
-
const [loadMore, hasMore, disposeFetch] = useLoadMoreFunction({
|
157
|
+
const [loadMore, hasMore, disposeFetch] = useLoadMoreFunction<TVariables>({
|
172
158
|
...args,
|
173
159
|
observer,
|
174
160
|
onReset: handleReset,
|
@@ -176,16 +162,37 @@ function useLoadMore<TQuery: OperationType>(
|
|
176
162
|
return [loadMore, hasMore, isLoadingMore, disposeFetch];
|
177
163
|
}
|
178
164
|
|
165
|
+
export type ReturnType<TVariables, TData, TKey> = {
|
166
|
+
// NOTE: This $Call ensures that the type of the returned data is either:
|
167
|
+
// - nullable if the provided ref type is nullable
|
168
|
+
// - non-nullable if the provided ref type is non-nullable
|
169
|
+
// prettier-ignore
|
170
|
+
data: $Call<
|
171
|
+
& (<TFragmentType>( { +$fragmentSpreads: TFragmentType, ... }) => TData)
|
172
|
+
& (<TFragmentType>(?{ +$fragmentSpreads: TFragmentType, ... }) => ?TData),
|
173
|
+
TKey,
|
174
|
+
>,
|
175
|
+
loadNext: LoadMoreFn<TVariables>,
|
176
|
+
loadPrevious: LoadMoreFn<TVariables>,
|
177
|
+
hasNext: boolean,
|
178
|
+
hasPrevious: boolean,
|
179
|
+
isLoadingNext: boolean,
|
180
|
+
isLoadingPrevious: boolean,
|
181
|
+
refetch: RefetchFn<TVariables, TKey>,
|
182
|
+
};
|
183
|
+
|
179
184
|
function usePaginationFragment<
|
180
|
-
|
181
|
-
|
185
|
+
TFragmentType: FragmentType,
|
186
|
+
TVariables: Variables,
|
187
|
+
TData,
|
188
|
+
TKey: ?{+$fragmentSpreads: TFragmentType, ...},
|
182
189
|
>(
|
183
|
-
fragmentInput:
|
190
|
+
fragmentInput: RefetchableFragment<TFragmentType, TData, TVariables>,
|
184
191
|
parentFragmentRef: TKey,
|
185
|
-
): ReturnType<
|
192
|
+
): ReturnType<TVariables, TData, TKey> {
|
186
193
|
const impl = HooksImplementation.get();
|
187
194
|
if (impl) {
|
188
|
-
return impl.usePaginationFragment<
|
195
|
+
return impl.usePaginationFragment<TFragmentType, TVariables, TData, TKey>(
|
189
196
|
fragmentInput,
|
190
197
|
parentFragmentRef,
|
191
198
|
);
|
@@ -4,19 +4,19 @@
|
|
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 {PreloadedQuery} from './EntryPointTypes.flow';
|
15
14
|
import type {
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
} from '
|
15
|
+
EnvironmentProviderOptions,
|
16
|
+
PreloadedQueryInner,
|
17
|
+
PreloadedQueryInner_DEPRECATED,
|
18
|
+
} from './EntryPointTypes.flow';
|
19
|
+
import type {Query, RenderPolicy, Variables} from 'relay-runtime';
|
20
20
|
|
21
21
|
const {useTrackLoadQueryInRender} = require('./loadQuery');
|
22
22
|
const useLazyLoadQueryNode = require('./useLazyLoadQueryNode');
|
@@ -29,24 +29,44 @@ const {
|
|
29
29
|
} = require('relay-runtime');
|
30
30
|
const warning = require('warning');
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
32
|
+
type PreloadedQuery<
|
33
|
+
TVariables: Variables,
|
34
|
+
TData,
|
35
|
+
TRawResponse,
|
36
|
+
TEnvironmentProviderOptions = EnvironmentProviderOptions,
|
37
|
+
> =
|
38
|
+
| PreloadedQueryInner_DEPRECATED<
|
39
|
+
{
|
40
|
+
variables: TVariables,
|
41
|
+
response: TData,
|
42
|
+
rawResponse?: TRawResponse,
|
43
|
+
},
|
44
|
+
TEnvironmentProviderOptions,
|
45
|
+
>
|
46
|
+
| PreloadedQueryInner<
|
47
|
+
{
|
48
|
+
variables: TVariables,
|
49
|
+
response: TData,
|
50
|
+
rawResponse?: TRawResponse,
|
51
|
+
},
|
52
|
+
TEnvironmentProviderOptions,
|
53
|
+
>;
|
42
54
|
|
43
|
-
function usePreloadedQuery<
|
44
|
-
|
45
|
-
|
55
|
+
function usePreloadedQuery<
|
56
|
+
TVariables: Variables,
|
57
|
+
TData,
|
58
|
+
TRawResponse: ?{...} = void,
|
59
|
+
>(
|
60
|
+
gqlQuery: Query<TVariables, TData, TRawResponse>,
|
61
|
+
preloadedQuery: PreloadedQuery<
|
62
|
+
TVariables,
|
63
|
+
TData,
|
64
|
+
$NonMaybeType<TRawResponse>,
|
65
|
+
>,
|
46
66
|
options?: {
|
47
67
|
UNSTABLE_renderPolicy?: RenderPolicy,
|
48
68
|
},
|
49
|
-
):
|
69
|
+
): TData {
|
50
70
|
// We need to use this hook in order to be able to track if
|
51
71
|
// loadQuery was called during render
|
52
72
|
useTrackLoadQueryInRender();
|
@@ -136,7 +156,12 @@ function usePreloadedQuery<TQuery: OperationType>(
|
|
136
156
|
};
|
137
157
|
}
|
138
158
|
|
139
|
-
const data = useLazyLoadQueryNode
|
159
|
+
const data = useLazyLoadQueryNode<{
|
160
|
+
variables: TVariables,
|
161
|
+
response: TData,
|
162
|
+
rawResponse?: $NonMaybeType<TRawResponse>,
|
163
|
+
}>(useLazyLoadQueryNodeParams);
|
164
|
+
|
140
165
|
if (__DEV__) {
|
141
166
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
142
167
|
useDebugValue({
|
@@ -151,4 +176,4 @@ function usePreloadedQuery<TQuery: OperationType>(
|
|
151
176
|
return data;
|
152
177
|
}
|
153
178
|
|
154
|
-
module.exports =
|
179
|
+
module.exports = usePreloadedQuery;
|
@@ -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,9 +17,10 @@ import type {
|
|
17
17
|
PreloadedQuery,
|
18
18
|
} from './EntryPointTypes.flow';
|
19
19
|
import type {
|
20
|
-
GraphQLTaggedNode,
|
21
20
|
IEnvironment,
|
22
21
|
OperationType,
|
22
|
+
Query,
|
23
|
+
Variables,
|
23
24
|
} from 'relay-runtime';
|
24
25
|
|
25
26
|
const {loadQuery, useTrackLoadQueryInRender} = require('./loadQuery');
|
@@ -38,12 +39,6 @@ export type UseQueryLoaderLoadQueryOptions = $ReadOnly<{
|
|
38
39
|
+__environment?: ?IEnvironment,
|
39
40
|
}>;
|
40
41
|
|
41
|
-
type UseQueryLoaderHookReturnType<TQuery: OperationType> = [
|
42
|
-
?PreloadedQuery<TQuery>,
|
43
|
-
LoaderFn<TQuery>,
|
44
|
-
() => void,
|
45
|
-
];
|
46
|
-
|
47
42
|
// NullQueryReference needs to implement referential equality,
|
48
43
|
// so that multiple NullQueryReferences can be in the same set
|
49
44
|
// (corresponding to multiple calls to disposeQuery).
|
@@ -52,20 +47,91 @@ type NullQueryReference = {
|
|
52
47
|
};
|
53
48
|
const initialNullQueryReferenceState = {kind: 'NullQueryReference'};
|
54
49
|
|
55
|
-
function requestIsLiveQuery<
|
56
|
-
|
50
|
+
function requestIsLiveQuery<
|
51
|
+
TVariables: Variables,
|
52
|
+
TData,
|
53
|
+
TRawResponse: ?{...} = void,
|
54
|
+
TQuery: OperationType = {
|
55
|
+
response: TData,
|
56
|
+
variables: TVariables,
|
57
|
+
rawResponse?: $NonMaybeType<TRawResponse>,
|
58
|
+
},
|
59
|
+
>(
|
60
|
+
preloadableRequest:
|
61
|
+
| Query<TVariables, TData, TRawResponse>
|
62
|
+
| PreloadableConcreteRequest<TQuery>,
|
57
63
|
): boolean {
|
58
64
|
if (preloadableRequest.kind === 'PreloadableConcreteRequest') {
|
59
|
-
return
|
65
|
+
return preloadableRequest.params.metadata.live !== undefined;
|
60
66
|
}
|
61
67
|
const request = getRequest(preloadableRequest);
|
62
68
|
return request.params.metadata.live !== undefined;
|
63
69
|
}
|
64
70
|
|
65
|
-
|
66
|
-
|
71
|
+
type UseQueryLoaderHookReturnType<
|
72
|
+
TVariables: Variables,
|
73
|
+
TData,
|
74
|
+
TRawResponse: ?{...} = void,
|
75
|
+
> = [
|
76
|
+
?PreloadedQuery<{
|
77
|
+
response: TData,
|
78
|
+
variables: TVariables,
|
79
|
+
rawResponse?: $NonMaybeType<TRawResponse>,
|
80
|
+
}>,
|
81
|
+
(variables: TVariables, options?: UseQueryLoaderLoadQueryOptions) => void,
|
82
|
+
() => void,
|
83
|
+
];
|
84
|
+
|
85
|
+
type ExtractVariablesType = <T>({+variables: T, ...}) => T;
|
86
|
+
type ExtractResponseType = <T>({+response: T, ...}) => T;
|
87
|
+
|
88
|
+
declare function useQueryLoader<
|
89
|
+
TVariables: Variables,
|
90
|
+
TData,
|
91
|
+
TRawResponse: ?{...} = void,
|
92
|
+
>(
|
93
|
+
preloadableRequest: Query<TVariables, TData, TRawResponse>,
|
94
|
+
): UseQueryLoaderHookReturnType<TVariables, TData>;
|
95
|
+
|
96
|
+
declare function useQueryLoader<
|
97
|
+
TVariables: Variables,
|
98
|
+
TData,
|
99
|
+
TRawResponse: ?{...} = void,
|
100
|
+
>(
|
101
|
+
preloadableRequest: Query<TVariables, TData, TRawResponse>,
|
102
|
+
initialQueryReference: ?PreloadedQuery<{
|
103
|
+
response: TData,
|
104
|
+
variables: TVariables,
|
105
|
+
rawResponse?: $NonMaybeType<TRawResponse>,
|
106
|
+
}>,
|
107
|
+
): UseQueryLoaderHookReturnType<TVariables, TData>;
|
108
|
+
|
109
|
+
declare function useQueryLoader<TQuery: OperationType>(
|
110
|
+
preloadableRequest: PreloadableConcreteRequest<TQuery>,
|
67
111
|
initialQueryReference?: ?PreloadedQuery<TQuery>,
|
68
|
-
): UseQueryLoaderHookReturnType<
|
112
|
+
): UseQueryLoaderHookReturnType<
|
113
|
+
$Call<ExtractVariablesType, TQuery>,
|
114
|
+
$Call<ExtractResponseType, TQuery>,
|
115
|
+
>;
|
116
|
+
|
117
|
+
function useQueryLoader<
|
118
|
+
TVariables: Variables,
|
119
|
+
TData,
|
120
|
+
TRawResponse: ?{...} = void,
|
121
|
+
>(
|
122
|
+
preloadableRequest: Query<TVariables, TData, TRawResponse>,
|
123
|
+
initialQueryReference?: ?PreloadedQuery<{
|
124
|
+
response: TData,
|
125
|
+
variables: TVariables,
|
126
|
+
rawResponse?: $NonMaybeType<TRawResponse>,
|
127
|
+
}>,
|
128
|
+
): UseQueryLoaderHookReturnType<TVariables, TData> {
|
129
|
+
type QueryType = {
|
130
|
+
response: TData,
|
131
|
+
variables: TVariables,
|
132
|
+
rawResponse?: $NonMaybeType<TRawResponse>,
|
133
|
+
};
|
134
|
+
|
69
135
|
/**
|
70
136
|
* We want to always call `queryReference.dispose()` for every call to
|
71
137
|
* `setQueryReference(loadQuery(...))` so that no leaks of data in Relay stores
|
@@ -94,15 +160,15 @@ function useQueryLoader<TQuery: OperationType>(
|
|
94
160
|
|
95
161
|
const isMountedRef = useIsMountedRef();
|
96
162
|
const undisposedQueryReferencesRef = useRef<
|
97
|
-
Set<PreloadedQuery<
|
163
|
+
Set<PreloadedQuery<QueryType> | NullQueryReference>,
|
98
164
|
>(new Set([initialQueryReferenceInternal]));
|
99
165
|
|
100
166
|
const [queryReference, setQueryReference] = useState<
|
101
|
-
PreloadedQuery<
|
167
|
+
PreloadedQuery<QueryType> | NullQueryReference,
|
102
168
|
>(() => initialQueryReferenceInternal);
|
103
169
|
|
104
170
|
const [previousInitialQueryReference, setPreviousInitialQueryReference] =
|
105
|
-
useState<PreloadedQuery<
|
171
|
+
useState<PreloadedQuery<QueryType> | NullQueryReference>(
|
106
172
|
() => initialQueryReferenceInternal,
|
107
173
|
);
|
108
174
|
|
@@ -125,10 +191,7 @@ function useQueryLoader<TQuery: OperationType>(
|
|
125
191
|
}, [isMountedRef]);
|
126
192
|
|
127
193
|
const queryLoaderCallback = useCallback(
|
128
|
-
(
|
129
|
-
variables: TQuery['variables'],
|
130
|
-
options?: ?UseQueryLoaderLoadQueryOptions,
|
131
|
-
) => {
|
194
|
+
(variables: TVariables, options?: ?UseQueryLoaderLoadQueryOptions) => {
|
132
195
|
const mergedOptions: ?UseQueryLoaderLoadQueryOptions =
|
133
196
|
options != null && options.hasOwnProperty('__environment')
|
134
197
|
? {
|
@@ -138,7 +201,7 @@ function useQueryLoader<TQuery: OperationType>(
|
|
138
201
|
}
|
139
202
|
: options;
|
140
203
|
if (isMountedRef.current) {
|
141
|
-
const updatedQueryReference = loadQuery(
|
204
|
+
const updatedQueryReference = loadQuery<QueryType>(
|
142
205
|
options?.__environment ?? environment,
|
143
206
|
preloadableRequest,
|
144
207
|
variables,
|
@@ -4,18 +4,19 @@
|
|
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 {
|
14
|
+
import type {Options} from './useRefetchableFragmentNode';
|
15
15
|
import type {
|
16
|
+
Disposable,
|
16
17
|
FragmentType,
|
17
|
-
|
18
|
-
|
18
|
+
RefetchableFragment,
|
19
|
+
Variables,
|
19
20
|
} from 'relay-runtime';
|
20
21
|
|
21
22
|
const HooksImplementation = require('./HooksImplementation');
|
@@ -24,66 +25,96 @@ const useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
|
|
24
25
|
const {useDebugValue} = require('react');
|
25
26
|
const {getFragment} = require('relay-runtime');
|
26
27
|
|
27
|
-
type
|
28
|
+
type RefetchVariables<TVariables, TKey> =
|
29
|
+
// NOTE: This $Call ensures that the type of the returned variables is either:
|
30
|
+
// - nullable if the provided ref type is nullable
|
31
|
+
// - non-nullable if the provided ref type is non-nullable
|
32
|
+
// prettier-ignore
|
33
|
+
$Call<
|
34
|
+
& (<TFragmentType>( { +$fragmentSpreads: TFragmentType, ... }) => $Shape<TVariables>)
|
35
|
+
& (<TFragmentType>(?{ +$fragmentSpreads: TFragmentType, ... }) => TVariables),
|
36
|
+
TKey,
|
37
|
+
>;
|
38
|
+
|
39
|
+
type RefetchFnBase<TVars, TOptions> = (
|
40
|
+
vars: TVars,
|
41
|
+
options?: TOptions,
|
42
|
+
) => Disposable;
|
43
|
+
|
44
|
+
export type RefetchFn<TVariables, TKey, TOptions = Options> = RefetchFnBase<
|
45
|
+
RefetchVariables<TVariables, TKey>,
|
46
|
+
TOptions,
|
47
|
+
>;
|
48
|
+
|
49
|
+
type ReturnType<TVariables, TData, TKey> = [
|
28
50
|
// NOTE: This $Call ensures that the type of the returned data is either:
|
29
51
|
// - nullable if the provided ref type is nullable
|
30
52
|
// - non-nullable if the provided ref type is non-nullable
|
31
53
|
// prettier-ignore
|
32
54
|
$Call<
|
33
|
-
& (<
|
34
|
-
& (<
|
55
|
+
& (<TFragmentType>( { +$fragmentSpreads: TFragmentType, ... }) => TData)
|
56
|
+
& (<TFragmentType>(?{ +$fragmentSpreads: TFragmentType, ... }) => ?TData),
|
35
57
|
TKey,
|
36
58
|
>,
|
37
|
-
|
59
|
+
RefetchFn<TVariables, TKey>,
|
38
60
|
];
|
39
61
|
|
40
|
-
// This separate type export is only needed as long as we are injecting
|
41
|
-
// a separate hooks implementation in ./HooksImplementation -- it can
|
42
|
-
// be removed after we stop doing that.
|
43
62
|
export type UseRefetchableFragmentType = <
|
44
|
-
|
45
|
-
|
63
|
+
TFragmentType: FragmentType,
|
64
|
+
TVariables: Variables,
|
65
|
+
TData,
|
66
|
+
TKey: ?{+$fragmentSpreads: TFragmentType, ...},
|
46
67
|
>(
|
47
|
-
|
48
|
-
|
49
|
-
) => ReturnType<
|
68
|
+
fragment: RefetchableFragment<TFragmentType, TData, TVariables>,
|
69
|
+
key: TKey,
|
70
|
+
) => ReturnType<TVariables, TData, TKey>;
|
50
71
|
|
51
72
|
function useRefetchableFragment_LEGACY<
|
52
|
-
|
53
|
-
|
73
|
+
TFragmentType: FragmentType,
|
74
|
+
TVariables: Variables,
|
75
|
+
TData,
|
76
|
+
TKey: ?{+$fragmentSpreads: TFragmentType, ...},
|
54
77
|
>(
|
55
|
-
fragmentInput:
|
78
|
+
fragmentInput: RefetchableFragment<TFragmentType, TData, TVariables>,
|
56
79
|
fragmentRef: TKey,
|
57
|
-
): ReturnType<
|
80
|
+
): ReturnType<TVariables, TData, TKey> {
|
58
81
|
const fragmentNode = getFragment(fragmentInput);
|
59
82
|
useStaticFragmentNodeWarning(
|
60
83
|
fragmentNode,
|
61
84
|
'first argument of useRefetchableFragment()',
|
62
85
|
);
|
63
|
-
const {fragmentData, refetch} = useRefetchableFragmentNode<
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
86
|
+
const {fragmentData, refetch} = useRefetchableFragmentNode<
|
87
|
+
{
|
88
|
+
response: TData,
|
89
|
+
variables: TVariables,
|
90
|
+
},
|
91
|
+
{
|
92
|
+
+$data: mixed,
|
93
|
+
...
|
94
|
+
},
|
95
|
+
>(fragmentNode, fragmentRef, 'useRefetchableFragment()');
|
68
96
|
if (__DEV__) {
|
69
97
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
70
98
|
useDebugValue({fragment: fragmentNode.name, data: fragmentData});
|
71
99
|
}
|
72
|
-
|
73
|
-
|
74
|
-
|
100
|
+
|
101
|
+
// $FlowFixMe[incompatible-return]
|
102
|
+
// $FlowFixMe[prop-missing]
|
103
|
+
return [fragmentData, refetch];
|
75
104
|
}
|
76
105
|
|
77
106
|
function useRefetchableFragment<
|
78
|
-
|
79
|
-
|
107
|
+
TFragmentType: FragmentType,
|
108
|
+
TVariables: Variables,
|
109
|
+
TData,
|
110
|
+
TKey: ?{+$fragmentSpreads: TFragmentType, ...},
|
80
111
|
>(
|
81
|
-
fragmentInput:
|
112
|
+
fragmentInput: RefetchableFragment<TFragmentType, TData, TVariables>,
|
82
113
|
parentFragmentRef: TKey,
|
83
|
-
): ReturnType<
|
114
|
+
): ReturnType<TVariables, TData, TKey> {
|
84
115
|
const impl = HooksImplementation.get();
|
85
116
|
if (impl) {
|
86
|
-
return impl.useRefetchableFragment<
|
117
|
+
return impl.useRefetchableFragment<TFragmentType, TVariables, TData, TKey>(
|
87
118
|
fragmentInput,
|
88
119
|
parentFragmentRef,
|
89
120
|
);
|
@@ -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';
|
@@ -207,8 +207,11 @@ function useRefetchableFragmentNode<
|
|
207
207
|
const shouldReset =
|
208
208
|
environment !== mirroredEnvironment ||
|
209
209
|
fragmentIdentifier !== mirroredFragmentIdentifier;
|
210
|
-
const [queryRef, loadQuery, disposeQuery] =
|
211
|
-
|
210
|
+
const [queryRef, loadQuery, disposeQuery] = useQueryLoader<
|
211
|
+
TQuery['variables'],
|
212
|
+
TQuery['response'],
|
213
|
+
TQuery['rawResponse'],
|
214
|
+
>((refetchableRequest: $FlowFixMe));
|
212
215
|
|
213
216
|
let fragmentRef = parentFragmentRef;
|
214
217
|
if (shouldReset) {
|
@@ -391,7 +394,10 @@ function useRefetchFunction<TQuery: OperationType>(
|
|
391
394
|
? fragmentData[identifierField]
|
392
395
|
: null;
|
393
396
|
return useCallback(
|
394
|
-
(
|
397
|
+
(
|
398
|
+
providedRefetchVariables: VariablesOf<TQuery>,
|
399
|
+
options: void | InternalOptions,
|
400
|
+
) => {
|
395
401
|
// Bail out and warn if we're trying to refetch after the component
|
396
402
|
// has unmounted
|
397
403
|
if (isMountedRef.current !== true) {
|
@@ -4,18 +4,18 @@
|
|
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 {IEnvironment} from 'relay-runtime';
|
15
15
|
|
16
|
+
const ReactRelayContext = require('./../ReactRelayContext');
|
16
17
|
const invariant = require('invariant');
|
17
18
|
const {useContext} = require('react');
|
18
|
-
const ReactRelayContext = require('react-relay/ReactRelayContext');
|
19
19
|
|
20
20
|
function useRelayEnvironment(): IEnvironment {
|
21
21
|
const context = useContext(ReactRelayContext);
|