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.
Files changed (194) hide show
  1. package/ReactRelayContainerUtils.js.flow +1 -2
  2. package/ReactRelayContext.js +1 -1
  3. package/ReactRelayContext.js.flow +1 -2
  4. package/ReactRelayFragmentContainer.js.flow +6 -4
  5. package/ReactRelayFragmentMockRenderer.js.flow +1 -2
  6. package/ReactRelayLocalQueryRenderer.js.flow +5 -5
  7. package/ReactRelayPaginationContainer.js.flow +21 -14
  8. package/ReactRelayQueryFetcher.js.flow +28 -16
  9. package/ReactRelayQueryRenderer.js.flow +42 -13
  10. package/ReactRelayQueryRendererContext.js.flow +2 -3
  11. package/ReactRelayRefetchContainer.js.flow +9 -9
  12. package/ReactRelayTestMocker.js.flow +3 -3
  13. package/ReactRelayTypes.js.flow +7 -8
  14. package/RelayContext.js.flow +1 -2
  15. package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +4 -5
  16. package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +4 -5
  17. package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +4 -5
  18. package/__flowtests__/RelayModern-flowtest.js.flow +3 -4
  19. package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +3 -4
  20. package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +3 -4
  21. package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +3 -4
  22. package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +3 -4
  23. package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +3 -1
  24. package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +3 -1
  25. package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +4 -2
  26. package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +3 -1
  27. package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +4 -2
  28. package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +3 -1
  29. package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +4 -2
  30. package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +4 -2
  31. package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +3 -1
  32. package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +3 -1
  33. package/assertFragmentMap.js.flow +1 -2
  34. package/buildReactRelayContainer.js.flow +7 -7
  35. package/getRootVariablesForFragments.js.flow +1 -3
  36. package/hooks.js +1 -1
  37. package/hooks.js.flow +4 -2
  38. package/index.js +1 -1
  39. package/index.js.flow +6 -2
  40. package/isRelayEnvironment.js.flow +1 -2
  41. package/jest-react/enqueueTask.js.flow +1 -1
  42. package/jest-react/index.js.flow +1 -1
  43. package/jest-react/internalAct.js.flow +1 -1
  44. package/legacy.js +1 -1
  45. package/legacy.js.flow +1 -2
  46. package/lib/ReactRelayContainerUtils.js +2 -3
  47. package/lib/ReactRelayContext.js +3 -4
  48. package/lib/ReactRelayFragmentContainer.js +47 -73
  49. package/lib/ReactRelayFragmentMockRenderer.js +2 -4
  50. package/lib/ReactRelayLocalQueryRenderer.js +18 -31
  51. package/lib/ReactRelayPaginationContainer.js +74 -164
  52. package/lib/ReactRelayQueryFetcher.js +49 -76
  53. package/lib/ReactRelayQueryRenderer.js +63 -84
  54. package/lib/ReactRelayQueryRendererContext.js +2 -2
  55. package/lib/ReactRelayRefetchContainer.js +58 -108
  56. package/lib/ReactRelayTestMocker.js +33 -68
  57. package/lib/ReactRelayTypes.js +2 -1
  58. package/lib/RelayContext.js +4 -7
  59. package/lib/assertFragmentMap.js +3 -5
  60. package/lib/buildReactRelayContainer.js +11 -27
  61. package/lib/getRootVariablesForFragments.js +6 -10
  62. package/lib/hooks.js +5 -18
  63. package/lib/index.js +7 -24
  64. package/lib/isRelayEnvironment.js +5 -4
  65. package/lib/jest-react/enqueueTask.js +5 -9
  66. package/lib/jest-react/index.js +0 -1
  67. package/lib/jest-react/internalAct.js +9 -20
  68. package/lib/legacy.js +2 -8
  69. package/lib/multi-actor/ActorChange.js +2 -5
  70. package/lib/multi-actor/index.js +2 -1
  71. package/lib/multi-actor/useRelayActorEnvironment.js +4 -8
  72. package/lib/relay-hooks/EntryPointContainer.react.js +9 -15
  73. package/lib/relay-hooks/EntryPointTypes.flow.js +5 -3
  74. package/lib/relay-hooks/FragmentResource.js +109 -203
  75. package/lib/relay-hooks/HooksImplementation.js +3 -6
  76. package/lib/relay-hooks/InternalLogger.js +2 -3
  77. package/lib/relay-hooks/LRUCache.js +2 -20
  78. package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +33 -54
  79. package/lib/relay-hooks/MatchContainer.js +15 -24
  80. package/lib/relay-hooks/ProfilerContext.js +3 -3
  81. package/lib/relay-hooks/QueryResource.js +31 -101
  82. package/lib/relay-hooks/RelayEnvironmentProvider.js +5 -9
  83. package/lib/relay-hooks/SuspenseResource.js +9 -33
  84. package/lib/relay-hooks/loadEntryPoint.js +19 -31
  85. package/lib/relay-hooks/loadQuery.js +42 -78
  86. package/lib/relay-hooks/preloadQuery_DEPRECATED.js +11 -37
  87. package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +9 -15
  88. package/lib/relay-hooks/react-cache/RelayReactCache.js +7 -12
  89. package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +27 -81
  90. package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +206 -0
  91. package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +195 -215
  92. package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +5 -15
  93. package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +17 -24
  94. package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +149 -0
  95. package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +24 -39
  96. package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +325 -0
  97. package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +37 -0
  98. package/lib/relay-hooks/useBlockingPaginationFragment.js +73 -93
  99. package/lib/relay-hooks/useClientQuery.js +30 -0
  100. package/lib/relay-hooks/useEntryPointLoader.js +18 -38
  101. package/lib/relay-hooks/useFetchTrackingRef.js +10 -12
  102. package/lib/relay-hooks/useFragment.js +8 -19
  103. package/lib/relay-hooks/useFragmentNode.js +20 -32
  104. package/lib/relay-hooks/useIsMountedRef.js +4 -6
  105. package/lib/relay-hooks/useIsOperationNodeActive.js +8 -20
  106. package/lib/relay-hooks/useIsParentQueryActive.js +3 -6
  107. package/lib/relay-hooks/useLazyLoadQuery.js +7 -24
  108. package/lib/relay-hooks/useLazyLoadQueryNode.js +23 -34
  109. package/lib/relay-hooks/useLoadMoreFunction.js +46 -78
  110. package/lib/relay-hooks/useMemoOperationDescriptor.js +6 -15
  111. package/lib/relay-hooks/useMemoVariables.js +15 -34
  112. package/lib/relay-hooks/useMutation.js +9 -27
  113. package/lib/relay-hooks/usePaginationFragment.js +73 -76
  114. package/lib/relay-hooks/usePreloadedQuery.js +13 -44
  115. package/lib/relay-hooks/useQueryLoader.js +24 -49
  116. package/lib/relay-hooks/useRefetchableFragment.js +19 -17
  117. package/lib/relay-hooks/useRefetchableFragmentNode.js +65 -109
  118. package/lib/relay-hooks/useRelayEnvironment.js +4 -8
  119. package/lib/relay-hooks/useStaticFragmentNodeWarning.js +4 -8
  120. package/lib/relay-hooks/useSubscribeToInvalidationState.js +8 -9
  121. package/lib/relay-hooks/useSubscription.js +5 -10
  122. package/lib/relay-hooks/useUnsafeRef_DEPRECATED.js +29 -0
  123. package/multi-actor/ActorChange.js.flow +1 -1
  124. package/multi-actor/index.js.flow +1 -1
  125. package/multi-actor/useRelayActorEnvironment.js.flow +2 -4
  126. package/package.json +2 -2
  127. package/react-relay-hooks.js +2 -2
  128. package/react-relay-hooks.min.js +2 -2
  129. package/react-relay-legacy.js +2 -2
  130. package/react-relay-legacy.min.js +2 -2
  131. package/react-relay.js +2 -2
  132. package/react-relay.min.js +2 -2
  133. package/relay-hooks/EntryPointContainer.react.js.flow +3 -5
  134. package/relay-hooks/EntryPointTypes.flow.js.flow +37 -37
  135. package/relay-hooks/FragmentResource.js.flow +43 -19
  136. package/relay-hooks/HooksImplementation.js.flow +7 -9
  137. package/relay-hooks/InternalLogger.js.flow +1 -3
  138. package/relay-hooks/LRUCache.js.flow +1 -3
  139. package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +19 -14
  140. package/relay-hooks/MatchContainer.js.flow +6 -8
  141. package/relay-hooks/ProfilerContext.js.flow +1 -3
  142. package/relay-hooks/QueryResource.js.flow +29 -11
  143. package/relay-hooks/RelayEnvironmentProvider.js.flow +4 -6
  144. package/relay-hooks/SuspenseResource.js.flow +1 -3
  145. package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +6 -4
  146. package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +4 -4
  147. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +3 -1
  148. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +3 -1
  149. package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +39 -39
  150. package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +1 -3
  151. package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +37 -38
  152. package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +18 -20
  153. package/relay-hooks/__flowtests__/utils.js.flow +21 -12
  154. package/relay-hooks/loadEntryPoint.js.flow +11 -6
  155. package/relay-hooks/loadQuery.js.flow +11 -7
  156. package/relay-hooks/preloadQuery_DEPRECATED.js.flow +9 -12
  157. package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +13 -10
  158. package/relay-hooks/react-cache/RelayReactCache.js.flow +1 -3
  159. package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +26 -20
  160. package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +297 -0
  161. package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +136 -96
  162. package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +1 -3
  163. package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +3 -5
  164. package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +190 -0
  165. package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +3 -6
  166. package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +601 -0
  167. package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +65 -0
  168. package/relay-hooks/useBlockingPaginationFragment.js.flow +86 -59
  169. package/relay-hooks/useClientQuery.js.flow +39 -0
  170. package/relay-hooks/useEntryPointLoader.js.flow +16 -14
  171. package/relay-hooks/useFetchTrackingRef.js.flow +7 -8
  172. package/relay-hooks/useFragment.js.flow +2 -4
  173. package/relay-hooks/useFragmentNode.js.flow +7 -8
  174. package/relay-hooks/useIsMountedRef.js.flow +2 -4
  175. package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
  176. package/relay-hooks/useIsParentQueryActive.js.flow +1 -1
  177. package/relay-hooks/useLazyLoadQuery.js.flow +9 -32
  178. package/relay-hooks/useLazyLoadQueryNode.js.flow +4 -6
  179. package/relay-hooks/useLoadMoreFunction.js.flow +20 -17
  180. package/relay-hooks/useMemoOperationDescriptor.js.flow +3 -5
  181. package/relay-hooks/useMemoVariables.js.flow +13 -31
  182. package/relay-hooks/useMutation.js.flow +6 -8
  183. package/relay-hooks/usePaginationFragment.js.flow +75 -43
  184. package/relay-hooks/usePreloadedQuery.js.flow +49 -43
  185. package/relay-hooks/useQueryLoader.js.flow +89 -28
  186. package/relay-hooks/useRefetchableFragment.js.flow +83 -23
  187. package/relay-hooks/useRefetchableFragmentNode.js.flow +26 -22
  188. package/relay-hooks/useRelayEnvironment.js.flow +2 -4
  189. package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -5
  190. package/relay-hooks/useSubscribeToInvalidationState.js.flow +2 -4
  191. package/relay-hooks/useSubscription.js.flow +1 -3
  192. package/relay-hooks/useUnsafeRef_DEPRECATED.js.flow +25 -0
  193. package/lib/readContext.js +0 -28
  194. package/readContext.js.flow +0 -31
