react-relay 14.0.0 → 15.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ReactRelayContainerUtils.js.flow +1 -2
- package/ReactRelayContext.js +1 -1
- package/ReactRelayContext.js.flow +1 -2
- package/ReactRelayFragmentContainer.js.flow +6 -4
- package/ReactRelayFragmentMockRenderer.js.flow +1 -2
- package/ReactRelayLocalQueryRenderer.js.flow +5 -5
- package/ReactRelayPaginationContainer.js.flow +21 -14
- package/ReactRelayQueryFetcher.js.flow +28 -16
- package/ReactRelayQueryRenderer.js.flow +42 -13
- package/ReactRelayQueryRendererContext.js.flow +2 -3
- package/ReactRelayRefetchContainer.js.flow +9 -9
- package/ReactRelayTestMocker.js.flow +3 -3
- package/ReactRelayTypes.js.flow +7 -8
- package/RelayContext.js.flow +1 -2
- package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +4 -5
- package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +4 -5
- package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +4 -5
- package/__flowtests__/RelayModern-flowtest.js.flow +3 -4
- package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +3 -4
- package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +3 -4
- package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +3 -4
- package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +3 -4
- 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 -2
- package/buildReactRelayContainer.js.flow +7 -7
- package/getRootVariablesForFragments.js.flow +1 -3
- package/hooks.js +1 -1
- package/hooks.js.flow +4 -2
- package/index.js +1 -1
- package/index.js.flow +6 -2
- package/isRelayEnvironment.js.flow +1 -2
- 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 -2
- package/lib/ReactRelayContainerUtils.js +2 -3
- package/lib/ReactRelayContext.js +3 -4
- package/lib/ReactRelayFragmentContainer.js +47 -73
- package/lib/ReactRelayFragmentMockRenderer.js +2 -4
- package/lib/ReactRelayLocalQueryRenderer.js +18 -31
- package/lib/ReactRelayPaginationContainer.js +74 -164
- package/lib/ReactRelayQueryFetcher.js +49 -76
- package/lib/ReactRelayQueryRenderer.js +63 -84
- package/lib/ReactRelayQueryRendererContext.js +2 -2
- package/lib/ReactRelayRefetchContainer.js +58 -108
- package/lib/ReactRelayTestMocker.js +33 -68
- package/lib/ReactRelayTypes.js +2 -1
- package/lib/RelayContext.js +4 -7
- package/lib/assertFragmentMap.js +3 -5
- package/lib/buildReactRelayContainer.js +11 -27
- package/lib/getRootVariablesForFragments.js +6 -10
- package/lib/hooks.js +5 -18
- package/lib/index.js +7 -24
- package/lib/isRelayEnvironment.js +5 -4
- 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 -8
- package/lib/multi-actor/ActorChange.js +2 -5
- package/lib/multi-actor/index.js +2 -1
- package/lib/multi-actor/useRelayActorEnvironment.js +4 -8
- package/lib/relay-hooks/EntryPointContainer.react.js +9 -15
- package/lib/relay-hooks/EntryPointTypes.flow.js +5 -3
- package/lib/relay-hooks/FragmentResource.js +109 -203
- package/lib/relay-hooks/HooksImplementation.js +3 -6
- package/lib/relay-hooks/InternalLogger.js +2 -3
- package/lib/relay-hooks/LRUCache.js +2 -20
- package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +33 -54
- package/lib/relay-hooks/MatchContainer.js +15 -24
- package/lib/relay-hooks/ProfilerContext.js +3 -3
- package/lib/relay-hooks/QueryResource.js +31 -101
- package/lib/relay-hooks/RelayEnvironmentProvider.js +5 -9
- package/lib/relay-hooks/SuspenseResource.js +9 -33
- package/lib/relay-hooks/loadEntryPoint.js +19 -31
- package/lib/relay-hooks/loadQuery.js +42 -78
- package/lib/relay-hooks/preloadQuery_DEPRECATED.js +11 -37
- package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +9 -15
- package/lib/relay-hooks/react-cache/RelayReactCache.js +7 -12
- package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +27 -81
- package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +206 -0
- package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +195 -215
- package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +5 -15
- package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +17 -24
- package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +149 -0
- package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +24 -39
- package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +325 -0
- package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +37 -0
- package/lib/relay-hooks/useBlockingPaginationFragment.js +73 -93
- package/lib/relay-hooks/useClientQuery.js +30 -0
- package/lib/relay-hooks/useEntryPointLoader.js +18 -38
- package/lib/relay-hooks/useFetchTrackingRef.js +10 -12
- package/lib/relay-hooks/useFragment.js +8 -19
- package/lib/relay-hooks/useFragmentNode.js +20 -32
- package/lib/relay-hooks/useIsMountedRef.js +4 -6
- package/lib/relay-hooks/useIsOperationNodeActive.js +8 -20
- package/lib/relay-hooks/useIsParentQueryActive.js +3 -6
- package/lib/relay-hooks/useLazyLoadQuery.js +7 -24
- package/lib/relay-hooks/useLazyLoadQueryNode.js +23 -34
- package/lib/relay-hooks/useLoadMoreFunction.js +46 -78
- package/lib/relay-hooks/useMemoOperationDescriptor.js +6 -15
- package/lib/relay-hooks/useMemoVariables.js +15 -34
- package/lib/relay-hooks/useMutation.js +9 -27
- package/lib/relay-hooks/usePaginationFragment.js +73 -76
- package/lib/relay-hooks/usePreloadedQuery.js +13 -44
- package/lib/relay-hooks/useQueryLoader.js +24 -49
- package/lib/relay-hooks/useRefetchableFragment.js +19 -17
- package/lib/relay-hooks/useRefetchableFragmentNode.js +65 -109
- package/lib/relay-hooks/useRelayEnvironment.js +4 -8
- package/lib/relay-hooks/useStaticFragmentNodeWarning.js +4 -8
- package/lib/relay-hooks/useSubscribeToInvalidationState.js +8 -9
- package/lib/relay-hooks/useSubscription.js +5 -10
- 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 -4
- 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 +3 -5
- package/relay-hooks/EntryPointTypes.flow.js.flow +37 -37
- package/relay-hooks/FragmentResource.js.flow +43 -19
- package/relay-hooks/HooksImplementation.js.flow +7 -9
- package/relay-hooks/InternalLogger.js.flow +1 -3
- package/relay-hooks/LRUCache.js.flow +1 -3
- package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +19 -14
- package/relay-hooks/MatchContainer.js.flow +6 -8
- package/relay-hooks/ProfilerContext.js.flow +1 -3
- package/relay-hooks/QueryResource.js.flow +29 -11
- package/relay-hooks/RelayEnvironmentProvider.js.flow +4 -6
- package/relay-hooks/SuspenseResource.js.flow +1 -3
- package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +6 -4
- package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +4 -4
- 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 +39 -39
- package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +1 -3
- package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +37 -38
- package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +18 -20
- package/relay-hooks/__flowtests__/utils.js.flow +21 -12
- package/relay-hooks/loadEntryPoint.js.flow +11 -6
- package/relay-hooks/loadQuery.js.flow +11 -7
- package/relay-hooks/preloadQuery_DEPRECATED.js.flow +9 -12
- package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +13 -10
- package/relay-hooks/react-cache/RelayReactCache.js.flow +1 -3
- package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +26 -20
- package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +297 -0
- package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +136 -96
- package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +1 -3
- package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +3 -5
- package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +190 -0
- package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +3 -6
- package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +601 -0
- package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +65 -0
- package/relay-hooks/useBlockingPaginationFragment.js.flow +86 -59
- package/relay-hooks/useClientQuery.js.flow +39 -0
- package/relay-hooks/useEntryPointLoader.js.flow +16 -14
- package/relay-hooks/useFetchTrackingRef.js.flow +7 -8
- package/relay-hooks/useFragment.js.flow +2 -4
- package/relay-hooks/useFragmentNode.js.flow +7 -8
- package/relay-hooks/useIsMountedRef.js.flow +2 -4
- package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
- package/relay-hooks/useIsParentQueryActive.js.flow +1 -1
- package/relay-hooks/useLazyLoadQuery.js.flow +9 -32
- package/relay-hooks/useLazyLoadQueryNode.js.flow +4 -6
- package/relay-hooks/useLoadMoreFunction.js.flow +20 -17
- package/relay-hooks/useMemoOperationDescriptor.js.flow +3 -5
- package/relay-hooks/useMemoVariables.js.flow +13 -31
- package/relay-hooks/useMutation.js.flow +6 -8
- package/relay-hooks/usePaginationFragment.js.flow +75 -43
- package/relay-hooks/usePreloadedQuery.js.flow +49 -43
- package/relay-hooks/useQueryLoader.js.flow +89 -28
- package/relay-hooks/useRefetchableFragment.js.flow +83 -23
- package/relay-hooks/useRefetchableFragmentNode.js.flow +26 -22
- package/relay-hooks/useRelayEnvironment.js.flow +2 -4
- package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -5
- package/relay-hooks/useSubscribeToInvalidationState.js.flow +2 -4
- package/relay-hooks/useSubscription.js.flow +1 -3
- package/relay-hooks/useUnsafeRef_DEPRECATED.js.flow +25 -0
- package/lib/readContext.js +0 -28
- package/readContext.js.flow +0 -31
|
@@ -4,23 +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
|
-
// flowlint ambiguous-object-type:error
|
|
13
|
-
|
|
14
12
|
'use strict';
|
|
15
13
|
|
|
14
|
+
import type {RefetchableFragment} from '../../relay-runtime/util/RelayRuntimeTypes';
|
|
16
15
|
import type {LoadMoreFn, UseLoadMoreFunctionArgs} from './useLoadMoreFunction';
|
|
17
|
-
import type {
|
|
16
|
+
import type {Options} from './useRefetchableFragmentNode';
|
|
18
17
|
import type {
|
|
18
|
+
Disposable,
|
|
19
19
|
FragmentType,
|
|
20
20
|
GraphQLResponse,
|
|
21
|
-
GraphQLTaggedNode,
|
|
22
21
|
Observer,
|
|
23
|
-
|
|
22
|
+
Variables,
|
|
24
23
|
} from 'relay-runtime';
|
|
25
24
|
|
|
26
25
|
const useLoadMoreFunction = require('./useLoadMoreFunction');
|
|
@@ -34,35 +33,54 @@ const {
|
|
|
34
33
|
getPaginationMetadata,
|
|
35
34
|
} = require('relay-runtime');
|
|
36
35
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
+
>;
|
|
45
46
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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> = {
|
|
56
58
|
// NOTE: This $Call ensures that the type of the returned data is either:
|
|
57
59
|
// - nullable if the provided ref type is nullable
|
|
58
60
|
// - non-nullable if the provided ref type is non-nullable
|
|
59
61
|
// prettier-ignore
|
|
60
|
-
$Call<
|
|
61
|
-
& (<
|
|
62
|
-
& (<
|
|
62
|
+
data: $Call<
|
|
63
|
+
& (<TFragmentType>( { +$fragmentSpreads: TFragmentType, ... }) => TData)
|
|
64
|
+
& (<TFragmentType>(?{ +$fragmentSpreads: TFragmentType, ... }) => ?TData),
|
|
63
65
|
TKey,
|
|
64
66
|
>,
|
|
65
|
-
|
|
67
|
+
loadNext: LoadMoreFn<TVariables>,
|
|
68
|
+
loadPrevious: LoadMoreFn<TVariables>,
|
|
69
|
+
hasNext: boolean,
|
|
70
|
+
hasPrevious: boolean,
|
|
71
|
+
refetch: RefetchFn<TVariables, TKey>,
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
function useBlockingPaginationFragment<
|
|
75
|
+
TFragmentType: FragmentType,
|
|
76
|
+
TVariables: Variables,
|
|
77
|
+
TData,
|
|
78
|
+
TKey: ?{+$fragmentSpreads: TFragmentType, ...},
|
|
79
|
+
>(
|
|
80
|
+
fragmentInput: RefetchableFragment<TFragmentType, TData, TVariables>,
|
|
81
|
+
parentFragmentRef: TKey,
|
|
82
|
+
componentDisplayName: string = 'useBlockingPaginationFragment()',
|
|
83
|
+
): ReturnType<TVariables, TData, TKey> {
|
|
66
84
|
const fragmentNode = getFragment(fragmentInput);
|
|
67
85
|
useStaticFragmentNodeWarning(
|
|
68
86
|
fragmentNode,
|
|
@@ -88,33 +106,39 @@ function useBlockingPaginationFragment<
|
|
|
88
106
|
refetch,
|
|
89
107
|
disableStoreUpdates,
|
|
90
108
|
enableStoreUpdates,
|
|
91
|
-
} = useRefetchableFragmentNode<
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
109
|
+
} = useRefetchableFragmentNode<
|
|
110
|
+
{
|
|
111
|
+
response: TData,
|
|
112
|
+
variables: TVariables,
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
+$data: mixed,
|
|
116
|
+
...
|
|
117
|
+
},
|
|
118
|
+
>(fragmentNode, parentFragmentRef, componentDisplayName);
|
|
96
119
|
const fragmentIdentifier = getFragmentIdentifier(fragmentNode, fragmentRef);
|
|
97
120
|
|
|
98
121
|
// Backward pagination
|
|
99
|
-
const [loadPrevious, hasPrevious, disposeFetchPrevious] = useLoadMore<
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
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
|
+
});
|
|
115
139
|
|
|
116
140
|
// Forward pagination
|
|
117
|
-
const [loadNext, hasNext, disposeFetchNext] = useLoadMore<
|
|
141
|
+
const [loadNext, hasNext, disposeFetchNext] = useLoadMore<TVariables, TData>({
|
|
118
142
|
componentDisplayName,
|
|
119
143
|
connectionPathInFragmentData,
|
|
120
144
|
direction: 'forward',
|
|
@@ -129,8 +153,8 @@ function useBlockingPaginationFragment<
|
|
|
129
153
|
paginationRequest,
|
|
130
154
|
});
|
|
131
155
|
|
|
132
|
-
const refetchPagination:
|
|
133
|
-
(variables, options) => {
|
|
156
|
+
const refetchPagination: RefetchFn<TVariables, TKey> = useCallback(
|
|
157
|
+
(variables: TVariables, options: void | Options) => {
|
|
134
158
|
disposeFetchNext();
|
|
135
159
|
disposeFetchPrevious();
|
|
136
160
|
return refetch(variables, {...options, __environment: undefined});
|
|
@@ -139,7 +163,8 @@ function useBlockingPaginationFragment<
|
|
|
139
163
|
);
|
|
140
164
|
|
|
141
165
|
return {
|
|
142
|
-
|
|
166
|
+
// $FlowFixMe[incompatible-cast]
|
|
167
|
+
data: (fragmentData: TData),
|
|
143
168
|
loadNext,
|
|
144
169
|
loadPrevious,
|
|
145
170
|
hasNext,
|
|
@@ -148,7 +173,7 @@ function useBlockingPaginationFragment<
|
|
|
148
173
|
};
|
|
149
174
|
}
|
|
150
175
|
|
|
151
|
-
function useLoadMore<
|
|
176
|
+
function useLoadMore<TVariables: Variables>(args: {
|
|
152
177
|
disableStoreUpdates: () => void,
|
|
153
178
|
enableStoreUpdates: () => void,
|
|
154
179
|
...$Exact<
|
|
@@ -161,11 +186,13 @@ function useLoadMore<TQuery: OperationType>(args: {|
|
|
|
161
186
|
},
|
|
162
187
|
>,
|
|
163
188
|
>,
|
|
164
|
-
|
|
189
|
+
}): [LoadMoreFn<TVariables>, boolean, () => void] {
|
|
165
190
|
const {disableStoreUpdates, enableStoreUpdates, ...loadMoreArgs} = args;
|
|
166
|
-
const [requestPromise, setRequestPromise] = useState(
|
|
167
|
-
|
|
168
|
-
|
|
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);
|
|
169
196
|
|
|
170
197
|
const promiseResolve = () => {
|
|
171
198
|
if (promiseResolveRef.current != null) {
|
|
@@ -210,7 +237,7 @@ function useLoadMore<TQuery: OperationType>(args: {|
|
|
|
210
237
|
// and blow away the whole list of items.
|
|
211
238
|
error: promiseResolve,
|
|
212
239
|
};
|
|
213
|
-
const [loadMore, hasMore, disposeFetch] = useLoadMoreFunction<
|
|
240
|
+
const [loadMore, hasMore, disposeFetch] = useLoadMoreFunction<TVariables>({
|
|
214
241
|
...loadMoreArgs,
|
|
215
242
|
observer,
|
|
216
243
|
onReset: handleReset,
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @flow strict-local
|
|
8
|
+
* @format
|
|
9
|
+
* @oncall relay
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
import type {ClientQuery, Query, RenderPolicy, Variables} from 'relay-runtime';
|
|
15
|
+
|
|
16
|
+
const useLazyLoadQuery = require('./useLazyLoadQuery');
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* This hook can be used to render client-only queries.
|
|
20
|
+
* These queries are consist of queries for client-only data,
|
|
21
|
+
* schematized via local schema extensions and/or Relay resolvers.
|
|
22
|
+
*/
|
|
23
|
+
function useClientQuery<TVariables: Variables, TData>(
|
|
24
|
+
gqlQuery: ClientQuery<TVariables, TData>,
|
|
25
|
+
variables: TVariables,
|
|
26
|
+
options?: {
|
|
27
|
+
UNSTABLE_renderPolicy?: RenderPolicy,
|
|
28
|
+
},
|
|
29
|
+
): TData {
|
|
30
|
+
// $FlowFixMe[incompatible-type] client queries can be used with useLazyLoadQuery, but only with `store-only` policy.
|
|
31
|
+
const query: Query<TVariables, TData> = gqlQuery;
|
|
32
|
+
|
|
33
|
+
return useLazyLoadQuery(query, variables, {
|
|
34
|
+
...options,
|
|
35
|
+
fetchPolicy: 'store-only',
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
module.exports = useClientQuery;
|
|
@@ -4,13 +4,11 @@
|
|
|
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
|
-
// flowlint ambiguous-object-type:error
|
|
13
|
-
|
|
14
12
|
'use strict';
|
|
15
13
|
|
|
16
14
|
import type {
|
|
@@ -47,9 +45,9 @@ type UseEntryPointLoaderHookReturnType<
|
|
|
47
45
|
// NullEntryPointReference needs to implement referential equality,
|
|
48
46
|
// so that multiple NullEntryPointReferences can be in the same set
|
|
49
47
|
// (corresponding to multiple calls to disposeEntryPoint).
|
|
50
|
-
type NullEntryPointReference = {
|
|
48
|
+
type NullEntryPointReference = {
|
|
51
49
|
kind: 'NullEntryPointReference',
|
|
52
|
-
|
|
50
|
+
};
|
|
53
51
|
const initialNullEntryPointReferenceState = {kind: 'NullEntryPointReference'};
|
|
54
52
|
|
|
55
53
|
function useLoadEntryPoint<
|
|
@@ -68,14 +66,14 @@ function useLoadEntryPoint<
|
|
|
68
66
|
>(
|
|
69
67
|
environmentProvider: IEnvironmentProvider<EnvironmentProviderOptions>,
|
|
70
68
|
entryPoint: TEntryPoint,
|
|
71
|
-
options?: ?{
|
|
69
|
+
options?: ?{
|
|
72
70
|
// TODO(T83890478): Remove once Offscreen API lands in xplat
|
|
73
71
|
// and we can use it in tests
|
|
74
|
-
TEST_ONLY__initialEntryPointData?: ?{
|
|
72
|
+
TEST_ONLY__initialEntryPointData?: ?{
|
|
75
73
|
entryPointReference: ?PreloadedEntryPoint<TEntryPointComponent>,
|
|
76
74
|
entryPointParams: ?TEntryPointParams,
|
|
77
|
-
|
|
78
|
-
|
|
75
|
+
},
|
|
76
|
+
},
|
|
79
77
|
): UseEntryPointLoaderHookReturnType<
|
|
80
78
|
TEntryPointParams,
|
|
81
79
|
TPreloadedQueries,
|
|
@@ -136,11 +134,15 @@ function useLoadEntryPoint<
|
|
|
136
134
|
const entryPointLoaderCallback = useCallback(
|
|
137
135
|
(params: TEntryPointParams) => {
|
|
138
136
|
if (isMountedRef.current) {
|
|
139
|
-
const updatedEntryPointReference = loadEntryPoint
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
137
|
+
const updatedEntryPointReference = loadEntryPoint<
|
|
138
|
+
TEntryPointParams,
|
|
139
|
+
TPreloadedQueries,
|
|
140
|
+
TPreloadedEntryPoints,
|
|
141
|
+
TRuntimeProps,
|
|
142
|
+
TExtraProps,
|
|
143
|
+
TEntryPointComponent,
|
|
144
|
+
TEntryPoint,
|
|
145
|
+
>(environmentProvider, entryPoint, params);
|
|
144
146
|
undisposedEntryPointReferencesRef.current.add(
|
|
145
147
|
updatedEntryPointReference,
|
|
146
148
|
);
|
|
@@ -4,18 +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
|
-
// flowlint ambiguous-object-type:error
|
|
13
|
-
|
|
14
12
|
'use strict';
|
|
15
13
|
|
|
16
14
|
import type {Subscription} from 'relay-runtime';
|
|
17
15
|
|
|
18
|
-
const
|
|
16
|
+
const useUnsafeRef_DEPRECATED = require('./useUnsafeRef_DEPRECATED');
|
|
17
|
+
const {useCallback, useEffect} = require('react');
|
|
19
18
|
|
|
20
19
|
/**
|
|
21
20
|
* This hook returns a mutable React ref that holds the value of whether a
|
|
@@ -29,14 +28,14 @@ const {useCallback, useEffect, useRef} = require('react');
|
|
|
29
28
|
* The additional functions returned by this Hook can be used to mutate
|
|
30
29
|
* the ref.
|
|
31
30
|
*/
|
|
32
|
-
function useFetchTrackingRef(): {
|
|
31
|
+
function useFetchTrackingRef(): {
|
|
33
32
|
isFetchingRef: {current: ?boolean, ...},
|
|
34
33
|
startFetch: Subscription => void,
|
|
35
34
|
disposeFetch: () => void,
|
|
36
35
|
completeFetch: () => void,
|
|
37
|
-
|
|
38
|
-
const subscriptionRef =
|
|
39
|
-
const isFetchingRef =
|
|
36
|
+
} {
|
|
37
|
+
const subscriptionRef = useUnsafeRef_DEPRECATED<?Subscription>(null);
|
|
38
|
+
const isFetchingRef = useUnsafeRef_DEPRECATED<?boolean>(false);
|
|
40
39
|
|
|
41
40
|
const disposeFetch = useCallback(() => {
|
|
42
41
|
if (subscriptionRef.current != null) {
|
|
@@ -4,13 +4,11 @@
|
|
|
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
|
-
// flowlint ambiguous-object-type:error
|
|
13
|
-
|
|
14
12
|
'use strict';
|
|
15
13
|
|
|
16
14
|
import type {Fragment, FragmentType, GraphQLTaggedNode} from 'relay-runtime';
|
|
@@ -52,7 +50,7 @@ function useFragment_LEGACY(fragment: GraphQLTaggedNode, key: mixed): mixed {
|
|
|
52
50
|
|
|
53
51
|
const fragmentNode = getFragment(fragment);
|
|
54
52
|
useStaticFragmentNodeWarning(fragmentNode, 'first argument of useFragment()');
|
|
55
|
-
const {data} = useFragmentNode<
|
|
53
|
+
const {data} = useFragmentNode<mixed>(fragmentNode, key, 'useFragment()');
|
|
56
54
|
if (__DEV__) {
|
|
57
55
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
58
56
|
useDebugValue({fragment: fragmentNode.name, data});
|
|
@@ -4,28 +4,27 @@
|
|
|
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
|
-
// flowlint ambiguous-object-type:error
|
|
13
|
-
|
|
14
12
|
'use strict';
|
|
15
13
|
|
|
16
14
|
import type {ReaderFragment} from 'relay-runtime';
|
|
17
15
|
|
|
18
16
|
const {getFragmentResourceForEnvironment} = require('./FragmentResource');
|
|
19
17
|
const useRelayEnvironment = require('./useRelayEnvironment');
|
|
20
|
-
const
|
|
18
|
+
const useUnsafeRef_DEPRECATED = require('./useUnsafeRef_DEPRECATED');
|
|
19
|
+
const {useEffect, useState} = require('react');
|
|
21
20
|
const {getFragmentIdentifier} = require('relay-runtime');
|
|
22
21
|
const warning = require('warning');
|
|
23
22
|
|
|
24
|
-
type ReturnType<TFragmentData: mixed> = {
|
|
23
|
+
type ReturnType<TFragmentData: mixed> = {
|
|
25
24
|
data: TFragmentData,
|
|
26
25
|
disableStoreUpdates: () => void,
|
|
27
26
|
enableStoreUpdates: () => void,
|
|
28
|
-
|
|
27
|
+
};
|
|
29
28
|
|
|
30
29
|
function useFragmentNode<TFragmentData: mixed>(
|
|
31
30
|
fragmentNode: ReaderFragment,
|
|
@@ -35,7 +34,7 @@ function useFragmentNode<TFragmentData: mixed>(
|
|
|
35
34
|
const environment = useRelayEnvironment();
|
|
36
35
|
const FragmentResource = getFragmentResourceForEnvironment(environment);
|
|
37
36
|
|
|
38
|
-
const isMountedRef =
|
|
37
|
+
const isMountedRef = useUnsafeRef_DEPRECATED(false);
|
|
39
38
|
const [, forceUpdate] = useState(0);
|
|
40
39
|
const fragmentIdentifier = getFragmentIdentifier(fragmentNode, fragmentRef);
|
|
41
40
|
|
|
@@ -47,7 +46,7 @@ function useFragmentNode<TFragmentData: mixed>(
|
|
|
47
46
|
componentDisplayName,
|
|
48
47
|
);
|
|
49
48
|
|
|
50
|
-
const isListeningForUpdatesRef =
|
|
49
|
+
const isListeningForUpdatesRef = useUnsafeRef_DEPRECATED(true);
|
|
51
50
|
function enableStoreUpdates() {
|
|
52
51
|
isListeningForUpdatesRef.current = true;
|
|
53
52
|
const didMissUpdates =
|
|
@@ -4,18 +4,16 @@
|
|
|
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
|
-
// flowlint ambiguous-object-type:error
|
|
13
|
-
|
|
14
12
|
'use strict';
|
|
15
13
|
|
|
16
14
|
const {useEffect, useRef} = require('react');
|
|
17
15
|
|
|
18
|
-
function useIsMountedRef(): {
|
|
16
|
+
function useIsMountedRef(): {current: boolean} {
|
|
19
17
|
const isMountedRef = useRef(true);
|
|
20
18
|
|
|
21
19
|
useEffect(() => {
|
|
@@ -4,25 +4,21 @@
|
|
|
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
|
-
// flowlint ambiguous-object-type:error
|
|
13
|
-
|
|
14
12
|
'use strict';
|
|
15
13
|
|
|
16
14
|
import type {
|
|
17
15
|
CacheConfig,
|
|
18
|
-
ClientQuery,
|
|
19
16
|
FetchPolicy,
|
|
20
17
|
Query,
|
|
21
18
|
RenderPolicy,
|
|
22
19
|
Variables,
|
|
23
20
|
} from 'relay-runtime';
|
|
24
21
|
|
|
25
|
-
const HooksImplementation = require('./HooksImplementation');
|
|
26
22
|
const {useTrackLoadQueryInRender} = require('./loadQuery');
|
|
27
23
|
const useLazyLoadQueryNode = require('./useLazyLoadQueryNode');
|
|
28
24
|
const useMemoOperationDescriptor = require('./useMemoOperationDescriptor');
|
|
@@ -35,25 +31,25 @@ const {
|
|
|
35
31
|
// a separate hooks implementation in ./HooksImplementation -- it can
|
|
36
32
|
// be removed after we stop doing that.
|
|
37
33
|
export type UseLazyLoadQueryHookType = <TVariables: Variables, TData>(
|
|
38
|
-
gqlQuery: Query<TVariables, TData
|
|
34
|
+
gqlQuery: Query<TVariables, TData>,
|
|
39
35
|
variables: TVariables,
|
|
40
|
-
options?: {
|
|
36
|
+
options?: {
|
|
41
37
|
fetchKey?: string | number,
|
|
42
38
|
fetchPolicy?: FetchPolicy,
|
|
43
39
|
networkCacheConfig?: CacheConfig,
|
|
44
40
|
UNSTABLE_renderPolicy?: RenderPolicy,
|
|
45
|
-
|
|
41
|
+
},
|
|
46
42
|
) => TData;
|
|
47
43
|
|
|
48
|
-
function
|
|
49
|
-
gqlQuery: Query<TVariables, TData
|
|
44
|
+
function useLazyLoadQuery<TVariables: Variables, TData>(
|
|
45
|
+
gqlQuery: Query<TVariables, TData>,
|
|
50
46
|
variables: TVariables,
|
|
51
|
-
options?: {
|
|
47
|
+
options?: {
|
|
52
48
|
fetchKey?: string | number,
|
|
53
49
|
fetchPolicy?: FetchPolicy,
|
|
54
50
|
networkCacheConfig?: CacheConfig,
|
|
55
51
|
UNSTABLE_renderPolicy?: RenderPolicy,
|
|
56
|
-
|
|
52
|
+
},
|
|
57
53
|
): TData {
|
|
58
54
|
// We need to use this hook in order to be able to track if
|
|
59
55
|
// loadQuery was called during render
|
|
@@ -68,7 +64,7 @@ function useLazyLoadQuery_LEGACY<TVariables: Variables, TData>(
|
|
|
68
64
|
? options.networkCacheConfig
|
|
69
65
|
: {force: true},
|
|
70
66
|
);
|
|
71
|
-
const data = useLazyLoadQueryNode({
|
|
67
|
+
const data = useLazyLoadQueryNode<$FlowFixMe>({
|
|
72
68
|
componentDisplayName: 'useLazyLoadQuery()',
|
|
73
69
|
fetchKey: options?.fetchKey,
|
|
74
70
|
fetchObservable: fetchQuery(environment, query),
|
|
@@ -79,23 +75,4 @@ function useLazyLoadQuery_LEGACY<TVariables: Variables, TData>(
|
|
|
79
75
|
return data;
|
|
80
76
|
}
|
|
81
77
|
|
|
82
|
-
function useLazyLoadQuery<TVariables: Variables, TData>(
|
|
83
|
-
gqlQuery: Query<TVariables, TData> | ClientQuery<TVariables, TData>,
|
|
84
|
-
variables: TVariables,
|
|
85
|
-
options?: {|
|
|
86
|
-
fetchKey?: string | number,
|
|
87
|
-
fetchPolicy?: FetchPolicy,
|
|
88
|
-
networkCacheConfig?: CacheConfig,
|
|
89
|
-
UNSTABLE_renderPolicy?: RenderPolicy,
|
|
90
|
-
|},
|
|
91
|
-
): TData {
|
|
92
|
-
const impl = HooksImplementation.get();
|
|
93
|
-
if (impl) {
|
|
94
|
-
return impl.useLazyLoadQuery(gqlQuery, variables, options);
|
|
95
|
-
} else {
|
|
96
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
97
|
-
return useLazyLoadQuery_LEGACY(gqlQuery, variables, options);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
78
|
module.exports = (useLazyLoadQuery: UseLazyLoadQueryHookType);
|
|
@@ -4,13 +4,11 @@
|
|
|
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
|
-
// flowlint ambiguous-object-type:error
|
|
13
|
-
|
|
14
12
|
'use strict';
|
|
15
13
|
|
|
16
14
|
import type {
|
|
@@ -41,14 +39,14 @@ function useLazyLoadQueryNode<TQuery: OperationType>({
|
|
|
41
39
|
fetchPolicy,
|
|
42
40
|
fetchKey,
|
|
43
41
|
renderPolicy,
|
|
44
|
-
}: {
|
|
42
|
+
}: {
|
|
45
43
|
query: OperationDescriptor,
|
|
46
44
|
componentDisplayName: string,
|
|
47
45
|
fetchObservable: Observable<GraphQLResponse>,
|
|
48
46
|
fetchPolicy?: ?FetchPolicy,
|
|
49
47
|
fetchKey?: ?string | ?number,
|
|
50
48
|
renderPolicy?: ?RenderPolicy,
|
|
51
|
-
|
|
49
|
+
}): TQuery['response'] {
|
|
52
50
|
const environment = useRelayEnvironment();
|
|
53
51
|
const profilerContext = useContext(ProfilerContext);
|
|
54
52
|
const QueryResource = getQueryResourceForEnvironment(environment);
|
|
@@ -127,7 +125,7 @@ function useLazyLoadQueryNode<TQuery: OperationType>({
|
|
|
127
125
|
});
|
|
128
126
|
|
|
129
127
|
const {fragmentNode, fragmentRef} = preparedQueryResult;
|
|
130
|
-
const {data} = useFragmentNode(
|
|
128
|
+
const {data} = useFragmentNode<$FlowFixMe>(
|
|
131
129
|
fragmentNode,
|
|
132
130
|
fragmentRef,
|
|
133
131
|
componentDisplayName,
|