react-relay 15.0.0 → 16.1.0
Sign up to get free protection for your applications and to get access to all the features.
- package/ReactRelayContext.js +1 -1
- package/ReactRelayQueryFetcher.js.flow +1 -5
- package/ReactRelayQueryRenderer.js.flow +9 -36
- package/ReactRelayTypes.js.flow +1 -0
- package/buildReactRelayContainer.js.flow +3 -1
- package/hooks.js +1 -1
- package/index.js +1 -1
- package/legacy.js +1 -1
- package/lib/ReactRelayContainerUtils.js +0 -11
- package/lib/ReactRelayContext.js +0 -11
- package/lib/ReactRelayFragmentContainer.js +6 -78
- package/lib/ReactRelayFragmentMockRenderer.js +0 -11
- package/lib/ReactRelayLocalQueryRenderer.js +0 -17
- package/lib/ReactRelayPaginationContainer.js +5 -208
- package/lib/ReactRelayQueryFetcher.js +2 -51
- package/lib/ReactRelayQueryRenderer.js +6 -94
- package/lib/ReactRelayQueryRendererContext.js +0 -11
- package/lib/ReactRelayRefetchContainer.js +5 -91
- package/lib/ReactRelayTestMocker.js +9 -85
- package/lib/ReactRelayTypes.js +0 -11
- package/lib/RelayContext.js +0 -21
- package/lib/assertFragmentMap.js +0 -15
- package/lib/buildReactRelayContainer.js +0 -19
- package/lib/getRootVariablesForFragments.js +0 -14
- package/lib/hooks.js +0 -15
- package/lib/index.js +0 -17
- package/lib/isRelayEnvironment.js +1 -18
- package/lib/jest-react/enqueueTask.js +0 -20
- package/lib/jest-react/internalAct.js +0 -38
- package/lib/legacy.js +0 -15
- package/lib/multi-actor/ActorChange.js +0 -11
- package/lib/multi-actor/index.js +0 -11
- package/lib/multi-actor/useRelayActorEnvironment.js +0 -11
- package/lib/relay-hooks/EntryPointContainer.react.js +0 -11
- package/lib/relay-hooks/EntryPointTypes.flow.js +1 -14
- package/lib/relay-hooks/FragmentResource.js +76 -132
- package/lib/relay-hooks/HooksImplementation.js +1 -12
- package/lib/relay-hooks/InternalLogger.js +0 -11
- package/lib/relay-hooks/LRUCache.js +0 -22
- package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +0 -18
- package/lib/relay-hooks/MatchContainer.js +0 -94
- package/lib/relay-hooks/NestedRelayEntryPointBuilderUtils.js +9 -0
- package/lib/relay-hooks/ProfilerContext.js +0 -15
- package/lib/relay-hooks/QueryResource.js +2 -68
- package/lib/relay-hooks/RelayEnvironmentProvider.js +0 -11
- package/lib/relay-hooks/SuspenseResource.js +0 -34
- package/lib/relay-hooks/{react-cache/readFragmentInternal_REACT_CACHE.js → experimental/readFragmentInternal_EXPERIMENTAL.js} +5 -29
- package/lib/relay-hooks/{react-cache/useFragmentInternal_REACT_CACHE.js → experimental/useFragmentInternal_EXPERIMENTAL.js} +35 -100
- package/lib/relay-hooks/{react-cache/useFragment_REACT_CACHE.js → experimental/useFragment_EXPERIMENTAL.js} +1 -16
- package/lib/relay-hooks/{react-cache/usePaginationFragment_REACT_CACHE.js → experimental/usePaginationFragment_EXPERIMENTAL.js} +2 -24
- package/lib/relay-hooks/{react-cache/useRefetchableFragmentInternal_REACT_CACHE.js → experimental/useRefetchableFragmentInternal_EXPERIMENTAL.js} +14 -98
- package/lib/relay-hooks/{react-cache/useRefetchableFragment_REACT_CACHE.js → experimental/useRefetchableFragment_EXPERIMENTAL.js} +1 -15
- package/lib/relay-hooks/loadEntryPoint.js +1 -24
- package/lib/relay-hooks/loadQuery.js +2 -106
- package/lib/relay-hooks/preloadQuery_DEPRECATED.js +2 -27
- package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +0 -13
- package/lib/relay-hooks/useBlockingPaginationFragment.js +0 -42
- package/lib/relay-hooks/useClientQuery.js +0 -18
- package/lib/relay-hooks/useEntryPointLoader.js +0 -69
- package/lib/relay-hooks/useFetchTrackingRef.js +0 -26
- package/lib/relay-hooks/useFragment.js +0 -17
- package/lib/relay-hooks/useFragmentNode.js +2 -32
- package/lib/relay-hooks/useIsMountedRef.js +0 -11
- package/lib/relay-hooks/useIsOperationNodeActive.js +0 -11
- package/lib/relay-hooks/useIsParentQueryActive.js +0 -11
- package/lib/relay-hooks/useLazyLoadQuery.js +0 -18
- package/lib/relay-hooks/useLazyLoadQueryNode.js +12 -37
- package/lib/relay-hooks/useLoadMoreFunction.js +9 -34
- package/lib/relay-hooks/useMemoOperationDescriptor.js +0 -11
- package/lib/relay-hooks/useMemoVariables.js +0 -17
- package/lib/relay-hooks/useMutation.js +0 -11
- package/lib/relay-hooks/usePaginationFragment.js +1 -26
- package/lib/relay-hooks/usePreloadedQuery.js +0 -27
- package/lib/relay-hooks/useQueryLoader.js +0 -74
- package/lib/relay-hooks/useRefetchableFragment.js +0 -16
- package/lib/relay-hooks/useRefetchableFragmentNode.js +14 -97
- package/lib/relay-hooks/useRelayEnvironment.js +0 -11
- package/lib/relay-hooks/useStaticFragmentNodeWarning.js +0 -15
- package/lib/relay-hooks/useSubscribeToInvalidationState.js +0 -25
- package/lib/relay-hooks/useSubscription.js +0 -15
- package/lib/relay-hooks/useUnsafeRef_DEPRECATED.js +0 -17
- package/package.json +2 -2
- package/react-relay-hooks.js +2 -2
- package/react-relay-hooks.min.js +2 -2
- package/react-relay-legacy.js +2 -2
- package/react-relay-legacy.min.js +2 -2
- package/react-relay.js +2 -2
- package/react-relay.min.js +2 -2
- package/relay-hooks/EntryPointContainer.react.js.flow +5 -0
- package/relay-hooks/EntryPointTypes.flow.js.flow +34 -35
- package/relay-hooks/FragmentResource.js.flow +114 -26
- package/relay-hooks/HooksImplementation.js.flow +3 -1
- package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +4 -2
- package/relay-hooks/NestedRelayEntryPointBuilderUtils.js.flow +51 -0
- package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +7 -5
- package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +5 -0
- package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +5 -0
- package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +2 -0
- package/relay-hooks/{react-cache/readFragmentInternal_REACT_CACHE.js.flow → experimental/readFragmentInternal_EXPERIMENTAL.js.flow} +4 -3
- package/relay-hooks/{react-cache/useFragmentInternal_REACT_CACHE.js.flow → experimental/useFragmentInternal_EXPERIMENTAL.js.flow} +32 -14
- package/relay-hooks/{react-cache/useFragment_REACT_CACHE.js.flow → experimental/useFragment_EXPERIMENTAL.js.flow} +4 -10
- package/relay-hooks/{react-cache/usePaginationFragment_REACT_CACHE.js.flow → experimental/usePaginationFragment_EXPERIMENTAL.js.flow} +30 -59
- package/relay-hooks/{react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow → experimental/useRefetchableFragmentInternal_EXPERIMENTAL.js.flow} +30 -23
- package/relay-hooks/experimental/useRefetchableFragment_EXPERIMENTAL.js.flow +49 -0
- package/relay-hooks/loadEntryPoint.js.flow +4 -2
- package/relay-hooks/loadQuery.js.flow +21 -1
- package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +4 -2
- package/relay-hooks/useBlockingPaginationFragment.js.flow +10 -17
- package/relay-hooks/useClientQuery.js.flow +2 -2
- package/relay-hooks/useFragmentNode.js.flow +2 -2
- package/relay-hooks/useLazyLoadQueryNode.js.flow +17 -1
- package/relay-hooks/useLoadMoreFunction.js.flow +15 -9
- package/relay-hooks/useMutation.js.flow +26 -9
- package/relay-hooks/usePaginationFragment.js.flow +7 -15
- package/relay-hooks/useQueryLoader.js.flow +2 -8
- package/relay-hooks/useRefetchableFragment.js.flow +14 -16
- package/relay-hooks/useRefetchableFragmentNode.js.flow +33 -20
- package/lib/relay-hooks/react-cache/RelayReactCache.js +0 -32
- package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +0 -290
- package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +0 -49
- package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +0 -110
- package/relay-hooks/react-cache/RelayReactCache.js.flow +0 -40
- package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +0 -430
- package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +0 -70
- package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +0 -150
- package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +0 -65
@@ -1,290 +0,0 @@
|
|
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
|
-
* @format
|
9
|
-
* @oncall relay
|
10
|
-
*/
|
11
|
-
|
12
|
-
'use strict';
|
13
|
-
|
14
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
15
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
16
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
17
|
-
var SuspenseResource = require('../SuspenseResource');
|
18
|
-
var _require = require('./RelayReactCache'),
|
19
|
-
getCacheForType = _require.getCacheForType,
|
20
|
-
getCacheSignal = _require.getCacheSignal;
|
21
|
-
var invariant = require('invariant');
|
22
|
-
var _require2 = require('relay-runtime'),
|
23
|
-
fetchQueryInternal = _require2.__internal.fetchQuery,
|
24
|
-
RelayFeatureFlags = _require2.RelayFeatureFlags;
|
25
|
-
var warning = require("fbjs/lib/warning");
|
26
|
-
var DEFAULT_FETCH_POLICY = 'store-or-network';
|
27
|
-
var WEAKMAP_SUPPORTED = typeof WeakMap === 'function';
|
28
|
-
var QueryCache = /*#__PURE__*/function () {
|
29
|
-
function QueryCache() {
|
30
|
-
this._map = WEAKMAP_SUPPORTED ? new WeakMap() : new Map();
|
31
|
-
}
|
32
|
-
var _proto = QueryCache.prototype;
|
33
|
-
_proto.get = function get(environment, key) {
|
34
|
-
var forEnv = this._map.get(environment);
|
35
|
-
if (!forEnv) {
|
36
|
-
forEnv = new Map();
|
37
|
-
this._map.set(environment, forEnv);
|
38
|
-
}
|
39
|
-
return forEnv.get(key);
|
40
|
-
};
|
41
|
-
_proto.set = function set(environment, key, value) {
|
42
|
-
var forEnv = this._map.get(environment);
|
43
|
-
if (!forEnv) {
|
44
|
-
forEnv = new Map();
|
45
|
-
this._map.set(environment, forEnv);
|
46
|
-
}
|
47
|
-
forEnv.set(key, value);
|
48
|
-
};
|
49
|
-
_proto["delete"] = function _delete(environment, key) {
|
50
|
-
var forEnv = this._map.get(environment);
|
51
|
-
if (!forEnv) {
|
52
|
-
return;
|
53
|
-
}
|
54
|
-
forEnv["delete"](key);
|
55
|
-
if (forEnv.size === 0) {
|
56
|
-
this._map["delete"](environment);
|
57
|
-
}
|
58
|
-
};
|
59
|
-
return QueryCache;
|
60
|
-
}();
|
61
|
-
function createQueryCache() {
|
62
|
-
return new QueryCache();
|
63
|
-
}
|
64
|
-
var noopOnCommit = function noopOnCommit() {
|
65
|
-
return function () {
|
66
|
-
return undefined;
|
67
|
-
};
|
68
|
-
};
|
69
|
-
var noopPromise = new Promise(function () {});
|
70
|
-
function getQueryCacheKey(operation, fetchPolicy, renderPolicy, fetchKey) {
|
71
|
-
return "".concat(fetchPolicy, "-").concat(renderPolicy, "-").concat(operation.request.identifier, "-").concat(fetchKey !== null && fetchKey !== void 0 ? fetchKey : '');
|
72
|
-
}
|
73
|
-
function constructQueryResult(operation) {
|
74
|
-
var rootFragmentRef = {
|
75
|
-
__id: operation.fragment.dataID,
|
76
|
-
__fragments: (0, _defineProperty2["default"])({}, operation.fragment.node.name, operation.request.variables),
|
77
|
-
__fragmentOwner: operation.request
|
78
|
-
};
|
79
|
-
return {
|
80
|
-
fragmentNode: operation.request.node.fragment,
|
81
|
-
fragmentRef: rootFragmentRef
|
82
|
-
};
|
83
|
-
}
|
84
|
-
function makeInitialCacheEntry() {
|
85
|
-
return {
|
86
|
-
status: 'pending',
|
87
|
-
promise: noopPromise,
|
88
|
-
onCommit: noopOnCommit,
|
89
|
-
suspenseResource: null
|
90
|
-
};
|
91
|
-
}
|
92
|
-
function getQueryResultOrFetchQuery_REACT_CACHE(environment, queryOperationDescriptor, options) {
|
93
|
-
var _options$fetchPolicy, _options$renderPolicy;
|
94
|
-
var fetchPolicy = (_options$fetchPolicy = options === null || options === void 0 ? void 0 : options.fetchPolicy) !== null && _options$fetchPolicy !== void 0 ? _options$fetchPolicy : DEFAULT_FETCH_POLICY;
|
95
|
-
var renderPolicy = (_options$renderPolicy = options === null || options === void 0 ? void 0 : options.renderPolicy) !== null && _options$renderPolicy !== void 0 ? _options$renderPolicy : environment.UNSTABLE_getDefaultRenderPolicy();
|
96
|
-
var cache = getCacheForType(createQueryCache);
|
97
|
-
var cacheKey = getQueryCacheKey(queryOperationDescriptor, fetchPolicy, renderPolicy, options === null || options === void 0 ? void 0 : options.fetchKey);
|
98
|
-
var initialEntry = cache.get(environment, cacheKey);
|
99
|
-
function updateCache(updater) {
|
100
|
-
var currentEntry = cache.get(environment, cacheKey);
|
101
|
-
if (!currentEntry) {
|
102
|
-
currentEntry = makeInitialCacheEntry();
|
103
|
-
cache.set(environment, cacheKey, currentEntry);
|
104
|
-
}
|
105
|
-
// $FlowExpectedError[prop-missing] Extra properties are passed in -- this is fine
|
106
|
-
var newStatus = updater(currentEntry);
|
107
|
-
// $FlowExpectedError[cannot-spread-inexact] Flow cannot understand that this is valid...
|
108
|
-
cache.set(environment, cacheKey, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, currentEntry), newStatus));
|
109
|
-
// ... but we can because QueryCacheEntry spreads QueryCacheEntryStatus, so spreading
|
110
|
-
// a QueryCacheEntryStatus into a QueryCacheEntry will result in a valid QueryCacheEntry.
|
111
|
-
}
|
112
|
-
|
113
|
-
// Initiate a query to fetch the data if needed:
|
114
|
-
if (RelayFeatureFlags.USE_REACT_CACHE_LEGACY_TIMEOUTS) {
|
115
|
-
var _entry;
|
116
|
-
if (initialEntry === undefined) {
|
117
|
-
onCacheMiss(environment, queryOperationDescriptor, fetchPolicy, renderPolicy, updateCache, options === null || options === void 0 ? void 0 : options.fetchObservable);
|
118
|
-
var createdEntry = cache.get(environment, cacheKey);
|
119
|
-
!(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;
|
120
|
-
_entry = createdEntry;
|
121
|
-
} else {
|
122
|
-
_entry = initialEntry;
|
123
|
-
}
|
124
|
-
if (!_entry.suspenseResource) {
|
125
|
-
_entry.suspenseResource = new SuspenseResource(function () {
|
126
|
-
var retention = environment.retain(queryOperationDescriptor);
|
127
|
-
return {
|
128
|
-
dispose: function dispose() {
|
129
|
-
retention.dispose();
|
130
|
-
cache["delete"](environment, cacheKey);
|
131
|
-
}
|
132
|
-
};
|
133
|
-
});
|
134
|
-
}
|
135
|
-
if (_entry.onCommit === noopOnCommit) {
|
136
|
-
_entry.onCommit = function () {
|
137
|
-
!_entry.suspenseResource ? process.env.NODE_ENV !== "production" ? invariant(false, 'SuspenseResource should have been initialized. This is a bug in Relay.') : invariant(false) : void 0;
|
138
|
-
var retention = _entry.suspenseResource.permanentRetain(environment);
|
139
|
-
return function () {
|
140
|
-
retention.dispose();
|
141
|
-
};
|
142
|
-
};
|
143
|
-
}
|
144
|
-
_entry.suspenseResource.temporaryRetain(environment);
|
145
|
-
} else {
|
146
|
-
if (initialEntry === undefined) {
|
147
|
-
// This is the behavior we eventually want: We retain the query until the
|
148
|
-
// presiding Cache component unmounts, at which point the AbortSignal
|
149
|
-
// will be triggered.
|
150
|
-
onCacheMiss(environment, queryOperationDescriptor, fetchPolicy, renderPolicy, updateCache, options === null || options === void 0 ? void 0 : options.fetchObservable);
|
151
|
-
|
152
|
-
// Since this is the first time rendering, retain the query. React will
|
153
|
-
// trigger the abort signal when this cache entry is no longer needed.
|
154
|
-
var retention = environment.retain(queryOperationDescriptor);
|
155
|
-
var dispose = function dispose() {
|
156
|
-
retention.dispose();
|
157
|
-
cache["delete"](environment, cacheKey);
|
158
|
-
};
|
159
|
-
var abortSignal = getCacheSignal();
|
160
|
-
abortSignal.addEventListener('abort', dispose, {
|
161
|
-
once: true
|
162
|
-
});
|
163
|
-
}
|
164
|
-
}
|
165
|
-
var entry = cache.get(environment, cacheKey); // could be a different entry now if synchronously resolved
|
166
|
-
!(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;
|
167
|
-
switch (entry.status) {
|
168
|
-
case 'pending':
|
169
|
-
throw entry.promise;
|
170
|
-
case 'rejected':
|
171
|
-
throw entry.error;
|
172
|
-
case 'resolved':
|
173
|
-
return [entry.result, entry.onCommit];
|
174
|
-
}
|
175
|
-
!false ? process.env.NODE_ENV !== "production" ? invariant(false, 'switch statement should be exhaustive') : invariant(false) : void 0;
|
176
|
-
}
|
177
|
-
function onCacheMiss(environment, operation, fetchPolicy, renderPolicy, updateCache, customFetchObservable) {
|
178
|
-
// NB: Besides checking if the data is available, calling `check` will write missing
|
179
|
-
// data to the store using any missing data handlers specified in the environment.
|
180
|
-
var queryAvailability = environment.check(operation);
|
181
|
-
var queryStatus = queryAvailability.status;
|
182
|
-
var hasFullQuery = queryStatus === 'available';
|
183
|
-
var canPartialRender = hasFullQuery || renderPolicy === 'partial' && queryStatus !== 'stale';
|
184
|
-
var shouldFetch;
|
185
|
-
var shouldRenderNow;
|
186
|
-
switch (fetchPolicy) {
|
187
|
-
case 'store-only':
|
188
|
-
{
|
189
|
-
shouldFetch = false;
|
190
|
-
shouldRenderNow = true;
|
191
|
-
break;
|
192
|
-
}
|
193
|
-
case 'store-or-network':
|
194
|
-
{
|
195
|
-
shouldFetch = !hasFullQuery;
|
196
|
-
shouldRenderNow = canPartialRender;
|
197
|
-
break;
|
198
|
-
}
|
199
|
-
case 'store-and-network':
|
200
|
-
{
|
201
|
-
shouldFetch = true;
|
202
|
-
shouldRenderNow = canPartialRender;
|
203
|
-
break;
|
204
|
-
}
|
205
|
-
case 'network-only':
|
206
|
-
default:
|
207
|
-
{
|
208
|
-
shouldFetch = true;
|
209
|
-
shouldRenderNow = false;
|
210
|
-
break;
|
211
|
-
}
|
212
|
-
}
|
213
|
-
if (shouldFetch) {
|
214
|
-
executeOperationAndKeepUpToDate(environment, operation, updateCache, customFetchObservable);
|
215
|
-
updateCache(function (existing) {
|
216
|
-
switch (existing.status) {
|
217
|
-
case 'resolved':
|
218
|
-
return existing;
|
219
|
-
case 'rejected':
|
220
|
-
return existing;
|
221
|
-
case 'pending':
|
222
|
-
return shouldRenderNow ? {
|
223
|
-
status: 'resolved',
|
224
|
-
result: constructQueryResult(operation)
|
225
|
-
} : existing;
|
226
|
-
}
|
227
|
-
});
|
228
|
-
} else {
|
229
|
-
!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;
|
230
|
-
updateCache(function (_existing) {
|
231
|
-
return {
|
232
|
-
status: 'resolved',
|
233
|
-
result: constructQueryResult(operation)
|
234
|
-
};
|
235
|
-
});
|
236
|
-
}
|
237
|
-
}
|
238
|
-
function executeOperationAndKeepUpToDate(environment, operation, updateCache, customFetchObservable) {
|
239
|
-
var resolvePromise;
|
240
|
-
var promise = new Promise(function (r) {
|
241
|
-
resolvePromise = r;
|
242
|
-
});
|
243
|
-
// $FlowExpectedError[prop-missing] Expando to annotate Promises.
|
244
|
-
promise.displayName = 'Relay(' + operation.request.node.operation.name + ')';
|
245
|
-
var isFirstPayload = true;
|
246
|
-
|
247
|
-
// FIXME We may still need to cancel network requests for live queries.
|
248
|
-
var fetchObservable = customFetchObservable !== null && customFetchObservable !== void 0 ? customFetchObservable : fetchQueryInternal(environment, operation);
|
249
|
-
fetchObservable.subscribe({
|
250
|
-
start: function start(subscription) {},
|
251
|
-
error: function error(_error) {
|
252
|
-
if (isFirstPayload) {
|
253
|
-
updateCache(function (_existing) {
|
254
|
-
return {
|
255
|
-
status: 'rejected',
|
256
|
-
error: _error
|
257
|
-
};
|
258
|
-
});
|
259
|
-
} else {
|
260
|
-
// TODO:T92030819 Remove this warning and actually throw the network error
|
261
|
-
// To complete this task we need to have a way of precisely tracking suspendable points
|
262
|
-
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;
|
263
|
-
}
|
264
|
-
resolvePromise();
|
265
|
-
isFirstPayload = false;
|
266
|
-
},
|
267
|
-
next: function next(response) {
|
268
|
-
// Stop suspending on the first payload because of streaming, defer, etc.
|
269
|
-
updateCache(function (_existing) {
|
270
|
-
return {
|
271
|
-
status: 'resolved',
|
272
|
-
result: constructQueryResult(operation)
|
273
|
-
};
|
274
|
-
});
|
275
|
-
resolvePromise();
|
276
|
-
isFirstPayload = false;
|
277
|
-
}
|
278
|
-
});
|
279
|
-
|
280
|
-
// If the above subscription yields a value synchronously, then one of the updates
|
281
|
-
// above will have already happened and we'll now be in a resolved or rejected state.
|
282
|
-
// But in the usual case, we save the promise to the entry here:
|
283
|
-
updateCache(function (existing) {
|
284
|
-
return existing.status === 'pending' ? {
|
285
|
-
status: 'pending',
|
286
|
-
promise: promise
|
287
|
-
} : existing;
|
288
|
-
});
|
289
|
-
}
|
290
|
-
module.exports = getQueryResultOrFetchQuery_REACT_CACHE;
|
@@ -1,49 +0,0 @@
|
|
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
|
-
* @format
|
9
|
-
* @oncall relay
|
10
|
-
*/
|
11
|
-
|
12
|
-
'use strict';
|
13
|
-
|
14
|
-
var _require = require('../loadQuery'),
|
15
|
-
useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
|
16
|
-
var useMemoOperationDescriptor = require('../useMemoOperationDescriptor');
|
17
|
-
var useRelayEnvironment = require('../useRelayEnvironment');
|
18
|
-
var getQueryResultOrFetchQuery = require('./getQueryResultOrFetchQuery_REACT_CACHE');
|
19
|
-
var useFragmentInternal = require('./useFragmentInternal_REACT_CACHE');
|
20
|
-
var _require2 = require('react'),
|
21
|
-
useEffect = _require2.useEffect;
|
22
|
-
function useLazyLoadQuery_REACT_CACHE(gqlQuery, variables, options) {
|
23
|
-
var _options$networkCache;
|
24
|
-
useTrackLoadQueryInRender();
|
25
|
-
var environment = useRelayEnvironment();
|
26
|
-
var queryOperationDescriptor = useMemoOperationDescriptor(gqlQuery, variables, (_options$networkCache = options === null || options === void 0 ? void 0 : options.networkCacheConfig) !== null && _options$networkCache !== void 0 ? _options$networkCache : {
|
27
|
-
force: true
|
28
|
-
});
|
29
|
-
|
30
|
-
// Get the query going if needed -- this may suspend.
|
31
|
-
var _getQueryResultOrFetc = getQueryResultOrFetchQuery(environment, queryOperationDescriptor, {
|
32
|
-
fetchPolicy: options === null || options === void 0 ? void 0 : options.fetchPolicy,
|
33
|
-
renderPolicy: options === null || options === void 0 ? void 0 : options.UNSTABLE_renderPolicy,
|
34
|
-
fetchKey: options === null || options === void 0 ? void 0 : options.fetchKey
|
35
|
-
}),
|
36
|
-
queryResult = _getQueryResultOrFetc[0],
|
37
|
-
effect = _getQueryResultOrFetc[1];
|
38
|
-
useEffect(effect);
|
39
|
-
|
40
|
-
// Read the query's root fragment -- this may suspend.
|
41
|
-
var fragmentNode = queryResult.fragmentNode,
|
42
|
-
fragmentRef = queryResult.fragmentRef;
|
43
|
-
// $FlowExpectedError[incompatible-return] Is this a fixable incompatible-return?
|
44
|
-
return useFragmentInternal(fragmentNode, fragmentRef, 'useLazyLoadQuery()', {
|
45
|
-
fetchPolicy: options === null || options === void 0 ? void 0 : options.fetchPolicy,
|
46
|
-
networkCacheConfig: options === null || options === void 0 ? void 0 : options.networkCacheConfig
|
47
|
-
});
|
48
|
-
}
|
49
|
-
module.exports = useLazyLoadQuery_REACT_CACHE;
|
@@ -1,110 +0,0 @@
|
|
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
|
-
* @format
|
9
|
-
* @oncall relay
|
10
|
-
*/
|
11
|
-
|
12
|
-
'use strict';
|
13
|
-
|
14
|
-
var _require = require('../loadQuery'),
|
15
|
-
useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
|
16
|
-
var useMemoOperationDescriptor = require('../useMemoOperationDescriptor');
|
17
|
-
var useRelayEnvironment = require('../useRelayEnvironment');
|
18
|
-
var getQueryResultOrFetchQuery = require('./getQueryResultOrFetchQuery_REACT_CACHE');
|
19
|
-
var useFragmentInternal = require('./useFragmentInternal_REACT_CACHE');
|
20
|
-
var invariant = require('invariant');
|
21
|
-
var _require2 = require('react'),
|
22
|
-
useDebugValue = _require2.useDebugValue,
|
23
|
-
useEffect = _require2.useEffect;
|
24
|
-
var _require3 = require('relay-runtime'),
|
25
|
-
_require3$__internal = _require3.__internal,
|
26
|
-
fetchQueryDeduped = _require3$__internal.fetchQueryDeduped,
|
27
|
-
fetchQuery = _require3$__internal.fetchQuery;
|
28
|
-
var warning = require("fbjs/lib/warning");
|
29
|
-
function usePreloadedQuery_REACT_CACHE(gqlQuery, preloadedQuery, options) {
|
30
|
-
var environment = useRelayEnvironment();
|
31
|
-
useTrackLoadQueryInRender();
|
32
|
-
var fetchKey = preloadedQuery.fetchKey,
|
33
|
-
fetchPolicy = preloadedQuery.fetchPolicy,
|
34
|
-
source = preloadedQuery.source,
|
35
|
-
variables = preloadedQuery.variables,
|
36
|
-
networkCacheConfig = preloadedQuery.networkCacheConfig;
|
37
|
-
var operation = useMemoOperationDescriptor(gqlQuery, variables, networkCacheConfig);
|
38
|
-
var fetchObservable;
|
39
|
-
if (preloadedQuery.kind === 'PreloadedQuery_DEPRECATED') {
|
40
|
-
!(operation.request.node.params.name === preloadedQuery.name) ? process.env.NODE_ENV !== "production" ? invariant(false, 'usePreloadedQuery(): Expected data to be prefetched for query `%s`, ' + 'got prefetch results for query `%s`.', operation.request.node.params.name, preloadedQuery.name) : invariant(false) : void 0;
|
41
|
-
fetchObservable = fetchQueryDeduped(environment, operation.request.identifier, function () {
|
42
|
-
if (environment === preloadedQuery.environment && source != null) {
|
43
|
-
return environment.executeWithSource({
|
44
|
-
operation: operation,
|
45
|
-
source: source
|
46
|
-
});
|
47
|
-
} else {
|
48
|
-
return environment.execute({
|
49
|
-
operation: operation
|
50
|
-
});
|
51
|
-
}
|
52
|
-
});
|
53
|
-
} else {
|
54
|
-
process.env.NODE_ENV !== "production" ? warning(preloadedQuery.isDisposed === false, 'usePreloadedQuery(): Expected preloadedQuery to not be disposed yet. ' + 'This is because disposing the query marks it for future garbage ' + 'collection, and as such query results may no longer be present in the Relay ' + 'store. In the future, this will become a hard error.') : void 0;
|
55
|
-
var fallbackFetchObservable = fetchQuery(environment, operation);
|
56
|
-
if (source != null && environment === preloadedQuery.environment) {
|
57
|
-
// If the source observable exists and the environments match, reuse
|
58
|
-
// the source observable.
|
59
|
-
// If the source observable happens to be empty, we need to fall back
|
60
|
-
// and re-execute and de-dupe the query (at render time).
|
61
|
-
fetchObservable = source.ifEmpty(fallbackFetchObservable);
|
62
|
-
} else if (environment !== preloadedQuery.environment) {
|
63
|
-
// If a call to loadQuery is made with a particular environment, and that
|
64
|
-
// preloaded query is passed to usePreloadedQuery in a different environment
|
65
|
-
// context, we cannot re-use the existing preloaded query.
|
66
|
-
// Instead, we need to fall back and re-execute and de-dupe the query with
|
67
|
-
// the new environment (at render time).
|
68
|
-
// TODO T68036756 track occurences of this warning and turn it into a hard error
|
69
|
-
process.env.NODE_ENV !== "production" ? warning(false, 'usePreloadedQuery(): usePreloadedQuery was passed a preloaded query ' + 'that was created with a different environment than the one that is currently ' + 'in context. In the future, this will become a hard error.') : void 0;
|
70
|
-
fetchObservable = fallbackFetchObservable;
|
71
|
-
} else {
|
72
|
-
// if (source == null)
|
73
|
-
// If the source observable does not exist, we need to
|
74
|
-
// fall back and re-execute and de-dupe the query (at render time).
|
75
|
-
fetchObservable = fallbackFetchObservable;
|
76
|
-
}
|
77
|
-
}
|
78
|
-
|
79
|
-
// Get the query going if needed -- this may suspend.
|
80
|
-
var _getQueryResultOrFetc = getQueryResultOrFetchQuery(environment, operation, {
|
81
|
-
fetchPolicy: fetchPolicy,
|
82
|
-
renderPolicy: options === null || options === void 0 ? void 0 : options.UNSTABLE_renderPolicy,
|
83
|
-
fetchKey: fetchKey,
|
84
|
-
fetchObservable: fetchObservable
|
85
|
-
}),
|
86
|
-
queryResult = _getQueryResultOrFetc[0],
|
87
|
-
effect = _getQueryResultOrFetc[1];
|
88
|
-
useEffect(effect);
|
89
|
-
|
90
|
-
// Read the query's root fragment -- this may suspend.
|
91
|
-
var fragmentNode = queryResult.fragmentNode,
|
92
|
-
fragmentRef = queryResult.fragmentRef;
|
93
|
-
var data = useFragmentInternal(fragmentNode, fragmentRef, 'usePreloadedQuery()', {
|
94
|
-
fetchPolicy: fetchPolicy,
|
95
|
-
networkCacheConfig: networkCacheConfig
|
96
|
-
});
|
97
|
-
if (process.env.NODE_ENV !== "production") {
|
98
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
99
|
-
useDebugValue({
|
100
|
-
query: preloadedQuery.name,
|
101
|
-
variables: preloadedQuery.variables,
|
102
|
-
data: data,
|
103
|
-
fetchKey: fetchKey,
|
104
|
-
fetchPolicy: fetchPolicy,
|
105
|
-
renderPolicy: options === null || options === void 0 ? void 0 : options.UNSTABLE_renderPolicy
|
106
|
-
});
|
107
|
-
}
|
108
|
-
return data;
|
109
|
-
}
|
110
|
-
module.exports = usePreloadedQuery_REACT_CACHE;
|
@@ -1,40 +0,0 @@
|
|
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
|
-
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
|
-
};
|