@@ -5,85 +5,68 @@
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
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
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 _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
21
-
22
18
  var LRUCache = require('./LRUCache');
23
-
24
19
  var _require = require('./QueryResource'),
25
- getQueryResourceForEnvironment = _require.getQueryResourceForEnvironment;
26
-
20
+ getQueryResourceForEnvironment = _require.getQueryResourceForEnvironment;
27
21
  var SuspenseResource = require('./SuspenseResource');
28
-
29
22
  var invariant = require('invariant');
30
-
31
23
  var _require2 = require('relay-runtime'),
32
- RelayFeatureFlags = _require2.RelayFeatureFlags,
33
- _require2$__internal = _require2.__internal,
34
- fetchQuery = _require2$__internal.fetchQuery,
35
- getPromiseForActiveRequest = _require2$__internal.getPromiseForActiveRequest,
36
- createOperationDescriptor = _require2.createOperationDescriptor,
37
- getFragmentIdentifier = _require2.getFragmentIdentifier,
38
- getPendingOperationsForFragment = _require2.getPendingOperationsForFragment,
39
- getSelector = _require2.getSelector,
40
- getVariablesFromFragment = _require2.getVariablesFromFragment,
41
- handlePotentialSnapshotErrors = _require2.handlePotentialSnapshotErrors,
42
- isPromise = _require2.isPromise,
43
- recycleNodesInto = _require2.recycleNodesInto;
44
-
24
+ _require2$__internal = _require2.__internal,
25
+ fetchQuery = _require2$__internal.fetchQuery,
26
+ getPromiseForActiveRequest = _require2$__internal.getPromiseForActiveRequest,
27
+ RelayFeatureFlags = _require2.RelayFeatureFlags,
28
+ createOperationDescriptor = _require2.createOperationDescriptor,
29
+ getFragmentIdentifier = _require2.getFragmentIdentifier,
30
+ getPendingOperationsForFragment = _require2.getPendingOperationsForFragment,
31
+ getSelector = _require2.getSelector,
32
+ getVariablesFromFragment = _require2.getVariablesFromFragment,
33
+ handlePotentialSnapshotErrors = _require2.handlePotentialSnapshotErrors,
34
+ isPromise = _require2.isPromise,
35
+ recycleNodesInto = _require2.recycleNodesInto;
45
36
  var WEAKMAP_SUPPORTED = typeof WeakMap === 'function';
