react-relay 14.1.0 → 16.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (196) 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 +20 -10
  9. package/ReactRelayQueryRenderer.js.flow +15 -11
  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 +2 -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 +10 -6
  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 +0 -11
  47. package/lib/ReactRelayContext.js +1 -12
  48. package/lib/ReactRelayFragmentContainer.js +23 -122
  49. package/lib/ReactRelayFragmentMockRenderer.js +0 -12
  50. package/lib/ReactRelayLocalQueryRenderer.js +12 -41
  51. package/lib/ReactRelayPaginationContainer.js +45 -341
  52. package/lib/ReactRelayQueryFetcher.js +36 -111
  53. package/lib/ReactRelayQueryRenderer.js +29 -137
  54. package/lib/ReactRelayQueryRendererContext.js +0 -10
  55. package/lib/ReactRelayRefetchContainer.js +33 -166
  56. package/lib/ReactRelayTestMocker.js +18 -128
  57. package/lib/ReactRelayTypes.js +0 -9
  58. package/lib/RelayContext.js +0 -23
  59. package/lib/assertFragmentMap.js +0 -16
  60. package/lib/buildReactRelayContainer.js +7 -41
  61. package/lib/getRootVariablesForFragments.js +2 -19
  62. package/lib/hooks.js +3 -30
  63. package/lib/index.js +3 -39
  64. package/lib/isRelayEnvironment.js +1 -16
  65. package/lib/jest-react/enqueueTask.js +1 -25
  66. package/lib/jest-react/index.js +0 -1
  67. package/lib/jest-react/internalAct.js +2 -51
  68. package/lib/legacy.js +0 -20
  69. package/lib/multi-actor/ActorChange.js +0 -14
  70. package/lib/multi-actor/index.js +0 -10
  71. package/lib/multi-actor/useRelayActorEnvironment.js +2 -16
  72. package/lib/relay-hooks/EntryPointContainer.react.js +7 -23
  73. package/lib/relay-hooks/EntryPointTypes.flow.js +0 -10
  74. package/lib/relay-hooks/FragmentResource.js +130 -280
  75. package/lib/relay-hooks/HooksImplementation.js +0 -14
  76. package/lib/relay-hooks/InternalLogger.js +0 -11
  77. package/lib/relay-hooks/LRUCache.js +0 -39
  78. package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +27 -65
  79. package/lib/relay-hooks/MatchContainer.js +9 -111
  80. package/lib/relay-hooks/NestedRelayEntryPointBuilderUtils.js +9 -0
  81. package/lib/relay-hooks/ProfilerContext.js +0 -14
  82. package/lib/relay-hooks/QueryResource.js +14 -149
  83. package/lib/relay-hooks/RelayEnvironmentProvider.js +3 -17
  84. package/lib/relay-hooks/SuspenseResource.js +2 -59
  85. package/lib/relay-hooks/loadEntryPoint.js +10 -45
  86. package/lib/relay-hooks/loadQuery.js +29 -169
  87. package/lib/relay-hooks/preloadQuery_DEPRECATED.js +8 -58
  88. package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +6 -24
  89. package/lib/relay-hooks/react-cache/RelayReactCache.js +4 -20
  90. package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +13 -102
  91. package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +18 -75
  92. package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +79 -222
  93. package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +3 -27
  94. package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +11 -33
  95. package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +62 -85
  96. package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +20 -63
  97. package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +53 -179
  98. package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +5 -27
  99. package/lib/relay-hooks/useBlockingPaginationFragment.js +58 -121
  100. package/lib/relay-hooks/useClientQuery.js +0 -21
  101. package/lib/relay-hooks/useEntryPointLoader.js +12 -100
  102. package/lib/relay-hooks/useFetchTrackingRef.js +6 -33
  103. package/lib/relay-hooks/useFragment.js +5 -32
  104. package/lib/relay-hooks/useFragmentNode.js +14 -55
  105. package/lib/relay-hooks/useIsMountedRef.js +2 -14
  106. package/lib/relay-hooks/useIsOperationNodeActive.js +6 -29
  107. package/lib/relay-hooks/useIsParentQueryActive.js +1 -15
  108. package/lib/relay-hooks/useLazyLoadQuery.js +2 -23
  109. package/lib/relay-hooks/useLazyLoadQueryNode.js +18 -63
  110. package/lib/relay-hooks/useLoadMoreFunction.js +44 -100
  111. package/lib/relay-hooks/useMemoOperationDescriptor.js +4 -23
  112. package/lib/relay-hooks/useMemoVariables.js +8 -43
  113. package/lib/relay-hooks/useMutation.js +6 -34
  114. package/lib/relay-hooks/usePaginationFragment.js +49 -89
  115. package/lib/relay-hooks/usePreloadedQuery.js +10 -54
  116. package/lib/relay-hooks/useQueryLoader.js +18 -116
  117. package/lib/relay-hooks/useRefetchableFragment.js +4 -30
  118. package/lib/relay-hooks/useRefetchableFragmentNode.js +58 -184
  119. package/lib/relay-hooks/useRelayEnvironment.js +2 -16
  120. package/lib/relay-hooks/useStaticFragmentNodeWarning.js +2 -20
  121. package/lib/relay-hooks/useSubscribeToInvalidationState.js +3 -28
  122. package/lib/relay-hooks/useSubscription.js +3 -22
  123. package/lib/relay-hooks/useUnsafeRef_DEPRECATED.js +12 -0
  124. package/multi-actor/ActorChange.js.flow +1 -1
  125. package/multi-actor/index.js.flow +1 -1
  126. package/multi-actor/useRelayActorEnvironment.js.flow +2 -2
  127. package/package.json +2 -2
  128. package/react-relay-hooks.js +2 -2
  129. package/react-relay-hooks.min.js +2 -2
  130. package/react-relay-legacy.js +2 -2
  131. package/react-relay-legacy.min.js +2 -2
  132. package/react-relay.js +2 -2
  133. package/react-relay.min.js +2 -2
  134. package/relay-hooks/EntryPointContainer.react.js.flow +6 -1
  135. package/relay-hooks/EntryPointTypes.flow.js.flow +23 -20
  136. package/relay-hooks/FragmentResource.js.flow +148 -34
  137. package/relay-hooks/HooksImplementation.js.flow +1 -1
  138. package/relay-hooks/InternalLogger.js.flow +1 -1
  139. package/relay-hooks/LRUCache.js.flow +1 -1
  140. package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +19 -10
  141. package/relay-hooks/MatchContainer.js.flow +1 -1
  142. package/relay-hooks/NestedRelayEntryPointBuilderUtils.js.flow +51 -0
  143. package/relay-hooks/ProfilerContext.js.flow +1 -1
  144. package/relay-hooks/QueryResource.js.flow +25 -5
  145. package/relay-hooks/RelayEnvironmentProvider.js.flow +2 -2
  146. package/relay-hooks/SuspenseResource.js.flow +1 -1
  147. package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +3 -1
  148. package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +9 -7
  149. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +3 -1
  150. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +3 -1
  151. package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +40 -33
  152. package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +1 -1
  153. package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +38 -32
  154. package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +20 -18
  155. package/relay-hooks/__flowtests__/utils.js.flow +13 -2
  156. package/relay-hooks/loadEntryPoint.js.flow +15 -8
  157. package/relay-hooks/loadQuery.js.flow +32 -8
  158. package/relay-hooks/preloadQuery_DEPRECATED.js.flow +5 -6
  159. package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +17 -10
  160. package/relay-hooks/react-cache/RelayReactCache.js.flow +1 -1
  161. package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +4 -4
  162. package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +5 -4
  163. package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +32 -14
  164. package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +4 -10
  165. package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +1 -1
  166. package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +39 -49
  167. package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +1 -2
  168. package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +29 -16
  169. package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +17 -33
  170. package/relay-hooks/useBlockingPaginationFragment.js.flow +85 -58
  171. package/relay-hooks/useClientQuery.js.flow +3 -3
  172. package/relay-hooks/useEntryPointLoader.js.flow +10 -6
  173. package/relay-hooks/useFetchTrackingRef.js.flow +5 -4
  174. package/relay-hooks/useFragment.js.flow +2 -2
  175. package/relay-hooks/useFragmentNode.js.flow +7 -6
  176. package/relay-hooks/useIsMountedRef.js.flow +1 -1
  177. package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
  178. package/relay-hooks/useIsParentQueryActive.js.flow +1 -1
  179. package/relay-hooks/useLazyLoadQuery.js.flow +2 -2
  180. package/relay-hooks/useLazyLoadQueryNode.js.flow +2 -2
  181. package/relay-hooks/useLoadMoreFunction.js.flow +27 -16
  182. package/relay-hooks/useMemoOperationDescriptor.js.flow +3 -3
  183. package/relay-hooks/useMemoVariables.js.flow +13 -29
  184. package/relay-hooks/useMutation.js.flow +30 -13
  185. package/relay-hooks/usePaginationFragment.js.flow +55 -54
  186. package/relay-hooks/usePreloadedQuery.js.flow +47 -22
  187. package/relay-hooks/useQueryLoader.js.flow +78 -21
  188. package/relay-hooks/useRefetchableFragment.js.flow +65 -33
  189. package/relay-hooks/useRefetchableFragmentNode.js.flow +38 -17
  190. package/relay-hooks/useRelayEnvironment.js.flow +2 -2
  191. package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -3
  192. package/relay-hooks/useSubscribeToInvalidationState.js.flow +2 -2
  193. package/relay-hooks/useSubscription.js.flow +1 -1
  194. package/relay-hooks/useUnsafeRef_DEPRECATED.js.flow +25 -0
  195. package/lib/readContext.js +0 -27
  196. package/readContext.js.flow +0 -29
