react-relay 17.0.0 → 18.1.0
Sign up to get free protection for your applications and to get access to all the features.
- package/ReactRelayContainerUtils.js.flow +2 -2
- package/ReactRelayContext.js +1 -1
- package/ReactRelayContext.js.flow +1 -1
- package/ReactRelayFragmentContainer.js.flow +2 -2
- package/ReactRelayPaginationContainer.js.flow +2 -2
- package/ReactRelayQueryRenderer.js.flow +1 -1
- package/ReactRelayQueryRendererContext.js.flow +1 -1
- package/ReactRelayRefetchContainer.js.flow +2 -2
- package/ReactRelayTypes.js.flow +45 -18
- package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +2 -2
- package/buildReactRelayContainer.js.flow +6 -5
- package/hooks.js +1 -1
- package/index.js +1 -1
- package/legacy.js +1 -1
- package/lib/relay-hooks/getConnectionState.js +47 -0
- package/lib/relay-hooks/legacy/FragmentResource.js +2 -6
- package/lib/relay-hooks/loadEntryPoint.js +8 -5
- package/lib/relay-hooks/loadQuery.js +2 -14
- package/lib/relay-hooks/readFragmentInternal.js +2 -4
- package/lib/relay-hooks/useEntryPointLoader.js +5 -8
- package/lib/relay-hooks/useFragment.js +4 -7
- package/lib/relay-hooks/useFragmentInternal.js +6 -484
- package/lib/relay-hooks/useFragmentInternal_CURRENT.js +477 -0
- package/lib/relay-hooks/useFragmentInternal_EXPERIMENTAL.js +499 -0
- package/lib/relay-hooks/useLazyLoadQuery.js +2 -5
- package/lib/relay-hooks/useLoadMoreFunction.js +10 -43
- package/lib/relay-hooks/useLoadMoreFunction_EXPERIMENTAL.js +130 -0
- package/lib/relay-hooks/usePreloadedQuery.js +6 -9
- package/lib/relay-hooks/useQueryLoader.js +9 -3
- package/lib/relay-hooks/useQueryLoader_EXPERIMENTAL.js +120 -0
- package/multi-actor/ActorChange.js.flow +1 -1
- package/package.json +3 -3
- package/react-relay-hooks.js +2 -2
- package/react-relay-hooks.min.js +2 -2
- package/react-relay-legacy.js +1 -1
- package/react-relay-legacy.min.js +1 -1
- package/react-relay.js +2 -2
- package/react-relay.min.js +2 -2
- package/relay-hooks/EntryPointTypes.flow.js.flow +35 -12
- package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +8 -4
- package/relay-hooks/MatchContainer.js.flow +1 -1
- package/relay-hooks/ProfilerContext.js.flow +1 -1
- package/relay-hooks/__flowtests__/EntryPointTypes/ExtractQueryTypes-flowtest.js.flow +43 -0
- package/relay-hooks/getConnectionState.js.flow +97 -0
- package/relay-hooks/legacy/FragmentResource.js.flow +2 -13
- package/relay-hooks/loadEntryPoint.js.flow +10 -4
- package/relay-hooks/loadQuery.js.flow +4 -28
- package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +4 -1
- package/relay-hooks/readFragmentInternal.js.flow +1 -10
- package/relay-hooks/useEntryPointLoader.js.flow +3 -4
- package/relay-hooks/useFragment.js.flow +0 -5
- package/relay-hooks/useFragmentInternal.js.flow +19 -643
- package/relay-hooks/useFragmentInternal_CURRENT.js.flow +656 -0
- package/relay-hooks/useFragmentInternal_EXPERIMENTAL.js.flow +718 -0
- package/relay-hooks/useLazyLoadQuery.js.flow +0 -5
- package/relay-hooks/useLoadMoreFunction.js.flow +14 -80
- package/relay-hooks/useLoadMoreFunction_EXPERIMENTAL.js.flow +280 -0
- package/relay-hooks/usePaginationFragment.js.flow +1 -1
- package/relay-hooks/usePreloadedQuery.js.flow +0 -5
- package/relay-hooks/useQueryLoader.js.flow +28 -5
- package/relay-hooks/useQueryLoader_EXPERIMENTAL.js.flow +253 -0
@@ -19,7 +19,6 @@ import type {
|
|
19
19
|
Variables,
|
20
20
|
} from 'relay-runtime';
|
21
21
|
|
22
|
-
const {useTrackLoadQueryInRender} = require('./loadQuery');
|
23
22
|
const useLazyLoadQueryNode = require('./useLazyLoadQueryNode');
|
24
23
|
const useMemoOperationDescriptor = require('./useMemoOperationDescriptor');
|
25
24
|
const useRelayEnvironment = require('./useRelayEnvironment');
|
@@ -51,10 +50,6 @@ hook useLazyLoadQuery<TVariables: Variables, TData>(
|
|
51
50
|
UNSTABLE_renderPolicy?: RenderPolicy,
|
52
51
|
},
|
53
52
|
): TData {
|
54
|
-
// We need to use this hook in order to be able to track if
|
55
|
-
// loadQuery was called during render
|
56
|
-
useTrackLoadQueryInRender();
|
57
|
-
|
58
53
|
const environment = useRelayEnvironment();
|
59
54
|
|
60
55
|
const query = useMemoOperationDescriptor(
|
@@ -22,20 +22,21 @@ import type {
|
|
22
22
|
Variables,
|
23
23
|
} from 'relay-runtime';
|
24
24
|
|
25
|
+
const getConnectionState = require('./getConnectionState');
|
25
26
|
const useFetchTrackingRef = require('./useFetchTrackingRef');
|
26
27
|
const useIsMountedRef = require('./useIsMountedRef');
|
27
28
|
const useIsOperationNodeActive = require('./useIsOperationNodeActive');
|
29
|
+
const useLoadMoreFunction_EXPERIMENTAL = require('./useLoadMoreFunction_EXPERIMENTAL');
|
28
30
|
const useRelayEnvironment = require('./useRelayEnvironment');
|
29
31
|
const invariant = require('invariant');
|
30
32
|
const {useCallback, useEffect, useState} = require('react');
|
31
33
|
const {
|
32
34
|
__internal: {fetchQuery},
|
33
|
-
|
35
|
+
RelayFeatureFlags,
|
34
36
|
createOperationDescriptor,
|
35
37
|
getPaginationVariables,
|
36
38
|
getRefetchMetadata,
|
37
39
|
getSelector,
|
38
|
-
getValueAtPath,
|
39
40
|
} = require('relay-runtime');
|
40
41
|
const warning = require('warning');
|
41
42
|
|
@@ -63,6 +64,17 @@ export type UseLoadMoreFunctionArgs = {
|
|
63
64
|
|
64
65
|
hook useLoadMoreFunction<TVariables: Variables>(
|
65
66
|
args: UseLoadMoreFunctionArgs,
|
67
|
+
): [LoadMoreFn<TVariables>, boolean, () => void] {
|
68
|
+
if (RelayFeatureFlags.ENABLE_ACTIVITY_COMPATIBILITY) {
|
69
|
+
// $FlowFixMe[react-rule-hook] - the condition is static
|
70
|
+
return useLoadMoreFunction_EXPERIMENTAL(args);
|
71
|
+
}
|
72
|
+
// $FlowFixMe[react-rule-hook] - the condition is static
|
73
|
+
return useLoadMoreFunction_CURRENT(args);
|
74
|
+
}
|
75
|
+
|
76
|
+
hook useLoadMoreFunction_CURRENT<TVariables: Variables>(
|
77
|
+
args: UseLoadMoreFunctionArgs,
|
66
78
|
): [LoadMoreFn<TVariables>, boolean, () => void] {
|
67
79
|
const {
|
68
80
|
direction,
|
@@ -269,82 +281,4 @@ hook useLoadMoreFunction<TVariables: Variables>(
|
|
269
281
|
return [loadMore, hasMore, disposeFetch];
|
270
282
|
}
|
271
283
|
|
272
|
-
function getConnectionState(
|
273
|
-
direction: Direction,
|
274
|
-
fragmentNode: ReaderFragment,
|
275
|
-
fragmentData: mixed,
|
276
|
-
connectionPathInFragmentData: $ReadOnlyArray<string | number>,
|
277
|
-
): {
|
278
|
-
cursor: ?string,
|
279
|
-
hasMore: boolean,
|
280
|
-
} {
|
281
|
-
const {
|
282
|
-
EDGES,
|
283
|
-
PAGE_INFO,
|
284
|
-
HAS_NEXT_PAGE,
|
285
|
-
HAS_PREV_PAGE,
|
286
|
-
END_CURSOR,
|
287
|
-
START_CURSOR,
|
288
|
-
} = ConnectionInterface.get();
|
289
|
-
const connection = getValueAtPath(fragmentData, connectionPathInFragmentData);
|
290
|
-
if (connection == null) {
|
291
|
-
return {cursor: null, hasMore: false};
|
292
|
-
}
|
293
|
-
|
294
|
-
invariant(
|
295
|
-
typeof connection === 'object',
|
296
|
-
'Relay: Expected connection in fragment `%s` to have been `null`, or ' +
|
297
|
-
'a plain object with %s and %s properties. Instead got `%s`.',
|
298
|
-
fragmentNode.name,
|
299
|
-
EDGES,
|
300
|
-
PAGE_INFO,
|
301
|
-
connection,
|
302
|
-
);
|
303
|
-
|
304
|
-
const edges = connection[EDGES];
|
305
|
-
const pageInfo = connection[PAGE_INFO];
|
306
|
-
if (edges == null || pageInfo == null) {
|
307
|
-
return {cursor: null, hasMore: false};
|
308
|
-
}
|
309
|
-
|
310
|
-
invariant(
|
311
|
-
Array.isArray(edges),
|
312
|
-
'Relay: Expected connection in fragment `%s` to have a plural `%s` field. ' +
|
313
|
-
'Instead got `%s`.',
|
314
|
-
fragmentNode.name,
|
315
|
-
EDGES,
|
316
|
-
edges,
|
317
|
-
);
|
318
|
-
invariant(
|
319
|
-
typeof pageInfo === 'object',
|
320
|
-
'Relay: Expected connection in fragment `%s` to have a `%s` field. ' +
|
321
|
-
'Instead got `%s`.',
|
322
|
-
fragmentNode.name,
|
323
|
-
PAGE_INFO,
|
324
|
-
pageInfo,
|
325
|
-
);
|
326
|
-
|
327
|
-
const cursor =
|
328
|
-
direction === 'forward'
|
329
|
-
? pageInfo[END_CURSOR] ?? null
|
330
|
-
: pageInfo[START_CURSOR] ?? null;
|
331
|
-
invariant(
|
332
|
-
cursor === null || typeof cursor === 'string',
|
333
|
-
'Relay: Expected page info for connection in fragment `%s` to have a ' +
|
334
|
-
'valid `%s`. Instead got `%s`.',
|
335
|
-
fragmentNode.name,
|
336
|
-
START_CURSOR,
|
337
|
-
cursor,
|
338
|
-
);
|
339
|
-
|
340
|
-
let hasMore;
|
341
|
-
if (direction === 'forward') {
|
342
|
-
hasMore = cursor != null && pageInfo[HAS_NEXT_PAGE] === true;
|
343
|
-
} else {
|
344
|
-
hasMore = cursor != null && pageInfo[HAS_PREV_PAGE] === true;
|
345
|
-
}
|
346
|
-
|
347
|
-
return {cursor, hasMore};
|
348
|
-
}
|
349
|
-
|
350
284
|
module.exports = useLoadMoreFunction;
|
@@ -0,0 +1,280 @@
|
|
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 {
|
15
|
+
ConcreteRequest,
|
16
|
+
Direction,
|
17
|
+
Disposable,
|
18
|
+
GraphQLResponse,
|
19
|
+
Observer,
|
20
|
+
ReaderFragment,
|
21
|
+
ReaderPaginationMetadata,
|
22
|
+
Subscription,
|
23
|
+
Variables,
|
24
|
+
} from 'relay-runtime';
|
25
|
+
|
26
|
+
const getConnectionState = require('./getConnectionState');
|
27
|
+
const useIsMountedRef = require('./useIsMountedRef');
|
28
|
+
const useIsOperationNodeActive = require('./useIsOperationNodeActive');
|
29
|
+
const useRelayEnvironment = require('./useRelayEnvironment');
|
30
|
+
const invariant = require('invariant');
|
31
|
+
const {useCallback, useRef, useState} = require('react');
|
32
|
+
const {
|
33
|
+
__internal: {fetchQuery},
|
34
|
+
createOperationDescriptor,
|
35
|
+
getPaginationVariables,
|
36
|
+
getRefetchMetadata,
|
37
|
+
getSelector,
|
38
|
+
} = require('relay-runtime');
|
39
|
+
const warning = require('warning');
|
40
|
+
|
41
|
+
export type LoadMoreFn<TVariables: Variables> = (
|
42
|
+
count: number,
|
43
|
+
options?: {
|
44
|
+
onComplete?: (Error | null) => void,
|
45
|
+
UNSTABLE_extraVariables?: Partial<TVariables>,
|
46
|
+
},
|
47
|
+
) => Disposable;
|
48
|
+
|
49
|
+
export type UseLoadMoreFunctionArgs = {
|
50
|
+
direction: Direction,
|
51
|
+
fragmentNode: ReaderFragment,
|
52
|
+
fragmentRef: mixed,
|
53
|
+
fragmentIdentifier: string,
|
54
|
+
fragmentData: mixed,
|
55
|
+
connectionPathInFragmentData: $ReadOnlyArray<string | number>,
|
56
|
+
paginationRequest: ConcreteRequest,
|
57
|
+
paginationMetadata: ReaderPaginationMetadata,
|
58
|
+
componentDisplayName: string,
|
59
|
+
observer: Observer<GraphQLResponse>,
|
60
|
+
onReset: () => void,
|
61
|
+
};
|
62
|
+
|
63
|
+
hook useLoadMoreFunction_EXPERIMENTAL<TVariables: Variables>(
|
64
|
+
args: UseLoadMoreFunctionArgs,
|
65
|
+
): [
|
66
|
+
// Function to load more data
|
67
|
+
LoadMoreFn<TVariables>,
|
68
|
+
// Whether the connection has more data to load
|
69
|
+
boolean,
|
70
|
+
// Force dispose function which cancels the in-flight fetch itself, and callbacks
|
71
|
+
() => void,
|
72
|
+
] {
|
73
|
+
const {
|
74
|
+
direction,
|
75
|
+
fragmentNode,
|
76
|
+
fragmentRef,
|
77
|
+
fragmentIdentifier,
|
78
|
+
fragmentData,
|
79
|
+
connectionPathInFragmentData,
|
80
|
+
paginationRequest,
|
81
|
+
paginationMetadata,
|
82
|
+
componentDisplayName,
|
83
|
+
observer,
|
84
|
+
onReset,
|
85
|
+
} = args;
|
86
|
+
const environment = useRelayEnvironment();
|
87
|
+
|
88
|
+
const {identifierInfo} = getRefetchMetadata(
|
89
|
+
fragmentNode,
|
90
|
+
componentDisplayName,
|
91
|
+
);
|
92
|
+
const identifierValue =
|
93
|
+
identifierInfo?.identifierField != null &&
|
94
|
+
fragmentData != null &&
|
95
|
+
typeof fragmentData === 'object'
|
96
|
+
? fragmentData[identifierInfo.identifierField]
|
97
|
+
: null;
|
98
|
+
|
99
|
+
const fetchStatusRef = useRef<
|
100
|
+
{kind: 'fetching', subscription: Subscription} | {kind: 'none'},
|
101
|
+
>({kind: 'none'});
|
102
|
+
const [mirroredEnvironment, setMirroredEnvironment] = useState(environment);
|
103
|
+
const [mirroredFragmentIdentifier, setMirroredFragmentIdentifier] =
|
104
|
+
useState(fragmentIdentifier);
|
105
|
+
|
106
|
+
const isParentQueryActive = useIsOperationNodeActive(
|
107
|
+
fragmentNode,
|
108
|
+
fragmentRef,
|
109
|
+
);
|
110
|
+
|
111
|
+
const forceDisposeFn = useCallback(() => {
|
112
|
+
// $FlowFixMe[react-rule-unsafe-ref]
|
113
|
+
if (fetchStatusRef.current.kind === 'fetching') {
|
114
|
+
// $FlowFixMe[react-rule-unsafe-ref]
|
115
|
+
fetchStatusRef.current.subscription.unsubscribe();
|
116
|
+
}
|
117
|
+
// $FlowFixMe[react-rule-unsafe-ref]
|
118
|
+
fetchStatusRef.current = {kind: 'none'};
|
119
|
+
}, []);
|
120
|
+
|
121
|
+
const shouldReset =
|
122
|
+
environment !== mirroredEnvironment ||
|
123
|
+
fragmentIdentifier !== mirroredFragmentIdentifier;
|
124
|
+
if (shouldReset) {
|
125
|
+
forceDisposeFn();
|
126
|
+
onReset();
|
127
|
+
setMirroredEnvironment(environment);
|
128
|
+
setMirroredFragmentIdentifier(fragmentIdentifier);
|
129
|
+
}
|
130
|
+
|
131
|
+
const {cursor, hasMore} = getConnectionState(
|
132
|
+
direction,
|
133
|
+
fragmentNode,
|
134
|
+
fragmentData,
|
135
|
+
connectionPathInFragmentData,
|
136
|
+
);
|
137
|
+
|
138
|
+
const isMountedRef = useIsMountedRef();
|
139
|
+
const loadMore = useCallback(
|
140
|
+
(
|
141
|
+
count: number,
|
142
|
+
options: void | {
|
143
|
+
UNSTABLE_extraVariables?: Partial<TVariables>,
|
144
|
+
onComplete?: (Error | null) => void,
|
145
|
+
},
|
146
|
+
) => {
|
147
|
+
// TODO(T41131846): Fetch/Caching policies for loadMore
|
148
|
+
|
149
|
+
const onComplete = options?.onComplete;
|
150
|
+
if (isMountedRef.current !== true) {
|
151
|
+
// Bail out and warn if we're trying to paginate after the component
|
152
|
+
// has unmounted
|
153
|
+
warning(
|
154
|
+
false,
|
155
|
+
'Relay: Unexpected fetch on unmounted component for fragment ' +
|
156
|
+
'`%s` in `%s`. It looks like some instances of your component are ' +
|
157
|
+
'still trying to fetch data but they already unmounted. ' +
|
158
|
+
'Please make sure you clear all timers, intervals, ' +
|
159
|
+
'async calls, etc that may trigger a fetch.',
|
160
|
+
fragmentNode.name,
|
161
|
+
componentDisplayName,
|
162
|
+
);
|
163
|
+
return {dispose: () => {}};
|
164
|
+
}
|
165
|
+
|
166
|
+
const fragmentSelector = getSelector(fragmentNode, fragmentRef);
|
167
|
+
if (
|
168
|
+
fetchStatusRef.current.kind === 'fetching' ||
|
169
|
+
fragmentData == null ||
|
170
|
+
isParentQueryActive
|
171
|
+
) {
|
172
|
+
if (fragmentSelector == null) {
|
173
|
+
warning(
|
174
|
+
false,
|
175
|
+
'Relay: Unexpected fetch while using a null fragment ref ' +
|
176
|
+
'for fragment `%s` in `%s`. When fetching more items, we expect ' +
|
177
|
+
"initial fragment data to be non-null. Please make sure you're " +
|
178
|
+
'passing a valid fragment ref to `%s` before paginating.',
|
179
|
+
fragmentNode.name,
|
180
|
+
componentDisplayName,
|
181
|
+
componentDisplayName,
|
182
|
+
);
|
183
|
+
}
|
184
|
+
|
185
|
+
if (onComplete) {
|
186
|
+
onComplete(null);
|
187
|
+
}
|
188
|
+
return {dispose: () => {}};
|
189
|
+
}
|
190
|
+
|
191
|
+
invariant(
|
192
|
+
fragmentSelector != null &&
|
193
|
+
fragmentSelector.kind !== 'PluralReaderSelector',
|
194
|
+
'Relay: Expected to be able to find a non-plural fragment owner for ' +
|
195
|
+
"fragment `%s` when using `%s`. If you're seeing this, " +
|
196
|
+
'this is likely a bug in Relay.',
|
197
|
+
fragmentNode.name,
|
198
|
+
componentDisplayName,
|
199
|
+
);
|
200
|
+
|
201
|
+
const parentVariables = fragmentSelector.owner.variables;
|
202
|
+
const fragmentVariables = fragmentSelector.variables;
|
203
|
+
const extraVariables = options?.UNSTABLE_extraVariables;
|
204
|
+
const baseVariables = {
|
205
|
+
...parentVariables,
|
206
|
+
...fragmentVariables,
|
207
|
+
};
|
208
|
+
const paginationVariables = getPaginationVariables(
|
209
|
+
direction,
|
210
|
+
count,
|
211
|
+
cursor,
|
212
|
+
baseVariables,
|
213
|
+
{...extraVariables},
|
214
|
+
paginationMetadata,
|
215
|
+
);
|
216
|
+
|
217
|
+
// If the query needs an identifier value ('id' or similar) and one
|
218
|
+
// was not explicitly provided, read it from the fragment data.
|
219
|
+
if (identifierInfo != null) {
|
220
|
+
// @refetchable fragments are guaranteed to have an `id` selection
|
221
|
+
// if the type is Node, implements Node, or is @fetchable. Double-check
|
222
|
+
// that there actually is a value at runtime.
|
223
|
+
if (typeof identifierValue !== 'string') {
|
224
|
+
warning(
|
225
|
+
false,
|
226
|
+
'Relay: Expected result to have a string ' +
|
227
|
+
'`%s` in order to refetch, got `%s`.',
|
228
|
+
identifierInfo.identifierField,
|
229
|
+
identifierValue,
|
230
|
+
);
|
231
|
+
}
|
232
|
+
paginationVariables[identifierInfo.identifierQueryVariableName] =
|
233
|
+
identifierValue;
|
234
|
+
}
|
235
|
+
|
236
|
+
const paginationQuery = createOperationDescriptor(
|
237
|
+
paginationRequest,
|
238
|
+
paginationVariables,
|
239
|
+
{force: true},
|
240
|
+
);
|
241
|
+
fetchQuery(environment, paginationQuery).subscribe({
|
242
|
+
...observer,
|
243
|
+
start: subscription => {
|
244
|
+
fetchStatusRef.current = {kind: 'fetching', subscription};
|
245
|
+
observer.start && observer.start(subscription);
|
246
|
+
},
|
247
|
+
complete: () => {
|
248
|
+
fetchStatusRef.current = {kind: 'none'};
|
249
|
+
observer.complete && observer.complete();
|
250
|
+
onComplete && onComplete(null);
|
251
|
+
},
|
252
|
+
error: error => {
|
253
|
+
fetchStatusRef.current = {kind: 'none'};
|
254
|
+
observer.complete && observer.complete();
|
255
|
+
onComplete && onComplete(error);
|
256
|
+
},
|
257
|
+
});
|
258
|
+
return {
|
259
|
+
dispose: () => {},
|
260
|
+
};
|
261
|
+
},
|
262
|
+
// NOTE: We disable react-hooks-deps warning because all values
|
263
|
+
// inside paginationMetadata are static
|
264
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
265
|
+
[
|
266
|
+
environment,
|
267
|
+
identifierValue,
|
268
|
+
direction,
|
269
|
+
cursor,
|
270
|
+
isParentQueryActive,
|
271
|
+
fragmentData,
|
272
|
+
fragmentNode.name,
|
273
|
+
fragmentRef,
|
274
|
+
componentDisplayName,
|
275
|
+
],
|
276
|
+
);
|
277
|
+
return [loadMore, hasMore, forceDisposeFn];
|
278
|
+
}
|
279
|
+
|
280
|
+
module.exports = useLoadMoreFunction_EXPERIMENTAL;
|
@@ -46,7 +46,7 @@ type RefetchFnBase<TVars, TOptions> = (
|
|
46
46
|
options?: TOptions,
|
47
47
|
) => Disposable;
|
48
48
|
|
49
|
-
type RefetchFn<TVariables, TKey, TOptions = Options> = RefetchFnBase<
|
49
|
+
export type RefetchFn<TVariables, TKey, TOptions = Options> = RefetchFnBase<
|
50
50
|
RefetchVariables<TVariables, TKey>,
|
51
51
|
TOptions,
|
52
52
|
>;
|
@@ -18,7 +18,6 @@ import type {
|
|
18
18
|
} from './EntryPointTypes.flow';
|
19
19
|
import type {Query, RenderPolicy, Variables} from 'relay-runtime';
|
20
20
|
|
21
|
-
const {useTrackLoadQueryInRender} = require('./loadQuery');
|
22
21
|
const useLazyLoadQueryNode = require('./useLazyLoadQueryNode');
|
23
22
|
const useMemoOperationDescriptor = require('./useMemoOperationDescriptor');
|
24
23
|
const useRelayEnvironment = require('./useRelayEnvironment');
|
@@ -67,10 +66,6 @@ hook usePreloadedQuery<
|
|
67
66
|
UNSTABLE_renderPolicy?: RenderPolicy,
|
68
67
|
},
|
69
68
|
): TData {
|
70
|
-
// We need to use this hook in order to be able to track if
|
71
|
-
// loadQuery was called during render
|
72
|
-
useTrackLoadQueryInRender();
|
73
|
-
|
74
69
|
const environment = useRelayEnvironment();
|
75
70
|
const {fetchKey, fetchPolicy, source, variables, networkCacheConfig} =
|
76
71
|
preloadedQuery;
|
@@ -23,11 +23,12 @@ import type {
|
|
23
23
|
Variables,
|
24
24
|
} from 'relay-runtime';
|
25
25
|
|
26
|
-
const {loadQuery
|
26
|
+
const {loadQuery} = require('./loadQuery');
|
27
27
|
const useIsMountedRef = require('./useIsMountedRef');
|
28
|
+
const useQueryLoader_EXPERIMENTAL = require('./useQueryLoader_EXPERIMENTAL');
|
28
29
|
const useRelayEnvironment = require('./useRelayEnvironment');
|
29
30
|
const {useCallback, useEffect, useRef, useState} = require('react');
|
30
|
-
const {getRequest} = require('relay-runtime');
|
31
|
+
const {RelayFeatureFlags, getRequest} = require('relay-runtime');
|
31
32
|
|
32
33
|
export type LoaderFn<TQuery: OperationType> = (
|
33
34
|
variables: TQuery['variables'],
|
@@ -42,7 +43,7 @@ export type UseQueryLoaderLoadQueryOptions = $ReadOnly<{
|
|
42
43
|
// NullQueryReference needs to implement referential equality,
|
43
44
|
// so that multiple NullQueryReferences can be in the same set
|
44
45
|
// (corresponding to multiple calls to disposeQuery).
|
45
|
-
type NullQueryReference = {
|
46
|
+
export type NullQueryReference = {
|
46
47
|
kind: 'NullQueryReference',
|
47
48
|
};
|
48
49
|
const initialNullQueryReferenceState = {kind: 'NullQueryReference'};
|
@@ -68,7 +69,7 @@ function requestIsLiveQuery<
|
|
68
69
|
return request.params.metadata.live !== undefined;
|
69
70
|
}
|
70
71
|
|
71
|
-
type UseQueryLoaderHookReturnType<
|
72
|
+
export type UseQueryLoaderHookReturnType<
|
72
73
|
TVariables: Variables,
|
73
74
|
TData,
|
74
75
|
TRawResponse: ?{...} = void,
|
@@ -115,6 +116,29 @@ hook useQueryLoader<TVariables: Variables, TData, TRawResponse: ?{...} = void>(
|
|
115
116
|
variables: TVariables,
|
116
117
|
rawResponse?: $NonMaybeType<TRawResponse>,
|
117
118
|
}>,
|
119
|
+
): UseQueryLoaderHookReturnType<TVariables, TData> {
|
120
|
+
if (RelayFeatureFlags.ENABLE_ACTIVITY_COMPATIBILITY) {
|
121
|
+
// $FlowFixMe[react-rule-hook] - the condition is static
|
122
|
+
return useQueryLoader_EXPERIMENTAL(
|
123
|
+
preloadableRequest,
|
124
|
+
initialQueryReference,
|
125
|
+
);
|
126
|
+
}
|
127
|
+
// $FlowFixMe[react-rule-hook] - the condition is static
|
128
|
+
return useQueryLoader_CURRENT(preloadableRequest, initialQueryReference);
|
129
|
+
}
|
130
|
+
|
131
|
+
hook useQueryLoader_CURRENT<
|
132
|
+
TVariables: Variables,
|
133
|
+
TData,
|
134
|
+
TRawResponse: ?{...} = void,
|
135
|
+
>(
|
136
|
+
preloadableRequest: Query<TVariables, TData, TRawResponse>,
|
137
|
+
initialQueryReference?: ?PreloadedQuery<{
|
138
|
+
response: TData,
|
139
|
+
variables: TVariables,
|
140
|
+
rawResponse?: $NonMaybeType<TRawResponse>,
|
141
|
+
}>,
|
118
142
|
): UseQueryLoaderHookReturnType<TVariables, TData> {
|
119
143
|
type QueryType = {
|
120
144
|
response: TData,
|
@@ -146,7 +170,6 @@ hook useQueryLoader<TVariables: Variables, TData, TRawResponse: ?{...} = void>(
|
|
146
170
|
initialQueryReference ?? initialNullQueryReferenceState;
|
147
171
|
|
148
172
|
const environment = useRelayEnvironment();
|
149
|
-
useTrackLoadQueryInRender();
|
150
173
|
|
151
174
|
const isMountedRef = useIsMountedRef();
|
152
175
|
const undisposedQueryReferencesRef = useRef<
|