46
37
  // TODO: Fix to not rely on LRU. If the number of active fragments exceeds this
47
38
  // capacity, readSpec() will fail to find cached entries and break object
48
39
  // identity even if data hasn't changed.
49
- var CACHE_CAPACITY = 1000000; // this is frozen so that users don't accidentally push data into the array
40
+ var CACHE_CAPACITY = 1000000;
50
41
 
42
+ // this is frozen so that users don't accidentally push data into the array
51
43
  var CONSTANT_READONLY_EMPTY_ARRAY = Object.freeze([]);
52
-
53
44
  function isMissingData(snapshot) {
54
45
  if (Array.isArray(snapshot)) {
55
46
  return snapshot.some(function (s) {
56
47
  return s.isMissingData;
57
48
  });
58
49
  }
59
-
60
50
  return snapshot.isMissingData;
61
51
  }
62
-
63
52
  function hasMissingClientEdges(snapshot) {
64
53
  var _snapshot$missingClie, _snapshot$missingClie2;
65
-
66
54
  if (Array.isArray(snapshot)) {
67
55
  return snapshot.some(function (s) {
68
56
  var _s$missingClientEdges, _s$missingClientEdges2;
69
-
70
57
  return ((_s$missingClientEdges = (_s$missingClientEdges2 = s.missingClientEdges) === null || _s$missingClientEdges2 === void 0 ? void 0 : _s$missingClientEdges2.length) !== null && _s$missingClientEdges !== void 0 ? _s$missingClientEdges : 0) > 0;
71
58
  });
72
59
  }
73
-
74
60
  return ((_snapshot$missingClie = (_snapshot$missingClie2 = snapshot.missingClientEdges) === null || _snapshot$missingClie2 === void 0 ? void 0 : _snapshot$missingClie2.length) !== null && _snapshot$missingClie !== void 0 ? _snapshot$missingClie : 0) > 0;
75
61
  }
76
-
77
62
  function missingLiveResolverFields(snapshot) {
78
63
  if (Array.isArray(snapshot)) {
79
64
  return snapshot.map(function (s) {
80
65
  return s.missingLiveResolverFields;
81
66
  }).filter(Boolean).flat();
82
67
  }
83
-
84
68
  return snapshot.missingLiveResolverFields;
85
69
  }