@@ -1,56 +1,38 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- * @emails oncall+relay
8
- *
9
- * @format
10
- */
11
1
  'use strict';
12
2
 
13
3
  var preloadQuery = require('./preloadQuery_DEPRECATED');
14
-
15
4
  function prepareEntryPoint(environmentProvider, entryPoint, entryPointParams) {
16
- // Start loading the code for the entrypoint
17
5
  if (entryPoint.root.getModuleIfRequired() == null) {
18
6
  entryPoint.root.load();
19
7
  }
20
-
21
8
  var preloadProps = entryPoint.getPreloadProps(entryPointParams);
22
9
  var queries = preloadProps.queries,
23
- entryPoints = preloadProps.entryPoints;
10
+ entryPoints = preloadProps.entryPoints;
24
11
  var preloadedQueries = {};
25
12
  var preloadedEntryPoints = {};
26
-
27
13
  if (queries != null) {
28
14
  var queriesPropNames = Object.keys(queries);
29
15
  queriesPropNames.forEach(function (queryPropName) {
30
16
  var _queries$queryPropNam = queries[queryPropName],
31
- environmentProviderOptions = _queries$queryPropNam.environmentProviderOptions,
32
- options = _queries$queryPropNam.options,
33
- parameters = _queries$queryPropNam.parameters,
34
- variables = _queries$queryPropNam.variables;
17
+ environmentProviderOptions = _queries$queryPropNam.environmentProviderOptions,
18
+ options = _queries$queryPropNam.options,
19
+ parameters = _queries$queryPropNam.parameters,
20
+ variables = _queries$queryPropNam.variables;
35
21
  var environment = environmentProvider.getEnvironment(environmentProviderOptions);
36
22
  preloadedQueries[queryPropName] = preloadQuery(environment, parameters, variables, options, environmentProviderOptions);
37
23
  });
38
24
  }
39
-
40
25
  if (entryPoints != null) {
41
26
  var entryPointPropNames = Object.keys(entryPoints);
42
27
  entryPointPropNames.forEach(function (entryPointPropName) {
43
28
  var entryPointDescription = entryPoints[entryPointPropName];
44
-
45
29
  if (entryPointDescription == null) {
46
30
  return;
47
31
  }
48
-
49
32
  var nestedEntryPoint = entryPointDescription.entryPoint,
50
- nestedParams = entryPointDescription.entryPointParams;
33
+ nestedParams = entryPointDescription.entryPointParams;
51
34
  preloadedEntryPoints[entryPointPropName] = prepareEntryPoint(environmentProvider, nestedEntryPoint, nestedParams);
52
35
  });
53
36
  }
54
37
  }
