react-relay 12.0.0 → 13.0.0-rc.0
Sign up to get free protection for your applications and to get access to all the features.
- package/ReactRelayContext.js +1 -1
- package/ReactRelayContext.js.flow +2 -3
- package/ReactRelayFragmentContainer.js.flow +10 -16
- package/ReactRelayFragmentMockRenderer.js.flow +1 -1
- package/ReactRelayLocalQueryRenderer.js.flow +6 -7
- package/ReactRelayPaginationContainer.js.flow +29 -39
- package/ReactRelayQueryFetcher.js.flow +9 -10
- package/ReactRelayQueryRenderer.js.flow +15 -15
- package/ReactRelayRefetchContainer.js.flow +24 -32
- package/ReactRelayTestMocker.js.flow +16 -14
- package/ReactRelayTypes.js.flow +10 -10
- package/RelayContext.js.flow +3 -3
- package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +1 -2
- package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +1 -2
- package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +1 -2
- package/__flowtests__/RelayModern-flowtest.js.flow +78 -46
- package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +5 -4
- package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +5 -4
- package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +4 -3
- package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +4 -3
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +13 -10
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +13 -10
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +13 -8
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +13 -10
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +13 -8
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +13 -10
- package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +15 -12
- package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +15 -12
- package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +13 -10
- package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +13 -10
- package/assertFragmentMap.js.flow +2 -2
- package/buildReactRelayContainer.js.flow +11 -10
- package/getRootVariablesForFragments.js.flow +2 -4
- package/hooks.js +1 -1
- package/hooks.js.flow +3 -5
- package/index.js +1 -1
- package/index.js.flow +4 -6
- package/jest-react/enqueueTask.js.flow +1 -1
- package/jest-react/internalAct.js.flow +1 -2
- package/legacy.js +1 -1
- package/lib/ReactRelayFragmentContainer.js +4 -4
- package/lib/ReactRelayFragmentMockRenderer.js +2 -2
- package/lib/ReactRelayLocalQueryRenderer.js +7 -8
- package/lib/ReactRelayPaginationContainer.js +18 -22
- package/lib/ReactRelayQueryFetcher.js +2 -2
- package/lib/ReactRelayQueryRenderer.js +4 -4
- package/lib/ReactRelayRefetchContainer.js +12 -14
- package/lib/ReactRelayTestMocker.js +7 -8
- package/lib/RelayContext.js +3 -2
- package/lib/assertFragmentMap.js +2 -1
- package/lib/buildReactRelayContainer.js +7 -7
- package/lib/getRootVariablesForFragments.js +1 -2
- package/lib/hooks.js +5 -5
- package/lib/index.js +7 -7
- package/lib/jest-react/internalAct.js +2 -2
- package/lib/multi-actor/ActorChange.js +2 -2
- package/lib/multi-actor/useRelayActorEnvironment.js +2 -2
- package/lib/relay-hooks/EntryPointContainer.react.js +3 -3
- package/lib/relay-hooks/FragmentResource.js +241 -45
- package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +4 -4
- package/lib/relay-hooks/MatchContainer.js +1 -1
- package/lib/relay-hooks/QueryResource.js +83 -4
- package/lib/relay-hooks/SuspenseResource.js +130 -0
- package/lib/relay-hooks/loadQuery.js +8 -9
- package/lib/relay-hooks/preloadQuery_DEPRECATED.js +24 -10
- package/lib/relay-hooks/useBlockingPaginationFragment.js +2 -2
- package/lib/relay-hooks/useEntryPointLoader.js +2 -2
- package/lib/relay-hooks/useFetchTrackingRef.js +2 -1
- package/lib/relay-hooks/useFragment.js +8 -7
- package/lib/relay-hooks/useFragmentNode.js +4 -4
- package/lib/relay-hooks/useIsOperationNodeActive.js +2 -2
- package/lib/relay-hooks/useLazyLoadQuery.js +3 -3
- package/lib/relay-hooks/useLazyLoadQueryNode.js +4 -4
- package/lib/relay-hooks/useLoadMoreFunction.js +7 -9
- package/lib/relay-hooks/useMemoOperationDescriptor.js +2 -2
- package/lib/relay-hooks/useMemoVariables.js +2 -2
- package/lib/relay-hooks/useMutation.js +17 -6
- package/lib/relay-hooks/usePreloadedQuery.js +5 -5
- package/lib/relay-hooks/useQueryLoader.js +4 -4
- package/lib/relay-hooks/useRefetchableFragmentNode.js +10 -12
- package/lib/relay-hooks/useRelayEnvironment.js +2 -2
- package/lib/relay-hooks/useStaticFragmentNodeWarning.js +2 -2
- package/lib/relay-hooks/useSubscribeToInvalidationState.js +2 -1
- package/multi-actor/ActorChange.js.flow +3 -4
- package/multi-actor/useRelayActorEnvironment.js.flow +5 -7
- 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 +8 -15
- package/relay-hooks/EntryPointTypes.flow.js.flow +18 -24
- package/relay-hooks/FragmentResource.js.flow +220 -34
- package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +32 -46
- package/relay-hooks/MatchContainer.js.flow +3 -2
- package/relay-hooks/QueryResource.js.flow +119 -17
- package/relay-hooks/RelayEnvironmentProvider.js.flow +9 -9
- package/relay-hooks/SuspenseResource.js.flow +115 -0
- package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +4 -3
- package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +1 -1
- package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +10 -9
- package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +8 -7
- package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +10 -9
- package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +10 -9
- package/relay-hooks/__flowtests__/utils.js.flow +8 -12
- package/relay-hooks/loadEntryPoint.js.flow +6 -12
- package/relay-hooks/loadQuery.js.flow +22 -23
- package/relay-hooks/preloadQuery_DEPRECATED.js.flow +29 -13
- package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +6 -12
- package/relay-hooks/useBlockingPaginationFragment.js.flow +12 -13
- package/relay-hooks/useEntryPointLoader.js.flow +7 -10
- package/relay-hooks/useFetchTrackingRef.js.flow +2 -2
- package/relay-hooks/useFragment.js.flow +26 -46
- package/relay-hooks/useFragmentNode.js.flow +5 -7
- package/relay-hooks/useIsOperationNodeActive.js.flow +3 -5
- package/relay-hooks/useIsParentQueryActive.js.flow +3 -4
- package/relay-hooks/useLazyLoadQuery.js.flow +9 -10
- package/relay-hooks/useLazyLoadQueryNode.js.flow +11 -13
- package/relay-hooks/useLoadMoreFunction.js.flow +19 -27
- package/relay-hooks/useMemoOperationDescriptor.js.flow +5 -7
- package/relay-hooks/useMemoVariables.js.flow +6 -6
- package/relay-hooks/useMutation.js.flow +26 -26
- package/relay-hooks/usePaginationFragment.js.flow +37 -46
- package/relay-hooks/usePreloadedQuery.js.flow +13 -19
- package/relay-hooks/useQueryLoader.js.flow +13 -16
- package/relay-hooks/useRefetchableFragment.js.flow +7 -8
- package/relay-hooks/useRefetchableFragmentNode.js.flow +22 -30
- package/relay-hooks/useRelayEnvironment.js.flow +2 -4
- package/relay-hooks/useStaticFragmentNodeWarning.js.flow +2 -3
- package/relay-hooks/useSubscribeToInvalidationState.js.flow +3 -6
- package/relay-hooks/useSubscription.js.flow +6 -7
@@ -19,16 +19,18 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
|
|
19
19
|
|
20
20
|
var LRUCache = require('./LRUCache');
|
21
21
|
|
22
|
-
var
|
22
|
+
var SuspenseResource = require('./SuspenseResource');
|
23
23
|
|
24
|
-
var
|
24
|
+
var invariant = require('invariant');
|
25
25
|
|
26
26
|
var _require = require('relay-runtime'),
|
27
|
+
RelayFeatureFlags = _require.RelayFeatureFlags,
|
27
28
|
isPromise = _require.isPromise;
|
28
29
|
|
30
|
+
var warning = require("fbjs/lib/warning");
|
31
|
+
|
29
32
|
var CACHE_CAPACITY = 1000;
|
30
33
|
var DEFAULT_FETCH_POLICY = 'store-or-network';
|
31
|
-
var DATA_RETENTION_TIMEOUT = 5 * 60 * 1000;
|
32
34
|
var WEAKMAP_SUPPORTED = typeof WeakMap === 'function';
|
33
35
|
|
34
36
|
function operationIsLiveQuery(operation) {
|
@@ -64,6 +66,77 @@ function getQueryResult(operation, cacheIdentifier) {
|
|
64
66
|
var nextID = 200000;
|
65
67
|
|
66
68
|
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
|
+
var isLiveQuery = operationIsLiveQuery(operation);
|
82
|
+
var currentValue = value;
|
83
|
+
var currentNetworkSubscription = networkSubscription;
|
84
|
+
var suspenseResource = new SuspenseResource(function (environment) {
|
85
|
+
var retention = environment.retain(operation);
|
86
|
+
return {
|
87
|
+
dispose: function dispose() {
|
88
|
+
// Normally if this entry never commits, the request would've ended by the
|
89
|
+
// time this timeout expires and the temporary retain is released. However,
|
90
|
+
// we need to do this for live queries which remain open indefinitely.
|
91
|
+
if (isLiveQuery && currentNetworkSubscription != null) {
|
92
|
+
currentNetworkSubscription.unsubscribe();
|
93
|
+
}
|
94
|
+
|
95
|
+
retention.dispose();
|
96
|
+
onDispose(cacheEntry);
|
97
|
+
}
|
98
|
+
};
|
99
|
+
});
|
100
|
+
var cacheEntry = {
|
101
|
+
cacheIdentifier: cacheIdentifier,
|
102
|
+
id: nextID++,
|
103
|
+
processedPayloadsCount: 0,
|
104
|
+
operationAvailability: operationAvailability,
|
105
|
+
getValue: function getValue() {
|
106
|
+
return currentValue;
|
107
|
+
},
|
108
|
+
setValue: function setValue(val) {
|
109
|
+
currentValue = val;
|
110
|
+
},
|
111
|
+
getRetainCount: function getRetainCount() {
|
112
|
+
return suspenseResource.getRetainCount();
|
113
|
+
},
|
114
|
+
getNetworkSubscription: function getNetworkSubscription() {
|
115
|
+
return currentNetworkSubscription;
|
116
|
+
},
|
117
|
+
setNetworkSubscription: function setNetworkSubscription(subscription) {
|
118
|
+
if (isLiveQuery && currentNetworkSubscription != null) {
|
119
|
+
currentNetworkSubscription.unsubscribe();
|
120
|
+
}
|
121
|
+
|
122
|
+
currentNetworkSubscription = subscription;
|
123
|
+
},
|
124
|
+
temporaryRetain: function temporaryRetain(environment) {
|
125
|
+
return suspenseResource.temporaryRetain(environment);
|
126
|
+
},
|
127
|
+
permanentRetain: function permanentRetain(environment) {
|
128
|
+
return suspenseResource.permanentRetain(environment);
|
129
|
+
},
|
130
|
+
releaseTemporaryRetain: function releaseTemporaryRetain() {
|
131
|
+
suspenseResource.releaseTemporaryRetain();
|
132
|
+
}
|
133
|
+
};
|
134
|
+
return cacheEntry;
|
135
|
+
}
|
136
|
+
|
137
|
+
var DATA_RETENTION_TIMEOUT = 5 * 60 * 1000;
|
138
|
+
|
139
|
+
function createCacheEntry_old(cacheIdentifier, operation, operationAvailability, value, networkSubscription, onDispose) {
|
67
140
|
var isLiveQuery = operationIsLiveQuery(operation);
|
68
141
|
var currentValue = value;
|
69
142
|
var retainCount = 0;
|
@@ -202,8 +275,14 @@ var QueryResourceImpl = /*#__PURE__*/function () {
|
|
202
275
|
var _this = this;
|
203
276
|
|
204
277
|
(0, _defineProperty2["default"])(this, "_clearCacheEntry", function (cacheEntry) {
|
205
|
-
|
278
|
+
// The new code does this retainCount <= 0 check within SuspenseResource
|
279
|
+
// before calling _clearCacheEntry, whereas with the old code we do it here.
|
280
|
+
if (RelayFeatureFlags.REFACTOR_SUSPENSE_RESOURCE) {
|
206
281
|
_this._cache["delete"](cacheEntry.cacheIdentifier);
|
282
|
+
} else {
|
283
|
+
if (cacheEntry.getRetainCount() <= 0) {
|
284
|
+
_this._cache["delete"](cacheEntry.cacheIdentifier);
|
285
|
+
}
|
207
286
|
}
|
208
287
|
});
|
209
288
|
this._environment = environment;
|
@@ -0,0 +1,130 @@
|
|
1
|
+
/**
|
2
|
+
* Copyright (c) Facebook, Inc. and its 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
|
+
// flowlint ambiguous-object-type:error
|
12
|
+
'use strict';
|
13
|
+
|
14
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
15
|
+
|
16
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
17
|
+
|
18
|
+
var invariant = require('invariant');
|
19
|
+
|
20
|
+
var TEMPORARY_RETAIN_DURATION_MS = 5 * 60 * 1000;
|
21
|
+
/**
|
22
|
+
* Allows you to retain a resource as part of a component lifecycle accounting
|
23
|
+
* for Suspense. You temporarily retain the resource during render, then
|
24
|
+
* permanently retain it during commit and release it during unmount.
|
25
|
+
*/
|
26
|
+
|
27
|
+
var SuspenseResource = /*#__PURE__*/function () {
|
28
|
+
function SuspenseResource(retain) {
|
29
|
+
var _this = this;
|
30
|
+
|
31
|
+
(0, _defineProperty2["default"])(this, "_retainCount", 0);
|
32
|
+
(0, _defineProperty2["default"])(this, "_retainDisposable", null);
|
33
|
+
(0, _defineProperty2["default"])(this, "_releaseTemporaryRetain", null);
|
34
|
+
|
35
|
+
this._retain = function (environment) {
|
36
|
+
_this._retainCount++;
|
37
|
+
|
38
|
+
if (_this._retainCount === 1) {
|
39
|
+
_this._retainDisposable = retain(environment);
|
40
|
+
}
|
41
|
+
|
42
|
+
return {
|
43
|
+
dispose: function dispose() {
|
44
|
+
_this._retainCount = Math.max(0, _this._retainCount - 1);
|
45
|
+
|
46
|
+
if (_this._retainCount === 0) {
|
47
|
+
!(_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
|
+
_this._retainDisposable.dispose();
|
50
|
+
|
51
|
+
_this._retainDisposable = null;
|
52
|
+
}
|
53
|
+
}
|
54
|
+
};
|
55
|
+
};
|
56
|
+
}
|
57
|
+
|
58
|
+
var _proto = SuspenseResource.prototype;
|
59
|
+
|
60
|
+
_proto.temporaryRetain = function temporaryRetain(environment) {
|
61
|
+
var _this2 = this;
|
62
|
+
|
63
|
+
var _this$_releaseTempora;
|
64
|
+
|
65
|
+
// If we're executing in a server environment, there's no need
|
66
|
+
// to create temporary retains, since the component will never commit.
|
67
|
+
if (environment.isServer()) {
|
68
|
+
return {
|
69
|
+
dispose: function dispose() {}
|
70
|
+
};
|
71
|
+
} // temporaryRetain is called during the render phase. However,
|
72
|
+
// given that we can't tell if this render will eventually commit or not,
|
73
|
+
// we create a timer to autodispose of this retain in case the associated
|
74
|
+
// component never commits.
|
75
|
+
// If the component /does/ commit, permanentRetain will clear this timeout
|
76
|
+
// and permanently retain the data.
|
77
|
+
|
78
|
+
|
79
|
+
var retention = this._retain(environment);
|
80
|
+
|
81
|
+
var releaseQueryTimeout = null;
|
82
|
+
|
83
|
+
var releaseTemporaryRetain = function releaseTemporaryRetain() {
|
84
|
+
clearTimeout(releaseQueryTimeout);
|
85
|
+
releaseQueryTimeout = null;
|
86
|
+
_this2._releaseTemporaryRetain = null;
|
87
|
+
retention.dispose();
|
88
|
+
};
|
89
|
+
|
90
|
+
releaseQueryTimeout = setTimeout(releaseTemporaryRetain, TEMPORARY_RETAIN_DURATION_MS); // NOTE: Since temporaryRetain can be called multiple times, we release
|
91
|
+
// the previous temporary retain after we re-establish a new one, since
|
92
|
+
// we only ever need a single temporary retain until the permanent retain is
|
93
|
+
// established.
|
94
|
+
// temporaryRetain may be called multiple times by React during the render
|
95
|
+
// phase, as well as multiple times by other query components that are
|
96
|
+
// rendering the same query/variables.
|
97
|
+
|
98
|
+
(_this$_releaseTempora = this._releaseTemporaryRetain) === null || _this$_releaseTempora === void 0 ? void 0 : _this$_releaseTempora.call(this);
|
99
|
+
this._releaseTemporaryRetain = releaseTemporaryRetain;
|
100
|
+
return {
|
101
|
+
dispose: function dispose() {
|
102
|
+
var _this$_releaseTempora2;
|
103
|
+
|
104
|
+
(_this$_releaseTempora2 = _this2._releaseTemporaryRetain) === null || _this$_releaseTempora2 === void 0 ? void 0 : _this$_releaseTempora2.call(_this2);
|
105
|
+
}
|
106
|
+
};
|
107
|
+
};
|
108
|
+
|
109
|
+
_proto.permanentRetain = function permanentRetain(environment) {
|
110
|
+
var disposable = this._retain(environment);
|
111
|
+
|
112
|
+
this.releaseTemporaryRetain();
|
113
|
+
return disposable;
|
114
|
+
};
|
115
|
+
|
116
|
+
_proto.releaseTemporaryRetain = function releaseTemporaryRetain() {
|
117
|
+
var _this$_releaseTempora3;
|
118
|
+
|
119
|
+
(_this$_releaseTempora3 = this._releaseTemporaryRetain) === null || _this$_releaseTempora3 === void 0 ? void 0 : _this$_releaseTempora3.call(this);
|
120
|
+
this._releaseTemporaryRetain = null;
|
121
|
+
};
|
122
|
+
|
123
|
+
_proto.getRetainCount = function getRetainCount() {
|
124
|
+
return this._retainCount;
|
125
|
+
};
|
126
|
+
|
127
|
+
return SuspenseResource;
|
128
|
+
}();
|
129
|
+
|
130
|
+
module.exports = SuspenseResource;
|
@@ -14,21 +14,21 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
14
14
|
|
15
15
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
16
16
|
|
17
|
-
var React = require('react');
|
18
|
-
|
19
17
|
var invariant = require('invariant');
|
20
18
|
|
21
|
-
var
|
19
|
+
var React = require('react');
|
22
20
|
|
23
21
|
var _require = require('relay-runtime'),
|
22
|
+
Observable = _require.Observable,
|
24
23
|
PreloadableQueryRegistry = _require.PreloadableQueryRegistry,
|
24
|
+
RelayFeatureFlags = _require.RelayFeatureFlags,
|
25
25
|
ReplaySubject = _require.ReplaySubject,
|
26
|
+
fetchQueryDeduped = _require.__internal.fetchQueryDeduped,
|
26
27
|
createOperationDescriptor = _require.createOperationDescriptor,
|
27
28
|
getRequest = _require.getRequest,
|
28
|
-
getRequestIdentifier = _require.getRequestIdentifier
|
29
|
-
|
30
|
-
|
31
|
-
fetchQueryDeduped = _require.__internal.fetchQueryDeduped;
|
29
|
+
getRequestIdentifier = _require.getRequestIdentifier;
|
30
|
+
|
31
|
+
var warning = require("fbjs/lib/warning");
|
32
32
|
|
33
33
|
var RenderDispatcher = null;
|
34
34
|
var fetchKey = 100001;
|
@@ -254,8 +254,7 @@ function loadQuery(environment, preloadableRequest, variables, options, environm
|
|
254
254
|
// store in the first place, so it couldn't have been cached.
|
255
255
|
var networkObservable = fetchPolicy === 'store-only' ? null : makeNetworkRequest(params); // $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
256
256
|
|
257
|
-
var _PreloadableQueryRegi = PreloadableQueryRegistry.onLoad(
|
258
|
-
queryId, function (preloadedModule) {
|
257
|
+
var _PreloadableQueryRegi = PreloadableQueryRegistry.onLoad(queryId, function (preloadedModule) {
|
259
258
|
cancelOnLoadCallback();
|
260
259
|
var operation = createOperationDescriptor(preloadedModule, variables, networkCacheConfig);
|
261
260
|
retainReference = environment.retain(operation);
|
@@ -16,14 +16,15 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
16
16
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
17
17
|
|
18
18
|
var _require = require('relay-runtime'),
|
19
|
-
createOperationDescriptor = _require.createOperationDescriptor,
|
20
|
-
getRequest = _require.getRequest,
|
21
|
-
getRequestIdentifier = _require.getRequestIdentifier,
|
22
19
|
Observable = _require.Observable,
|
23
20
|
PreloadableQueryRegistry = _require.PreloadableQueryRegistry,
|
24
|
-
|
21
|
+
RelayFeatureFlags = _require.RelayFeatureFlags,
|
22
|
+
ReplaySubject = _require.ReplaySubject,
|
23
|
+
createOperationDescriptor = _require.createOperationDescriptor,
|
24
|
+
getRequest = _require.getRequest,
|
25
|
+
getRequestIdentifier = _require.getRequestIdentifier; // Expire results by this delay after they resolve.
|
26
|
+
|
25
27
|
|
26
|
-
// Expire results by this delay after they resolve.
|
27
28
|
var DEFAULT_PREFETCH_TIMEOUT = 30 * 1000; // 30 seconds
|
28
29
|
|
29
30
|
var WEAKMAP_SUPPORTED = typeof WeakMap === 'function';
|
@@ -58,7 +59,22 @@ function preloadQuery(environment, preloadableRequest, variables, options, envir
|
|
58
59
|
var _subscription;
|
59
60
|
|
60
61
|
(_subscription = subscription) === null || _subscription === void 0 ? void 0 : _subscription.unsubscribe();
|
61
|
-
|
62
|
+
|
63
|
+
if (environment.isServer()) {
|
64
|
+
return;
|
65
|
+
}
|
66
|
+
|
67
|
+
if (RelayFeatureFlags.DELAY_CLEANUP_OF_PENDING_PRELOAD_QUERIES === true) {
|
68
|
+
setTimeout(function () {
|
69
|
+
// Clear the cache entry after the default timeout
|
70
|
+
// null-check for Flow
|
71
|
+
if (queryEntry != null) {
|
72
|
+
cleanup(pendingQueries, queryEntry);
|
73
|
+
}
|
74
|
+
}, DEFAULT_PREFETCH_TIMEOUT);
|
75
|
+
} else {
|
76
|
+
cleanup(pendingQueries, queryEntry);
|
77
|
+
}
|
62
78
|
};
|
63
79
|
}) : null;
|
64
80
|
return {
|
@@ -173,11 +189,9 @@ function preloadQueryDeduped(environment, pendingQueries, preloadableRequest, va
|
|
173
189
|
};
|
174
190
|
} else {
|
175
191
|
nextQueryEntry = prevQueryEntry;
|
176
|
-
}
|
177
|
-
|
178
|
-
|
179
|
-
pendingQueries.set(cacheKey, nextQueryEntry); // $FlowFixMe[incompatible-return]
|
192
|
+
}
|
180
193
|
|
194
|
+
pendingQueries.set(cacheKey, nextQueryEntry);
|
181
195
|
return nextQueryEntry;
|
182
196
|
}
|
183
197
|
|
@@ -17,14 +17,14 @@ var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runt
|
|
17
17
|
|
18
18
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
19
19
|
|
20
|
-
var invariant = require('invariant');
|
21
|
-
|
22
20
|
var useLoadMoreFunction = require('./useLoadMoreFunction');
|
23
21
|
|
24
22
|
var useRefetchableFragmentNode = require('./useRefetchableFragmentNode');
|
25
23
|
|
26
24
|
var useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
|
27
25
|
|
26
|
+
var invariant = require('invariant');
|
27
|
+
|
28
28
|
var _require = require('react'),
|
29
29
|
useCallback = _require.useCallback,
|
30
30
|
useEffect = _require.useEffect,
|
@@ -17,11 +17,11 @@ var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime
|
|
17
17
|
|
18
18
|
var loadEntryPoint = require('./loadEntryPoint');
|
19
19
|
|
20
|
-
var useIsMountedRef = require('./useIsMountedRef');
|
21
|
-
|
22
20
|
var _require = require('./loadQuery'),
|
23
21
|
useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
|
24
22
|
|
23
|
+
var useIsMountedRef = require('./useIsMountedRef');
|
24
|
+
|
25
25
|
var _require2 = require('react'),
|
26
26
|
useCallback = _require2.useCallback,
|
27
27
|
useEffect = _require2.useEffect,
|
@@ -15,7 +15,6 @@ var _require = require('react'),
|
|
15
15
|
useCallback = _require.useCallback,
|
16
16
|
useEffect = _require.useEffect,
|
17
17
|
useRef = _require.useRef;
|
18
|
-
|
19
18
|
/**
|
20
19
|
* This hook returns a mutable React ref that holds the value of whether a
|
21
20
|
* fetch request is in flight. The reason this is a mutable ref instead of
|
@@ -28,6 +27,8 @@ var _require = require('react'),
|
|
28
27
|
* The additional functions returned by this Hook can be used to mutate
|
29
28
|
* the ref.
|
30
29
|
*/
|
30
|
+
|
31
|
+
|
31
32
|
function useFetchTrackingRef() {
|
32
33
|
var subscriptionRef = useRef(null);
|
33
34
|
var isFetchingRef = useRef(false);
|
@@ -11,27 +11,28 @@
|
|
11
11
|
// flowlint ambiguous-object-type:error
|
12
12
|
'use strict';
|
13
13
|
|
14
|
+
var _require = require('./loadQuery'),
|
15
|
+
useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
|
16
|
+
|
14
17
|
var useFragmentNode = require('./useFragmentNode');
|
15
18
|
|
16
19
|
var useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
|
17
20
|
|
18
|
-
var _require = require('./loadQuery'),
|
19
|
-
useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
|
20
|
-
|
21
21
|
var _require2 = require('react'),
|
22
22
|
useDebugValue = _require2.useDebugValue;
|
23
23
|
|
24
24
|
var _require3 = require('relay-runtime'),
|
25
|
-
getFragment = _require3.getFragment;
|
25
|
+
getFragment = _require3.getFragment; // if the key is non-nullable, return non-nullable value
|
26
|
+
|
26
27
|
|
27
|
-
function useFragment(
|
28
|
+
function useFragment(fragment, key) {
|
28
29
|
// We need to use this hook in order to be able to track if
|
29
30
|
// loadQuery was called during render
|
30
31
|
useTrackLoadQueryInRender();
|
31
|
-
var fragmentNode = getFragment(
|
32
|
+
var fragmentNode = getFragment(fragment);
|
32
33
|
useStaticFragmentNodeWarning(fragmentNode, 'first argument of useFragment()');
|
33
34
|
|
34
|
-
var _useFragmentNode = useFragmentNode(fragmentNode,
|
35
|
+
var _useFragmentNode = useFragmentNode(fragmentNode, key, 'useFragment()'),
|
35
36
|
data = _useFragmentNode.data;
|
36
37
|
|
37
38
|
if (process.env.NODE_ENV !== "production") {
|
@@ -11,13 +11,11 @@
|
|
11
11
|
// flowlint ambiguous-object-type:error
|
12
12
|
'use strict';
|
13
13
|
|
14
|
-
var useRelayEnvironment = require('./useRelayEnvironment');
|
15
|
-
|
16
|
-
var warning = require("fbjs/lib/warning");
|
17
|
-
|
18
14
|
var _require = require('./FragmentResource'),
|
19
15
|
getFragmentResourceForEnvironment = _require.getFragmentResourceForEnvironment;
|
20
16
|
|
17
|
+
var useRelayEnvironment = require('./useRelayEnvironment');
|
18
|
+
|
21
19
|
var _require2 = require('react'),
|
22
20
|
useEffect = _require2.useEffect,
|
23
21
|
useRef = _require2.useRef,
|
@@ -26,6 +24,8 @@ var _require2 = require('react'),
|
|
26
24
|
var _require3 = require('relay-runtime'),
|
27
25
|
getFragmentIdentifier = _require3.getFragmentIdentifier;
|
28
26
|
|
27
|
+
var warning = require("fbjs/lib/warning");
|
28
|
+
|
29
29
|
function useFragmentNode(fragmentNode, fragmentRef, componentDisplayName) {
|
30
30
|
var environment = useRelayEnvironment();
|
31
31
|
var FragmentResource = getFragmentResourceForEnvironment(environment);
|
@@ -10,11 +10,11 @@
|
|
10
10
|
*/
|
11
11
|
'use strict';
|
12
12
|
|
13
|
-
var
|
13
|
+
var useRelayEnvironment = require('./useRelayEnvironment');
|
14
14
|
|
15
15
|
var invariant = require('invariant');
|
16
16
|
|
17
|
-
var
|
17
|
+
var React = require('react');
|
18
18
|
|
19
19
|
var _require = require('relay-runtime'),
|
20
20
|
getObservableForActiveRequest = _require.__internal.getObservableForActiveRequest,
|
@@ -11,15 +11,15 @@
|
|
11
11
|
// flowlint ambiguous-object-type:error
|
12
12
|
'use strict';
|
13
13
|
|
14
|
+
var _require = require('./loadQuery'),
|
15
|
+
useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
|
16
|
+
|
14
17
|
var useLazyLoadQueryNode = require('./useLazyLoadQueryNode');
|
15
18
|
|
16
19
|
var useMemoOperationDescriptor = require('./useMemoOperationDescriptor');
|
17
20
|
|
18
21
|
var useRelayEnvironment = require('./useRelayEnvironment');
|
19
22
|
|
20
|
-
var _require = require('./loadQuery'),
|
21
|
-
useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
|
22
|
-
|
23
23
|
var _require2 = require('relay-runtime'),
|
24
24
|
fetchQuery = _require2.__internal.fetchQuery;
|
25
25
|
|
@@ -13,7 +13,9 @@
|
|
13
13
|
|
14
14
|
var ProfilerContext = require('./ProfilerContext');
|
15
15
|
|
16
|
-
var
|
16
|
+
var _require = require('./QueryResource'),
|
17
|
+
getQueryCacheIdentifier = _require.getQueryCacheIdentifier,
|
18
|
+
getQueryResourceForEnvironment = _require.getQueryResourceForEnvironment;
|
17
19
|
|
18
20
|
var useFetchTrackingRef = require('./useFetchTrackingRef');
|
19
21
|
|
@@ -21,9 +23,7 @@ var useFragmentNode = require('./useFragmentNode');
|
|
21
23
|
|
22
24
|
var useRelayEnvironment = require('./useRelayEnvironment');
|
23
25
|
|
24
|
-
var
|
25
|
-
getQueryResourceForEnvironment = _require.getQueryResourceForEnvironment,
|
26
|
-
getQueryCacheIdentifier = _require.getQueryCacheIdentifier;
|
26
|
+
var React = require('react');
|
27
27
|
|
28
28
|
var useContext = React.useContext,
|
29
29
|
useEffect = React.useEffect,
|
@@ -15,8 +15,6 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
15
15
|
|
16
16
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
17
17
|
|
18
|
-
var invariant = require('invariant');
|
19
|
-
|
20
18
|
var useFetchTrackingRef = require('./useFetchTrackingRef');
|
21
19
|
|
22
20
|
var useIsMountedRef = require('./useIsMountedRef');
|
@@ -25,7 +23,7 @@ var useIsOperationNodeActive = require('./useIsOperationNodeActive');
|
|
25
23
|
|
26
24
|
var useRelayEnvironment = require('./useRelayEnvironment');
|
27
25
|
|
28
|
-
var
|
26
|
+
var invariant = require('invariant');
|
29
27
|
|
30
28
|
var _require = require('react'),
|
31
29
|
useCallback = _require.useCallback,
|
@@ -37,8 +35,10 @@ var _require2 = require('relay-runtime'),
|
|
37
35
|
fetchQuery = _require2.__internal.fetchQuery,
|
38
36
|
createOperationDescriptor = _require2.createOperationDescriptor,
|
39
37
|
getPaginationVariables = _require2.getPaginationVariables,
|
40
|
-
|
41
|
-
|
38
|
+
getSelector = _require2.getSelector,
|
39
|
+
getValueAtPath = _require2.getValueAtPath;
|
40
|
+
|
41
|
+
var warning = require("fbjs/lib/warning");
|
42
42
|
|
43
43
|
function useLoadMoreFunction(args) {
|
44
44
|
var direction = args.direction,
|
@@ -124,11 +124,9 @@ function useLoadMoreFunction(args) {
|
|
124
124
|
!(fragmentSelector != null && fragmentSelector.kind !== 'PluralReaderSelector') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected to be able to find a non-plural fragment owner for ' + "fragment `%s` when using `%s`. If you're seeing this, " + 'this is likely a bug in Relay.', fragmentNode.name, componentDisplayName) : invariant(false) : void 0;
|
125
125
|
var parentVariables = fragmentSelector.owner.variables;
|
126
126
|
var fragmentVariables = fragmentSelector.variables;
|
127
|
-
var extraVariables = options === null || options === void 0 ? void 0 : options.UNSTABLE_extraVariables;
|
128
|
-
|
127
|
+
var extraVariables = options === null || options === void 0 ? void 0 : options.UNSTABLE_extraVariables;
|
129
128
|
var baseVariables = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, parentVariables), fragmentVariables);
|
130
|
-
var paginationVariables = getPaginationVariables(direction, count, cursor, baseVariables,
|
131
|
-
(0, _objectSpread2["default"])({}, extraVariables), paginationMetadata); // If the query needs an identifier value ('id' or similar) and one
|
129
|
+
var paginationVariables = getPaginationVariables(direction, count, cursor, baseVariables, (0, _objectSpread2["default"])({}, extraVariables), paginationMetadata); // If the query needs an identifier value ('id' or similar) and one
|
132
130
|
// was not explicitly provided, read it from the fragment data.
|
133
131
|
|
134
132
|
if (identifierField != null) {
|
@@ -11,10 +11,10 @@
|
|
11
11
|
// flowlint ambiguous-object-type:error
|
12
12
|
'use strict';
|
13
13
|
|
14
|
-
var React = require('react');
|
15
|
-
|
16
14
|
var useMemoVariables = require('./useMemoVariables');
|
17
15
|
|
16
|
+
var React = require('react');
|
17
|
+
|
18
18
|
var _require = require('relay-runtime'),
|
19
19
|
createOperationDescriptor = _require.createOperationDescriptor,
|
20
20
|
getRequest = _require.getRequest;
|
@@ -11,10 +11,10 @@
|
|
11
11
|
// flowlint ambiguous-object-type:error
|
12
12
|
'use strict';
|
13
13
|
|
14
|
-
var React = require('react');
|
15
|
-
|
16
14
|
var areEqual = require("fbjs/lib/areEqual");
|
17
15
|
|
16
|
+
var React = require('react');
|
17
|
+
|
18
18
|
var useMemo = React.useMemo,
|
19
19
|
useRef = React.useRef,
|
20
20
|
useState = React.useState;
|
@@ -15,10 +15,12 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
15
15
|
|
16
16
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
17
17
|
|
18
|
-
var
|
18
|
+
var useIsMountedRef = require('./useIsMountedRef');
|
19
19
|
|
20
20
|
var useRelayEnvironment = require('./useRelayEnvironment');
|
21
21
|
|
22
|
+
var React = require('react');
|
23
|
+
|
22
24
|
var _require = require('relay-runtime'),
|
23
25
|
defaultCommitMutation = _require.commitMutation;
|
24
26
|
|
@@ -27,8 +29,6 @@ var useState = React.useState,
|
|
27
29
|
useRef = React.useRef,
|
28
30
|
useCallback = React.useCallback;
|
29
31
|
|
30
|
-
var useIsMountedRef = require('./useIsMountedRef');
|
31
|
-
|
32
32
|
function useMutation(mutation) {
|
33
33
|
var commitMutationFn = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultCommitMutation;
|
34
34
|
var environment = useRelayEnvironment();
|
@@ -66,16 +66,27 @@ function useMutation(mutation) {
|
|
66
66
|
var disposable = commitMutationFn(environment, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, config), {}, {
|
67
67
|
mutation: mutation,
|
68
68
|
onCompleted: function onCompleted(response, errors) {
|
69
|
+
var _config$onCompleted;
|
70
|
+
|
69
71
|
cleanup(disposable);
|
70
|
-
config.onCompleted
|
72
|
+
(_config$onCompleted = config.onCompleted) === null || _config$onCompleted === void 0 ? void 0 : _config$onCompleted.call(config, response, errors);
|
71
73
|
},
|
72
74
|
onError: function onError(error) {
|
75
|
+
var _config$onError;
|
76
|
+
|
73
77
|
cleanup(disposable);
|
74
|
-
config.onError
|
78
|
+
(_config$onError = config.onError) === null || _config$onError === void 0 ? void 0 : _config$onError.call(config, error);
|
75
79
|
},
|
76
80
|
onUnsubscribe: function onUnsubscribe() {
|
81
|
+
var _config$onUnsubscribe;
|
82
|
+
|
77
83
|
cleanup(disposable);
|
78
|
-
config.onUnsubscribe
|
84
|
+
(_config$onUnsubscribe = config.onUnsubscribe) === null || _config$onUnsubscribe === void 0 ? void 0 : _config$onUnsubscribe.call(config);
|
85
|
+
},
|
86
|
+
onNext: function onNext() {
|
87
|
+
var _config$onNext;
|
88
|
+
|
89
|
+
(_config$onNext = config.onNext) === null || _config$onNext === void 0 ? void 0 : _config$onNext.call(config);
|
79
90
|
}
|
80
91
|
}));
|
81
92
|
inFlightMutationsRef.current.add(disposable);
|
@@ -11,7 +11,8 @@
|
|
11
11
|
// flowlint ambiguous-object-type:error
|
12
12
|
'use strict';
|
13
13
|
|
14
|
-
var
|
14
|
+
var _require = require('./loadQuery'),
|
15
|
+
useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
|
15
16
|
|
16
17
|
var useLazyLoadQueryNode = require('./useLazyLoadQueryNode');
|
17
18
|
|
@@ -19,10 +20,7 @@ var useMemoOperationDescriptor = require('./useMemoOperationDescriptor');
|
|
19
20
|
|
20
21
|
var useRelayEnvironment = require('./useRelayEnvironment');
|
21
22
|
|
22
|
-
var
|
23
|
-
|
24
|
-
var _require = require('./loadQuery'),
|
25
|
-
useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
|
23
|
+
var invariant = require('invariant');
|
26
24
|
|
27
25
|
var _require2 = require('react'),
|
28
26
|
useDebugValue = _require2.useDebugValue;
|
@@ -32,6 +30,8 @@ var _require3 = require('relay-runtime'),
|
|
32
30
|
fetchQueryDeduped = _require3$__internal.fetchQueryDeduped,
|
33
31
|
fetchQuery = _require3$__internal.fetchQuery;
|
34
32
|
|
33
|
+
var warning = require("fbjs/lib/warning");
|
34
|
+
|
35
35
|
function usePreloadedQuery(gqlQuery, preloadedQuery, options) {
|
36
36
|
// We need to use this hook in order to be able to track if
|
37
37
|
// loadQuery was called during render
|