86
-
87
70
  function singularOrPluralForEach(snapshot, f) {
88
71
  if (Array.isArray(snapshot)) {
89
72
  snapshot.forEach(f);
@@ -91,7 +74,6 @@ function singularOrPluralForEach(snapshot, f) {
91
74
  f(snapshot);
92
75
  }
93
76
  }
94
-
95
77
  function getFragmentResult(cacheKey, snapshot, storeEpoch) {
96
78
  if (Array.isArray(snapshot)) {
97
79
  return {
@@ -104,7 +86,6 @@ function getFragmentResult(cacheKey, snapshot, storeEpoch) {
104
86
  storeEpoch: storeEpoch
105
87
  };
106
88
  }
107
-
108
89
  return {
109
90
  cacheKey: cacheKey,
110
91
  snapshot: snapshot,
@@ -113,119 +94,95 @@ function getFragmentResult(cacheKey, snapshot, storeEpoch) {
113
94
  storeEpoch: storeEpoch
114
95
  };
115
96
  }
97
+
116
98
  /**
117
99
  * The purpose of this cache is to allow information to be passed from an
118
100
  * initial read which suspends through to the commit that follows a subsequent
119
101
  * successful read. Specifically, the QueryResource result for the data fetch
120
102
  * is passed through so that that query can be retained on commit.
121
103
  */
122
-
123
-
124
104
  var ClientEdgeQueryResultsCache = /*#__PURE__*/function () {
125
105
  function ClientEdgeQueryResultsCache(environment) {
126
106
  (0, _defineProperty2["default"])(this, "_cache", new Map());
127
107
  (0, _defineProperty2["default"])(this, "_retainCounts", new Map());
128
108
  this._environment = environment;
129
109
  }
130
-
131
110
  var _proto = ClientEdgeQueryResultsCache.prototype;
132
-
133
111
  _proto.get = function get(fragmentIdentifier) {
134
112
  var _this$_cache$get$, _this$_cache$get;
135
-
136
113
  return (_this$_cache$get$ = (_this$_cache$get = this._cache.get(fragmentIdentifier)) === null || _this$_cache$get === void 0 ? void 0 : _this$_cache$get[0]) !== null && _this$_cache$get$ !== void 0 ? _this$_cache$get$ : undefined;
137
114
  };
138
-
139
- _proto.recordQueryResults = function recordQueryResults(fragmentIdentifier, value) {
115
+ _proto.recordQueryResults = function recordQueryResults(fragmentIdentifier, value // may be mutated after being passed here
116
+ ) {
140
117
  var _this = this;
141
-
142
118
  var existing = this._cache.get(fragmentIdentifier);
143
-
144
119
  if (!existing) {
145
120
  var suspenseResource = new SuspenseResource(function () {
146
121
  return _this._retain(fragmentIdentifier);
147
122
  });
148
-
149
123
  this._cache.set(fragmentIdentifier, [value, suspenseResource]);
150
-
151
124
  suspenseResource.temporaryRetain(this._environment);
152
125
  } else {
153
126
  var existingResults = existing[0],
154
- _suspenseResource = existing[1];
127
+ _suspenseResource = existing[1];
155
128
  value.forEach(function (queryResult) {
156
129
  existingResults.push(queryResult);
157
130
  });
158
-
159
131
  _suspenseResource.temporaryRetain(this._environment);
160
132
  }
161
133
  };
162
-
163
134
  _proto._retain = function _retain(id) {
164
135
  var _this2 = this;
165
-
166
136
  var _this$_retainCounts$g;
167
-
168
137
  var retainCount = ((_this$_retainCounts$g = this._retainCounts.get(id)) !== null && _this$_retainCounts$g !== void 0 ? _this$_retainCounts$g : 0) + 1;
169
-
170
138
  this._retainCounts.set(id, retainCount);
171
-
172
139
  return {
173
140
  dispose: function dispose() {
174
141
  var _this$_retainCounts$g2;
175
-
176
142
  var newRetainCount = ((_this$_retainCounts$g2 = _this2._retainCounts.get(id)) !== null && _this$_retainCounts$g2 !== void 0 ? _this$_retainCounts$g2 : 0) - 1;
177
-
178
143
  if (newRetainCount > 0) {
179
144
  _this2._retainCounts.set(id, newRetainCount);
180
145
  } else {
181
146
  _this2._retainCounts["delete"](id);
182
-
183
147
  _this2._cache["delete"](id);
184
148
  }
185
149
  }
186
150
  };
187
151
  };
188
-
189
152
  return ClientEdgeQueryResultsCache;
190
153
  }();
191
-
192
154
  var FragmentResourceImpl = /*#__PURE__*/function () {
193
155
  function FragmentResourceImpl(environment) {
194
156
  this._environment = environment;
195
157
  this._cache = LRUCache.create(CACHE_CAPACITY);
196
-
197
158
  if (RelayFeatureFlags.ENABLE_CLIENT_EDGES) {
198
159
  this._clientEdgeQueryResultsCache = new ClientEdgeQueryResultsCache(environment);
199
160
  }
200
161
  }
162
+
201
163
  /**
202
164
  * This function should be called during a Component's render function,
203
165
  * to read the data for a fragment, or suspend if the fragment is being
204
166
  * fetched.
205
167
  */
206
-
207
-
208
168
  var _proto2 = FragmentResourceImpl.prototype;
209
-
210
169
  _proto2.read = function read(fragmentNode, fragmentRef, componentDisplayName, fragmentKey) {
211
170
  return this.readWithIdentifier(fragmentNode, fragmentRef, getFragmentIdentifier(fragmentNode, fragmentRef), componentDisplayName, fragmentKey);
212
171
  }
172
+
213
173
  /**
214
174
  * Like `read`, but with a pre-computed fragmentIdentifier that should be
215
175
  * equal to `getFragmentIdentifier(fragmentNode, fragmentRef)` from the
216
176
  * arguments.
217
- */
218
- ;
219
-
177
+ */;
220
178
  _proto2.readWithIdentifier = function readWithIdentifier(fragmentNode, fragmentRef, fragmentIdentifier, componentDisplayName, fragmentKey) {
221
179
  var _this3 = this;
222
-
223
180
  var _fragmentNode$metadat, _fragmentNode$metadat2, _missingLiveResolverF2, _missingLiveResolverF3;
181
+ var environment = this._environment;
224
182
 
225
- var environment = this._environment; // If fragmentRef is null or undefined, pass it directly through.
183
+ // If fragmentRef is null or undefined, pass it directly through.
226
184
  // This is a convenience when consuming fragments via a HOC API, when the
227
185
  // prop corresponding to the fragment ref might be passed as null.
228
-
229
186
  if (fragmentRef == null) {
230
187
  return {
231
188
  cacheKey: fragmentIdentifier,
@@ -235,13 +192,12 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
235
192
  storeEpoch: 0
236
193
  };
237
194
  }
195
+ var storeEpoch = environment.getStore().getEpoch();
238
196
 
239
- var storeEpoch = environment.getStore().getEpoch(); // If fragmentRef is plural, ensure that it is an array.
197
+ // If fragmentRef is plural, ensure that it is an array.
240
198
  // If it's empty, return the empty array directly before doing any more work.
241
-
242
199
  if ((fragmentNode === null || fragmentNode === void 0 ? void 0 : (_fragmentNode$metadat = fragmentNode.metadata) === null || _fragmentNode$metadat === void 0 ? void 0 : _fragmentNode$metadat.plural) === true) {
243
200
  !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;
244
-
245
201
  if (fragmentRef.length === 0) {
246
202
  return {
247
203
  cacheKey: fragmentIdentifier,
@@ -251,15 +207,14 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
251
207
  storeEpoch: storeEpoch
252
208
  };
253
209
  }
254
- } // Now we actually attempt to read the fragment:
255
- // 1. Check if there's a cached value for this fragment
210
+ }
256
211
 
212
+ // Now we actually attempt to read the fragment:
257
213
 
214
+ // 1. Check if there's a cached value for this fragment
258
215
  var cachedValue = this._cache.get(fragmentIdentifier);
259
-
260
216
  if (cachedValue != null) {
261
217
  var _missingLiveResolverF;
262
-
263
218
  if (cachedValue.kind === 'pending' && isPromise(cachedValue.promise)) {
264
219
  environment.__log({
265
220
  name: 'suspense.fragment',
@@ -270,36 +225,47 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
270
225
  isPromiseCached: true,
271
226
  pendingOperations: cachedValue.pendingOperations
272
227
  });
273
-
274
228
  throw cachedValue.promise;
275
229
  }
276
-
277
- if (cachedValue.kind === 'done' && cachedValue.result.snapshot && !((_missingLiveResolverF = missingLiveResolverFields(cachedValue.result.snapshot)) === null || _missingLiveResolverF === void 0 ? void 0 : _missingLiveResolverF.length)) {
278
- this._handlePotentialSnapshotErrorsInSnapshot(cachedValue.result.snapshot);
279
-
230
+ if (cachedValue.kind === 'done' && cachedValue.result.snapshot && !((_missingLiveResolverF = missingLiveResolverFields(cachedValue.result.snapshot)) !== null && _missingLiveResolverF !== void 0 && _missingLiveResolverF.length)) {
231
+ this._throwOrLogErrorsInSnapshot(
232
+ // $FlowFixMe[incompatible-call]
233
+ cachedValue.result.snapshot);
234
+
235
+ // This cache gets populated directly whenever the store notifies us of
236
+ // an update. That mechanism does not check for missing data, or
237
+ // in-flight requests.
238
+ if (cachedValue.result.isMissingData) {
239
+ environment.__log({
240
+ name: 'fragmentresource.missing_data',
241
+ data: cachedValue.result.data,
242
+ fragment: fragmentNode,
243
+ isRelayHooks: true,
244
+ cached: true
245
+ });
246
+ }
280
247
  return cachedValue.result;
281
248
  }
282
- } // 2. If not, try reading the fragment from the Relay store.
283
- // If the snapshot has data, return it and save it in cache
284
-
249
+ }
285
250
 
251
+ // 2. If not, try reading the fragment from the Relay store.
252
+ // If the snapshot has data, return it and save it in cache
286
253
  var fragmentSelector = getSelector(fragmentNode, fragmentRef);
287
254
  !(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, componentDisplayName, fragmentNode.name, fragmentKey == null ? 'a fragment reference' : "the `".concat(fragmentKey, "`"), componentDisplayName) : invariant(false) : void 0;
288
255
  var snapshot = fragmentSelector.kind === 'PluralReaderSelector' ? fragmentSelector.selectors.map(function (s) {
289
256
  return environment.lookup(s);
290
257
  }) : environment.lookup(fragmentSelector);
291
258
  var fragmentResult = getFragmentResult(fragmentIdentifier, snapshot, storeEpoch);
292
-
293
259
  if (!fragmentResult.isMissingData) {
294
- this._handlePotentialSnapshotErrorsInSnapshot(snapshot);
295
-
260
+ this._throwOrLogErrorsInSnapshot(snapshot);
296
261
  this._cache.set(fragmentIdentifier, {
297
262
  kind: 'done',
298
263
  result: fragmentResult
299
264
  });
300
-
301
265
  return fragmentResult;
302
- } // 3. If we don't have data in the store, there's two cases where we should
266
+ }
267
+
268
+ // 3. If we don't have data in the store, there's two cases where we should
303
269
  // suspend to await the data: First if any client edges were traversed where
304
270
  // the destination record was missing data; in that case we initiate a query
305
271
  // here to fetch the missing data. Second, there may already be a request
@@ -307,64 +273,51 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
307
273
  // may affect the parent's query data, such as a mutation or subscription.
308
274
  // For any of these cases we can get a promise, which we will cache and
309
275
  // suspend on.
310
- // First, initiate a query for any client edges that were missing data:
311
-
312
276
 
277
+ // First, initiate a query for any client edges that were missing data:
313
278
  var clientEdgeRequests = null;
314
-
315
279
  if (RelayFeatureFlags.ENABLE_CLIENT_EDGES && ((_fragmentNode$metadat2 = fragmentNode.metadata) === null || _fragmentNode$metadat2 === void 0 ? void 0 : _fragmentNode$metadat2.hasClientEdges) === true && hasMissingClientEdges(snapshot)) {
316
280
  clientEdgeRequests = [];
317
281
  var queryResource = getQueryResourceForEnvironment(this._environment);
318
282
  var queryResults = [];
319
283
  singularOrPluralForEach(snapshot, function (snap) {
320
284
  var _snap$missingClientEd;
321
-
322
285
  (_snap$missingClientEd = snap.missingClientEdges) === null || _snap$missingClientEd === void 0 ? void 0 : _snap$missingClientEd.forEach(function (_ref) {
323
286
  var _clientEdgeRequests;
324
-
325
287
  var request = _ref.request,
326
- clientEdgeDestinationID = _ref.clientEdgeDestinationID;
327
-
288
+ clientEdgeDestinationID = _ref.clientEdgeDestinationID;
328
289
  var _this3$_performClient = _this3._performClientEdgeQuery(queryResource, fragmentNode, fragmentRef, request, clientEdgeDestinationID),
329
- queryResult = _this3$_performClient.queryResult,
330
- requestDescriptor = _this3$_performClient.requestDescriptor;
331
-
290
+ queryResult = _this3$_performClient.queryResult,
291
+ requestDescriptor = _this3$_performClient.requestDescriptor;
332
292
  queryResults.push(queryResult);
333
293
  (_clientEdgeRequests = clientEdgeRequests) === null || _clientEdgeRequests === void 0 ? void 0 : _clientEdgeRequests.push(requestDescriptor);
334
294
  });
335
- }); // Store the query so that it can be retained when our own fragment is
295
+ });
296
+ // Store the query so that it can be retained when our own fragment is
336
297
  // subscribed to. This merges with any existing query results:
337
-
338
298
  !(this._clientEdgeQueryResultsCache != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Client edge query result cache should exist when ENABLE_CLIENT_EDGES is on.') : invariant(false) : void 0;
339
-
340
299
  this._clientEdgeQueryResultsCache.recordQueryResults(fragmentIdentifier, queryResults);
341
300
  }
342
-
343
301
  var clientEdgePromises = [];
344
-
345
302
  if (RelayFeatureFlags.ENABLE_CLIENT_EDGES && clientEdgeRequests) {
346
303
  clientEdgePromises = clientEdgeRequests.map(function (request) {
347
304
  return getPromiseForActiveRequest(_this3._environment, request);
348
305
  }).filter(Boolean);
349
- } // Finally look for operations in flight for our parent query:
350
-
306
+ }
351
307
 
308
+ // Finally look for operations in flight for our parent query:
352
309
  var fragmentOwner = fragmentSelector.kind === 'PluralReaderSelector' ? fragmentSelector.selectors[0].owner : fragmentSelector.owner;
353
-
354
310
  var parentQueryPromiseResult = this._getAndSavePromiseForFragmentRequestInFlight(fragmentIdentifier, fragmentNode, fragmentOwner, fragmentResult);
355
-
356
311
  var parentQueryPromiseResultPromise = parentQueryPromiseResult === null || parentQueryPromiseResult === void 0 ? void 0 : parentQueryPromiseResult.promise; // for refinement
357
-
358
312
  var missingResolverFieldPromises = (_missingLiveResolverF2 = (_missingLiveResolverF3 = missingLiveResolverFields(snapshot)) === null || _missingLiveResolverF3 === void 0 ? void 0 : _missingLiveResolverF3.map(function (_ref2) {
359
313
  var liveStateID = _ref2.liveStateID;
360
- var store = environment.getStore(); // $FlowFixMe[prop-missing] This is expected to be a LiveResolverStore
314
+ var store = environment.getStore();
361
315
 
316
+ // $FlowFixMe[prop-missing] This is expected to be a LiveResolverStore
362
317
  return store.getLiveResolverPromise(liveStateID);
363
318
  })) !== null && _missingLiveResolverF2 !== void 0 ? _missingLiveResolverF2 : [];
364
-
365
319
  if (clientEdgePromises.length || missingResolverFieldPromises.length || isPromise(parentQueryPromiseResultPromise)) {
366
320
  var _parentQueryPromiseRe, _clientEdgeRequests2;
367
-
368
321
  environment.__log({
369
322
  name: 'suspense.fragment',
370
323
  data: fragmentResult.data,
@@ -375,58 +328,63 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
375
328
  // TODO! Attach information here about missing live resolver fields
376
329
  pendingOperations: [].concat((0, _toConsumableArray2["default"])((_parentQueryPromiseRe = parentQueryPromiseResult === null || parentQueryPromiseResult === void 0 ? void 0 : parentQueryPromiseResult.pendingOperations) !== null && _parentQueryPromiseRe !== void 0 ? _parentQueryPromiseRe : []), (0, _toConsumableArray2["default"])((_clientEdgeRequests2 = clientEdgeRequests) !== null && _clientEdgeRequests2 !== void 0 ? _clientEdgeRequests2 : []))
377
330
  });
378
-
379
331
  var promises = [];
380
-
381
332
  if (clientEdgePromises.length > 0) {
382
333
  promises = promises.concat(clientEdgePromises);
383
334
  }
384
-
385
335
  if (missingResolverFieldPromises.length > 0) {
386
336
  promises = promises.concat(missingResolverFieldPromises);
387
337
  }
388
-
389
338
  if (promises.length > 0) {
390
339
  if (parentQueryPromiseResultPromise) {
391
340
  promises.push(parentQueryPromiseResultPromise);
392
341
  }
393
-
394
342
  throw Promise.all(promises);
395
- } // Note: we are re-throwing the `parentQueryPromiseResultPromise` here,
343
+ }
344
+
345
+ // Note: we are re-throwing the `parentQueryPromiseResultPromise` here,
396
346
  // because some of our suspense-related code is relying on the instance equality
397
347
  // of thrown promises. See FragmentResource-test.js
398
-
399
-
400
348
  if (parentQueryPromiseResultPromise) {
401
349
  throw parentQueryPromiseResultPromise;
402
350
  }
403
351
  }
404
-
405
- this._handlePotentialSnapshotErrorsInSnapshot(snapshot);
406
-
352
+ this._throwOrLogErrorsInSnapshot(snapshot);
353
+
354
+ // At this point, there's nothing we can do. We don't have all the expected
355
+ // data, but there's no indication the missing data will be fulfilled. So we
356
+ // choose to return potentially non-typesafe data. The data returned here
357
+ // might not match the generated types for this fragment/operation.
358
+ environment.__log({
359
+ name: 'fragmentresource.missing_data',
360
+ data: fragmentResult.data,
361
+ fragment: fragmentNode,
362
+ isRelayHooks: true,
363
+ cached: false
364
+ });
407
365
  return getFragmentResult(fragmentIdentifier, snapshot, storeEpoch);
408
366
  };
