react-relay 14.1.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 -0
  2. package/ReactRelayContext.js +1 -1
  3. package/ReactRelayContext.js.flow +1 -0
  4. package/ReactRelayFragmentContainer.js.flow +6 -2
  5. package/ReactRelayFragmentMockRenderer.js.flow +1 -0
  6. package/ReactRelayLocalQueryRenderer.js.flow +5 -3
  7. package/ReactRelayPaginationContainer.js.flow +21 -12
  8. package/ReactRelayQueryFetcher.js.flow +19 -5
  9. package/ReactRelayQueryRenderer.js.flow +32 -1
  10. package/ReactRelayQueryRendererContext.js.flow +1 -0
  11. package/ReactRelayRefetchContainer.js.flow +9 -5
  12. package/ReactRelayTestMocker.js.flow +3 -1
  13. package/ReactRelayTypes.js.flow +1 -0
  14. package/RelayContext.js.flow +1 -0
  15. package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +2 -1
  16. package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +1 -0
  17. package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +1 -0
  18. package/__flowtests__/RelayModern-flowtest.js.flow +1 -0
  19. package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +1 -0
  20. package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +1 -0
  21. package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +1 -0
  22. package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +1 -0
  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 -0
  34. package/buildReactRelayContainer.js.flow +7 -5
  35. package/getRootVariablesForFragments.js.flow +1 -1
  36. package/hooks.js +1 -1
  37. package/hooks.js.flow +4 -0
  38. package/index.js +1 -1
  39. package/index.js.flow +4 -0
  40. package/isRelayEnvironment.js.flow +1 -0
  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 -0
  46. package/lib/ReactRelayContainerUtils.js +2 -2
  47. package/lib/ReactRelayContext.js +3 -3
  48. package/lib/ReactRelayFragmentContainer.js +39 -66
  49. package/lib/ReactRelayFragmentMockRenderer.js +2 -3
  50. package/lib/ReactRelayLocalQueryRenderer.js +18 -30
  51. package/lib/ReactRelayPaginationContainer.js +66 -159
  52. package/lib/ReactRelayQueryFetcher.js +48 -74
  53. package/lib/ReactRelayQueryRenderer.js +62 -82
  54. package/lib/ReactRelayQueryRendererContext.js +2 -1
  55. package/lib/ReactRelayRefetchContainer.js +52 -99
  56. package/lib/ReactRelayTestMocker.js +32 -66
  57. package/lib/ReactRelayTypes.js +2 -0
  58. package/lib/RelayContext.js +4 -6
  59. package/lib/assertFragmentMap.js +3 -4
  60. package/lib/buildReactRelayContainer.js +10 -25
  61. package/lib/getRootVariablesForFragments.js +5 -8
  62. package/lib/hooks.js +5 -17
  63. package/lib/index.js +5 -24
  64. package/lib/isRelayEnvironment.js +5 -3
  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 -7
  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 -7
  72. package/lib/relay-hooks/EntryPointContainer.react.js +9 -14
  73. package/lib/relay-hooks/EntryPointTypes.flow.js +5 -2
  74. package/lib/relay-hooks/FragmentResource.js +102 -196
  75. package/lib/relay-hooks/HooksImplementation.js +2 -5
  76. package/lib/relay-hooks/InternalLogger.js +2 -2
  77. package/lib/relay-hooks/LRUCache.js +2 -19
  78. package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +33 -53
  79. package/lib/relay-hooks/MatchContainer.js +14 -22
  80. package/lib/relay-hooks/ProfilerContext.js +3 -2
  81. package/lib/relay-hooks/QueryResource.js +30 -99
  82. package/lib/relay-hooks/RelayEnvironmentProvider.js +5 -8
  83. package/lib/relay-hooks/SuspenseResource.js +8 -31
  84. package/lib/relay-hooks/loadEntryPoint.js +19 -31
  85. package/lib/relay-hooks/loadQuery.js +41 -77
  86. package/lib/relay-hooks/preloadQuery_DEPRECATED.js +10 -35
  87. package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +9 -14
  88. package/lib/relay-hooks/react-cache/RelayReactCache.js +7 -11
  89. package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +24 -78
  90. package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +23 -56
  91. package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +65 -143
  92. package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +5 -14
  93. package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +17 -23
  94. package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +73 -74
  95. package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +24 -38
  96. package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +60 -102
  97. package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +7 -15
  98. package/lib/relay-hooks/useBlockingPaginationFragment.js +71 -92
  99. package/lib/relay-hooks/useClientQuery.js +3 -6
  100. package/lib/relay-hooks/useEntryPointLoader.js +17 -36
  101. package/lib/relay-hooks/useFetchTrackingRef.js +10 -11
  102. package/lib/relay-hooks/useFragment.js +8 -18
  103. package/lib/relay-hooks/useFragmentNode.js +20 -31
  104. package/lib/relay-hooks/useIsMountedRef.js +4 -5
  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 +6 -9
  108. package/lib/relay-hooks/useLazyLoadQueryNode.js +23 -33
  109. package/lib/relay-hooks/useLoadMoreFunction.js +45 -76
  110. package/lib/relay-hooks/useMemoOperationDescriptor.js +6 -14
  111. package/lib/relay-hooks/useMemoVariables.js +15 -33
  112. package/lib/relay-hooks/useMutation.js +8 -25
  113. package/lib/relay-hooks/usePaginationFragment.js +61 -76
  114. package/lib/relay-hooks/usePreloadedQuery.js +12 -29
  115. package/lib/relay-hooks/useQueryLoader.js +23 -47
  116. package/lib/relay-hooks/useRefetchableFragment.js +8 -18
  117. package/lib/relay-hooks/useRefetchableFragmentNode.js +64 -107
  118. package/lib/relay-hooks/useRelayEnvironment.js +4 -7
  119. package/lib/relay-hooks/useStaticFragmentNodeWarning.js +4 -7
  120. package/lib/relay-hooks/useSubscribeToInvalidationState.js +8 -8
  121. package/lib/relay-hooks/useSubscription.js +5 -9
  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 -2
  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 +1 -1
  134. package/relay-hooks/EntryPointTypes.flow.js.flow +7 -5
  135. package/relay-hooks/FragmentResource.js.flow +34 -8
  136. package/relay-hooks/HooksImplementation.js.flow +1 -1
  137. package/relay-hooks/InternalLogger.js.flow +1 -1
  138. package/relay-hooks/LRUCache.js.flow +1 -1
  139. package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +15 -8
  140. package/relay-hooks/MatchContainer.js.flow +1 -1
  141. package/relay-hooks/ProfilerContext.js.flow +1 -1
  142. package/relay-hooks/QueryResource.js.flow +25 -5
  143. package/relay-hooks/RelayEnvironmentProvider.js.flow +2 -2
  144. package/relay-hooks/SuspenseResource.js.flow +1 -1
  145. package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +3 -1
  146. package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +2 -2
  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 +35 -33
  150. package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +1 -1
  151. package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +33 -32
  152. package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +18 -18
  153. package/relay-hooks/__flowtests__/utils.js.flow +13 -2
  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 +5 -6
  157. package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +13 -8
  158. package/relay-hooks/react-cache/RelayReactCache.js.flow +1 -1
  159. package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +4 -4
  160. package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +3 -3
  161. package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +4 -4
  162. package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +1 -1
  163. package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +1 -1
  164. package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +41 -22
  165. package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +1 -2
  166. package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +11 -5
  167. package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +2 -2
  168. package/relay-hooks/useBlockingPaginationFragment.js.flow +85 -56
  169. package/relay-hooks/useClientQuery.js.flow +1 -1
  170. package/relay-hooks/useEntryPointLoader.js.flow +10 -6
  171. package/relay-hooks/useFetchTrackingRef.js.flow +5 -4
  172. package/relay-hooks/useFragment.js.flow +2 -2
  173. package/relay-hooks/useFragmentNode.js.flow +5 -4
  174. package/relay-hooks/useIsMountedRef.js.flow +1 -1
  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 +2 -2
  178. package/relay-hooks/useLazyLoadQueryNode.js.flow +2 -2
  179. package/relay-hooks/useLoadMoreFunction.js.flow +14 -9
  180. package/relay-hooks/useMemoOperationDescriptor.js.flow +3 -3
  181. package/relay-hooks/useMemoVariables.js.flow +13 -29
  182. package/relay-hooks/useMutation.js.flow +4 -4
  183. package/relay-hooks/usePaginationFragment.js.flow +53 -46
  184. package/relay-hooks/usePreloadedQuery.js.flow +47 -22
  185. package/relay-hooks/useQueryLoader.js.flow +85 -22
  186. package/relay-hooks/useRefetchableFragment.js.flow +64 -33
  187. package/relay-hooks/useRefetchableFragmentNode.js.flow +10 -4
  188. package/relay-hooks/useRelayEnvironment.js.flow +2 -2
  189. package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -3
  190. package/relay-hooks/useSubscribeToInvalidationState.js.flow +2 -2
  191. package/relay-hooks/useSubscription.js.flow +1 -1
  192. package/relay-hooks/useUnsafeRef_DEPRECATED.js.flow +25 -0
  193. package/lib/readContext.js +0 -27
  194. package/readContext.js.flow +0 -29
