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