409
-
410
367
  _proto2._performClientEdgeQuery = function _performClientEdgeQuery(queryResource, fragmentNode, fragmentRef, request, clientEdgeDestinationID) {
411
368
  var originalVariables = getVariablesFromFragment(fragmentNode, fragmentRef);
412
369
  var variables = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, originalVariables), {}, {
413
370
  id: clientEdgeDestinationID // TODO should be a reserved name
414
-
415
371
  });
372
+
416
373
  var operation = createOperationDescriptor(request, variables, {} // TODO cacheConfig should probably inherent from parent operation
417
374
  );
375
+
418
376
  var fetchObservable = fetchQuery(this._environment, operation);
419
- var queryResult = queryResource.prepare(operation, fetchObservable // TODO should inherent render policy etc. from parent operation
377
+ var queryResult = queryResource.prepare(operation, fetchObservable
378
+ // TODO should inherent render policy etc. from parent operation
420
379
  );
380
+
421
381
  return {
422
382
  requestDescriptor: operation.request,
423
383
  queryResult: queryResult
424
384
  };
425
385
  };
426
-
427
- _proto2._handlePotentialSnapshotErrorsInSnapshot = function _handlePotentialSnapshotErrorsInSnapshot(snapshot) {
386
+ _proto2._throwOrLogErrorsInSnapshot = function _throwOrLogErrorsInSnapshot(snapshot) {
428
387
  var _this4 = this;
429
-
430
388
  if (Array.isArray(snapshot)) {
431
389
  snapshot.forEach(function (s) {
432
390
  handlePotentialSnapshotErrors(_this4._environment, s.missingRequiredFields, s.relayResolverErrors);
@@ -435,53 +393,44 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
435
393
  handlePotentialSnapshotErrors(this._environment, snapshot.missingRequiredFields, snapshot.relayResolverErrors);
436
394
  }
437
395
  };
438
-
439
396
  _proto2.readSpec = function readSpec(fragmentNodes, fragmentRefs, componentDisplayName) {
440
397
  var result = {};
441
-
442
- for (var _key in fragmentNodes) {
443
- result[_key] = this.read(fragmentNodes[_key], fragmentRefs[_key], componentDisplayName, _key);
398
+ for (var key in fragmentNodes) {
399
+ result[key] = this.read(fragmentNodes[key], fragmentRefs[key], componentDisplayName, key);
444
400
  }
445
-
446
401
  return result;
447
402
  };
448
-
449
403
  _proto2.subscribe = function subscribe(fragmentResult, callback) {
450
404
  var _this5 = this;
451
-
452
405
  var environment = this._environment;
453
406
  var cacheKey = fragmentResult.cacheKey;
454
407
  var renderedSnapshot = fragmentResult.snapshot;
455
-
456
408
  if (!renderedSnapshot) {
457
409
  return {
458
410
  dispose: function dispose() {}
459
411
  };
460
- } // 1. Check for any updates missed during render phase
461
- // TODO(T44066760): More efficiently detect if we missed an update
462
-
412
+ }
463
413
 
414
+ // 1. Check for any updates missed during render phase
415
+ // TODO(T44066760): More efficiently detect if we missed an update
464
416
  var _this$checkMissedUpda = this.checkMissedUpdates(fragmentResult),
465
- didMissUpdates = _this$checkMissedUpda[0],
466
- currentSnapshot = _this$checkMissedUpda[1]; // 2. If an update was missed, notify the component so it updates with
467
- // the latest data.
468
-
417
+ didMissUpdates = _this$checkMissedUpda[0],
418
+ currentSnapshot = _this$checkMissedUpda[1];
469
419
 
420
+ // 2. If an update was missed, notify the component so it updates with
421
+ // the latest data.
470
422
  if (didMissUpdates) {
471
423
  callback();
472
- } // 3. Establish subscriptions on the snapshot(s)
473
-
424
+ }
474
425
 
426
+ // 3. Establish subscriptions on the snapshot(s)
475
427
  var disposables = [];
476
-
477
428
  if (Array.isArray(renderedSnapshot)) {
478
429
  !Array.isArray(currentSnapshot) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected snapshots to be plural. ' + "If you're seeing this, this is likely a bug in Relay.") : invariant(false) : void 0;
479
430
  currentSnapshot.forEach(function (snapshot, idx) {
480
431
  disposables.push(environment.subscribe(snapshot, function (latestSnapshot) {
481
432
  var storeEpoch = environment.getStore().getEpoch();
482
-
483
433
  _this5._updatePluralSnapshot(cacheKey, currentSnapshot, latestSnapshot, idx, storeEpoch);
484
-
485
434
  callback();
486
435
  }));
487
436
  });
@@ -489,43 +438,34 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
489
438
  !(currentSnapshot != null && !Array.isArray(currentSnapshot)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected snapshot to be singular. ' + "If you're seeing this, this is likely a bug in Relay.") : invariant(false) : void 0;
490
439
  disposables.push(environment.subscribe(currentSnapshot, function (latestSnapshot) {
491
440
  var storeEpoch = environment.getStore().getEpoch();
492
-
493
441
  _this5._cache.set(cacheKey, {
494
442
  kind: 'done',
495
443
  result: getFragmentResult(cacheKey, latestSnapshot, storeEpoch)
496
444
  });
497
-
498
445
  callback();
499
446
  }));
500
447
  }
501
-
502
448
  if (RelayFeatureFlags.ENABLE_CLIENT_EDGES) {
503
449
  var _this$_clientEdgeQuer, _this$_clientEdgeQuer2;
504
-
505
450
  var clientEdgeQueryResults = (_this$_clientEdgeQuer = (_this$_clientEdgeQuer2 = this._clientEdgeQueryResultsCache) === null || _this$_clientEdgeQuer2 === void 0 ? void 0 : _this$_clientEdgeQuer2.get(cacheKey)) !== null && _this$_clientEdgeQuer !== void 0 ? _this$_clientEdgeQuer : undefined;
506
-
507
- if (clientEdgeQueryResults === null || clientEdgeQueryResults === void 0 ? void 0 : clientEdgeQueryResults.length) {
451
+ if (clientEdgeQueryResults !== null && clientEdgeQueryResults !== void 0 && clientEdgeQueryResults.length) {
508
452
  var queryResource = getQueryResourceForEnvironment(this._environment);
509
453
  clientEdgeQueryResults.forEach(function (queryResult) {
510
454
  disposables.push(queryResource.retain(queryResult));
511
455
  });
512
456
  }
513
457
  }
514
-
515
458
  return {
516
459
  dispose: function dispose() {
517
460
  disposables.forEach(function (s) {
518
461
  return s.dispose();
519
462
  });
520
-
521
463
  _this5._cache["delete"](cacheKey);
522
464
  }
523
465
  };
524
466
  };
525
-
526
467
  _proto2.subscribeSpec = function subscribeSpec(fragmentResults, callback) {
527
468
  var _this6 = this;
528
-
529
469
  var disposables = Object.keys(fragmentResults).map(function (key) {
530
470
  return _this6.subscribe(fragmentResults[key], callback);
531
471
  });
@@ -537,25 +477,19 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
537
477
  }
538
478
  };
539
479
  };
540
-
541
480
  _proto2.checkMissedUpdates = function checkMissedUpdates(fragmentResult) {
542
481
  var environment = this._environment;
543
482
  var renderedSnapshot = fragmentResult.snapshot;
544
-
545
483
  if (!renderedSnapshot) {
546
484
  return [false, null];
547
485
  }
548
-
549
- var storeEpoch = null; // Bail out if the store hasn't been written since last read
550
-
486
+ var storeEpoch = null;
487
+ // Bail out if the store hasn't been written since last read
551
488
  storeEpoch = environment.getStore().getEpoch();
552
-
553
489
  if (fragmentResult.storeEpoch === storeEpoch) {
554
490
  return [false, fragmentResult.snapshot];
555
491
  }
556
-
557
492
  var cacheKey = fragmentResult.cacheKey;
558
-
559
493
  if (Array.isArray(renderedSnapshot)) {
560
494
  var didMissUpdates = false;
561
495
  var currentSnapshots = [];
@@ -564,28 +498,24 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
564
498
  var renderData = snapshot.data;
565
499
  var currentData = currentSnapshot.data;
566
500
  var updatedData = recycleNodesInto(renderData, currentData);
567
-
568
501
  if (updatedData !== renderData) {
569
502
  currentSnapshot = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, currentSnapshot), {}, {
570
503
  data: updatedData
571
504
  });
572
505
  didMissUpdates = true;
573
506
  }
574
-
575
507
  currentSnapshots[idx] = currentSnapshot;
576
- }); // Only update the cache when the data is changed to avoid
508
+ });
509
+ // Only update the cache when the data is changed to avoid
577
510
  // returning different `data` instances