@@ -5,84 +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
+
11
12
  'use strict';
12
13
 
13
14
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
14
-
15
15
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
16
-
17
16
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
18
-
19
17
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
20
-
21
18
  var LRUCache = require('./LRUCache');
22
-
23
19
  var _require = require('./QueryResource'),
24
- getQueryResourceForEnvironment = _require.getQueryResourceForEnvironment;
25
-
20
+ getQueryResourceForEnvironment = _require.getQueryResourceForEnvironment;
26
21
  var SuspenseResource = require('./SuspenseResource');
27
-
28
22
  var invariant = require('invariant');
29
-
30
23
  var _require2 = require('relay-runtime'),
31
- RelayFeatureFlags = _require2.RelayFeatureFlags,
32
- _require2$__internal = _require2.__internal,
33
- fetchQuery = _require2$__internal.fetchQuery,
34
- getPromiseForActiveRequest = _require2$__internal.getPromiseForActiveRequest,
35
- createOperationDescriptor = _require2.createOperationDescriptor,
36
- getFragmentIdentifier = _require2.getFragmentIdentifier,
37
- getPendingOperationsForFragment = _require2.getPendingOperationsForFragment,
38
- getSelector = _require2.getSelector,
39
- getVariablesFromFragment = _require2.getVariablesFromFragment,
40
- handlePotentialSnapshotErrors = _require2.handlePotentialSnapshotErrors,
41
- isPromise = _require2.isPromise,
42
- recycleNodesInto = _require2.recycleNodesInto;
43
-
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;
44
36
  var WEAKMAP_SUPPORTED = typeof WeakMap === 'function';
