react-relay 13.1.1 → 14.1.0
Sign up to get free protection for your applications and to get access to all the features.
- package/ReactRelayContainerUtils.js.flow +0 -2
- package/ReactRelayContext.js +1 -1
- package/ReactRelayContext.js.flow +0 -2
- package/ReactRelayFragmentContainer.js.flow +7 -6
- package/ReactRelayFragmentMockRenderer.js.flow +0 -2
- package/ReactRelayLocalQueryRenderer.js.flow +1 -3
- package/ReactRelayPaginationContainer.js.flow +13 -10
- package/ReactRelayQueryFetcher.js.flow +10 -11
- package/ReactRelayQueryRenderer.js.flow +15 -16
- package/ReactRelayQueryRendererContext.js.flow +1 -3
- package/ReactRelayRefetchContainer.js.flow +10 -7
- package/ReactRelayTestMocker.js.flow +0 -2
- package/ReactRelayTypes.js.flow +6 -8
- package/RelayContext.js.flow +0 -2
- package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +2 -4
- package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +3 -5
- package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +3 -5
- package/__flowtests__/RelayModern-flowtest.js.flow +2 -4
- package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +2 -4
- package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +2 -4
- package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +2 -4
- package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +2 -4
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +2 -2
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +2 -2
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +3 -3
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +3 -3
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +3 -3
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +3 -3
- package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +2 -2
- package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +2 -2
- package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +2 -2
- package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +2 -2
- package/assertFragmentMap.js.flow +0 -2
- package/buildReactRelayContainer.js.flow +2 -4
- package/getRootVariablesForFragments.js.flow +0 -2
- package/hooks.js +1 -1
- package/hooks.js.flow +0 -2
- package/index.js +1 -1
- package/index.js.flow +2 -2
- package/isRelayEnvironment.js.flow +0 -2
- package/jest-react/internalAct.js.flow +25 -9
- package/legacy.js +1 -1
- package/legacy.js.flow +0 -2
- package/lib/ReactRelayContainerUtils.js +0 -1
- package/lib/ReactRelayContext.js +0 -1
- package/lib/ReactRelayFragmentContainer.js +10 -9
- package/lib/ReactRelayFragmentMockRenderer.js +0 -1
- package/lib/ReactRelayLocalQueryRenderer.js +0 -1
- package/lib/ReactRelayPaginationContainer.js +14 -11
- package/lib/ReactRelayQueryFetcher.js +2 -2
- package/lib/ReactRelayQueryRenderer.js +2 -4
- package/lib/ReactRelayQueryRendererContext.js +0 -1
- package/lib/ReactRelayRefetchContainer.js +11 -14
- package/lib/ReactRelayTestMocker.js +1 -2
- package/lib/ReactRelayTypes.js +0 -1
- package/lib/RelayContext.js +0 -1
- package/lib/assertFragmentMap.js +0 -1
- package/lib/buildReactRelayContainer.js +1 -2
- package/lib/getRootVariablesForFragments.js +1 -2
- package/lib/hooks.js +0 -1
- package/lib/index.js +3 -1
- package/lib/isRelayEnvironment.js +0 -1
- package/lib/jest-react/internalAct.js +24 -4
- package/lib/legacy.js +0 -1
- package/lib/multi-actor/useRelayActorEnvironment.js +0 -1
- package/lib/readContext.js +2 -2
- package/lib/relay-hooks/EntryPointContainer.react.js +0 -1
- package/lib/relay-hooks/EntryPointTypes.flow.js +0 -1
- package/lib/relay-hooks/FragmentResource.js +68 -29
- package/lib/relay-hooks/HooksImplementation.js +29 -0
- package/lib/relay-hooks/InternalLogger.js +0 -1
- package/lib/relay-hooks/LRUCache.js +0 -1
- package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +0 -1
- package/lib/relay-hooks/MatchContainer.js +2 -2
- package/lib/relay-hooks/ProfilerContext.js +0 -1
- package/lib/relay-hooks/QueryResource.js +5 -168
- package/lib/relay-hooks/RelayEnvironmentProvider.js +0 -1
- package/lib/relay-hooks/SuspenseResource.js +1 -2
- package/lib/relay-hooks/loadQuery.js +1 -1
- package/lib/relay-hooks/preloadQuery_DEPRECATED.js +8 -13
- package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +0 -1
- package/lib/relay-hooks/react-cache/RelayReactCache.js +36 -0
- package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +344 -0
- package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +239 -0
- package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +598 -0
- package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +50 -0
- package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +55 -0
- package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +150 -0
- package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +124 -0
- package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +367 -0
- package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +45 -0
- package/lib/relay-hooks/useBlockingPaginationFragment.js +4 -3
- package/lib/relay-hooks/useClientQuery.js +33 -0
- package/lib/relay-hooks/useEntryPointLoader.js +1 -2
- package/lib/relay-hooks/useFetchTrackingRef.js +0 -1
- package/lib/relay-hooks/useFragment.js +15 -2
- package/lib/relay-hooks/useFragmentNode.js +0 -1
- package/lib/relay-hooks/useIsMountedRef.js +0 -1
- package/lib/relay-hooks/useLazyLoadQuery.js +4 -2
- package/lib/relay-hooks/useLazyLoadQueryNode.js +0 -1
- package/lib/relay-hooks/useLoadMoreFunction.js +1 -2
- package/lib/relay-hooks/useMemoOperationDescriptor.js +0 -1
- package/lib/relay-hooks/useMemoVariables.js +0 -1
- package/lib/relay-hooks/useMutation.js +5 -7
- package/lib/relay-hooks/usePaginationFragment.js +15 -3
- package/lib/relay-hooks/usePreloadedQuery.js +4 -2
- package/lib/relay-hooks/useQueryLoader.js +1 -2
- package/lib/relay-hooks/useRefetchableFragment.js +14 -2
- package/lib/relay-hooks/useRefetchableFragmentNode.js +1 -2
- package/lib/relay-hooks/useRelayEnvironment.js +0 -1
- package/lib/relay-hooks/useStaticFragmentNodeWarning.js +0 -1
- package/lib/relay-hooks/useSubscribeToInvalidationState.js +0 -1
- package/lib/relay-hooks/useSubscription.js +0 -1
- package/multi-actor/useRelayActorEnvironment.js.flow +0 -2
- 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 +2 -2
- package/react-relay-legacy.min.js +2 -2
- package/react-relay.js +2 -2
- package/react-relay.min.js +2 -2
- package/readContext.js.flow +1 -2
- package/relay-hooks/EntryPointContainer.react.js.flow +2 -4
- package/relay-hooks/EntryPointTypes.flow.js.flow +30 -32
- package/relay-hooks/FragmentResource.js.flow +80 -37
- package/relay-hooks/HooksImplementation.js.flow +43 -0
- package/relay-hooks/InternalLogger.js.flow +0 -2
- package/relay-hooks/LRUCache.js.flow +0 -2
- package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +4 -6
- package/relay-hooks/MatchContainer.js.flow +11 -6
- package/relay-hooks/ProfilerContext.js.flow +0 -2
- package/relay-hooks/QueryResource.js.flow +12 -209
- package/relay-hooks/RelayEnvironmentProvider.js.flow +2 -4
- package/relay-hooks/SuspenseResource.js.flow +0 -2
- package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +3 -3
- package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +2 -2
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +2 -2
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +2 -2
- package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +4 -6
- package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +0 -2
- package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +4 -6
- package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +0 -2
- package/relay-hooks/__flowtests__/utils.js.flow +8 -10
- package/relay-hooks/loadQuery.js.flow +2 -1
- package/relay-hooks/preloadQuery_DEPRECATED.js.flow +11 -20
- package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +0 -2
- package/relay-hooks/react-cache/RelayReactCache.js.flow +40 -0
- package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +430 -0
- package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +297 -0
- package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +599 -0
- package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +72 -0
- package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +70 -0
- package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +171 -0
- package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +151 -0
- package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +595 -0
- package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +65 -0
- package/relay-hooks/useBlockingPaginationFragment.js.flow +4 -6
- package/relay-hooks/useClientQuery.js.flow +39 -0
- package/relay-hooks/useEntryPointLoader.js.flow +6 -8
- package/relay-hooks/useFetchTrackingRef.js.flow +2 -4
- package/relay-hooks/useFragment.js.flow +17 -12
- package/relay-hooks/useFragmentNode.js.flow +2 -4
- package/relay-hooks/useIsMountedRef.js.flow +1 -3
- package/relay-hooks/useLazyLoadQuery.js.flow +17 -5
- package/relay-hooks/useLazyLoadQueryNode.js.flow +2 -4
- package/relay-hooks/useLoadMoreFunction.js.flow +6 -8
- package/relay-hooks/useMemoOperationDescriptor.js.flow +0 -2
- package/relay-hooks/useMemoVariables.js.flow +0 -2
- package/relay-hooks/useMutation.js.flow +5 -7
- package/relay-hooks/usePaginationFragment.js.flow +44 -19
- package/relay-hooks/usePreloadedQuery.js.flow +14 -5
- package/relay-hooks/useQueryLoader.js.flow +4 -6
- package/relay-hooks/useRefetchableFragment.js.flow +32 -3
- package/relay-hooks/useRefetchableFragmentNode.js.flow +38 -25
- package/relay-hooks/useRelayEnvironment.js.flow +0 -2
- package/relay-hooks/useStaticFragmentNodeWarning.js.flow +0 -2
- package/relay-hooks/useSubscribeToInvalidationState.js.flow +0 -2
- package/relay-hooks/useSubscription.js.flow +14 -10
@@ -9,8 +9,6 @@
|
|
9
9
|
* @format
|
10
10
|
*/
|
11
11
|
|
12
|
-
// flowlint ambiguous-object-type:error
|
13
|
-
|
14
12
|
'use strict';
|
15
13
|
|
16
14
|
import type {Cache} from './LRUCache';
|
@@ -32,7 +30,7 @@ import type {
|
|
32
30
|
const LRUCache = require('./LRUCache');
|
33
31
|
const SuspenseResource = require('./SuspenseResource');
|
34
32
|
const invariant = require('invariant');
|
35
|
-
const {
|
33
|
+
const {isPromise} = require('relay-runtime');
|
36
34
|
const warning = require('warning');
|
37
35
|
|
38
36
|
const CACHE_CAPACITY = 1000;
|
@@ -41,7 +39,7 @@ const DEFAULT_FETCH_POLICY = 'store-or-network';
|
|
41
39
|
export type QueryResource = QueryResourceImpl;
|
42
40
|
|
43
41
|
type QueryResourceCache = Cache<QueryResourceCacheEntry>;
|
44
|
-
type QueryResourceCacheEntry = {
|
42
|
+
type QueryResourceCacheEntry = {
|
45
43
|
+id: number,
|
46
44
|
+cacheIdentifier: string,
|
47
45
|
+operationAvailability: ?OperationAvailability,
|
@@ -50,25 +48,23 @@ type QueryResourceCacheEntry = {|
|
|
50
48
|
// from the incremental responses, so later we can choose how to handle errors
|
51
49
|
// in the incremental payloads.
|
52
50
|
processedPayloadsCount: number,
|
53
|
-
getRetainCount(): number,
|
54
|
-
getNetworkSubscription(): ?Subscription,
|
55
51
|
setNetworkSubscription(?Subscription): void,
|
56
52
|
getValue(): Error | Promise<void> | QueryResult,
|
57
53
|
setValue(Error | Promise<void> | QueryResult): void,
|
58
54
|
temporaryRetain(environment: IEnvironment): Disposable,
|
59
55
|
permanentRetain(environment: IEnvironment): Disposable,
|
60
56
|
releaseTemporaryRetain(): void,
|
61
|
-
|
57
|
+
};
|
62
58
|
export opaque type QueryResult: {
|
63
59
|
fragmentNode: ReaderFragment,
|
64
60
|
fragmentRef: mixed,
|
65
61
|
...
|
66
|
-
} = {
|
62
|
+
} = {
|
67
63
|
cacheIdentifier: string,
|
68
64
|
fragmentNode: ReaderFragment,
|
69
65
|
fragmentRef: mixed,
|
70
66
|
operation: OperationDescriptor,
|
71
|
-
|
67
|
+
};
|
72
68
|
|
73
69
|
const WEAKMAP_SUPPORTED = typeof WeakMap === 'function';
|
74
70
|
interface IMap<K, V> {
|
@@ -125,39 +121,6 @@ function createCacheEntry(
|
|
125
121
|
value: Error | Promise<void> | QueryResult,
|
126
122
|
networkSubscription: ?Subscription,
|
127
123
|
onDispose: QueryResourceCacheEntry => void,
|
128
|
-
): QueryResourceCacheEntry {
|
129
|
-
// There should be no behavior difference between createCacheEntry_new and
|
130
|
-
// createCacheEntry_old, and it doesn't directly relate to Client Edges.
|
131
|
-
// It was just a refactoring that was needed for Client Edges but that
|
132
|
-
// is behind the feature flag just in case there is any accidental breakage.
|
133
|
-
if (RelayFeatureFlags.REFACTOR_SUSPENSE_RESOURCE) {
|
134
|
-
return createCacheEntry_new(
|
135
|
-
cacheIdentifier,
|
136
|
-
operation,
|
137
|
-
operationAvailability,
|
138
|
-
value,
|
139
|
-
networkSubscription,
|
140
|
-
onDispose,
|
141
|
-
);
|
142
|
-
} else {
|
143
|
-
return createCacheEntry_old(
|
144
|
-
cacheIdentifier,
|
145
|
-
operation,
|
146
|
-
operationAvailability,
|
147
|
-
value,
|
148
|
-
networkSubscription,
|
149
|
-
onDispose,
|
150
|
-
);
|
151
|
-
}
|
152
|
-
}
|
153
|
-
|
154
|
-
function createCacheEntry_new(
|
155
|
-
cacheIdentifier: string,
|
156
|
-
operation: OperationDescriptor,
|
157
|
-
operationAvailability: ?OperationAvailability,
|
158
|
-
value: Error | Promise<void> | QueryResult,
|
159
|
-
networkSubscription: ?Subscription,
|
160
|
-
onDispose: QueryResourceCacheEntry => void,
|
161
124
|
): QueryResourceCacheEntry {
|
162
125
|
const isLiveQuery = operationIsLiveQuery(operation);
|
163
126
|
|
@@ -191,12 +154,6 @@ function createCacheEntry_new(
|
|
191
154
|
setValue(val: QueryResult | Promise<void> | Error) {
|
192
155
|
currentValue = val;
|
193
156
|
},
|
194
|
-
getRetainCount() {
|
195
|
-
return suspenseResource.getRetainCount();
|
196
|
-
},
|
197
|
-
getNetworkSubscription() {
|
198
|
-
return currentNetworkSubscription;
|
199
|
-
},
|
200
157
|
setNetworkSubscription(subscription: ?Subscription) {
|
201
158
|
if (isLiveQuery && currentNetworkSubscription != null) {
|
202
159
|
currentNetworkSubscription.unsubscribe();
|
@@ -217,153 +174,6 @@ function createCacheEntry_new(
|
|
217
174
|
return cacheEntry;
|
218
175
|
}
|
219
176
|
|
220
|
-
const DATA_RETENTION_TIMEOUT = 5 * 60 * 1000;
|
221
|
-
function createCacheEntry_old(
|
222
|
-
cacheIdentifier: string,
|
223
|
-
operation: OperationDescriptor,
|
224
|
-
operationAvailability: ?OperationAvailability,
|
225
|
-
value: Error | Promise<void> | QueryResult,
|
226
|
-
networkSubscription: ?Subscription,
|
227
|
-
onDispose: QueryResourceCacheEntry => void,
|
228
|
-
): QueryResourceCacheEntry {
|
229
|
-
const isLiveQuery = operationIsLiveQuery(operation);
|
230
|
-
|
231
|
-
let currentValue: Error | Promise<void> | QueryResult = value;
|
232
|
-
let retainCount = 0;
|
233
|
-
let retainDisposable: ?Disposable = null;
|
234
|
-
let releaseTemporaryRetain: ?() => void = null;
|
235
|
-
let currentNetworkSubscription: ?Subscription = networkSubscription;
|
236
|
-
|
237
|
-
const retain = (environment: IEnvironment) => {
|
238
|
-
retainCount++;
|
239
|
-
if (retainCount === 1) {
|
240
|
-
retainDisposable = environment.retain(operation);
|
241
|
-
}
|
242
|
-
return {
|
243
|
-
dispose: () => {
|
244
|
-
retainCount = Math.max(0, retainCount - 1);
|
245
|
-
if (retainCount === 0) {
|
246
|
-
invariant(
|
247
|
-
retainDisposable != null,
|
248
|
-
'Relay: Expected disposable to release query to be defined.' +
|
249
|
-
"If you're seeing this, this is likely a bug in Relay.",
|
250
|
-
);
|
251
|
-
retainDisposable.dispose();
|
252
|
-
retainDisposable = null;
|
253
|
-
}
|
254
|
-
onDispose(cacheEntry);
|
255
|
-
},
|
256
|
-
};
|
257
|
-
};
|
258
|
-
|
259
|
-
const cacheEntry = {
|
260
|
-
cacheIdentifier,
|
261
|
-
id: nextID++,
|
262
|
-
processedPayloadsCount: 0,
|
263
|
-
operationAvailability,
|
264
|
-
getValue() {
|
265
|
-
return currentValue;
|
266
|
-
},
|
267
|
-
setValue(val: QueryResult | Promise<void> | Error) {
|
268
|
-
currentValue = val;
|
269
|
-
},
|
270
|
-
getRetainCount() {
|
271
|
-
return retainCount;
|
272
|
-
},
|
273
|
-
getNetworkSubscription() {
|
274
|
-
return currentNetworkSubscription;
|
275
|
-
},
|
276
|
-
setNetworkSubscription(subscription: ?Subscription) {
|
277
|
-
if (isLiveQuery && currentNetworkSubscription != null) {
|
278
|
-
currentNetworkSubscription.unsubscribe();
|
279
|
-
}
|
280
|
-
currentNetworkSubscription = subscription;
|
281
|
-
},
|
282
|
-
temporaryRetain(environment: IEnvironment): Disposable {
|
283
|
-
// NOTE: If we're executing in a server environment, there's no need
|
284
|
-
// to create temporary retains, since the component will never commit.
|
285
|
-
if (environment.isServer()) {
|
286
|
-
return {dispose: () => {}};
|
287
|
-
}
|
288
|
-
|
289
|
-
// NOTE: temporaryRetain is called during the render phase. However,
|
290
|
-
// given that we can't tell if this render will eventually commit or not,
|
291
|
-
// we create a timer to autodispose of this retain in case the associated
|
292
|
-
// component never commits.
|
293
|
-
// If the component /does/ commit, permanentRetain will clear this timeout
|
294
|
-
// and permanently retain the data.
|
295
|
-
const disposable = retain(environment);
|
296
|
-
let releaseQueryTimeout = null;
|
297
|
-
const localReleaseTemporaryRetain = () => {
|
298
|
-
clearTimeout(releaseQueryTimeout);
|
299
|
-
releaseQueryTimeout = null;
|
300
|
-
releaseTemporaryRetain = null;
|
301
|
-
disposable.dispose();
|
302
|
-
// Normally if this entry never commits, the request would've ended by the
|
303
|
-
// time this timeout expires and the temporary retain is released. However,
|
304
|
-
// we need to do this for live queries which remain open indefinitely.
|
305
|
-
if (
|
306
|
-
isLiveQuery &&
|
307
|
-
retainCount <= 0 &&
|
308
|
-
currentNetworkSubscription != null
|
309
|
-
) {
|
310
|
-
currentNetworkSubscription.unsubscribe();
|
311
|
-
}
|
312
|
-
};
|
313
|
-
releaseQueryTimeout = setTimeout(
|
314
|
-
localReleaseTemporaryRetain,
|
315
|
-
DATA_RETENTION_TIMEOUT,
|
316
|
-
);
|
317
|
-
|
318
|
-
// NOTE: Since temporaryRetain can be called multiple times, we release
|
319
|
-
// the previous temporary retain after we re-establish a new one, since
|
320
|
-
// we only ever need a single temporary retain until the permanent retain is
|
321
|
-
// established.
|
322
|
-
// temporaryRetain may be called multiple times by React during the render
|
323
|
-
// phase, as well as multiple times by other query components that are
|
324
|
-
// rendering the same query/variables.
|
325
|
-
if (releaseTemporaryRetain != null) {
|
326
|
-
releaseTemporaryRetain();
|
327
|
-
}
|
328
|
-
releaseTemporaryRetain = localReleaseTemporaryRetain;
|
329
|
-
|
330
|
-
return {
|
331
|
-
dispose: () => {
|
332
|
-
releaseTemporaryRetain && releaseTemporaryRetain();
|
333
|
-
},
|
334
|
-
};
|
335
|
-
},
|
336
|
-
permanentRetain(environment: IEnvironment): Disposable {
|
337
|
-
const disposable = retain(environment);
|
338
|
-
if (releaseTemporaryRetain != null) {
|
339
|
-
releaseTemporaryRetain();
|
340
|
-
releaseTemporaryRetain = null;
|
341
|
-
}
|
342
|
-
|
343
|
-
return {
|
344
|
-
dispose: () => {
|
345
|
-
disposable.dispose();
|
346
|
-
if (
|
347
|
-
isLiveQuery &&
|
348
|
-
retainCount <= 0 &&
|
349
|
-
currentNetworkSubscription != null
|
350
|
-
) {
|
351
|
-
currentNetworkSubscription.unsubscribe();
|
352
|
-
}
|
353
|
-
},
|
354
|
-
};
|
355
|
-
},
|
356
|
-
releaseTemporaryRetain() {
|
357
|
-
if (releaseTemporaryRetain != null) {
|
358
|
-
releaseTemporaryRetain();
|
359
|
-
releaseTemporaryRetain = null;
|
360
|
-
}
|
361
|
-
},
|
362
|
-
};
|
363
|
-
|
364
|
-
return cacheEntry;
|
365
|
-
}
|
366
|
-
|
367
177
|
class QueryResourceImpl {
|
368
178
|
_environment: IEnvironment;
|
369
179
|
_cache: QueryResourceCache;
|
@@ -532,15 +342,7 @@ class QueryResourceImpl {
|
|
532
342
|
}
|
533
343
|
|
534
344
|
_clearCacheEntry = (cacheEntry: QueryResourceCacheEntry): void => {
|
535
|
-
|
536
|
-
// before calling _clearCacheEntry, whereas with the old code we do it here.
|
537
|
-
if (RelayFeatureFlags.REFACTOR_SUSPENSE_RESOURCE) {
|
538
|
-
this._cache.delete(cacheEntry.cacheIdentifier);
|
539
|
-
} else {
|
540
|
-
if (cacheEntry.getRetainCount() <= 0) {
|
541
|
-
this._cache.delete(cacheEntry.cacheIdentifier);
|
542
|
-
}
|
543
|
-
}
|
345
|
+
this._cache.delete(cacheEntry.cacheIdentifier);
|
544
346
|
};
|
545
347
|
|
546
348
|
_getOrCreateCacheEntry(
|
@@ -588,7 +390,9 @@ class QueryResourceImpl {
|
|
588
390
|
|
589
391
|
let shouldFetch;
|
590
392
|
let shouldAllowRender;
|
591
|
-
|
393
|
+
// Different definitions for Promise in our repos can cause this variable
|
394
|
+
// to cause errors when synced elsewhere
|
395
|
+
let resolveNetworkPromise: $FlowFixMe = () => {};
|
592
396
|
switch (fetchPolicy) {
|
593
397
|
case 'store-only': {
|
594
398
|
shouldFetch = false;
|
@@ -632,7 +436,7 @@ class QueryResourceImpl {
|
|
632
436
|
|
633
437
|
if (shouldFetch) {
|
634
438
|
const queryResult = getQueryResult(operation, cacheIdentifier);
|
635
|
-
let networkSubscription;
|
439
|
+
let networkSubscription: ?Subscription;
|
636
440
|
fetchObservable.subscribe({
|
637
441
|
start: subscription => {
|
638
442
|
networkSubscription = subscription;
|
@@ -693,10 +497,9 @@ class QueryResourceImpl {
|
|
693
497
|
// To complete this task we need to have a way of precisely tracking suspendable points
|
694
498
|
warning(
|
695
499
|
false,
|
696
|
-
'QueryResource: An incremental payload for query
|
500
|
+
'QueryResource: An incremental payload for query `%s` returned an error: `%s`.',
|
697
501
|
operation.fragment.node.name,
|
698
|
-
error.message,
|
699
|
-
error.stack,
|
502
|
+
String(error.message),
|
700
503
|
);
|
701
504
|
}
|
702
505
|
resolveNetworkPromise();
|
@@ -9,8 +9,6 @@
|
|
9
9
|
* @format
|
10
10
|
*/
|
11
11
|
|
12
|
-
// flowlint ambiguous-object-type:error
|
13
|
-
|
14
12
|
'use strict';
|
15
13
|
|
16
14
|
import type {IEnvironment} from 'relay-runtime';
|
@@ -24,13 +22,13 @@ const ReactRelayContext = require('react-relay/ReactRelayContext');
|
|
24
22
|
|
25
23
|
const {useMemo} = React;
|
26
24
|
|
27
|
-
type Props = $ReadOnly<{
|
25
|
+
type Props = $ReadOnly<{
|
28
26
|
children: React.Node,
|
29
27
|
environment: IEnvironment,
|
30
28
|
getEnvironmentForActor?: ?(
|
31
29
|
actorIdentifier: ActorIdentifier,
|
32
30
|
) => IActorEnvironment,
|
33
|
-
|
31
|
+
}>;
|
34
32
|
|
35
33
|
function RelayEnvironmentProvider(props: Props): React.Node {
|
36
34
|
const {children, environment, getEnvironmentForActor} = props;
|
@@ -17,15 +17,15 @@ import type {
|
|
17
17
|
EntryPointProps,
|
18
18
|
} from '../../EntryPointTypes.flow';
|
19
19
|
|
20
|
-
type MyComponentOtherProps = $ReadOnly<{
|
20
|
+
type MyComponentOtherProps = $ReadOnly<{
|
21
21
|
foo: string,
|
22
|
-
|
22
|
+
}>;
|
23
23
|
|
24
24
|
type MyComponentProps = EntryPointProps<{}, {}, MyComponentOtherProps, {}>;
|
25
25
|
|
26
26
|
const MyComponent = (_props: MyComponentProps) => null;
|
27
27
|
|
28
|
-
type PreloadParams = $ReadOnly<{
|
28
|
+
type PreloadParams = $ReadOnly<{}>;
|
29
29
|
|
30
30
|
type MyComponentEntryPointType = EntryPoint<PreloadParams, typeof MyComponent>;
|
31
31
|
|
@@ -27,9 +27,9 @@ type NestedEntrypointComponentProps = EntryPointProps<{}>;
|
|
27
27
|
const NestedEntrypointComponent = (_props: NestedEntrypointComponentProps) =>
|
28
28
|
null;
|
29
29
|
|
30
|
-
type NestedEntrypointPreloadParams = $ReadOnly<{
|
30
|
+
type NestedEntrypointPreloadParams = $ReadOnly<{
|
31
31
|
subEntrypointPreloadParam: string,
|
32
|
-
|
32
|
+
}>;
|
33
33
|
|
34
34
|
type NestedEntryPointType = EntryPoint<
|
35
35
|
NestedEntrypointPreloadParams,
|
@@ -1,10 +1,10 @@
|
|
1
1
|
/**
|
2
2
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
|
-
*
|
3
|
+
*
|
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
|
-
* @generated SignedSource<<
|
7
|
+
* @generated SignedSource<<8a8e68a3fde4da3f77546ac4952f2635>>
|
8
8
|
* @flow
|
9
9
|
* @lightSyntaxTransform
|
10
10
|
* @nogrep
|
@@ -1,10 +1,10 @@
|
|
1
1
|
/**
|
2
2
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
3
|
-
*
|
3
|
+
*
|
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
|
-
* @generated SignedSource<<
|
7
|
+
* @generated SignedSource<<0b4a6e76a104111de9ddd4dd9abe667c>>
|
8
8
|
* @flow
|
9
9
|
* @lightSyntaxTransform
|
10
10
|
* @nogrep
|
@@ -9,8 +9,6 @@
|
|
9
9
|
* @format
|
10
10
|
*/
|
11
11
|
|
12
|
-
// flowlint ambiguous-object-type:error
|
13
|
-
|
14
12
|
import type {LoadMoreFn} from '../useLoadMoreFunction';
|
15
13
|
import type {
|
16
14
|
FetchFn,
|
@@ -36,14 +34,14 @@ type ExpectedReturnType<
|
|
36
34
|
TQuery: OperationType,
|
37
35
|
TQueryVariables,
|
38
36
|
TFragmentData,
|
39
|
-
> = {
|
37
|
+
> = {
|
40
38
|
data: TFragmentData,
|
41
39
|
loadNext: LoadMoreFn<TQuery>,
|
42
40
|
loadPrevious: LoadMoreFn<TQuery>,
|
43
41
|
hasNext: boolean,
|
44
42
|
hasPrevious: boolean,
|
45
43
|
refetch: FetchFn<TQueryVariables>,
|
46
|
-
|
44
|
+
};
|
47
45
|
|
48
46
|
/* eslint-disable react-hooks/rules-of-hooks */
|
49
47
|
|
@@ -103,8 +101,8 @@ refetch(variables, {
|
|
103
101
|
});
|
104
102
|
|
105
103
|
// LoadMore options
|
106
|
-
declare var extraVariables: {
|
107
|
-
declare var invalidVariables: {
|
104
|
+
declare var extraVariables: {nickname: string};
|
105
|
+
declare var invalidVariables: {foo: string};
|
108
106
|
|
109
107
|
const {loadNext} = useBlockingPaginationFragment<QueryOperation, _>(
|
110
108
|
fragmentInput,
|
@@ -9,8 +9,6 @@
|
|
9
9
|
* @format
|
10
10
|
*/
|
11
11
|
|
12
|
-
// flowlint ambiguous-object-type:error
|
13
|
-
|
14
12
|
import type {LoadMoreFn} from '../useLoadMoreFunction';
|
15
13
|
import type {
|
16
14
|
FetchFn,
|
@@ -36,7 +34,7 @@ type ExpectedReturnType<
|
|
36
34
|
TQuery: OperationType,
|
37
35
|
TQueryVariables,
|
38
36
|
TFragmentData,
|
39
|
-
> = {
|
37
|
+
> = {
|
40
38
|
data: TFragmentData,
|
41
39
|
loadNext: LoadMoreFn<TQuery>,
|
42
40
|
loadPrevious: LoadMoreFn<TQuery>,
|
@@ -45,7 +43,7 @@ type ExpectedReturnType<
|
|
45
43
|
isLoadingNext: boolean,
|
46
44
|
isLoadingPrevious: boolean,
|
47
45
|
refetch: FetchFn<TQueryVariables>,
|
48
|
-
|
46
|
+
};
|
49
47
|
|
50
48
|
/* eslint-disable react-hooks/rules-of-hooks */
|
51
49
|
|
@@ -105,8 +103,8 @@ refetch(variables, {
|
|
105
103
|
});
|
106
104
|
|
107
105
|
// LoadMore options
|
108
|
-
declare var extraVariables: {
|
109
|
-
declare var invalidVariables: {
|
106
|
+
declare var extraVariables: {nickname: string};
|
107
|
+
declare var invalidVariables: {foo: string};
|
110
108
|
|
111
109
|
const {loadNext} = usePaginationFragment<QueryOperation, _>(
|
112
110
|
fragmentInput,
|
@@ -9,8 +9,6 @@
|
|
9
9
|
* @format
|
10
10
|
*/
|
11
11
|
|
12
|
-
// flowlint ambiguous-object-type:error
|
13
|
-
|
14
12
|
'use strict';
|
15
13
|
|
16
14
|
import type {Disposable, Fragment, FragmentType} from 'relay-runtime';
|
@@ -28,18 +26,18 @@ export type Example_user$key = {
|
|
28
26
|
...
|
29
27
|
};
|
30
28
|
|
31
|
-
export type NonNullableData = {
|
29
|
+
export type NonNullableData = {
|
32
30
|
+id: string,
|
33
31
|
+count: number,
|
34
|
-
|
32
|
+
};
|
35
33
|
export type NullableData = ?NonNullableData;
|
36
34
|
export type NonNullablePluralData = $ReadOnlyArray<NonNullableData>;
|
37
35
|
export type NullablePluralData = ?$ReadOnlyArray<NonNullableData>;
|
38
36
|
|
39
|
-
export type AnotherNonNullableData = {
|
37
|
+
export type AnotherNonNullableData = {
|
40
38
|
+name: ?string,
|
41
39
|
+friends: ?number,
|
42
|
-
|
40
|
+
};
|
43
41
|
|
44
42
|
declare export var keyNonNullable: Example_user$key;
|
45
43
|
|
@@ -66,16 +64,16 @@ declare export var fragmentData: {
|
|
66
64
|
...
|
67
65
|
};
|
68
66
|
|
69
|
-
export type QueryOperation = {
|
67
|
+
export type QueryOperation = {
|
70
68
|
+variables: QueryVariables,
|
71
69
|
+response: {...},
|
72
|
-
|
70
|
+
};
|
73
71
|
|
74
|
-
export type QueryVariables = {
|
72
|
+
export type QueryVariables = {
|
75
73
|
id: string,
|
76
74
|
nickname: ?string,
|
77
75
|
name: string,
|
78
|
-
|
76
|
+
};
|
79
77
|
|
80
78
|
export type QueryVariablesSubset = {
|
81
79
|
id: string,
|
@@ -17,6 +17,7 @@ import type {
|
|
17
17
|
PreloadedQueryInner,
|
18
18
|
} from './EntryPointTypes.flow';
|
19
19
|
import type {
|
20
|
+
ConcreteRequest,
|
20
21
|
GraphQLResponse,
|
21
22
|
GraphQLTaggedNode,
|
22
23
|
IEnvironment,
|
@@ -236,7 +237,7 @@ function loadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
|
|
236
237
|
}));
|
237
238
|
};
|
238
239
|
|
239
|
-
const checkAvailabilityAndExecute = concreteRequest => {
|
240
|
+
const checkAvailabilityAndExecute = (concreteRequest: ConcreteRequest) => {
|
240
241
|
const operation = createOperationDescriptor(
|
241
242
|
concreteRequest,
|
242
243
|
variables,
|
@@ -9,8 +9,6 @@
|
|
9
9
|
* @format
|
10
10
|
*/
|
11
11
|
|
12
|
-
// flowlint ambiguous-object-type:error
|
13
|
-
|
14
12
|
'use strict';
|
15
13
|
|
16
14
|
import type {
|
@@ -51,7 +49,7 @@ const pendingQueriesByEnvironment = WEAKMAP_SUPPORTED
|
|
51
49
|
: new Map();
|
52
50
|
|
53
51
|
type PendingQueryEntry =
|
54
|
-
| $ReadOnly<{
|
52
|
+
| $ReadOnly<{
|
55
53
|
cacheKey: string,
|
56
54
|
fetchKey: ?string | ?number,
|
57
55
|
fetchPolicy: PreloadFetchPolicy,
|
@@ -61,8 +59,8 @@ type PendingQueryEntry =
|
|
61
59
|
status: PreloadQueryStatus,
|
62
60
|
subject: ReplaySubject<GraphQLResponse>,
|
63
61
|
subscription: Subscription,
|
64
|
-
|
65
|
-
| $ReadOnly<{
|
62
|
+
}>
|
63
|
+
| $ReadOnly<{
|
66
64
|
cacheKey: string,
|
67
65
|
fetchKey: ?string | ?number,
|
68
66
|
fetchPolicy: PreloadFetchPolicy,
|
@@ -70,7 +68,7 @@ type PendingQueryEntry =
|
|
70
68
|
id: ?string,
|
71
69
|
name: string,
|
72
70
|
status: PreloadQueryStatus,
|
73
|
-
|
71
|
+
}>;
|
74
72
|
|
75
73
|
function preloadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
|
76
74
|
environment: IEnvironment,
|
@@ -115,20 +113,13 @@ function preloadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
|
|
115
113
|
if (environment.isServer()) {
|
116
114
|
return;
|
117
115
|
}
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
if (queryEntry != null) {
|
126
|
-
cleanup(pendingQueries, queryEntry);
|
127
|
-
}
|
128
|
-
}, DEFAULT_PREFETCH_TIMEOUT);
|
129
|
-
} else {
|
130
|
-
cleanup(pendingQueries, queryEntry);
|
131
|
-
}
|
116
|
+
setTimeout(() => {
|
117
|
+
// Clear the cache entry after the default timeout
|
118
|
+
// null-check for Flow
|
119
|
+
if (queryEntry != null) {
|
120
|
+
cleanup(pendingQueries, queryEntry);
|
121
|
+
}
|
122
|
+
}, DEFAULT_PREFETCH_TIMEOUT);
|
132
123
|
};
|
133
124
|
})
|
134
125
|
: null;
|
@@ -0,0 +1,40 @@
|
|
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
|
+
* @emails oncall+relay
|
9
|
+
* @format
|
10
|
+
*/
|
11
|
+
|
12
|
+
'use strict';
|
13
|
+
|
14
|
+
const invariant = require('invariant');
|
15
|
+
// $FlowFixMe[prop-missing] These exist in experimental builds but aren't in React's types yet.
|
16
|
+
const {unstable_getCacheForType, unstable_getCacheSignal} = require('react');
|
17
|
+
const {RelayFeatureFlags} = require('relay-runtime');
|
18
|
+
|
19
|
+
function getCacheForType<T>(factory: () => T): T {
|
20
|
+
invariant(
|
21
|
+
typeof unstable_getCacheForType === 'function' &&
|
22
|
+
RelayFeatureFlags.USE_REACT_CACHE,
|
23
|
+
'RelayReactCache.getCacheForType should only be called when the USE_REACT_CACHE feature flag is enabled and when on an experimental React build that supports it.',
|
24
|
+
);
|
25
|
+
return unstable_getCacheForType(factory);
|
26
|
+
}
|
27
|
+
|
28
|
+
function getCacheSignal(): AbortSignal {
|
29
|
+
invariant(
|
30
|
+
typeof unstable_getCacheSignal === 'function' &&
|
31
|
+
RelayFeatureFlags.USE_REACT_CACHE,
|
32
|
+
'RelayReactCache.getCacheSignal should only be called when the USE_REACT_CACHE feature flag is enabled and when on an experimental React build that supports it.',
|
33
|
+
);
|
34
|
+
return unstable_getCacheSignal();
|
35
|
+
}
|
36
|
+
|
37
|
+
module.exports = {
|
38
|
+
getCacheForType,
|
39
|
+
getCacheSignal,
|
40
|
+
};
|