578
-
579
511
  if (didMissUpdates) {
580
512
  this._cache.set(cacheKey, {
581
513
  kind: 'done',
582
514
  result: getFragmentResult(cacheKey, currentSnapshots, storeEpoch)
583
515
  });
584
516
  }
585
-
586
517
  return [didMissUpdates, currentSnapshots];
587
518
  }
588
-
589
519
  var currentSnapshot = environment.lookup(renderedSnapshot.selector);
590
520
  var renderData = renderedSnapshot.data;
591
521
  var currentData = currentSnapshot.data;
@@ -600,111 +530,87 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
600
530
  missingRequiredFields: currentSnapshot.missingRequiredFields,
601
531
  relayResolverErrors: currentSnapshot.relayResolverErrors
602
532
  };
603
-
604
533
  if (updatedData !== renderData) {
605
534
  this._cache.set(cacheKey, {
606
535
  kind: 'done',
607
536
  result: getFragmentResult(cacheKey, updatedCurrentSnapshot, storeEpoch)
608
537
  });
609
538
  }
610
-
611
539
  return [updatedData !== renderData, updatedCurrentSnapshot];
612
540
  };
613
-
614
541
  _proto2.checkMissedUpdatesSpec = function checkMissedUpdatesSpec(fragmentResults) {
615
542
  var _this7 = this;
616
-
617
543
  return Object.keys(fragmentResults).some(function (key) {
618
544
  return _this7.checkMissedUpdates(fragmentResults[key])[0];
619
545
  });
620
546
  };