55
-
56
38
  module.exports = prepareEntryPoint;
@@ -1,35 +1,19 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- *
8
- * @emails oncall+relay
9
- * @format
10
- */
11
1
  'use strict';
12
2
 
13
- var invariant = require('invariant'); // $FlowFixMe[prop-missing] These exist in experimental builds but aren't in React's types yet.
14
-
15
-
3
+ var invariant = require('invariant');
16
4
  var _require = require('react'),
17
- unstable_getCacheForType = _require.unstable_getCacheForType,
18
- unstable_getCacheSignal = _require.unstable_getCacheSignal;
19
-
5
+ unstable_getCacheForType = _require.unstable_getCacheForType,
6
+ unstable_getCacheSignal = _require.unstable_getCacheSignal;
20
7
  var _require2 = require('relay-runtime'),
21
- RelayFeatureFlags = _require2.RelayFeatureFlags;
22
-
8
+ RelayFeatureFlags = _require2.RelayFeatureFlags;
23
9
  function getCacheForType(factory) {
24
10
  !(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
11
  return unstable_getCacheForType(factory);
26
12
  }
27
-
28
13
  function getCacheSignal() {
29
14
  !(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
15
  return unstable_getCacheSignal();
31
16
  }
32
-
33
17
  module.exports = {
34
18
  getCacheForType: getCacheForType,
35
19
  getCacheSignal: getCacheSignal
@@ -1,102 +1,64 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- *
8
- * @emails oncall+relay
9
- * @format
10
- */
11
1
  'use strict';
12
2
 
13
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
14
-
15
4
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
16
-
17
5
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
18
-
19
6
  var SuspenseResource = require('../SuspenseResource');
20
-
21
7
  var _require = require('./RelayReactCache'),
22
- getCacheForType = _require.getCacheForType,
23
- getCacheSignal = _require.getCacheSignal;
24
-
8
+ getCacheForType = _require.getCacheForType,
9
+ getCacheSignal = _require.getCacheSignal;
25
10
  var invariant = require('invariant');
26
-
27
11
  var _require2 = require('relay-runtime'),
28
- RelayFeatureFlags = _require2.RelayFeatureFlags,
29
- fetchQueryInternal = _require2.__internal.fetchQuery;
30
-
12
+ fetchQueryInternal = _require2.__internal.fetchQuery,
13
+ RelayFeatureFlags = _require2.RelayFeatureFlags;
31
14
  var warning = require("fbjs/lib/warning");
32
-
33
15
  var DEFAULT_FETCH_POLICY = 'store-or-network';
34
16
  var WEAKMAP_SUPPORTED = typeof WeakMap === 'function';
35
-
36
17
  var QueryCache = /*#__PURE__*/function () {
37
18
  function QueryCache() {
38
19
  this._map = WEAKMAP_SUPPORTED ? new WeakMap() : new Map();
39
20
  }
40
-
41
21
  var _proto = QueryCache.prototype;
42
-
43
22
  _proto.get = function get(environment, key) {
44
23
  var forEnv = this._map.get(environment);
45
-
46
24
  if (!forEnv) {
47
25
  forEnv = new Map();
48
-
49
26
  this._map.set(environment, forEnv);
50
27
  }
51
-
52
28
  return forEnv.get(key);
53
29
  };
54
-
55
30
  _proto.set = function set(environment, key, value) {
56
31
  var forEnv = this._map.get(environment);
57
-
58
32
  if (!forEnv) {
59
33
  forEnv = new Map();
60
-
61
34
  this._map.set(environment, forEnv);
62
35
  }
63
-
64
36
  forEnv.set(key, value);
65
37
  };
66
-
67
38
  _proto["delete"] = function _delete(environment, key) {
68
39
  var forEnv = this._map.get(environment);
69
-
70
40
  if (!forEnv) {
71
41
  return;
72
42
  }
73
-
74
43
  forEnv["delete"](key);
75
-
76
44
  if (forEnv.size === 0) {
77
45
  this._map["delete"](environment);
78
46
  }
79
47
  };
80
-
81
48
  return QueryCache;
82
49
  }();
83
-
84
50
  function createQueryCache() {
85
51
  return new QueryCache();
86
52
  }
87
-
88
53
  var noopOnCommit = function noopOnCommit() {
89
54
  return function () {
90
55
  return undefined;
91
56
  };
92
57
  };
93
-
94
58
  var noopPromise = new Promise(function () {});
95
-
96
59
  function getQueryCacheKey(operation, fetchPolicy, renderPolicy, fetchKey) {
97
60
  return "".concat(fetchPolicy, "-").concat(renderPolicy, "-").concat(operation.request.identifier, "-").concat(fetchKey !== null && fetchKey !== void 0 ? fetchKey : '');
98
61
  }
99
-
100
62
  function constructQueryResult(operation) {
101
63
  var rootFragmentRef = {
102
64
  __id: operation.fragment.dataID,
@@ -108,7 +70,6 @@ function constructQueryResult(operation) {
108
70
  fragmentRef: rootFragmentRef
109
71
  };
110
72
  }
111
-
112
73
  function makeInitialCacheEntry() {
113
74
  return {
114
75
  status: 'pending',
@@ -117,35 +78,24 @@ function makeInitialCacheEntry() {
117
78
  suspenseResource: null
118
79
  };
119
80
  }
120
-
121
81
  function getQueryResultOrFetchQuery_REACT_CACHE(environment, queryOperationDescriptor, options) {
122
82
  var _options$fetchPolicy, _options$renderPolicy;
123
-
124
83
  var fetchPolicy = (_options$fetchPolicy = options === null || options === void 0 ? void 0 : options.fetchPolicy) !== null && _options$fetchPolicy !== void 0 ? _options$fetchPolicy : DEFAULT_FETCH_POLICY;
125
84
  var renderPolicy = (_options$renderPolicy = options === null || options === void 0 ? void 0 : options.renderPolicy) !== null && _options$renderPolicy !== void 0 ? _options$renderPolicy : environment.UNSTABLE_getDefaultRenderPolicy();
126
85
  var cache = getCacheForType(createQueryCache);
127
86
  var cacheKey = getQueryCacheKey(queryOperationDescriptor, fetchPolicy, renderPolicy, options === null || options === void 0 ? void 0 : options.fetchKey);
128
87
  var initialEntry = cache.get(environment, cacheKey);
129
-
130
88
  function updateCache(updater) {
131
89
  var currentEntry = cache.get(environment, cacheKey);
132
-
133
90
  if (!currentEntry) {
134
91
  currentEntry = makeInitialCacheEntry();
135
92
  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
142
- // a QueryCacheEntryStatus into a QueryCacheEntry will result in a valid QueryCacheEntry.
143
- } // Initiate a query to fetch the data if needed:
144
-
145
-
93
+ }
94
+ var newStatus = updater(currentEntry);
95
+ cache.set(environment, cacheKey, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, currentEntry), newStatus));
96
+ }
146
97
  if (RelayFeatureFlags.USE_REACT_CACHE_LEGACY_TIMEOUTS) {
147
98
  var _entry;
148
-
149
99
  if (initialEntry === undefined) {
150
100
  onCacheMiss(environment, queryOperationDescriptor, fetchPolicy, renderPolicy, updateCache, options === null || options === void 0 ? void 0 : options.fetchObservable);
151
101
  var createdEntry = cache.get(environment, cacheKey);
@@ -154,7 +104,6 @@ function getQueryResultOrFetchQuery_REACT_CACHE(environment, queryOperationDescr
154
104
  } else {
155
105
  _entry = initialEntry;
156
106
  }
157
-
158
107
  if (!_entry.suspenseResource) {
159
108
  _entry.suspenseResource = new SuspenseResource(function () {
160
109
  var retention = environment.retain(queryOperationDescriptor);
@@ -166,70 +115,49 @@ function getQueryResultOrFetchQuery_REACT_CACHE(environment, queryOperationDescr
166
115
  };
167
116
  });
168
117
  }
169
-
170
118
  if (_entry.onCommit === noopOnCommit) {
171
119
  _entry.onCommit = function () {
172
120
  !_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
121
  var retention = _entry.suspenseResource.permanentRetain(environment);
175
-
176
122
  return function () {
177
123
  retention.dispose();
178
124
  };
179
125
  };
180
126
  }
181
-
182
127
  _entry.suspenseResource.temporaryRetain(environment);
183
128
  } else {
184
129
  if (initialEntry === undefined) {
185
- // This is the behavior we eventually want: We retain the query until the
186
- // presiding Cache component unmounts, at which point the AbortSignal
187
- // 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.
190
-
130
+ onCacheMiss(environment, queryOperationDescriptor, fetchPolicy, renderPolicy, updateCache, options === null || options === void 0 ? void 0 : options.fetchObservable);
191
131
  var retention = environment.retain(queryOperationDescriptor);
192
-
193
132
  var dispose = function dispose() {
194
133
  retention.dispose();
195
134
  cache["delete"](environment, cacheKey);
196
135
  };
197
-
198
136
  var abortSignal = getCacheSignal();
199
137
  abortSignal.addEventListener('abort', dispose, {
200
138
  once: true
201
139
  });
202
140
  }
203
141
  }
204
-
205
- var entry = cache.get(environment, cacheKey); // could be a different entry now if synchronously resolved
206
-
142
+ var entry = cache.get(environment, cacheKey);
207
143
  !(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
144
  switch (entry.status) {
210
145
  case 'pending':
211
146
  throw entry.promise;
212
-
213
147
  case 'rejected':
214
148
  throw entry.error;
215
-
216
149
  case 'resolved':
217
150
  return [entry.result, entry.onCommit];
218
151
  }
219
-
220
152
  !false ? process.env.NODE_ENV !== "production" ? invariant(false, 'switch statement should be exhaustive') : invariant(false) : void 0;
221
153
  }
222
-
223
154
  function onCacheMiss(environment, operation, fetchPolicy, renderPolicy, updateCache, customFetchObservable) {
224
- // NB: Besides checking if the data is available, calling `check` will write missing
225
- // data to the store using any missing data handlers specified in the environment.
226
155
  var queryAvailability = environment.check(operation);
227
156
  var queryStatus = queryAvailability.status;
228
157
  var hasFullQuery = queryStatus === 'available';
229
158
  var canPartialRender = hasFullQuery || renderPolicy === 'partial' && queryStatus !== 'stale';
230
159
  var shouldFetch;
231
160
  var shouldRenderNow;
232
-
233
161
  switch (fetchPolicy) {
234
162
  case 'store-only':
235
163
  {
@@ -237,21 +165,18 @@ function onCacheMiss(environment, operation, fetchPolicy, renderPolicy, updateCa
237
165
  shouldRenderNow = true;
238
166
  break;
239
167
  }
240
-
241
168
  case 'store-or-network':
242
169
  {
243
170
  shouldFetch = !hasFullQuery;
244
171
  shouldRenderNow = canPartialRender;
245
172
  break;
246
173
  }
247
-
248
174
  case 'store-and-network':
249
175
  {
250
176
  shouldFetch = true;
251
177
  shouldRenderNow = canPartialRender;
252
178
  break;
253
179
  }
254
-
255
180
  case 'network-only':
256
181
  default:
257
182
  {
@@ -260,17 +185,14 @@ function onCacheMiss(environment, operation, fetchPolicy, renderPolicy, updateCa
260
185
  break;
261
186
  }
262
187
  }
263
-
264
188
  if (shouldFetch) {
265
189
  executeOperationAndKeepUpToDate(environment, operation, updateCache, customFetchObservable);
266
190
  updateCache(function (existing) {
267
191
  switch (existing.status) {
268
192
  case 'resolved':
269
193
  return existing;
270
-
271
194
  case 'rejected':
272
195
  return existing;
273
-
274
196
  case 'pending':
275
197
  return shouldRenderNow ? {
276
198
  status: 'resolved',
@@ -288,16 +210,13 @@ function onCacheMiss(environment, operation, fetchPolicy, renderPolicy, updateCa
288
210
  });
289
211
  }
290
212
  }
291
-
292
213
  function executeOperationAndKeepUpToDate(environment, operation, updateCache, customFetchObservable) {
293
214
  var resolvePromise;
294
215
  var promise = new Promise(function (r) {
295
216
  resolvePromise = r;
296
- }); // $FlowExpectedError[prop-missing] Expando to annotate Promises.
297
-
217
+ });
298
218
  promise.displayName = 'Relay(' + operation.request.node.operation.name + ')';
299
- var isFirstPayload = true; // FIXME We may still need to cancel network requests for live queries.
300
-
219
+ var isFirstPayload = true;
301
220
  var fetchObservable = customFetchObservable !== null && customFetchObservable !== void 0 ? customFetchObservable : fetchQueryInternal(environment, operation);
302
221
  fetchObservable.subscribe({
303
222
  start: function start(subscription) {},
@@ -310,16 +229,12 @@ function executeOperationAndKeepUpToDate(environment, operation, updateCache, cu
310
229
  };
311
230
  });
312
231
  } else {
313
- // TODO:T92030819 Remove this warning and actually throw the network error
314
- // To complete this task we need to have a way of precisely tracking suspendable points
315
232
  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
233
  }
317
-
318
234
  resolvePromise();
319
235
  isFirstPayload = false;
320
236
  },
321
237
  next: function next(response) {
322
- // Stop suspending on the first payload because of streaming, defer, etc.
323
238
  updateCache(function (_existing) {
324
239
  return {
325
240
  status: 'resolved',
@@ -329,10 +244,7 @@ function executeOperationAndKeepUpToDate(environment, operation, updateCache, cu
329
244
  resolvePromise();
330
245
  isFirstPayload = false;
331
246
  }
332
- }); // If the above subscription yields a value synchronously, then one of the updates
333
- // above will have already happened and we'll now be in a resolved or rejected state.
334
- // But in the usual case, we save the promise to the entry here:
335
-
247
+ });
336
248
  updateCache(function (existing) {
337
249
  return existing.status === 'pending' ? {
338
250
  status: 'pending',
@@ -340,5 +252,4 @@ function executeOperationAndKeepUpToDate(environment, operation, updateCache, cu
340
252
  } : existing;
341
253
  });
342
254
  }
343
-
344
255
  module.exports = getQueryResultOrFetchQuery_REACT_CACHE;
@@ -1,36 +1,20 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- *
8
- * @emails oncall+relay
9
- * @format
10
- */
11
1
  'use strict';
12
2
 
13
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
14
-
15
4
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
16
-
17
5
  var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
18
-
19
6
  var _require = require('../QueryResource'),
20
- getQueryResourceForEnvironment = _require.getQueryResourceForEnvironment;
21
-
7
+ getQueryResourceForEnvironment = _require.getQueryResourceForEnvironment;
22
8
  var invariant = require('invariant');
23
-
24
9
  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
-
10
+ fetchQueryInternal = _require2.__internal.fetchQuery,
11
+ RelayFeatureFlags = _require2.RelayFeatureFlags,
12
+ createOperationDescriptor = _require2.createOperationDescriptor,
13
+ getPendingOperationsForFragment = _require2.getPendingOperationsForFragment,
14
+ getSelector = _require2.getSelector,
15
+ getVariablesFromFragment = _require2.getVariablesFromFragment,
16
+ handlePotentialSnapshotErrors = _require2.handlePotentialSnapshotErrors;
32
17
  var warning = require("fbjs/lib/warning");
33
-
34
18
  function isMissingData(state) {
35
19
  if (state.kind === 'bailout') {
36
20
  return false;
@@ -42,32 +26,24 @@ function isMissingData(state) {
42
26
  });
43
27
  }
44
28
  }
45
-
46
29
  function getMissingClientEdges(state) {
47
30
  if (state.kind === 'bailout') {
48
31
  return null;
49
32
  } else if (state.kind === 'singular') {
50
33
  var _state$snapshot$missi;
51
-
52
34
  return (_state$snapshot$missi = state.snapshot.missingClientEdges) !== null && _state$snapshot$missi !== void 0 ? _state$snapshot$missi : null;
53
35
  } else {
54
36
  var edges = null;
55
-
56
37
  var _iterator = (0, _createForOfIteratorHelper2["default"])(state.snapshots),
57
- _step;
58
-
38
+ _step;
59
39
  try {
60
40
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
61
41
  var snapshot = _step.value;
62
-
63
42
  if (snapshot.missingClientEdges) {
64
43
  var _edges;
65
-
66
44
  edges = (_edges = edges) !== null && _edges !== void 0 ? _edges : [];
67
-
68
45
  var _iterator2 = (0, _createForOfIteratorHelper2["default"])(snapshot.missingClientEdges),
69
- _step2;
70
-
46
+ _step2;
71
47
  try {
72
48
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
73
49
  var edge = _step2.value;
@@ -85,18 +61,15 @@ function getMissingClientEdges(state) {
85
61
  } finally {
86
62
  _iterator.f();
87
63
  }
88
-
89
64
  return edges;
90
65
  }
91
66
  }
92
-
93
67
  function handlePotentialSnapshotErrorsForState(environment, state) {
94
68
  if (state.kind === 'singular') {
95
69
  handlePotentialSnapshotErrors(environment, state.snapshot.missingRequiredFields, state.snapshot.relayResolverErrors);
96
70
  } else if (state.kind === 'plural') {
97
71
  var _iterator3 = (0, _createForOfIteratorHelper2["default"])(state.snapshots),
98
- _step3;
99
-
72
+ _step3;
100
73
  try {
101
74
  for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
102
75
  var snapshot = _step3.value;
@@ -109,22 +82,15 @@ function handlePotentialSnapshotErrorsForState(environment, state) {
109
82
  }
110
83
  }
111
84
  }
112
-
113
85
  function handleMissingClientEdge(environment, parentFragmentNode, parentFragmentRef, missingClientEdgeRequestInfo, queryOptions) {
114
86
  var originalVariables = getVariablesFromFragment(parentFragmentNode, parentFragmentRef);
115
87
  var variables = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, originalVariables), {}, {
116
- id: missingClientEdgeRequestInfo.clientEdgeDestinationID // TODO should be a reserved name
117
-
88
+ id: missingClientEdgeRequestInfo.clientEdgeDestinationID
118
89
  });
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
120
- // doing here is started the query if needed and retaining and releasing it
121
- // according to the component mount/suspense cycle; QueryResource
122
- // already handles this by itself.
123
-
90
+ var queryOperationDescriptor = createOperationDescriptor(missingClientEdgeRequestInfo.request, variables, queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.networkCacheConfig);
124
91
  var QueryResource = getQueryResourceForEnvironment(environment);
125
92
  return QueryResource.prepare(queryOperationDescriptor, fetchQueryInternal(environment, queryOperationDescriptor), queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.fetchPolicy);
126
93
  }
127
-
128
94
  function getFragmentState(environment, fragmentSelector) {
129
95
  if (fragmentSelector == null) {
130
96
  return {
@@ -151,36 +117,25 @@ function getFragmentState(environment, fragmentSelector) {
151
117
  epoch: environment.getStore().getEpoch()
152
118
  };
153
119
  }
154
- } // fragmentNode cannot change during the lifetime of the component, though fragmentRef may change.
155
-
156
-
120
+ }
157
121
  function readFragmentInternal_REACT_CACHE(environment, fragmentNode, fragmentRef, hookDisplayName, queryOptions, fragmentKey) {
158
122
  var _fragmentNode$metadat, _fragmentNode$metadat2;
159
-
160
123
  var fragmentSelector = getSelector(fragmentNode, fragmentRef);
161
124
  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
125
  if (isPlural) {
164
126
  !(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
127
  } else {
166
128
  !!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
129
  }
168
-
169
130
  !(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.
172
-
131
+ var state = getFragmentState(environment, fragmentSelector);
173
132
  var clientEdgeQueries = null;
174
-
175
133
  if (((_fragmentNode$metadat2 = fragmentNode.metadata) === null || _fragmentNode$metadat2 === void 0 ? void 0 : _fragmentNode$metadat2.hasClientEdges) === true) {
176
134
  var missingClientEdges = getMissingClientEdges(state);
177
-
178
135
  if (missingClientEdges !== null && missingClientEdges !== void 0 && missingClientEdges.length) {
179
136
  clientEdgeQueries = [];
180
-
181
137
  var _iterator4 = (0, _createForOfIteratorHelper2["default"])(missingClientEdges),
182
- _step4;
183
-
138
+ _step4;
184
139
  try {
185
140
  for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
186
141
  var edge = _step4.value;
@@ -193,25 +148,16 @@ function readFragmentInternal_REACT_CACHE(environment, fragmentNode, fragmentRef
193
148
  }
194
149
  }
195
150
  }
196
-
197
151
  if (isMissingData(state)) {
198
- // Suspend if an active operation bears on this fragment, either the
199
- // fragment's owner or some other mutation etc. that could affect it:
200
152
  !(fragmentSelector != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'refinement, see invariants above') : invariant(false) : void 0;
201
153
  var fragmentOwner = fragmentSelector.kind === 'PluralReaderSelector' ? fragmentSelector.selectors[0].owner : fragmentSelector.owner;
202
154
  var pendingOperationsResult = getPendingOperationsForFragment(environment, fragmentNode, fragmentOwner);
203
-
204
155
  if (pendingOperationsResult) {
205
156
  throw pendingOperationsResult.promise;
206
- } // Report required fields only if we're not suspending, since that means
207
- // they're missing even though we are out of options for possibly fetching them:
208
-
209
-
157
+ }
210
158
  handlePotentialSnapshotErrorsForState(environment, state);
211
159
  }
212
-
213
160
  var data;
214
-
215
161
  if (state.kind === 'bailout') {
216
162
  data = isPlural ? [] : null;
217
163
  } else if (state.kind === 'singular') {
@@ -221,19 +167,16 @@ function readFragmentInternal_REACT_CACHE(environment, fragmentNode, fragmentRef
221
167
  return s.data;
222
168
  });
223
169
  }
224
-
225
- if (process.env.NODE_ENV !== "production") {
170
+ if (RelayFeatureFlags.LOG_MISSING_RECORDS_IN_PROD || process.env.NODE_ENV !== "production") {
226
171
  if (fragmentRef != null && (data === undefined || Array.isArray(data) && data.length > 0 && data.every(function (d) {
227
172
  return d === undefined;
228
173
  }))) {
229
174
  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
175
  }
231
176
  }
232
-
233
177
  return {
234
178
  data: data,
235
179
  clientEdgeQueries: clientEdgeQueries
236
180
  };
237
181
  }
238
-
239
182
  module.exports = readFragmentInternal_REACT_CACHE;