react-relay 14.0.0 → 15.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/ReactRelayContainerUtils.js.flow +1 -2
- package/ReactRelayContext.js +1 -1
- package/ReactRelayContext.js.flow +1 -2
- package/ReactRelayFragmentContainer.js.flow +6 -4
- package/ReactRelayFragmentMockRenderer.js.flow +1 -2
- package/ReactRelayLocalQueryRenderer.js.flow +5 -5
- package/ReactRelayPaginationContainer.js.flow +21 -14
- package/ReactRelayQueryFetcher.js.flow +28 -16
- package/ReactRelayQueryRenderer.js.flow +42 -13
- package/ReactRelayQueryRendererContext.js.flow +2 -3
- package/ReactRelayRefetchContainer.js.flow +9 -9
- package/ReactRelayTestMocker.js.flow +3 -3
- package/ReactRelayTypes.js.flow +7 -8
- package/RelayContext.js.flow +1 -2
- package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +4 -5
- package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +4 -5
- package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +4 -5
- package/__flowtests__/RelayModern-flowtest.js.flow +3 -4
- package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +3 -4
- package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +3 -4
- package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +3 -4
- package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +3 -4
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +3 -1
- package/assertFragmentMap.js.flow +1 -2
- package/buildReactRelayContainer.js.flow +7 -7
- package/getRootVariablesForFragments.js.flow +1 -3
- package/hooks.js +1 -1
- package/hooks.js.flow +4 -2
- package/index.js +1 -1
- package/index.js.flow +6 -2
- package/isRelayEnvironment.js.flow +1 -2
- package/jest-react/enqueueTask.js.flow +1 -1
- package/jest-react/index.js.flow +1 -1
- package/jest-react/internalAct.js.flow +1 -1
- package/legacy.js +1 -1
- package/legacy.js.flow +1 -2
- package/lib/ReactRelayContainerUtils.js +2 -3
- package/lib/ReactRelayContext.js +3 -4
- package/lib/ReactRelayFragmentContainer.js +47 -73
- package/lib/ReactRelayFragmentMockRenderer.js +2 -4
- package/lib/ReactRelayLocalQueryRenderer.js +18 -31
- package/lib/ReactRelayPaginationContainer.js +74 -164
- package/lib/ReactRelayQueryFetcher.js +49 -76
- package/lib/ReactRelayQueryRenderer.js +63 -84
- package/lib/ReactRelayQueryRendererContext.js +2 -2
- package/lib/ReactRelayRefetchContainer.js +58 -108
- package/lib/ReactRelayTestMocker.js +33 -68
- package/lib/ReactRelayTypes.js +2 -1
- package/lib/RelayContext.js +4 -7
- package/lib/assertFragmentMap.js +3 -5
- package/lib/buildReactRelayContainer.js +11 -27
- package/lib/getRootVariablesForFragments.js +6 -10
- package/lib/hooks.js +5 -18
- package/lib/index.js +7 -24
- package/lib/isRelayEnvironment.js +5 -4
- package/lib/jest-react/enqueueTask.js +5 -9
- package/lib/jest-react/index.js +0 -1
- package/lib/jest-react/internalAct.js +9 -20
- package/lib/legacy.js +2 -8
- package/lib/multi-actor/ActorChange.js +2 -5
- package/lib/multi-actor/index.js +2 -1
- package/lib/multi-actor/useRelayActorEnvironment.js +4 -8
- package/lib/relay-hooks/EntryPointContainer.react.js +9 -15
- package/lib/relay-hooks/EntryPointTypes.flow.js +5 -3
- package/lib/relay-hooks/FragmentResource.js +109 -203
- package/lib/relay-hooks/HooksImplementation.js +3 -6
- package/lib/relay-hooks/InternalLogger.js +2 -3
- package/lib/relay-hooks/LRUCache.js +2 -20
- package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +33 -54
- package/lib/relay-hooks/MatchContainer.js +15 -24
- package/lib/relay-hooks/ProfilerContext.js +3 -3
- package/lib/relay-hooks/QueryResource.js +31 -101
- package/lib/relay-hooks/RelayEnvironmentProvider.js +5 -9
- package/lib/relay-hooks/SuspenseResource.js +9 -33
- package/lib/relay-hooks/loadEntryPoint.js +19 -31
- package/lib/relay-hooks/loadQuery.js +42 -78
- package/lib/relay-hooks/preloadQuery_DEPRECATED.js +11 -37
- package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +9 -15
- package/lib/relay-hooks/react-cache/RelayReactCache.js +7 -12
- package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +27 -81
- package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +206 -0
- package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +195 -215
- package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +5 -15
- package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +17 -24
- package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +149 -0
- package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +24 -39
- package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +325 -0
- package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +37 -0
- package/lib/relay-hooks/useBlockingPaginationFragment.js +73 -93
- package/lib/relay-hooks/useClientQuery.js +30 -0
- package/lib/relay-hooks/useEntryPointLoader.js +18 -38
- package/lib/relay-hooks/useFetchTrackingRef.js +10 -12
- package/lib/relay-hooks/useFragment.js +8 -19
- package/lib/relay-hooks/useFragmentNode.js +20 -32
- package/lib/relay-hooks/useIsMountedRef.js +4 -6
- package/lib/relay-hooks/useIsOperationNodeActive.js +8 -20
- package/lib/relay-hooks/useIsParentQueryActive.js +3 -6
- package/lib/relay-hooks/useLazyLoadQuery.js +7 -24
- package/lib/relay-hooks/useLazyLoadQueryNode.js +23 -34
- package/lib/relay-hooks/useLoadMoreFunction.js +46 -78
- package/lib/relay-hooks/useMemoOperationDescriptor.js +6 -15
- package/lib/relay-hooks/useMemoVariables.js +15 -34
- package/lib/relay-hooks/useMutation.js +9 -27
- package/lib/relay-hooks/usePaginationFragment.js +73 -76
- package/lib/relay-hooks/usePreloadedQuery.js +13 -44
- package/lib/relay-hooks/useQueryLoader.js +24 -49
- package/lib/relay-hooks/useRefetchableFragment.js +19 -17
- package/lib/relay-hooks/useRefetchableFragmentNode.js +65 -109
- package/lib/relay-hooks/useRelayEnvironment.js +4 -8
- package/lib/relay-hooks/useStaticFragmentNodeWarning.js +4 -8
- package/lib/relay-hooks/useSubscribeToInvalidationState.js +8 -9
- package/lib/relay-hooks/useSubscription.js +5 -10
- package/lib/relay-hooks/useUnsafeRef_DEPRECATED.js +29 -0
- package/multi-actor/ActorChange.js.flow +1 -1
- package/multi-actor/index.js.flow +1 -1
- package/multi-actor/useRelayActorEnvironment.js.flow +2 -4
- package/package.json +2 -2
- package/react-relay-hooks.js +2 -2
- package/react-relay-hooks.min.js +2 -2
- package/react-relay-legacy.js +2 -2
- package/react-relay-legacy.min.js +2 -2
- package/react-relay.js +2 -2
- package/react-relay.min.js +2 -2
- package/relay-hooks/EntryPointContainer.react.js.flow +3 -5
- package/relay-hooks/EntryPointTypes.flow.js.flow +37 -37
- package/relay-hooks/FragmentResource.js.flow +43 -19
- package/relay-hooks/HooksImplementation.js.flow +7 -9
- package/relay-hooks/InternalLogger.js.flow +1 -3
- package/relay-hooks/LRUCache.js.flow +1 -3
- package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +19 -14
- package/relay-hooks/MatchContainer.js.flow +6 -8
- package/relay-hooks/ProfilerContext.js.flow +1 -3
- package/relay-hooks/QueryResource.js.flow +29 -11
- package/relay-hooks/RelayEnvironmentProvider.js.flow +4 -6
- package/relay-hooks/SuspenseResource.js.flow +1 -3
- package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +6 -4
- package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +4 -4
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +3 -1
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +3 -1
- package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +39 -39
- package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +1 -3
- package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +37 -38
- package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +18 -20
- package/relay-hooks/__flowtests__/utils.js.flow +21 -12
- package/relay-hooks/loadEntryPoint.js.flow +11 -6
- package/relay-hooks/loadQuery.js.flow +11 -7
- package/relay-hooks/preloadQuery_DEPRECATED.js.flow +9 -12
- package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +13 -10
- package/relay-hooks/react-cache/RelayReactCache.js.flow +1 -3
- package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +26 -20
- package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +297 -0
- package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +136 -96
- package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +1 -3
- package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +3 -5
- package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +190 -0
- package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +3 -6
- package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +601 -0
- package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +65 -0
- package/relay-hooks/useBlockingPaginationFragment.js.flow +86 -59
- package/relay-hooks/useClientQuery.js.flow +39 -0
- package/relay-hooks/useEntryPointLoader.js.flow +16 -14
- package/relay-hooks/useFetchTrackingRef.js.flow +7 -8
- package/relay-hooks/useFragment.js.flow +2 -4
- package/relay-hooks/useFragmentNode.js.flow +7 -8
- package/relay-hooks/useIsMountedRef.js.flow +2 -4
- package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
- package/relay-hooks/useIsParentQueryActive.js.flow +1 -1
- package/relay-hooks/useLazyLoadQuery.js.flow +9 -32
- package/relay-hooks/useLazyLoadQueryNode.js.flow +4 -6
- package/relay-hooks/useLoadMoreFunction.js.flow +20 -17
- package/relay-hooks/useMemoOperationDescriptor.js.flow +3 -5
- package/relay-hooks/useMemoVariables.js.flow +13 -31
- package/relay-hooks/useMutation.js.flow +6 -8
- package/relay-hooks/usePaginationFragment.js.flow +75 -43
- package/relay-hooks/usePreloadedQuery.js.flow +49 -43
- package/relay-hooks/useQueryLoader.js.flow +89 -28
- package/relay-hooks/useRefetchableFragment.js.flow +83 -23
- package/relay-hooks/useRefetchableFragmentNode.js.flow +26 -22
- package/relay-hooks/useRelayEnvironment.js.flow +2 -4
- package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -5
- package/relay-hooks/useSubscribeToInvalidationState.js.flow +2 -4
- package/relay-hooks/useSubscription.js.flow +1 -3
- package/relay-hooks/useUnsafeRef_DEPRECATED.js.flow +25 -0
- package/lib/readContext.js +0 -28
- package/readContext.js.flow +0 -31
@@ -5,49 +5,37 @@
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*
|
7
7
|
*
|
8
|
-
* @emails oncall+relay
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
|
-
// flowlint ambiguous-object-type:error
|
12
|
-
'use strict';
|
13
11
|
|
14
|
-
|
12
|
+
'use strict';
|
15
13
|
|
14
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
16
15
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
17
|
-
|
18
16
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
19
|
-
|
20
17
|
var LRUCache = require('./LRUCache');
|
21
|
-
|
22
18
|
var SuspenseResource = require('./SuspenseResource');
|
23
|
-
|
24
19
|
var invariant = require('invariant');
|
25
|
-
|
26
20
|
var _require = require('relay-runtime'),
|
27
|
-
|
28
|
-
|
21
|
+
isPromise = _require.isPromise;
|
29
22
|
var warning = require("fbjs/lib/warning");
|
30
|
-
|
31
23
|
var CACHE_CAPACITY = 1000;
|
32
24
|
var DEFAULT_FETCH_POLICY = 'store-or-network';
|
25
|
+
var DEFAULT_LIVE_FETCH_POLICY = 'store-and-network';
|
33
26
|
var WEAKMAP_SUPPORTED = typeof WeakMap === 'function';
|
34
|
-
|
35
27
|
function operationIsLiveQuery(operation) {
|
36
28
|
return operation.request.node.params.metadata.live !== undefined;
|
37
29
|
}
|
38
|
-
|
39
30
|
function getQueryCacheIdentifier(environment, operation, maybeFetchPolicy, maybeRenderPolicy, cacheBreaker) {
|
40
|
-
var fetchPolicy = maybeFetchPolicy !== null && maybeFetchPolicy !== void 0 ? maybeFetchPolicy : DEFAULT_FETCH_POLICY;
|
31
|
+
var fetchPolicy = maybeFetchPolicy !== null && maybeFetchPolicy !== void 0 ? maybeFetchPolicy : operationIsLiveQuery(operation) ? DEFAULT_LIVE_FETCH_POLICY : DEFAULT_FETCH_POLICY;
|
41
32
|
var renderPolicy = maybeRenderPolicy !== null && maybeRenderPolicy !== void 0 ? maybeRenderPolicy : environment.UNSTABLE_getDefaultRenderPolicy();
|
42
33
|
var cacheIdentifier = "".concat(fetchPolicy, "-").concat(renderPolicy, "-").concat(operation.request.identifier);
|
43
|
-
|
44
34
|
if (cacheBreaker != null) {
|
45
35
|
return "".concat(cacheIdentifier, "-").concat(cacheBreaker);
|
46
36
|
}
|
47
|
-
|
48
37
|
return cacheIdentifier;
|
49
38
|
}
|
50
|
-
|
51
39
|
function getQueryResult(operation, cacheIdentifier) {
|
52
40
|
var rootFragmentRef = {
|
53
41
|
__id: operation.fragment.dataID,
|
@@ -61,9 +49,7 @@ function getQueryResult(operation, cacheIdentifier) {
|
|
61
49
|
operation: operation
|
62
50
|
};
|
63
51
|
}
|
64
|
-
|
65
52
|
var nextID = 200000;
|
66
|
-
|
67
53
|
function createCacheEntry(cacheIdentifier, operation, operationAvailability, value, networkSubscription, onDispose) {
|
68
54
|
var isLiveQuery = operationIsLiveQuery(operation);
|
69
55
|
var currentValue = value;
|
@@ -78,7 +64,6 @@ function createCacheEntry(cacheIdentifier, operation, operationAvailability, val
|
|
78
64
|
if (isLiveQuery && currentNetworkSubscription != null) {
|
79
65
|
currentNetworkSubscription.unsubscribe();
|
80
66
|
}
|
81
|
-
|
82
67
|
retention.dispose();
|
83
68
|
onDispose(cacheEntry);
|
84
69
|
}
|
@@ -99,7 +84,6 @@ function createCacheEntry(cacheIdentifier, operation, operationAvailability, val
|
|
99
84
|
if (isLiveQuery && currentNetworkSubscription != null) {
|
100
85
|
currentNetworkSubscription.unsubscribe();
|
101
86
|
}
|
102
|
-
|
103
87
|
currentNetworkSubscription = subscription;
|
104
88
|
},
|
105
89
|
temporaryRetain: function temporaryRetain(environment) {
|
@@ -114,42 +98,36 @@ function createCacheEntry(cacheIdentifier, operation, operationAvailability, val
|
|
114
98
|
};
|
115
99
|
return cacheEntry;
|
116
100
|
}
|
117
|
-
|
118
101
|
var QueryResourceImpl = /*#__PURE__*/function () {
|
119
102
|
function QueryResourceImpl(environment) {
|
120
103
|
var _this = this;
|
121
|
-
|
122
104
|
(0, _defineProperty2["default"])(this, "_clearCacheEntry", function (cacheEntry) {
|
123
105
|
_this._cache["delete"](cacheEntry.cacheIdentifier);
|
124
106
|
});
|
125
107
|
this._environment = environment;
|
126
108
|
this._cache = LRUCache.create(CACHE_CAPACITY);
|
127
109
|
}
|
128
|
-
|
129
110
|
var _proto = QueryResourceImpl.prototype;
|
130
|
-
|
131
111
|
_proto.prepare = function prepare(operation, fetchObservable, maybeFetchPolicy, maybeRenderPolicy, observer, cacheBreaker, profilerContext) {
|
132
112
|
var cacheIdentifier = getQueryCacheIdentifier(this._environment, operation, maybeFetchPolicy, maybeRenderPolicy, cacheBreaker);
|
133
113
|
return this.prepareWithIdentifier(cacheIdentifier, operation, fetchObservable, maybeFetchPolicy, maybeRenderPolicy, observer, profilerContext);
|
134
114
|
}
|
115
|
+
|
135
116
|
/**
|
136
117
|
* This function should be called during a Component's render function,
|
137
118
|
* to either read an existing cached value for the query, or fetch the query
|
138
119
|
* and suspend.
|
139
|
-
|
140
|
-
;
|
141
|
-
|
120
|
+
*/;
|
142
121
|
_proto.prepareWithIdentifier = function prepareWithIdentifier(cacheIdentifier, operation, fetchObservable, maybeFetchPolicy, maybeRenderPolicy, observer, profilerContext) {
|
143
122
|
var environment = this._environment;
|
144
|
-
var fetchPolicy = maybeFetchPolicy !== null && maybeFetchPolicy !== void 0 ? maybeFetchPolicy : DEFAULT_FETCH_POLICY;
|
145
|
-
var renderPolicy = maybeRenderPolicy !== null && maybeRenderPolicy !== void 0 ? maybeRenderPolicy : environment.UNSTABLE_getDefaultRenderPolicy();
|
146
|
-
// it's available
|
123
|
+
var fetchPolicy = maybeFetchPolicy !== null && maybeFetchPolicy !== void 0 ? maybeFetchPolicy : operationIsLiveQuery(operation) ? DEFAULT_LIVE_FETCH_POLICY : DEFAULT_FETCH_POLICY;
|
124
|
+
var renderPolicy = maybeRenderPolicy !== null && maybeRenderPolicy !== void 0 ? maybeRenderPolicy : environment.UNSTABLE_getDefaultRenderPolicy();
|
147
125
|
|
126
|
+
// 1. Check if there's a cached value for this operation, and reuse it if
|
127
|
+
// it's available
|
148
128
|
var cacheEntry = this._cache.get(cacheIdentifier);
|
149
|
-
|
150
129
|
var temporaryRetainDisposable = null;
|
151
130
|
var entryWasCached = cacheEntry != null;
|
152
|
-
|
153
131
|
if (cacheEntry == null) {
|
154
132
|
// 2. If a cached value isn't available, try fetching the operation.
|
155
133
|
// _fetchAndSaveQuery will update the cache with either a Promise or
|
@@ -164,21 +142,19 @@ var QueryResourceImpl = /*#__PURE__*/function () {
|
|
164
142
|
if (temporaryRetainDisposable != null) {
|
165
143
|
temporaryRetainDisposable.dispose();
|
166
144
|
}
|
167
|
-
|
168
145
|
var observerUnsubscribe = observer === null || observer === void 0 ? void 0 : observer.unsubscribe;
|
169
146
|
observerUnsubscribe && observerUnsubscribe(subscription);
|
170
147
|
}
|
171
148
|
}));
|
172
|
-
}
|
149
|
+
}
|
150
|
+
|
151
|
+
// 3. Temporarily retain here in render phase. When the component reading
|
173
152
|
// the operation is committed, we will transfer ownership of data retention
|
174
153
|
// to the component.
|
175
154
|
// In case the component never commits (mounts or updates) from this render,
|
176
155
|
// this data retention hold will auto-release itself after a timeout.
|
177
|
-
|
178
|
-
|
179
156
|
temporaryRetainDisposable = cacheEntry.temporaryRetain(environment);
|
180
157
|
var cachedValue = cacheEntry.getValue();
|
181
|
-
|
182
158
|
if (isPromise(cachedValue)) {
|
183
159
|
environment.__log({
|
184
160
|
name: 'suspense.query',
|
@@ -188,89 +164,72 @@ var QueryResourceImpl = /*#__PURE__*/function () {
|
|
188
164
|
queryAvailability: cacheEntry.operationAvailability,
|
189
165
|
renderPolicy: renderPolicy
|
190
166
|
});
|
191
|
-
|
192
167
|
throw cachedValue;
|
193
168
|
}
|
194
|
-
|
195
169
|
if (cachedValue instanceof Error) {
|
196
170
|
throw cachedValue;
|
197
171
|
}
|
198
|
-
|
199
172
|
return cachedValue;
|
200
173
|
}
|
174
|
+
|
201
175
|
/**
|
202
176
|
* This function should be called during a component's commit phase
|
203
177
|
* (e.g. inside useEffect), in order to retain the operation in the Relay store
|
204
178
|
* and transfer ownership of the operation to the component lifecycle.
|
205
|
-
|
206
|
-
;
|
207
|
-
|
179
|
+
*/;
|
208
180
|
_proto.retain = function retain(queryResult, profilerContext) {
|
209
181
|
var environment = this._environment;
|
210
182
|
var cacheIdentifier = queryResult.cacheIdentifier,
|
211
|
-
|
212
|
-
|
183
|
+
operation = queryResult.operation;
|
213
184
|
var cacheEntry = this._getOrCreateCacheEntry(cacheIdentifier, operation, null, queryResult, null);
|
214
|
-
|
215
185
|
var disposable = cacheEntry.permanentRetain(environment);
|
216
|
-
|
217
186
|
environment.__log({
|
218
187
|
name: 'queryresource.retain',
|
219
188
|
profilerContext: profilerContext,
|
220
189
|
resourceID: cacheEntry.id
|
221
190
|
});
|
222
|
-
|
223
191
|
return {
|
224
192
|
dispose: function dispose() {
|
225
193
|
disposable.dispose();
|
226
194
|
}
|
227
195
|
};
|
228
196
|
};
|
229
|
-
|
230
197
|
_proto.releaseTemporaryRetain = function releaseTemporaryRetain(queryResult) {
|
231
198
|
var cacheEntry = this._cache.get(queryResult.cacheIdentifier);
|
232
|
-
|
233
199
|
if (cacheEntry != null) {
|
234
200
|
cacheEntry.releaseTemporaryRetain();
|
235
201
|
}
|
236
202
|
};
|
237
|
-
|
238
203
|
_proto.TESTS_ONLY__getCacheEntry = function TESTS_ONLY__getCacheEntry(operation, maybeFetchPolicy, maybeRenderPolicy, cacheBreaker) {
|
239
204
|
var environment = this._environment;
|
240
205
|
var cacheIdentifier = getQueryCacheIdentifier(environment, operation, maybeFetchPolicy, maybeRenderPolicy, cacheBreaker);
|
241
206
|
return this._cache.get(cacheIdentifier);
|
242
207
|
};
|
243
|
-
|
244
208
|
_proto._getOrCreateCacheEntry = function _getOrCreateCacheEntry(cacheIdentifier, operation, operationAvailability, value, networkSubscription) {
|
245
209
|
var cacheEntry = this._cache.get(cacheIdentifier);
|
246
|
-
|
247
210
|
if (cacheEntry == null) {
|
248
211
|
cacheEntry = createCacheEntry(cacheIdentifier, operation, operationAvailability, value, networkSubscription, this._clearCacheEntry);
|
249
|
-
|
250
212
|
this._cache.set(cacheIdentifier, cacheEntry);
|
251
213
|
}
|
252
|
-
|
253
214
|
return cacheEntry;
|
254
215
|
};
|
255
|
-
|
256
216
|
_proto._fetchAndSaveQuery = function _fetchAndSaveQuery(cacheIdentifier, operation, fetchObservable, fetchPolicy, renderPolicy, profilerContext, observer) {
|
257
217
|
var _this2 = this;
|
218
|
+
var environment = this._environment;
|
258
219
|
|
259
|
-
|
220
|
+
// NOTE: Running `check` will write missing data to the store using any
|
260
221
|
// missing data handlers specified on the environment;
|
261
222
|
// We run it here first to make the handlers get a chance to populate
|
262
223
|
// missing data.
|
263
|
-
|
264
224
|
var queryAvailability = environment.check(operation);
|
265
225
|
var queryStatus = queryAvailability.status;
|
266
226
|
var hasFullQuery = queryStatus === 'available';
|
267
227
|
var canPartialRender = hasFullQuery || renderPolicy === 'partial' && queryStatus !== 'stale';
|
268
228
|
var shouldFetch;
|
269
|
-
var shouldAllowRender;
|
229
|
+
var shouldAllowRender;
|
230
|
+
// Different definitions for Promise in our repos can cause this variable
|
270
231
|
// to cause errors when synced elsewhere
|
271
|
-
|
272
232
|
var resolveNetworkPromise = function resolveNetworkPromise() {};
|
273
|
-
|
274
233
|
switch (fetchPolicy) {
|
275
234
|
case 'store-only':
|
276
235
|
{
|
@@ -278,21 +237,18 @@ var QueryResourceImpl = /*#__PURE__*/function () {
|
|
278
237
|
shouldAllowRender = true;
|
279
238
|
break;
|
280
239
|
}
|
281
|
-
|
282
240
|
case 'store-or-network':
|
283
241
|
{
|
284
242
|
shouldFetch = !hasFullQuery;
|
285
243
|
shouldAllowRender = canPartialRender;
|
286
244
|
break;
|
287
245
|
}
|
288
|
-
|
289
246
|
case 'store-and-network':
|
290
247
|
{
|
291
248
|
shouldFetch = true;
|
292
249
|
shouldAllowRender = canPartialRender;
|
293
250
|
break;
|
294
251
|
}
|
295
|
-
|
296
252
|
case 'network-only':
|
297
253
|
default:
|
298
254
|
{
|
@@ -300,36 +256,28 @@ var QueryResourceImpl = /*#__PURE__*/function () {
|
|
300
256
|
shouldAllowRender = false;
|
301
257
|
break;
|
302
258
|
}
|
303
|
-
}
|
259
|
+
}
|
260
|
+
|
261
|
+
// NOTE: If this value is false, we will cache a promise for this
|
304
262
|
// query, which means we will suspend here at this query root.
|
305
263
|
// If it's true, we will cache the query resource and allow rendering to
|
306
264
|
// continue.
|
307
|
-
|
308
|
-
|
309
265
|
if (shouldAllowRender) {
|
310
266
|
var queryResult = getQueryResult(operation, cacheIdentifier);
|
311
|
-
|
312
267
|
var _cacheEntry = createCacheEntry(cacheIdentifier, operation, queryAvailability, queryResult, null, this._clearCacheEntry);
|
313
|
-
|
314
268
|
this._cache.set(cacheIdentifier, _cacheEntry);
|
315
269
|
}
|
316
|
-
|
317
270
|
if (shouldFetch) {
|
318
271
|
var _queryResult = getQueryResult(operation, cacheIdentifier);
|
319
|
-
|
320
272
|
var networkSubscription;
|
321
273
|
fetchObservable.subscribe({
|
322
274
|
start: function start(subscription) {
|
323
275
|
networkSubscription = subscription;
|
324
|
-
|
325
276
|
var cacheEntry = _this2._cache.get(cacheIdentifier);
|
326
|
-
|
327
277
|
if (cacheEntry) {
|
328
278
|
cacheEntry.setNetworkSubscription(networkSubscription);
|
329
279
|
}
|
330
|
-
|
331
280
|
var observerStart = observer === null || observer === void 0 ? void 0 : observer.start;
|
332
|
-
|
333
281
|
if (observerStart) {
|
334
282
|
var subscriptionWithConditionalCancelation = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, subscription), {}, {
|
335
283
|
unsubscribe: function unsubscribe() {
|
@@ -344,24 +292,23 @@ var QueryResourceImpl = /*#__PURE__*/function () {
|
|
344
292
|
},
|
345
293
|
next: function next() {
|
346
294
|
var cacheEntry = _this2._getOrCreateCacheEntry(cacheIdentifier, operation, queryAvailability, _queryResult, networkSubscription);
|
347
|
-
|
348
295
|
cacheEntry.processedPayloadsCount += 1;
|
349
296
|
cacheEntry.setValue(_queryResult);
|
350
297
|
resolveNetworkPromise();
|
351
298
|
var observerNext = observer === null || observer === void 0 ? void 0 : observer.next;
|
352
|
-
|
353
299
|
if (observerNext != null) {
|
354
300
|
var snapshot = environment.lookup(operation.fragment);
|
355
301
|
observerNext(snapshot);
|
356
302
|
}
|
357
303
|
},
|
358
304
|
error: function error(_error) {
|
359
|
-
var cacheEntry = _this2._getOrCreateCacheEntry(cacheIdentifier, operation, queryAvailability, _error, networkSubscription);
|
305
|
+
var cacheEntry = _this2._getOrCreateCacheEntry(cacheIdentifier, operation, queryAvailability, _error, networkSubscription);
|
306
|
+
|
307
|
+
// If, this is the first thing we receive for the query,
|
360
308
|
// before any other payload handled is error, we will cache and
|
361
309
|
// re-throw that error later.
|
362
|
-
// We will ignore errors for any incremental payloads we receive.
|
363
|
-
|
364
310
|
|
311
|
+
// We will ignore errors for any incremental payloads we receive.
|
365
312
|
if (cacheEntry.processedPayloadsCount === 0) {
|
366
313
|
cacheEntry.setValue(_error);
|
367
314
|
} else {
|
@@ -369,7 +316,6 @@ var QueryResourceImpl = /*#__PURE__*/function () {
|
|
369
316
|
// To complete this task we need to have a way of precisely tracking suspendable points
|
370
317
|
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;
|
371
318
|
}
|
372
|
-
|
373
319
|
resolveNetworkPromise();
|
374
320
|
networkSubscription = null;
|
375
321
|
cacheEntry.setNetworkSubscription(null);
|
@@ -379,40 +325,32 @@ var QueryResourceImpl = /*#__PURE__*/function () {
|
|
379
325
|
complete: function complete() {
|
380
326
|
resolveNetworkPromise();
|
381
327
|
networkSubscription = null;
|
382
|
-
|
383
328
|
var cacheEntry = _this2._cache.get(cacheIdentifier);
|
384
|
-
|
385
329
|
if (cacheEntry) {
|
386
330
|
cacheEntry.setNetworkSubscription(null);
|
387
331
|
}
|
388
|
-
|
389
332
|
var observerComplete = observer === null || observer === void 0 ? void 0 : observer.complete;
|
390
333
|
observerComplete && observerComplete();
|
391
334
|
},
|
392
335
|
unsubscribe: observer === null || observer === void 0 ? void 0 : observer.unsubscribe
|
393
336
|
});
|
394
|
-
|
395
337
|
var _cacheEntry2 = this._cache.get(cacheIdentifier);
|
396
|
-
|
397
338
|
if (!_cacheEntry2) {
|
398
339
|
var networkPromise = new Promise(function (resolve) {
|
399
340
|
resolveNetworkPromise = resolve;
|
400
|
-
});
|
341
|
+
});
|
401
342
|
|
343
|
+
// $FlowExpectedError[prop-missing] Expando to annotate Promises.
|
402
344
|
networkPromise.displayName = 'Relay(' + operation.fragment.node.name + ')';
|
403
345
|
_cacheEntry2 = createCacheEntry(cacheIdentifier, operation, queryAvailability, networkPromise, networkSubscription, this._clearCacheEntry);
|
404
|
-
|
405
346
|
this._cache.set(cacheIdentifier, _cacheEntry2);
|
406
347
|
}
|
407
348
|
} else {
|
408
349
|
var observerComplete = observer === null || observer === void 0 ? void 0 : observer.complete;
|
409
350
|
observerComplete && observerComplete();
|
410
351
|
}
|
411
|
-
|
412
352
|
var cacheEntry = this._cache.get(cacheIdentifier);
|
413
|
-
|
414
353
|
!(cacheEntry != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected to have cached a result when attempting to fetch query.' + "If you're seeing this, this is likely a bug in Relay.") : invariant(false) : void 0;
|
415
|
-
|
416
354
|
environment.__log({
|
417
355
|
name: 'queryresource.fetch',
|
418
356
|
resourceID: cacheEntry.id,
|
@@ -423,31 +361,23 @@ var QueryResourceImpl = /*#__PURE__*/function () {
|
|
423
361
|
queryAvailability: queryAvailability,
|
424
362
|
shouldFetch: shouldFetch
|
425
363
|
});
|
426
|
-
|
427
364
|
return cacheEntry;
|
428
365
|
};
|
429
|
-
|
430
366
|
return QueryResourceImpl;
|
431
367
|
}();
|
432
|
-
|
433
368
|
function createQueryResource(environment) {
|
434
369
|
return new QueryResourceImpl(environment);
|
435
370
|
}
|
436
|
-
|
437
371
|
var dataResources = WEAKMAP_SUPPORTED ? new WeakMap() : new Map();
|
438
|
-
|
439
372
|
function getQueryResourceForEnvironment(environment) {
|
440
373
|
var cached = dataResources.get(environment);
|
441
|
-
|
442
374
|
if (cached) {
|
443
375
|
return cached;
|
444
376
|
}
|
445
|
-
|
446
377
|
var newDataResource = createQueryResource(environment);
|
447
378
|
dataResources.set(environment, newDataResource);
|
448
379
|
return newDataResource;
|
449
380
|
}
|
450
|
-
|
451
381
|
module.exports = {
|
452
382
|
createQueryResource: createQueryResource,
|
453
383
|
getQueryResourceForEnvironment: getQueryResourceForEnvironment,
|
@@ -4,23 +4,20 @@
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*
|
7
|
-
* @emails oncall+relay
|
8
7
|
*
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
|
-
|
11
|
+
|
12
12
|
'use strict';
|
13
13
|
|
14
|
+
var ReactRelayContext = require('./../ReactRelayContext');
|
14
15
|
var React = require('react');
|
15
|
-
|
16
|
-
var ReactRelayContext = require('react-relay/ReactRelayContext');
|
17
|
-
|
18
16
|
var useMemo = React.useMemo;
|
19
|
-
|
20
17
|
function RelayEnvironmentProvider(props) {
|
21
18
|
var children = props.children,
|
22
|
-
|
23
|
-
|
19
|
+
environment = props.environment,
|
20
|
+
getEnvironmentForActor = props.getEnvironmentForActor;
|
24
21
|
var context = useMemo(function () {
|
25
22
|
return {
|
26
23
|
environment: environment,
|
@@ -31,5 +28,4 @@ function RelayEnvironmentProvider(props) {
|
|
31
28
|
value: context
|
32
29
|
}, children);
|
33
30
|
}
|
34
|
-
|
35
31
|
module.exports = RelayEnvironmentProvider;
|
@@ -5,126 +5,102 @@
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*
|
7
7
|
*
|
8
|
-
* @emails oncall+relay
|
9
8
|
* @format
|
9
|
+
* @oncall relay
|
10
10
|
*/
|
11
|
-
// flowlint ambiguous-object-type:error
|
12
|
-
'use strict';
|
13
11
|
|
14
|
-
|
12
|
+
'use strict';
|
15
13
|
|
14
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
16
15
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
17
|
-
|
18
16
|
var invariant = require('invariant');
|
19
|
-
|
20
17
|
var TEMPORARY_RETAIN_DURATION_MS = 5 * 60 * 1000;
|
18
|
+
|
21
19
|
/**
|
22
20
|
* Allows you to retain a resource as part of a component lifecycle accounting
|
23
21
|
* for Suspense. You temporarily retain the resource during render, then
|
24
22
|
* permanently retain it during commit and release it during unmount.
|
25
23
|
*/
|
26
|
-
|
27
24
|
var SuspenseResource = /*#__PURE__*/function () {
|
28
25
|
function SuspenseResource(retain) {
|
29
26
|
var _this = this;
|
30
|
-
|
31
27
|
(0, _defineProperty2["default"])(this, "_retainCount", 0);
|
32
28
|
(0, _defineProperty2["default"])(this, "_retainDisposable", null);
|
33
29
|
(0, _defineProperty2["default"])(this, "_releaseTemporaryRetain", null);
|
34
|
-
|
35
30
|
this._retain = function (environment) {
|
36
31
|
_this._retainCount++;
|
37
|
-
|
38
32
|
if (_this._retainCount === 1) {
|
39
33
|
_this._retainDisposable = retain(environment);
|
40
34
|
}
|
41
|
-
|
42
35
|
return {
|
43
36
|
dispose: function dispose() {
|
44
37
|
_this._retainCount = Math.max(0, _this._retainCount - 1);
|
45
|
-
|
46
38
|
if (_this._retainCount === 0) {
|
47
39
|
!(_this._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;
|
48
|
-
|
49
40
|
_this._retainDisposable.dispose();
|
50
|
-
|
51
41
|
_this._retainDisposable = null;
|
52
42
|
}
|
53
43
|
}
|
54
44
|
};
|
55
45
|
};
|
56
46
|
}
|
57
|
-
|
58
47
|
var _proto = SuspenseResource.prototype;
|
59
|
-
|
60
48
|
_proto.temporaryRetain = function temporaryRetain(environment) {
|
61
49
|
var _this2 = this;
|
62
|
-
|
63
50
|
var _this$_releaseTempora;
|
64
|
-
|
65
51
|
// If we're executing in a server environment, there's no need
|
66
52
|
// to create temporary retains, since the component will never commit.
|
67
53
|
if (environment.isServer()) {
|
68
54
|
return {
|
69
55
|
dispose: function dispose() {}
|
70
56
|
};
|
71
|
-
}
|
57
|
+
}
|
58
|
+
|
59
|
+
// temporaryRetain is called during the render phase. However,
|
72
60
|
// given that we can't tell if this render will eventually commit or not,
|
73
61
|
// we create a timer to autodispose of this retain in case the associated
|
74
62
|
// component never commits.
|
75
63
|
// If the component /does/ commit, permanentRetain will clear this timeout
|
76
64
|
// and permanently retain the data.
|
77
|
-
|
78
|
-
|
79
65
|
var retention = this._retain(environment);
|
80
|
-
|
81
66
|
var releaseQueryTimeout = null;
|
82
|
-
|
83
67
|
var releaseTemporaryRetain = function releaseTemporaryRetain() {
|
84
68
|
clearTimeout(releaseQueryTimeout);
|
85
69
|
releaseQueryTimeout = null;
|
86
70
|
_this2._releaseTemporaryRetain = null;
|
87
71
|
retention.dispose();
|
88
72
|
};
|
73
|
+
releaseQueryTimeout = setTimeout(releaseTemporaryRetain, TEMPORARY_RETAIN_DURATION_MS);
|
89
74
|
|
90
|
-
|
75
|
+
// NOTE: Since temporaryRetain can be called multiple times, we release
|
91
76
|
// the previous temporary retain after we re-establish a new one, since
|
92
77
|
// we only ever need a single temporary retain until the permanent retain is
|
93
78
|
// established.
|
94
79
|
// temporaryRetain may be called multiple times by React during the render
|
95
80
|
// phase, as well as multiple times by other query components that are
|
96
81
|
// rendering the same query/variables.
|
97
|
-
|
98
82
|
(_this$_releaseTempora = this._releaseTemporaryRetain) === null || _this$_releaseTempora === void 0 ? void 0 : _this$_releaseTempora.call(this);
|
99
83
|
this._releaseTemporaryRetain = releaseTemporaryRetain;
|
100
84
|
return {
|
101
85
|
dispose: function dispose() {
|
102
86
|
var _this$_releaseTempora2;
|
103
|
-
|
104
87
|
(_this$_releaseTempora2 = _this2._releaseTemporaryRetain) === null || _this$_releaseTempora2 === void 0 ? void 0 : _this$_releaseTempora2.call(_this2);
|
105
88
|
}
|
106
89
|
};
|
107
90
|
};
|
108
|
-
|
109
91
|
_proto.permanentRetain = function permanentRetain(environment) {
|
110
92
|
var disposable = this._retain(environment);
|
111
|
-
|
112
93
|
this.releaseTemporaryRetain();
|
113
94
|
return disposable;
|
114
95
|
};
|
115
|
-
|
116
96
|
_proto.releaseTemporaryRetain = function releaseTemporaryRetain() {
|
117
97
|
var _this$_releaseTempora3;
|
118
|
-
|
119
98
|
(_this$_releaseTempora3 = this._releaseTemporaryRetain) === null || _this$_releaseTempora3 === void 0 ? void 0 : _this$_releaseTempora3.call(this);
|
120
99
|
this._releaseTemporaryRetain = null;
|
121
100
|
};
|
122
|
-
|
123
101
|
_proto.getRetainCount = function getRetainCount() {
|
124
102
|
return this._retainCount;
|
125
103
|
};
|
126
|
-
|
127
104
|
return SuspenseResource;
|
128
105
|
}();
|
129
|
-
|
130
106
|
module.exports = SuspenseResource;
|