621
-
622
547
  _proto2._getAndSavePromiseForFragmentRequestInFlight = function _getAndSavePromiseForFragmentRequestInFlight(cacheKey, fragmentNode, fragmentOwner, fragmentResult) {
623
548
  var _this8 = this;
624
-
625
549
  var pendingOperationsResult = getPendingOperationsForFragment(this._environment, fragmentNode, fragmentOwner);
626
-
627
550
  if (pendingOperationsResult == null) {
628
551
  return null;
629
- } // When the Promise for the request resolves, we need to make sure to
552
+ }
553
+
554
+ // When the Promise for the request resolves, we need to make sure to
630
555
  // update the cache with the latest data available in the store before
631
556
  // resolving the Promise
632
-
633
-
634
557
  var networkPromise = pendingOperationsResult.promise;
635
558
  var pendingOperations = pendingOperationsResult.pendingOperations;
636
559
  var promise = networkPromise.then(function () {
637
560
  _this8._cache["delete"](cacheKey);
638
561
  })["catch"](function (error) {
639
562
  _this8._cache["delete"](cacheKey);
640
- }); // $FlowExpectedError[prop-missing] Expando to annotate Promises.
641
-
563
+ });
564
+ // $FlowExpectedError[prop-missing] Expando to annotate Promises.
642
565
  promise.displayName = networkPromise.displayName;
