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,32 +5,27 @@
|
|
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
|
-
|
14
|
-
var invariant = require('invariant'); // $FlowFixMe[prop-missing] These exist in experimental builds but aren't in React's types yet.
|
15
11
|
|
12
|
+
'use strict';
|
16
13
|
|
14
|
+
var invariant = require('invariant');
|
15
|
+
// $FlowFixMe[prop-missing] These exist in experimental builds but aren't in React's types yet.
|
17
16
|
var _require = require('react'),
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
unstable_getCacheForType = _require.unstable_getCacheForType,
|
18
|
+
unstable_getCacheSignal = _require.unstable_getCacheSignal;
|
21
19
|
var _require2 = require('relay-runtime'),
|
22
|
-
|
23
|
-
|
20
|
+
RelayFeatureFlags = _require2.RelayFeatureFlags;
|
24
21
|
function getCacheForType(factory) {
|
25
22
|
!(typeof unstable_getCacheForType === 'function' && RelayFeatureFlags.USE_REACT_CACHE) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReactCache.getCacheForType should only be called when the USE_REACT_CACHE feature flag is enabled and when on an experimental React build that supports it.') : invariant(false) : void 0;
|
26
23
|
return unstable_getCacheForType(factory);
|
27
24
|
}
|
28
|
-
|
29
25
|
function getCacheSignal() {
|
30
26
|
!(typeof unstable_getCacheSignal === 'function' && RelayFeatureFlags.USE_REACT_CACHE) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReactCache.getCacheSignal should only be called when the USE_REACT_CACHE feature flag is enabled and when on an experimental React build that supports it.') : invariant(false) : void 0;
|
31
27
|
return unstable_getCacheSignal();
|
32
28
|
}
|
33
|
-
|
34
29
|
module.exports = {
|
35
30
|
getCacheForType: getCacheForType,
|
36
31
|
getCacheSignal: getCacheSignal
|
@@ -5,98 +5,71 @@
|
|
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 SuspenseResource = require('../SuspenseResource');
|
21
|
-
|
22
18
|
var _require = require('./RelayReactCache'),
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
getCacheForType = _require.getCacheForType,
|
20
|
+
getCacheSignal = _require.getCacheSignal;
|
26
21
|
var invariant = require('invariant');
|
27
|
-
|
28
22
|
var _require2 = require('relay-runtime'),
|
29
|
-
|
30
|
-
|
31
|
-
|
23
|
+
fetchQueryInternal = _require2.__internal.fetchQuery,
|
24
|
+
RelayFeatureFlags = _require2.RelayFeatureFlags;
|
32
25
|
var warning = require("fbjs/lib/warning");
|
33
|
-
|
34
26
|
var DEFAULT_FETCH_POLICY = 'store-or-network';
|
35
|
-
|
27
|
+
var WEAKMAP_SUPPORTED = typeof WeakMap === 'function';
|
36
28
|
var QueryCache = /*#__PURE__*/function () {
|
37
29
|
function QueryCache() {
|
38
|
-
this._map = new Map();
|
30
|
+
this._map = WEAKMAP_SUPPORTED ? new WeakMap() : new Map();
|
39
31
|
}
|
40
|
-
|
41
32
|
var _proto = QueryCache.prototype;
|
42
|
-
|
43
33
|
_proto.get = function get(environment, key) {
|
44
34
|
var forEnv = this._map.get(environment);
|
45
|
-
|
46
35
|
if (!forEnv) {
|
47
36
|
forEnv = new Map();
|
48
|
-
|
49
37
|
this._map.set(environment, forEnv);
|
50
38
|
}
|
51
|
-
|
52
39
|
return forEnv.get(key);
|
53
40
|
};
|
54
|
-
|
55
41
|
_proto.set = function set(environment, key, value) {
|
56
42
|
var forEnv = this._map.get(environment);
|
57
|
-
|
58
43
|
if (!forEnv) {
|
59
44
|
forEnv = new Map();
|
60
|
-
|
61
45
|
this._map.set(environment, forEnv);
|
62
46
|
}
|
63
|
-
|
64
47
|
forEnv.set(key, value);
|
65
48
|
};
|
66
|
-
|
67
49
|
_proto["delete"] = function _delete(environment, key) {
|
68
50
|
var forEnv = this._map.get(environment);
|
69
|
-
|
70
51
|
if (!forEnv) {
|
71
52
|
return;
|
72
53
|
}
|
73
|
-
|
74
54
|
forEnv["delete"](key);
|
75
|
-
|
76
55
|
if (forEnv.size === 0) {
|
77
56
|
this._map["delete"](environment);
|
78
57
|
}
|
79
58
|
};
|
80
|
-
|
81
59
|
return QueryCache;
|
82
60
|
}();
|
83
|
-
|
84
61
|
function createQueryCache() {
|
85
62
|
return new QueryCache();
|
86
63
|
}
|
87
|
-
|
88
64
|
var noopOnCommit = function noopOnCommit() {
|
89
65
|
return function () {
|
90
66
|
return undefined;
|
91
67
|
};
|
92
68
|
};
|
93
|
-
|
94
69
|
var noopPromise = new Promise(function () {});
|
95
|
-
|
96
70
|
function getQueryCacheKey(operation, fetchPolicy, renderPolicy, fetchKey) {
|
97
71
|
return "".concat(fetchPolicy, "-").concat(renderPolicy, "-").concat(operation.request.identifier, "-").concat(fetchKey !== null && fetchKey !== void 0 ? fetchKey : '');
|
98
72
|
}
|
99
|
-
|
100
73
|
function constructQueryResult(operation) {
|
101
74
|
var rootFragmentRef = {
|
102
75
|
__id: operation.fragment.dataID,
|
@@ -108,7 +81,6 @@ function constructQueryResult(operation) {
|
|
108
81
|
fragmentRef: rootFragmentRef
|
109
82
|
};
|
110
83
|
}
|
111
|
-
|
112
84
|
function makeInitialCacheEntry() {
|
113
85
|
return {
|
114
86
|
status: 'pending',
|
@@ -117,35 +89,30 @@ function makeInitialCacheEntry() {
|
|
117
89
|
suspenseResource: null
|
118
90
|
};
|
119
91
|
}
|
120
|
-
|
121
92
|
function getQueryResultOrFetchQuery_REACT_CACHE(environment, queryOperationDescriptor, options) {
|
122
93
|
var _options$fetchPolicy, _options$renderPolicy;
|
123
|
-
|
124
94
|
var fetchPolicy = (_options$fetchPolicy = options === null || options === void 0 ? void 0 : options.fetchPolicy) !== null && _options$fetchPolicy !== void 0 ? _options$fetchPolicy : DEFAULT_FETCH_POLICY;
|
125
95
|
var renderPolicy = (_options$renderPolicy = options === null || options === void 0 ? void 0 : options.renderPolicy) !== null && _options$renderPolicy !== void 0 ? _options$renderPolicy : environment.UNSTABLE_getDefaultRenderPolicy();
|
126
96
|
var cache = getCacheForType(createQueryCache);
|
127
97
|
var cacheKey = getQueryCacheKey(queryOperationDescriptor, fetchPolicy, renderPolicy, options === null || options === void 0 ? void 0 : options.fetchKey);
|
128
98
|
var initialEntry = cache.get(environment, cacheKey);
|
129
|
-
|
130
99
|
function updateCache(updater) {
|
131
100
|
var currentEntry = cache.get(environment, cacheKey);
|
132
|
-
|
133
101
|
if (!currentEntry) {
|
134
102
|
currentEntry = makeInitialCacheEntry();
|
135
103
|
cache.set(environment, cacheKey, currentEntry);
|
136
|
-
}
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
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
|
142
110
|
// a QueryCacheEntryStatus into a QueryCacheEntry will result in a valid QueryCacheEntry.
|
143
|
-
}
|
144
|
-
|
111
|
+
}
|
145
112
|
|
113
|
+
// Initiate a query to fetch the data if needed:
|
146
114
|
if (RelayFeatureFlags.USE_REACT_CACHE_LEGACY_TIMEOUTS) {
|
147
115
|
var _entry;
|
148
|
-
|
149
116
|
if (initialEntry === undefined) {
|
150
117
|
onCacheMiss(environment, queryOperationDescriptor, fetchPolicy, renderPolicy, updateCache, options === null || options === void 0 ? void 0 : options.fetchObservable);
|
151
118
|
var createdEntry = cache.get(environment, cacheKey);
|
@@ -154,7 +121,6 @@ function getQueryResultOrFetchQuery_REACT_CACHE(environment, queryOperationDescr
|
|
154
121
|
} else {
|
155
122
|
_entry = initialEntry;
|
156
123
|
}
|
157
|
-
|
158
124
|
if (!_entry.suspenseResource) {
|
159
125
|
_entry.suspenseResource = new SuspenseResource(function () {
|
160
126
|
var retention = environment.retain(queryOperationDescriptor);
|
@@ -166,60 +132,48 @@ function getQueryResultOrFetchQuery_REACT_CACHE(environment, queryOperationDescr
|
|
166
132
|
};
|
167
133
|
});
|
168
134
|
}
|
169
|
-
|
170
135
|
if (_entry.onCommit === noopOnCommit) {
|
171
136
|
_entry.onCommit = function () {
|
172
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;
|
173
|
-
|
174
138
|
var retention = _entry.suspenseResource.permanentRetain(environment);
|
175
|
-
|
176
139
|
return function () {
|
177
140
|
retention.dispose();
|
178
141
|
};
|
179
142
|
};
|
180
143
|
}
|
181
|
-
|
182
144
|
_entry.suspenseResource.temporaryRetain(environment);
|
183
145
|
} else {
|
184
146
|
if (initialEntry === undefined) {
|
185
147
|
// This is the behavior we eventually want: We retain the query until the
|
186
148
|
// presiding Cache component unmounts, at which point the AbortSignal
|
187
149
|
// will be triggered.
|
188
|
-
onCacheMiss(environment, queryOperationDescriptor, fetchPolicy, renderPolicy, updateCache, options === null || options === void 0 ? void 0 : options.fetchObservable);
|
189
|
-
// trigger the abort signal when this cache entry is no longer needed.
|
150
|
+
onCacheMiss(environment, queryOperationDescriptor, fetchPolicy, renderPolicy, updateCache, options === null || options === void 0 ? void 0 : options.fetchObservable);
|
190
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.
|
191
154
|
var retention = environment.retain(queryOperationDescriptor);
|
192
|
-
|
193
155
|
var dispose = function dispose() {
|
194
156
|
retention.dispose();
|
195
157
|
cache["delete"](environment, cacheKey);
|
196
158
|
};
|
197
|
-
|
198
159
|
var abortSignal = getCacheSignal();
|
199
160
|
abortSignal.addEventListener('abort', dispose, {
|
200
161
|
once: true
|
201
162
|
});
|
202
163
|
}
|
203
164
|
}
|
204
|
-
|
205
165
|
var entry = cache.get(environment, cacheKey); // could be a different entry now if synchronously resolved
|
206
|
-
|
207
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;
|
208
|
-
|
209
167
|
switch (entry.status) {
|
210
168
|
case 'pending':
|
211
169
|
throw entry.promise;
|
212
|
-
|
213
170
|
case 'rejected':
|
214
171
|
throw entry.error;
|
215
|
-
|
216
172
|
case 'resolved':
|
217
173
|
return [entry.result, entry.onCommit];
|
218
174
|
}
|
219
|
-
|
220
175
|
!false ? process.env.NODE_ENV !== "production" ? invariant(false, 'switch statement should be exhaustive') : invariant(false) : void 0;
|
221
176
|
}
|
222
|
-
|
223
177
|
function onCacheMiss(environment, operation, fetchPolicy, renderPolicy, updateCache, customFetchObservable) {
|
224
178
|
// NB: Besides checking if the data is available, calling `check` will write missing
|
225
179
|
// data to the store using any missing data handlers specified in the environment.
|
@@ -229,7 +183,6 @@ function onCacheMiss(environment, operation, fetchPolicy, renderPolicy, updateCa
|
|
229
183
|
var canPartialRender = hasFullQuery || renderPolicy === 'partial' && queryStatus !== 'stale';
|
230
184
|
var shouldFetch;
|
231
185
|
var shouldRenderNow;
|
232
|
-
|
233
186
|
switch (fetchPolicy) {
|
234
187
|
case 'store-only':
|
235
188
|
{
|
@@ -237,21 +190,18 @@ function onCacheMiss(environment, operation, fetchPolicy, renderPolicy, updateCa
|
|
237
190
|
shouldRenderNow = true;
|
238
191
|
break;
|
239
192
|
}
|
240
|
-
|
241
193
|
case 'store-or-network':
|
242
194
|
{
|
243
195
|
shouldFetch = !hasFullQuery;
|
244
196
|
shouldRenderNow = canPartialRender;
|
245
197
|
break;
|
246
198
|
}
|
247
|
-
|
248
199
|
case 'store-and-network':
|
249
200
|
{
|
250
201
|
shouldFetch = true;
|
251
202
|
shouldRenderNow = canPartialRender;
|
252
203
|
break;
|
253
204
|
}
|
254
|
-
|
255
205
|
case 'network-only':
|
256
206
|
default:
|
257
207
|
{
|
@@ -260,17 +210,14 @@ function onCacheMiss(environment, operation, fetchPolicy, renderPolicy, updateCa
|
|
260
210
|
break;
|
261
211
|
}
|
262
212
|
}
|
263
|
-
|
264
213
|
if (shouldFetch) {
|
265
214
|
executeOperationAndKeepUpToDate(environment, operation, updateCache, customFetchObservable);
|
266
215
|
updateCache(function (existing) {
|
267
216
|
switch (existing.status) {
|
268
217
|
case 'resolved':
|
269
218
|
return existing;
|
270
|
-
|
271
219
|
case 'rejected':
|
272
220
|
return existing;
|
273
|
-
|
274
221
|
case 'pending':
|
275
222
|
return shouldRenderNow ? {
|
276
223
|
status: 'resolved',
|
@@ -288,16 +235,16 @@ function onCacheMiss(environment, operation, fetchPolicy, renderPolicy, updateCa
|
|
288
235
|
});
|
289
236
|
}
|
290
237
|
}
|
291
|
-
|
292
238
|
function executeOperationAndKeepUpToDate(environment, operation, updateCache, customFetchObservable) {
|
293
239
|
var resolvePromise;
|
294
240
|
var promise = new Promise(function (r) {
|
295
241
|
resolvePromise = r;
|
296
|
-
});
|
297
|
-
|
242
|
+
});
|
243
|
+
// $FlowExpectedError[prop-missing] Expando to annotate Promises.
|
298
244
|
promise.displayName = 'Relay(' + operation.request.node.operation.name + ')';
|
299
|
-
var isFirstPayload = true;
|
245
|
+
var isFirstPayload = true;
|
300
246
|
|
247
|
+
// FIXME We may still need to cancel network requests for live queries.
|
301
248
|
var fetchObservable = customFetchObservable !== null && customFetchObservable !== void 0 ? customFetchObservable : fetchQueryInternal(environment, operation);
|
302
249
|
fetchObservable.subscribe({
|
303
250
|
start: function start(subscription) {},
|
@@ -314,7 +261,6 @@ function executeOperationAndKeepUpToDate(environment, operation, updateCache, cu
|
|
314
261
|
// To complete this task we need to have a way of precisely tracking suspendable points
|
315
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;
|
316
263
|
}
|
317
|
-
|
318
264
|
resolvePromise();
|
319
265
|
isFirstPayload = false;
|
320
266
|
},
|
@@ -329,10 +275,11 @@ function executeOperationAndKeepUpToDate(environment, operation, updateCache, cu
|
|
329
275
|
resolvePromise();
|
330
276
|
isFirstPayload = false;
|
331
277
|
}
|
332
|
-
});
|
278
|
+
});
|
279
|
+
|
280
|
+
// If the above subscription yields a value synchronously, then one of the updates
|
333
281
|
// above will have already happened and we'll now be in a resolved or rejected state.
|
334
282
|
// But in the usual case, we save the promise to the entry here:
|
335
|
-
|
336
283
|
updateCache(function (existing) {
|
337
284
|
return existing.status === 'pending' ? {
|
338
285
|
status: 'pending',
|
@@ -340,5 +287,4 @@ function executeOperationAndKeepUpToDate(environment, operation, updateCache, cu
|
|
340
287
|
} : existing;
|
341
288
|
});
|
342
289
|
}
|
343
|
-
|
344
290
|
module.exports = getQueryResultOrFetchQuery_REACT_CACHE;
|
@@ -0,0 +1,206 @@
|
|
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 _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
|
17
|
+
var _require = require('../QueryResource'),
|
18
|
+
getQueryResourceForEnvironment = _require.getQueryResourceForEnvironment;
|
19
|
+
var invariant = require('invariant');
|
20
|
+
var _require2 = require('relay-runtime'),
|
21
|
+
fetchQueryInternal = _require2.__internal.fetchQuery,
|
22
|
+
createOperationDescriptor = _require2.createOperationDescriptor,
|
23
|
+
getPendingOperationsForFragment = _require2.getPendingOperationsForFragment,
|
24
|
+
getSelector = _require2.getSelector,
|
25
|
+
getVariablesFromFragment = _require2.getVariablesFromFragment,
|
26
|
+
handlePotentialSnapshotErrors = _require2.handlePotentialSnapshotErrors;
|
27
|
+
var warning = require("fbjs/lib/warning");
|
28
|
+
function isMissingData(state) {
|
29
|
+
if (state.kind === 'bailout') {
|
30
|
+
return false;
|
31
|
+
} else if (state.kind === 'singular') {
|
32
|
+
return state.snapshot.isMissingData;
|
33
|
+
} else {
|
34
|
+
return state.snapshots.some(function (s) {
|
35
|
+
return s.isMissingData;
|
36
|
+
});
|
37
|
+
}
|
38
|
+
}
|
39
|
+
function getMissingClientEdges(state) {
|
40
|
+
if (state.kind === 'bailout') {
|
41
|
+
return null;
|
42
|
+
} else if (state.kind === 'singular') {
|
43
|
+
var _state$snapshot$missi;
|
44
|
+
return (_state$snapshot$missi = state.snapshot.missingClientEdges) !== null && _state$snapshot$missi !== void 0 ? _state$snapshot$missi : null;
|
45
|
+
} else {
|
46
|
+
var edges = null;
|
47
|
+
var _iterator = (0, _createForOfIteratorHelper2["default"])(state.snapshots),
|
48
|
+
_step;
|
49
|
+
try {
|
50
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
51
|
+
var snapshot = _step.value;
|
52
|
+
if (snapshot.missingClientEdges) {
|
53
|
+
var _edges;
|
54
|
+
edges = (_edges = edges) !== null && _edges !== void 0 ? _edges : [];
|
55
|
+
var _iterator2 = (0, _createForOfIteratorHelper2["default"])(snapshot.missingClientEdges),
|
56
|
+
_step2;
|
57
|
+
try {
|
58
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
59
|
+
var edge = _step2.value;
|
60
|
+
edges.push(edge);
|
61
|
+
}
|
62
|
+
} catch (err) {
|
63
|
+
_iterator2.e(err);
|
64
|
+
} finally {
|
65
|
+
_iterator2.f();
|
66
|
+
}
|
67
|
+
}
|
68
|
+
}
|
69
|
+
} catch (err) {
|
70
|
+
_iterator.e(err);
|
71
|
+
} finally {
|
72
|
+
_iterator.f();
|
73
|
+
}
|
74
|
+
return edges;
|
75
|
+
}
|
76
|
+
}
|
77
|
+
function handlePotentialSnapshotErrorsForState(environment, state) {
|
78
|
+
if (state.kind === 'singular') {
|
79
|
+
handlePotentialSnapshotErrors(environment, state.snapshot.missingRequiredFields, state.snapshot.relayResolverErrors);
|
80
|
+
} else if (state.kind === 'plural') {
|
81
|
+
var _iterator3 = (0, _createForOfIteratorHelper2["default"])(state.snapshots),
|
82
|
+
_step3;
|
83
|
+
try {
|
84
|
+
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
85
|
+
var snapshot = _step3.value;
|
86
|
+
handlePotentialSnapshotErrors(environment, snapshot.missingRequiredFields, snapshot.relayResolverErrors);
|
87
|
+
}
|
88
|
+
} catch (err) {
|
89
|
+
_iterator3.e(err);
|
90
|
+
} finally {
|
91
|
+
_iterator3.f();
|
92
|
+
}
|
93
|
+
}
|
94
|
+
}
|
95
|
+
function handleMissingClientEdge(environment, parentFragmentNode, parentFragmentRef, missingClientEdgeRequestInfo, queryOptions) {
|
96
|
+
var originalVariables = getVariablesFromFragment(parentFragmentNode, parentFragmentRef);
|
97
|
+
var variables = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, originalVariables), {}, {
|
98
|
+
id: missingClientEdgeRequestInfo.clientEdgeDestinationID // TODO should be a reserved name
|
99
|
+
});
|
100
|
+
|
101
|
+
var queryOperationDescriptor = createOperationDescriptor(missingClientEdgeRequestInfo.request, variables, queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.networkCacheConfig);
|
102
|
+
// This may suspend. We don't need to do anything with the results; all we're
|
103
|
+
// doing here is started the query if needed and retaining and releasing it
|
104
|
+
// according to the component mount/suspense cycle; QueryResource
|
105
|
+
// already handles this by itself.
|
106
|
+
var QueryResource = getQueryResourceForEnvironment(environment);
|
107
|
+
return QueryResource.prepare(queryOperationDescriptor, fetchQueryInternal(environment, queryOperationDescriptor), queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.fetchPolicy);
|
108
|
+
}
|
109
|
+
function getFragmentState(environment, fragmentSelector) {
|
110
|
+
if (fragmentSelector == null) {
|
111
|
+
return {
|
112
|
+
kind: 'bailout'
|
113
|
+
};
|
114
|
+
} else if (fragmentSelector.kind === 'PluralReaderSelector') {
|
115
|
+
if (fragmentSelector.selectors.length === 0) {
|
116
|
+
return {
|
117
|
+
kind: 'bailout'
|
118
|
+
};
|
119
|
+
} else {
|
120
|
+
return {
|
121
|
+
kind: 'plural',
|
122
|
+
snapshots: fragmentSelector.selectors.map(function (s) {
|
123
|
+
return environment.lookup(s);
|
124
|
+
}),
|
125
|
+
epoch: environment.getStore().getEpoch()
|
126
|
+
};
|
127
|
+
}
|
128
|
+
} else {
|
129
|
+
return {
|
130
|
+
kind: 'singular',
|
131
|
+
snapshot: environment.lookup(fragmentSelector),
|
132
|
+
epoch: environment.getStore().getEpoch()
|
133
|
+
};
|
134
|
+
}
|
135
|
+
}
|
136
|
+
|
137
|
+
// fragmentNode cannot change during the lifetime of the component, though fragmentRef may change.
|
138
|
+
function readFragmentInternal_REACT_CACHE(environment, fragmentNode, fragmentRef, hookDisplayName, queryOptions, fragmentKey) {
|
139
|
+
var _fragmentNode$metadat, _fragmentNode$metadat2;
|
140
|
+
var fragmentSelector = getSelector(fragmentNode, fragmentRef);
|
141
|
+
var isPlural = (fragmentNode === null || fragmentNode === void 0 ? void 0 : (_fragmentNode$metadat = fragmentNode.metadata) === null || _fragmentNode$metadat === void 0 ? void 0 : _fragmentNode$metadat.plural) === true;
|
142
|
+
if (isPlural) {
|
143
|
+
!(fragmentRef == null || Array.isArray(fragmentRef)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected fragment pointer%s for fragment `%s` to be ' + 'an array, instead got `%s`. Remove `@relay(plural: true)` ' + 'from fragment `%s` to allow the prop to be an object.', fragmentKey != null ? " for key `".concat(fragmentKey, "`") : '', fragmentNode.name, typeof fragmentRef, fragmentNode.name) : invariant(false) : void 0;
|
144
|
+
} else {
|
145
|
+
!!Array.isArray(fragmentRef) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected fragment pointer%s for fragment `%s` not to be ' + 'an array, instead got `%s`. Add `@relay(plural: true)` ' + 'to fragment `%s` to allow the prop to be an array.', fragmentKey != null ? " for key `".concat(fragmentKey, "`") : '', fragmentNode.name, typeof fragmentRef, fragmentNode.name) : invariant(false) : void 0;
|
146
|
+
}
|
147
|
+
!(fragmentRef == null || isPlural && Array.isArray(fragmentRef) && fragmentRef.length === 0 || fragmentSelector != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected to receive an object where `...%s` was spread, ' + 'but the fragment reference was not found`. This is most ' + 'likely the result of:\n' + "- Forgetting to spread `%s` in `%s`'s parent's fragment.\n" + '- Conditionally fetching `%s` but unconditionally passing %s prop ' + 'to `%s`. If the parent fragment only fetches the fragment conditionally ' + '- with e.g. `@include`, `@skip`, or inside a `... on SomeType { }` ' + 'spread - then the fragment reference will not exist. ' + 'In this case, pass `null` if the conditions for evaluating the ' + 'fragment are not met (e.g. if the `@include(if)` value is false.)', fragmentNode.name, fragmentNode.name, hookDisplayName, fragmentNode.name, fragmentKey == null ? 'a fragment reference' : "the `".concat(fragmentKey, "`"), hookDisplayName) : invariant(false) : void 0;
|
148
|
+
var state = getFragmentState(environment, fragmentSelector);
|
149
|
+
|
150
|
+
// Handle the queries for any missing client edges; this may suspend.
|
151
|
+
// FIXME handle client edges in parallel.
|
152
|
+
var clientEdgeQueries = null;
|
153
|
+
if (((_fragmentNode$metadat2 = fragmentNode.metadata) === null || _fragmentNode$metadat2 === void 0 ? void 0 : _fragmentNode$metadat2.hasClientEdges) === true) {
|
154
|
+
var missingClientEdges = getMissingClientEdges(state);
|
155
|
+
if (missingClientEdges !== null && missingClientEdges !== void 0 && missingClientEdges.length) {
|
156
|
+
clientEdgeQueries = [];
|
157
|
+
var _iterator4 = (0, _createForOfIteratorHelper2["default"])(missingClientEdges),
|
158
|
+
_step4;
|
159
|
+
try {
|
160
|
+
for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
|
161
|
+
var edge = _step4.value;
|
162
|
+
clientEdgeQueries.push(handleMissingClientEdge(environment, fragmentNode, fragmentRef, edge, queryOptions));
|
163
|
+
}
|
164
|
+
} catch (err) {
|
165
|
+
_iterator4.e(err);
|
166
|
+
} finally {
|
167
|
+
_iterator4.f();
|
168
|
+
}
|
169
|
+
}
|
170
|
+
}
|
171
|
+
if (isMissingData(state)) {
|
172
|
+
// Suspend if an active operation bears on this fragment, either the
|
173
|
+
// fragment's owner or some other mutation etc. that could affect it:
|
174
|
+
!(fragmentSelector != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'refinement, see invariants above') : invariant(false) : void 0;
|
175
|
+
var fragmentOwner = fragmentSelector.kind === 'PluralReaderSelector' ? fragmentSelector.selectors[0].owner : fragmentSelector.owner;
|
176
|
+
var pendingOperationsResult = getPendingOperationsForFragment(environment, fragmentNode, fragmentOwner);
|
177
|
+
if (pendingOperationsResult) {
|
178
|
+
throw pendingOperationsResult.promise;
|
179
|
+
}
|
180
|
+
// Report required fields only if we're not suspending, since that means
|
181
|
+
// they're missing even though we are out of options for possibly fetching them:
|
182
|
+
handlePotentialSnapshotErrorsForState(environment, state);
|
183
|
+
}
|
184
|
+
var data;
|
185
|
+
if (state.kind === 'bailout') {
|
186
|
+
data = isPlural ? [] : null;
|
187
|
+
} else if (state.kind === 'singular') {
|
188
|
+
data = state.snapshot.data;
|
189
|
+
} else {
|
190
|
+
data = state.snapshots.map(function (s) {
|
191
|
+
return s.data;
|
192
|
+
});
|
193
|
+
}
|
194
|
+
if (process.env.NODE_ENV !== "production") {
|
195
|
+
if (fragmentRef != null && (data === undefined || Array.isArray(data) && data.length > 0 && data.every(function (d) {
|
196
|
+
return d === undefined;
|
197
|
+
}))) {
|
198
|
+
process.env.NODE_ENV !== "production" ? warning(false, 'Relay: Expected to have been able to read non-null data for ' + 'fragment `%s` declared in ' + '`%s`, since fragment reference was non-null. ' + "Make sure that that `%s`'s parent isn't " + 'holding on to and/or passing a fragment reference for data that ' + 'has been deleted.', fragmentNode.name, hookDisplayName, hookDisplayName) : void 0;
|
199
|
+
}
|
200
|
+
}
|
201
|
+
return {
|
202
|
+
data: data,
|
203
|
+
clientEdgeQueries: clientEdgeQueries
|
204
|
+
};
|
205
|
+
}
|
206
|
+
module.exports = readFragmentInternal_REACT_CACHE;
|