react-relay 14.1.0 → 15.0.0

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