643
-
644
566
  this._cache.set(cacheKey, {
645
567
  kind: 'pending',
646
568
  pendingOperations: pendingOperations,
647
569
  promise: promise,
648
570
  result: fragmentResult
649
571
  });
650
-
651
572
  return {
652
573
  promise: promise,
653
574
  pendingOperations: pendingOperations
654
575
  };
655
576
  };
656
-
657
577
  _proto2._updatePluralSnapshot = function _updatePluralSnapshot(cacheKey, baseSnapshots, latestSnapshot, idx, storeEpoch) {
658
578
  var _currentFragmentResul;
659
-
660
579
  var currentFragmentResult = this._cache.get(cacheKey);
661
-
662
580
  if (isPromise(currentFragmentResult)) {
663
581
  reportInvalidCachedData(latestSnapshot.selector.node.name);
664
582
  return;
665
583
  }
666
-
667
584
  var currentSnapshot = currentFragmentResult === null || currentFragmentResult === void 0 ? void 0 : (_currentFragmentResul = currentFragmentResult.result) === null || _currentFragmentResul === void 0 ? void 0 : _currentFragmentResul.snapshot;
668
-
669
585
  if (currentSnapshot && !Array.isArray(currentSnapshot)) {
670
586
  reportInvalidCachedData(latestSnapshot.selector.node.name);
671
587
  return;
672
588
  }
673
-
674
589
  var nextSnapshots = currentSnapshot ? (0, _toConsumableArray2["default"])(currentSnapshot) : (0, _toConsumableArray2["default"])(baseSnapshots);
675
590
  nextSnapshots[idx] = latestSnapshot;
676
-
677
591
  this._cache.set(cacheKey, {
678
592
  kind: 'done',
679
593
  result: getFragmentResult(cacheKey, nextSnapshots, storeEpoch)
680
594
  });
681
595
  };
682
-
683
596
  return FragmentResourceImpl;
684
597
  }();
685
-
686
598
  function reportInvalidCachedData(nodeName) {
687
599
  !false ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected to find cached data for plural fragment `%s` when ' + 'receiving a subscription. ' + "If you're seeing this, this is likely a bug in Relay.", nodeName) : invariant(false) : void 0;
688
600
  }
689
-
690
601
  function createFragmentResource(environment) {
691
602
  return new FragmentResourceImpl(environment);
692
603
  }
693
-
694
604
  var dataResources = WEAKMAP_SUPPORTED ? new WeakMap() : new Map();
695
-
696
605
  function getFragmentResourceForEnvironment(environment) {
697
606
  var cached = dataResources.get(environment);
698
-
699
607
  if (cached) {
700
608
  return cached;
701
609
  }
702
-
703
610
  var newDataResource = createFragmentResource(environment);
704
611
  dataResources.set(environment, newDataResource);
705
612
  return newDataResource;
706
613
  }
707
-
708
614
  module.exports = {
709
615
  createFragmentResource: createFragmentResource,
710
616
  getFragmentResourceForEnvironment: getFragmentResourceForEnvironment