45
37
  // TODO: Fix to not rely on LRU. If the number of active fragments exceeds this
46
38
  // capacity, readSpec() will fail to find cached entries and break object
47
39
  // identity even if data hasn't changed.
48
- var CACHE_CAPACITY = 1000000; // this is frozen so that users don't accidentally push data into the array
40
+ var CACHE_CAPACITY = 1000000;
49
41
 
42
+ // this is frozen so that users don't accidentally push data into the array
50
43
  var CONSTANT_READONLY_EMPTY_ARRAY = Object.freeze([]);
51
-
52
44
  function isMissingData(snapshot) {
53
45
  if (Array.isArray(snapshot)) {
54
46
  return snapshot.some(function (s) {
55
47
  return s.isMissingData;
56
48
  });
57
49
  }
58
-
59
50
  return snapshot.isMissingData;
60
51
  }
61
-
62
52
  function hasMissingClientEdges(snapshot) {
63
53
  var _snapshot$missingClie, _snapshot$missingClie2;
64
-
65
54
  if (Array.isArray(snapshot)) {
66
55
  return snapshot.some(function (s) {
67
56
  var _s$missingClientEdges, _s$missingClientEdges2;
68
-
69
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;
70
58
  });
71
59
  }
72
-
73
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;
74
61
  }
