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
@@ -8,10 +8,9 @@
|
|
8
8
|
* @emails oncall+relay
|
9
9
|
* @format
|
10
10
|
*/
|
11
|
-
// flowlint ambiguous-object-type:error
|
12
11
|
'use strict';
|
13
12
|
|
14
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
13
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
15
14
|
|
16
15
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
17
16
|
|
@@ -24,7 +23,6 @@ var SuspenseResource = require('./SuspenseResource');
|
|
24
23
|
var invariant = require('invariant');
|
25
24
|
|
26
25
|
var _require = require('relay-runtime'),
|
27
|
-
RelayFeatureFlags = _require.RelayFeatureFlags,
|
28
26
|
isPromise = _require.isPromise;
|
29
27
|
|
30
28
|
var warning = require("fbjs/lib/warning");
|
@@ -66,18 +64,6 @@ function getQueryResult(operation, cacheIdentifier) {
|
|
66
64
|
var nextID = 200000;
|
67
65
|
|
68
66
|
function createCacheEntry(cacheIdentifier, operation, operationAvailability, value, networkSubscription, onDispose) {
|
69
|
-
// There should be no behavior difference between createCacheEntry_new and
|
70
|
-
// createCacheEntry_old, and it doesn't directly relate to Client Edges.
|
71
|
-
// It was just a refactoring that was needed for Client Edges but that
|
72
|
-
// is behind the feature flag just in case there is any accidental breakage.
|
73
|
-
if (RelayFeatureFlags.REFACTOR_SUSPENSE_RESOURCE) {
|
74
|
-
return createCacheEntry_new(cacheIdentifier, operation, operationAvailability, value, networkSubscription, onDispose);
|
75
|
-
} else {
|
76
|
-
return createCacheEntry_old(cacheIdentifier, operation, operationAvailability, value, networkSubscription, onDispose);
|
77
|
-
}
|
78
|
-
}
|
79
|
-
|
80
|
-
function createCacheEntry_new(cacheIdentifier, operation, operationAvailability, value, networkSubscription, onDispose) {
|
81
67
|
var isLiveQuery = operationIsLiveQuery(operation);
|
82
68
|
var currentValue = value;
|
83
69
|
var currentNetworkSubscription = networkSubscription;
|
@@ -108,12 +94,6 @@ function createCacheEntry_new(cacheIdentifier, operation, operationAvailability,
|
|
108
94
|
setValue: function setValue(val) {
|
109
95
|
currentValue = val;
|
110
96
|
},
|
111
|
-
getRetainCount: function getRetainCount() {
|
112
|
-
return suspenseResource.getRetainCount();
|
113
|
-
},
|
114
|
-
getNetworkSubscription: function getNetworkSubscription() {
|
115
|
-
return currentNetworkSubscription;
|
116
|
-
},
|
117
97
|
setNetworkSubscription: function setNetworkSubscription(subscription) {
|
118
98
|
if (isLiveQuery && currentNetworkSubscription != null) {
|
119
99
|
currentNetworkSubscription.unsubscribe();
|
@@ -134,156 +114,12 @@ function createCacheEntry_new(cacheIdentifier, operation, operationAvailability,
|
|
134
114
|
return cacheEntry;
|
135
115
|
}
|
136
116
|
|
137
|
-
var DATA_RETENTION_TIMEOUT = 5 * 60 * 1000;
|
138
|
-
|
139
|
-
function createCacheEntry_old(cacheIdentifier, operation, operationAvailability, value, networkSubscription, onDispose) {
|
140
|
-
var isLiveQuery = operationIsLiveQuery(operation);
|
141
|
-
var currentValue = value;
|
142
|
-
var retainCount = 0;
|
143
|
-
var retainDisposable = null;
|
144
|
-
var _releaseTemporaryRetain = null;
|
145
|
-
var currentNetworkSubscription = networkSubscription;
|
146
|
-
|
147
|
-
var retain = function retain(environment) {
|
148
|
-
retainCount++;
|
149
|
-
|
150
|
-
if (retainCount === 1) {
|
151
|
-
retainDisposable = environment.retain(operation);
|
152
|
-
}
|
153
|
-
|
154
|
-
return {
|
155
|
-
dispose: function dispose() {
|
156
|
-
retainCount = Math.max(0, retainCount - 1);
|
157
|
-
|
158
|
-
if (retainCount === 0) {
|
159
|
-
!(retainDisposable != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected disposable to release query to be defined.' + "If you're seeing this, this is likely a bug in Relay.") : invariant(false) : void 0;
|
160
|
-
retainDisposable.dispose();
|
161
|
-
retainDisposable = null;
|
162
|
-
}
|
163
|
-
|
164
|
-
onDispose(cacheEntry);
|
165
|
-
}
|
166
|
-
};
|
167
|
-
};
|
168
|
-
|
169
|
-
var cacheEntry = {
|
170
|
-
cacheIdentifier: cacheIdentifier,
|
171
|
-
id: nextID++,
|
172
|
-
processedPayloadsCount: 0,
|
173
|
-
operationAvailability: operationAvailability,
|
174
|
-
getValue: function getValue() {
|
175
|
-
return currentValue;
|
176
|
-
},
|
177
|
-
setValue: function setValue(val) {
|
178
|
-
currentValue = val;
|
179
|
-
},
|
180
|
-
getRetainCount: function getRetainCount() {
|
181
|
-
return retainCount;
|
182
|
-
},
|
183
|
-
getNetworkSubscription: function getNetworkSubscription() {
|
184
|
-
return currentNetworkSubscription;
|
185
|
-
},
|
186
|
-
setNetworkSubscription: function setNetworkSubscription(subscription) {
|
187
|
-
if (isLiveQuery && currentNetworkSubscription != null) {
|
188
|
-
currentNetworkSubscription.unsubscribe();
|
189
|
-
}
|
190
|
-
|
191
|
-
currentNetworkSubscription = subscription;
|
192
|
-
},
|
193
|
-
temporaryRetain: function temporaryRetain(environment) {
|
194
|
-
// NOTE: If we're executing in a server environment, there's no need
|
195
|
-
// to create temporary retains, since the component will never commit.
|
196
|
-
if (environment.isServer()) {
|
197
|
-
return {
|
198
|
-
dispose: function dispose() {}
|
199
|
-
};
|
200
|
-
} // NOTE: temporaryRetain is called during the render phase. However,
|
201
|
-
// given that we can't tell if this render will eventually commit or not,
|
202
|
-
// we create a timer to autodispose of this retain in case the associated
|
203
|
-
// component never commits.
|
204
|
-
// If the component /does/ commit, permanentRetain will clear this timeout
|
205
|
-
// and permanently retain the data.
|
206
|
-
|
207
|
-
|
208
|
-
var disposable = retain(environment);
|
209
|
-
var releaseQueryTimeout = null;
|
210
|
-
|
211
|
-
var localReleaseTemporaryRetain = function localReleaseTemporaryRetain() {
|
212
|
-
clearTimeout(releaseQueryTimeout);
|
213
|
-
releaseQueryTimeout = null;
|
214
|
-
_releaseTemporaryRetain = null;
|
215
|
-
disposable.dispose(); // Normally if this entry never commits, the request would've ended by the
|
216
|
-
// time this timeout expires and the temporary retain is released. However,
|
217
|
-
// we need to do this for live queries which remain open indefinitely.
|
218
|
-
|
219
|
-
if (isLiveQuery && retainCount <= 0 && currentNetworkSubscription != null) {
|
220
|
-
currentNetworkSubscription.unsubscribe();
|
221
|
-
}
|
222
|
-
};
|
223
|
-
|
224
|
-
releaseQueryTimeout = setTimeout(localReleaseTemporaryRetain, DATA_RETENTION_TIMEOUT); // NOTE: Since temporaryRetain can be called multiple times, we release
|
225
|
-
// the previous temporary retain after we re-establish a new one, since
|
226
|
-
// we only ever need a single temporary retain until the permanent retain is
|
227
|
-
// established.
|
228
|
-
// temporaryRetain may be called multiple times by React during the render
|
229
|
-
// phase, as well as multiple times by other query components that are
|
230
|
-
// rendering the same query/variables.
|
231
|
-
|
232
|
-
if (_releaseTemporaryRetain != null) {
|
233
|
-
_releaseTemporaryRetain();
|
234
|
-
}
|
235
|
-
|
236
|
-
_releaseTemporaryRetain = localReleaseTemporaryRetain;
|
237
|
-
return {
|
238
|
-
dispose: function dispose() {
|
239
|
-
_releaseTemporaryRetain && _releaseTemporaryRetain();
|
240
|
-
}
|
241
|
-
};
|
242
|
-
},
|
243
|
-
permanentRetain: function permanentRetain(environment) {
|
244
|
-
var disposable = retain(environment);
|
245
|
-
|
246
|
-
if (_releaseTemporaryRetain != null) {
|
247
|
-
_releaseTemporaryRetain();
|
248
|
-
|
249
|
-
_releaseTemporaryRetain = null;
|
250
|
-
}
|
251
|
-
|
252
|
-
return {
|
253
|
-
dispose: function dispose() {
|
254
|
-
disposable.dispose();
|
255
|
-
|
256
|
-
if (isLiveQuery && retainCount <= 0 && currentNetworkSubscription != null) {
|
257
|
-
currentNetworkSubscription.unsubscribe();
|
258
|
-
}
|
259
|
-
}
|
260
|
-
};
|
261
|
-
},
|
262
|
-
releaseTemporaryRetain: function releaseTemporaryRetain() {
|
263
|
-
if (_releaseTemporaryRetain != null) {
|
264
|
-
_releaseTemporaryRetain();
|
265
|
-
|
266
|
-
_releaseTemporaryRetain = null;
|
267
|
-
}
|
268
|
-
}
|
269
|
-
};
|
270
|
-
return cacheEntry;
|
271
|
-
}
|
272
|
-
|
273
117
|
var QueryResourceImpl = /*#__PURE__*/function () {
|
274
118
|
function QueryResourceImpl(environment) {
|
275
119
|
var _this = this;
|
276
120
|
|
277
121
|
(0, _defineProperty2["default"])(this, "_clearCacheEntry", function (cacheEntry) {
|
278
|
-
|
279
|
-
// before calling _clearCacheEntry, whereas with the old code we do it here.
|
280
|
-
if (RelayFeatureFlags.REFACTOR_SUSPENSE_RESOURCE) {
|
281
|
-
_this._cache["delete"](cacheEntry.cacheIdentifier);
|
282
|
-
} else {
|
283
|
-
if (cacheEntry.getRetainCount() <= 0) {
|
284
|
-
_this._cache["delete"](cacheEntry.cacheIdentifier);
|
285
|
-
}
|
286
|
-
}
|
122
|
+
_this._cache["delete"](cacheEntry.cacheIdentifier);
|
287
123
|
});
|
288
124
|
this._environment = environment;
|
289
125
|
this._cache = LRUCache.create(CACHE_CAPACITY);
|
@@ -429,7 +265,8 @@ var QueryResourceImpl = /*#__PURE__*/function () {
|
|
429
265
|
var hasFullQuery = queryStatus === 'available';
|
430
266
|
var canPartialRender = hasFullQuery || renderPolicy === 'partial' && queryStatus !== 'stale';
|
431
267
|
var shouldFetch;
|
432
|
-
var shouldAllowRender;
|
268
|
+
var shouldAllowRender; // Different definitions for Promise in our repos can cause this variable
|
269
|
+
// to cause errors when synced elsewhere
|
433
270
|
|
434
271
|
var resolveNetworkPromise = function resolveNetworkPromise() {};
|
435
272
|
|
@@ -529,7 +366,7 @@ var QueryResourceImpl = /*#__PURE__*/function () {
|
|
529
366
|
} else {
|
530
367
|
// TODO:T92030819 Remove this warning and actually throw the network error
|
531
368
|
// To complete this task we need to have a way of precisely tracking suspendable points
|
532
|
-
process.env.NODE_ENV !== "production" ? warning(false, 'QueryResource: An incremental payload for query
|
369
|
+
process.env.NODE_ENV !== "production" ? warning(false, 'QueryResource: An incremental payload for query `%s` returned an error: `%s`.', operation.fragment.node.name, String(_error.message)) : void 0;
|
533
370
|
}
|
534
371
|
|
535
372
|
resolveNetworkPromise();
|
@@ -8,10 +8,9 @@
|
|
8
8
|
* @emails oncall+relay
|
9
9
|
* @format
|
10
10
|
*/
|
11
|
-
// flowlint ambiguous-object-type:error
|
12
11
|
'use strict';
|
13
12
|
|
14
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
13
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
15
14
|
|
16
15
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
17
16
|
|
@@ -10,7 +10,7 @@
|
|
10
10
|
*/
|
11
11
|
'use strict';
|
12
12
|
|
13
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
13
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
14
14
|
|
15
15
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
16
16
|
|
@@ -8,10 +8,9 @@
|
|
8
8
|
*
|
9
9
|
* @format
|
10
10
|
*/
|
11
|
-
// flowlint ambiguous-object-type:error
|
12
11
|
'use strict';
|
13
12
|
|
14
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
13
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
15
14
|
|
16
15
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
17
16
|
|
@@ -64,17 +63,13 @@ function preloadQuery(environment, preloadableRequest, variables, options, envir
|
|
64
63
|
return;
|
65
64
|
}
|
66
65
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
}, DEFAULT_PREFETCH_TIMEOUT);
|
75
|
-
} else {
|
76
|
-
cleanup(pendingQueries, queryEntry);
|
77
|
-
}
|
66
|
+
setTimeout(function () {
|
67
|
+
// Clear the cache entry after the default timeout
|
68
|
+
// null-check for Flow
|
69
|
+
if (queryEntry != null) {
|
70
|
+
cleanup(pendingQueries, queryEntry);
|
71
|
+
}
|
72
|
+
}, DEFAULT_PREFETCH_TIMEOUT);
|
78
73
|
};
|
79
74
|
}) : null;
|
80
75
|
return {
|
@@ -0,0 +1,36 @@
|
|
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
|
+
*
|
8
|
+
* @emails oncall+relay
|
9
|
+
* @format
|
10
|
+
*/
|
11
|
+
'use strict';
|
12
|
+
|
13
|
+
var invariant = require('invariant'); // $FlowFixMe[prop-missing] These exist in experimental builds but aren't in React's types yet.
|
14
|
+
|
15
|
+
|
16
|
+
var _require = require('react'),
|
17
|
+
unstable_getCacheForType = _require.unstable_getCacheForType,
|
18
|
+
unstable_getCacheSignal = _require.unstable_getCacheSignal;
|
19
|
+
|
20
|
+
var _require2 = require('relay-runtime'),
|
21
|
+
RelayFeatureFlags = _require2.RelayFeatureFlags;
|
22
|
+
|
23
|
+
function getCacheForType(factory) {
|
24
|
+
!(typeof unstable_getCacheForType === 'function' && RelayFeatureFlags.USE_REACT_CACHE) ? process.env.NODE_ENV !== "production" ? invariant(false, '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.') : invariant(false) : void 0;
|
25
|
+
return unstable_getCacheForType(factory);
|
26
|
+
}
|
27
|
+
|
28
|
+
function getCacheSignal() {
|
29
|
+
!(typeof unstable_getCacheSignal === 'function' && RelayFeatureFlags.USE_REACT_CACHE) ? process.env.NODE_ENV !== "production" ? invariant(false, '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.') : invariant(false) : void 0;
|
30
|
+
return unstable_getCacheSignal();
|
31
|
+
}
|
32
|
+
|
33
|
+
module.exports = {
|
34
|
+
getCacheForType: getCacheForType,
|
35
|
+
getCacheSignal: getCacheSignal
|
36
|
+
};
|
@@ -0,0 +1,344 @@
|
|
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
|
+
*
|
8
|
+
* @emails oncall+relay
|
9
|
+
* @format
|
10
|
+
*/
|
11
|
+
'use strict';
|
12
|
+
|
13
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
14
|
+
|
15
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
16
|
+
|
17
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
18
|
+
|
19
|
+
var SuspenseResource = require('../SuspenseResource');
|
20
|
+
|
21
|
+
var _require = require('./RelayReactCache'),
|
22
|
+
getCacheForType = _require.getCacheForType,
|
23
|
+
getCacheSignal = _require.getCacheSignal;
|
24
|
+
|
25
|
+
var invariant = require('invariant');
|
26
|
+
|
27
|
+
var _require2 = require('relay-runtime'),
|
28
|
+
RelayFeatureFlags = _require2.RelayFeatureFlags,
|
29
|
+
fetchQueryInternal = _require2.__internal.fetchQuery;
|
30
|
+
|
31
|
+
var warning = require("fbjs/lib/warning");
|
32
|
+
|
33
|
+
var DEFAULT_FETCH_POLICY = 'store-or-network';
|
34
|
+
var WEAKMAP_SUPPORTED = typeof WeakMap === 'function';
|
35
|
+
|
36
|
+
var QueryCache = /*#__PURE__*/function () {
|
37
|
+
function QueryCache() {
|
38
|
+
this._map = WEAKMAP_SUPPORTED ? new WeakMap() : new Map();
|
39
|
+
}
|
40
|
+
|
41
|
+
var _proto = QueryCache.prototype;
|
42
|
+
|
43
|
+
_proto.get = function get(environment, key) {
|
44
|
+
var forEnv = this._map.get(environment);
|
45
|
+
|
46
|
+
if (!forEnv) {
|
47
|
+
forEnv = new Map();
|
48
|
+
|
49
|
+
this._map.set(environment, forEnv);
|
50
|
+
}
|
51
|
+
|
52
|
+
return forEnv.get(key);
|
53
|
+
};
|
54
|
+
|
55
|
+
_proto.set = function set(environment, key, value) {
|
56
|
+
var forEnv = this._map.get(environment);
|
57
|
+
|
58
|
+
if (!forEnv) {
|
59
|
+
forEnv = new Map();
|
60
|
+
|
61
|
+
this._map.set(environment, forEnv);
|
62
|
+
}
|
63
|
+
|
64
|
+
forEnv.set(key, value);
|
65
|
+
};
|
66
|
+
|
67
|
+
_proto["delete"] = function _delete(environment, key) {
|
68
|
+
var forEnv = this._map.get(environment);
|
69
|
+
|
70
|
+
if (!forEnv) {
|
71
|
+
return;
|
72
|
+
}
|
73
|
+
|
74
|
+
forEnv["delete"](key);
|
75
|
+
|
76
|
+
if (forEnv.size === 0) {
|
77
|
+
this._map["delete"](environment);
|
78
|
+
}
|
79
|
+
};
|
80
|
+
|
81
|
+
return QueryCache;
|
82
|
+
}();
|
83
|
+
|
84
|
+
function createQueryCache() {
|
85
|
+
return new QueryCache();
|
86
|
+
}
|
87
|
+
|
88
|
+
var noopOnCommit = function noopOnCommit() {
|
89
|
+
return function () {
|
90
|
+
return undefined;
|
91
|
+
};
|
92
|
+
};
|
93
|
+
|
94
|
+
var noopPromise = new Promise(function () {});
|
95
|
+
|
96
|
+
function getQueryCacheKey(operation, fetchPolicy, renderPolicy, fetchKey) {
|
97
|
+
return "".concat(fetchPolicy, "-").concat(renderPolicy, "-").concat(operation.request.identifier, "-").concat(fetchKey !== null && fetchKey !== void 0 ? fetchKey : '');
|
98
|
+
}
|
99
|
+
|
100
|
+
function constructQueryResult(operation) {
|
101
|
+
var rootFragmentRef = {
|
102
|
+
__id: operation.fragment.dataID,
|
103
|
+
__fragments: (0, _defineProperty2["default"])({}, operation.fragment.node.name, operation.request.variables),
|
104
|
+
__fragmentOwner: operation.request
|
105
|
+
};
|
106
|
+
return {
|
107
|
+
fragmentNode: operation.request.node.fragment,
|
108
|
+
fragmentRef: rootFragmentRef
|
109
|
+
};
|
110
|
+
}
|
111
|
+
|
112
|
+
function makeInitialCacheEntry() {
|
113
|
+
return {
|
114
|
+
status: 'pending',
|
115
|
+
promise: noopPromise,
|
116
|
+
onCommit: noopOnCommit,
|
117
|
+
suspenseResource: null
|
118
|
+
};
|
119
|
+
}
|
120
|
+
|
121
|
+
function getQueryResultOrFetchQuery_REACT_CACHE(environment, queryOperationDescriptor, options) {
|
122
|
+
var _options$fetchPolicy, _options$renderPolicy;
|
123
|
+
|
124
|
+
var fetchPolicy = (_options$fetchPolicy = options === null || options === void 0 ? void 0 : options.fetchPolicy) !== null && _options$fetchPolicy !== void 0 ? _options$fetchPolicy : DEFAULT_FETCH_POLICY;
|
125
|
+
var renderPolicy = (_options$renderPolicy = options === null || options === void 0 ? void 0 : options.renderPolicy) !== null && _options$renderPolicy !== void 0 ? _options$renderPolicy : environment.UNSTABLE_getDefaultRenderPolicy();
|
126
|
+
var cache = getCacheForType(createQueryCache);
|
127
|
+
var cacheKey = getQueryCacheKey(queryOperationDescriptor, fetchPolicy, renderPolicy, options === null || options === void 0 ? void 0 : options.fetchKey);
|
128
|
+
var initialEntry = cache.get(environment, cacheKey);
|
129
|
+
|
130
|
+
function updateCache(updater) {
|
131
|
+
var currentEntry = cache.get(environment, cacheKey);
|
132
|
+
|
133
|
+
if (!currentEntry) {
|
134
|
+
currentEntry = makeInitialCacheEntry();
|
135
|
+
cache.set(environment, cacheKey, currentEntry);
|
136
|
+
} // $FlowExpectedError[prop-missing] Extra properties are passed in -- this is fine
|
137
|
+
|
138
|
+
|
139
|
+
var newStatus = updater(currentEntry); // $FlowExpectedError[cannot-spread-inexact] Flow cannot understand that this is valid...
|
140
|
+
|
141
|
+
cache.set(environment, cacheKey, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, currentEntry), newStatus)); // ... but we can because QueryCacheEntry spreads QueryCacheEntryStatus, so spreading
|
142
|
+
// a QueryCacheEntryStatus into a QueryCacheEntry will result in a valid QueryCacheEntry.
|
143
|
+
} // Initiate a query to fetch the data if needed:
|
144
|
+
|
145
|
+
|
146
|
+
if (RelayFeatureFlags.USE_REACT_CACHE_LEGACY_TIMEOUTS) {
|
147
|
+
var _entry;
|
148
|
+
|
149
|
+
if (initialEntry === undefined) {
|
150
|
+
onCacheMiss(environment, queryOperationDescriptor, fetchPolicy, renderPolicy, updateCache, options === null || options === void 0 ? void 0 : options.fetchObservable);
|
151
|
+
var createdEntry = cache.get(environment, cacheKey);
|
152
|
+
!(createdEntry !== undefined) ? process.env.NODE_ENV !== "production" ? invariant(false, 'An entry should have been created by onCacheMiss. This is a bug in Relay.') : invariant(false) : void 0;
|
153
|
+
_entry = createdEntry;
|
154
|
+
} else {
|
155
|
+
_entry = initialEntry;
|
156
|
+
}
|
157
|
+
|
158
|
+
if (!_entry.suspenseResource) {
|
159
|
+
_entry.suspenseResource = new SuspenseResource(function () {
|
160
|
+
var retention = environment.retain(queryOperationDescriptor);
|
161
|
+
return {
|
162
|
+
dispose: function dispose() {
|
163
|
+
retention.dispose();
|
164
|
+
cache["delete"](environment, cacheKey);
|
165
|
+
}
|
166
|
+
};
|
167
|
+
});
|
168
|
+
}
|
169
|
+
|
170
|
+
if (_entry.onCommit === noopOnCommit) {
|
171
|
+
_entry.onCommit = function () {
|
172
|
+
!_entry.suspenseResource ? process.env.NODE_ENV !== "production" ? invariant(false, 'SuspenseResource should have been initialized. This is a bug in Relay.') : invariant(false) : void 0;
|
173
|
+
|
174
|
+
var retention = _entry.suspenseResource.permanentRetain(environment);
|
175
|
+
|
176
|
+
return function () {
|
177
|
+
retention.dispose();
|
178
|
+
};
|
179
|
+
};
|
180
|
+
}
|
181
|
+
|
182
|
+
_entry.suspenseResource.temporaryRetain(environment);
|
183
|
+
} else {
|
184
|
+
if (initialEntry === undefined) {
|
185
|
+
// This is the behavior we eventually want: We retain the query until the
|
186
|
+
// presiding Cache component unmounts, at which point the AbortSignal
|
187
|
+
// will be triggered.
|
188
|
+
onCacheMiss(environment, queryOperationDescriptor, fetchPolicy, renderPolicy, updateCache, options === null || options === void 0 ? void 0 : options.fetchObservable); // Since this is the first time rendering, retain the query. React will
|
189
|
+
// trigger the abort signal when this cache entry is no longer needed.
|
190
|
+
|
191
|
+
var retention = environment.retain(queryOperationDescriptor);
|
192
|
+
|
193
|
+
var dispose = function dispose() {
|
194
|
+
retention.dispose();
|
195
|
+
cache["delete"](environment, cacheKey);
|
196
|
+
};
|
197
|
+
|
198
|
+
var abortSignal = getCacheSignal();
|
199
|
+
abortSignal.addEventListener('abort', dispose, {
|
200
|
+
once: true
|
201
|
+
});
|
202
|
+
}
|
203
|
+
}
|
204
|
+
|
205
|
+
var entry = cache.get(environment, cacheKey); // could be a different entry now if synchronously resolved
|
206
|
+
|
207
|
+
!(entry !== undefined) ? process.env.NODE_ENV !== "production" ? invariant(false, 'An entry should have been created by onCacheMiss. This is a bug in Relay.') : invariant(false) : void 0;
|
208
|
+
|
209
|
+
switch (entry.status) {
|
210
|
+
case 'pending':
|
211
|
+
throw entry.promise;
|
212
|
+
|
213
|
+
case 'rejected':
|
214
|
+
throw entry.error;
|
215
|
+
|
216
|
+
case 'resolved':
|
217
|
+
return [entry.result, entry.onCommit];
|
218
|
+
}
|
219
|
+
|
220
|
+
!false ? process.env.NODE_ENV !== "production" ? invariant(false, 'switch statement should be exhaustive') : invariant(false) : void 0;
|
221
|
+
}
|
222
|
+
|
223
|
+
function onCacheMiss(environment, operation, fetchPolicy, renderPolicy, updateCache, customFetchObservable) {
|
224
|
+
// NB: Besides checking if the data is available, calling `check` will write missing
|
225
|
+
// data to the store using any missing data handlers specified in the environment.
|
226
|
+
var queryAvailability = environment.check(operation);
|
227
|
+
var queryStatus = queryAvailability.status;
|
228
|
+
var hasFullQuery = queryStatus === 'available';
|
229
|
+
var canPartialRender = hasFullQuery || renderPolicy === 'partial' && queryStatus !== 'stale';
|
230
|
+
var shouldFetch;
|
231
|
+
var shouldRenderNow;
|
232
|
+
|
233
|
+
switch (fetchPolicy) {
|
234
|
+
case 'store-only':
|
235
|
+
{
|
236
|
+
shouldFetch = false;
|
237
|
+
shouldRenderNow = true;
|
238
|
+
break;
|
239
|
+
}
|
240
|
+
|
241
|
+
case 'store-or-network':
|
242
|
+
{
|
243
|
+
shouldFetch = !hasFullQuery;
|
244
|
+
shouldRenderNow = canPartialRender;
|
245
|
+
break;
|
246
|
+
}
|
247
|
+
|
248
|
+
case 'store-and-network':
|
249
|
+
{
|
250
|
+
shouldFetch = true;
|
251
|
+
shouldRenderNow = canPartialRender;
|
252
|
+
break;
|
253
|
+
}
|
254
|
+
|
255
|
+
case 'network-only':
|
256
|
+
default:
|
257
|
+
{
|
258
|
+
shouldFetch = true;
|
259
|
+
shouldRenderNow = false;
|
260
|
+
break;
|
261
|
+
}
|
262
|
+
}
|
263
|
+
|
264
|
+
if (shouldFetch) {
|
265
|
+
executeOperationAndKeepUpToDate(environment, operation, updateCache, customFetchObservable);
|
266
|
+
updateCache(function (existing) {
|
267
|
+
switch (existing.status) {
|
268
|
+
case 'resolved':
|
269
|
+
return existing;
|
270
|
+
|
271
|
+
case 'rejected':
|
272
|
+
return existing;
|
273
|
+
|
274
|
+
case 'pending':
|
275
|
+
return shouldRenderNow ? {
|
276
|
+
status: 'resolved',
|
277
|
+
result: constructQueryResult(operation)
|
278
|
+
} : existing;
|
279
|
+
}
|
280
|
+
});
|
281
|
+
} else {
|
282
|
+
!shouldRenderNow ? process.env.NODE_ENV !== "production" ? invariant(false, 'Should either fetch or be willing to render. This is a bug in Relay.') : invariant(false) : void 0;
|
283
|
+
updateCache(function (_existing) {
|
284
|
+
return {
|
285
|
+
status: 'resolved',
|
286
|
+
result: constructQueryResult(operation)
|
287
|
+
};
|
288
|
+
});
|
289
|
+
}
|
290
|
+
}
|
291
|
+
|
292
|
+
function executeOperationAndKeepUpToDate(environment, operation, updateCache, customFetchObservable) {
|
293
|
+
var resolvePromise;
|
294
|
+
var promise = new Promise(function (r) {
|
295
|
+
resolvePromise = r;
|
296
|
+
}); // $FlowExpectedError[prop-missing] Expando to annotate Promises.
|
297
|
+
|
298
|
+
promise.displayName = 'Relay(' + operation.request.node.operation.name + ')';
|
299
|
+
var isFirstPayload = true; // FIXME We may still need to cancel network requests for live queries.
|
300
|
+
|
301
|
+
var fetchObservable = customFetchObservable !== null && customFetchObservable !== void 0 ? customFetchObservable : fetchQueryInternal(environment, operation);
|
302
|
+
fetchObservable.subscribe({
|
303
|
+
start: function start(subscription) {},
|
304
|
+
error: function error(_error) {
|
305
|
+
if (isFirstPayload) {
|
306
|
+
updateCache(function (_existing) {
|
307
|
+
return {
|
308
|
+
status: 'rejected',
|
309
|
+
error: _error
|
310
|
+
};
|
311
|
+
});
|
312
|
+
} else {
|
313
|
+
// TODO:T92030819 Remove this warning and actually throw the network error
|
314
|
+
// To complete this task we need to have a way of precisely tracking suspendable points
|
315
|
+
process.env.NODE_ENV !== "production" ? warning(false, 'getQueryResultOrFetchQuery: An incremental payload for query `%` returned an error: `%`:`%`.', operation.request.node.operation.name, _error.message, _error.stack) : void 0;
|
316
|
+
}
|
317
|
+
|
318
|
+
resolvePromise();
|
319
|
+
isFirstPayload = false;
|
320
|
+
},
|
321
|
+
next: function next(response) {
|
322
|
+
// Stop suspending on the first payload because of streaming, defer, etc.
|
323
|
+
updateCache(function (_existing) {
|
324
|
+
return {
|
325
|
+
status: 'resolved',
|
326
|
+
result: constructQueryResult(operation)
|
327
|
+
};
|
328
|
+
});
|
329
|
+
resolvePromise();
|
330
|
+
isFirstPayload = false;
|
331
|
+
}
|
332
|
+
}); // If the above subscription yields a value synchronously, then one of the updates
|
333
|
+
// above will have already happened and we'll now be in a resolved or rejected state.
|
334
|
+
// But in the usual case, we save the promise to the entry here:
|
335
|
+
|
336
|
+
updateCache(function (existing) {
|
337
|
+
return existing.status === 'pending' ? {
|
338
|
+
status: 'pending',
|
339
|
+
promise: promise
|
340
|
+
} : existing;
|
341
|
+
});
|
342
|
+
}
|
343
|
+
|
344
|
+
module.exports = getQueryResultOrFetchQuery_REACT_CACHE;
|