75
-
76
62
  function missingLiveResolverFields(snapshot) {
77
63
  if (Array.isArray(snapshot)) {
78
64
  return snapshot.map(function (s) {
79
65
  return s.missingLiveResolverFields;
80
66
  }).filter(Boolean).flat();
81
67
  }
82
-
83
68
  return snapshot.missingLiveResolverFields;
84
69
  }
85
-
86
70
  function singularOrPluralForEach(snapshot, f) {
87
71
  if (Array.isArray(snapshot)) {
88
72
  snapshot.forEach(f);
@@ -90,7 +74,6 @@ function singularOrPluralForEach(snapshot, f) {
90
74
  f(snapshot);
91
75
  }
92
76
  }
93
-
94
77
  function getFragmentResult(cacheKey, snapshot, storeEpoch) {
95
78
  if (Array.isArray(snapshot)) {
96
79
  return {
@@ -103,7 +86,6 @@ function getFragmentResult(cacheKey, snapshot, storeEpoch) {
103
86
  storeEpoch: storeEpoch
104
87
  };
105
88
  }
106
-
107
89
  return {
108
90
  cacheKey: cacheKey,
109
91
  snapshot: snapshot,
@@ -112,120 +94,95 @@ function getFragmentResult(cacheKey, snapshot, storeEpoch) {
112
94
  storeEpoch: storeEpoch
113
95
  };
114
96
  }
97
+
115
98
  /**
116
99
  * The purpose of this cache is to allow information to be passed from an
117
100
  * initial read which suspends through to the commit that follows a subsequent
118
101
  * successful read. Specifically, the QueryResource result for the data fetch
119
102
  * is passed through so that that query can be retained on commit.
120
103
  */
121
-
122
-
123
104
  var ClientEdgeQueryResultsCache = /*#__PURE__*/function () {
124
105
  function ClientEdgeQueryResultsCache(environment) {
125
106
  (0, _defineProperty2["default"])(this, "_cache", new Map());
126
107
  (0, _defineProperty2["default"])(this, "_retainCounts", new Map());
127
108
  this._environment = environment;
128
109
  }
129
-
130
110
  var _proto = ClientEdgeQueryResultsCache.prototype;
131
-
132
111
  _proto.get = function get(fragmentIdentifier) {
133
112
  var _this$_cache$get$, _this$_cache$get;
134
-
135
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;
136
114
  };
137
-
138
115
  _proto.recordQueryResults = function recordQueryResults(fragmentIdentifier, value // may be mutated after being passed here
139
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
230
  if (cachedValue.kind === 'done' && cachedValue.result.snapshot && !((_missingLiveResolverF = missingLiveResolverFields(cachedValue.result.snapshot)) !== null && _missingLiveResolverF !== void 0 && _missingLiveResolverF.length)) {
278
- this._handlePotentialSnapshotErrorsInSnapshot(cachedValue.result.snapshot);
279
-
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
398
  for (var key in fragmentNodes) {
443
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,21 +438,16 @@ 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
451
  if (clientEdgeQueryResults !== null && clientEdgeQueryResults !== void 0 && clientEdgeQueryResults.length) {
508
452
  var queryResource = getQueryResourceForEnvironment(this._environment);
509
453
  clientEdgeQueryResults.forEach(function (queryResult) {
@@ -511,21 +455,17 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
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