react-relay 15.0.0 → 16.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 (119) hide show
  1. package/ReactRelayContext.js +1 -1
  2. package/ReactRelayQueryFetcher.js.flow +1 -5
  3. package/ReactRelayQueryRenderer.js.flow +9 -36
  4. package/ReactRelayTypes.js.flow +1 -0
  5. package/buildReactRelayContainer.js.flow +3 -1
  6. package/hooks.js +1 -1
  7. package/index.js +1 -1
  8. package/legacy.js +1 -1
  9. package/lib/ReactRelayContainerUtils.js +0 -11
  10. package/lib/ReactRelayContext.js +0 -11
  11. package/lib/ReactRelayFragmentContainer.js +6 -78
  12. package/lib/ReactRelayFragmentMockRenderer.js +0 -11
  13. package/lib/ReactRelayLocalQueryRenderer.js +0 -17
  14. package/lib/ReactRelayPaginationContainer.js +5 -208
  15. package/lib/ReactRelayQueryFetcher.js +2 -51
  16. package/lib/ReactRelayQueryRenderer.js +6 -94
  17. package/lib/ReactRelayQueryRendererContext.js +0 -11
  18. package/lib/ReactRelayRefetchContainer.js +5 -91
  19. package/lib/ReactRelayTestMocker.js +9 -85
  20. package/lib/ReactRelayTypes.js +0 -11
  21. package/lib/RelayContext.js +0 -21
  22. package/lib/assertFragmentMap.js +0 -15
  23. package/lib/buildReactRelayContainer.js +0 -19
  24. package/lib/getRootVariablesForFragments.js +0 -14
  25. package/lib/hooks.js +0 -15
  26. package/lib/index.js +0 -17
  27. package/lib/isRelayEnvironment.js +1 -18
  28. package/lib/jest-react/enqueueTask.js +0 -20
  29. package/lib/jest-react/internalAct.js +0 -38
  30. package/lib/legacy.js +0 -15
  31. package/lib/multi-actor/ActorChange.js +0 -11
  32. package/lib/multi-actor/index.js +0 -11
  33. package/lib/multi-actor/useRelayActorEnvironment.js +0 -11
  34. package/lib/relay-hooks/EntryPointContainer.react.js +0 -11
  35. package/lib/relay-hooks/EntryPointTypes.flow.js +1 -14
  36. package/lib/relay-hooks/FragmentResource.js +76 -132
  37. package/lib/relay-hooks/HooksImplementation.js +0 -11
  38. package/lib/relay-hooks/InternalLogger.js +0 -11
  39. package/lib/relay-hooks/LRUCache.js +0 -22
  40. package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +0 -18
  41. package/lib/relay-hooks/MatchContainer.js +0 -94
  42. package/lib/relay-hooks/NestedRelayEntryPointBuilderUtils.js +9 -0
  43. package/lib/relay-hooks/ProfilerContext.js +0 -15
  44. package/lib/relay-hooks/QueryResource.js +2 -68
  45. package/lib/relay-hooks/RelayEnvironmentProvider.js +0 -11
  46. package/lib/relay-hooks/SuspenseResource.js +0 -34
  47. package/lib/relay-hooks/loadEntryPoint.js +1 -24
  48. package/lib/relay-hooks/loadQuery.js +2 -106
  49. package/lib/relay-hooks/preloadQuery_DEPRECATED.js +2 -27
  50. package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +0 -13
  51. package/lib/relay-hooks/react-cache/RelayReactCache.js +0 -12
  52. package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +1 -36
  53. package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +3 -27
  54. package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +34 -99
  55. package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +0 -15
  56. package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +0 -16
  57. package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +1 -23
  58. package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +0 -29
  59. package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +12 -96
  60. package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +0 -14
  61. package/lib/relay-hooks/useBlockingPaginationFragment.js +0 -42
  62. package/lib/relay-hooks/useClientQuery.js +0 -18
  63. package/lib/relay-hooks/useEntryPointLoader.js +0 -69
  64. package/lib/relay-hooks/useFetchTrackingRef.js +0 -26
  65. package/lib/relay-hooks/useFragment.js +0 -17
  66. package/lib/relay-hooks/useFragmentNode.js +2 -32
  67. package/lib/relay-hooks/useIsMountedRef.js +0 -11
  68. package/lib/relay-hooks/useIsOperationNodeActive.js +0 -11
  69. package/lib/relay-hooks/useIsParentQueryActive.js +0 -11
  70. package/lib/relay-hooks/useLazyLoadQuery.js +0 -18
  71. package/lib/relay-hooks/useLazyLoadQueryNode.js +0 -35
  72. package/lib/relay-hooks/useLoadMoreFunction.js +9 -34
  73. package/lib/relay-hooks/useMemoOperationDescriptor.js +0 -11
  74. package/lib/relay-hooks/useMemoVariables.js +0 -17
  75. package/lib/relay-hooks/useMutation.js +0 -11
  76. package/lib/relay-hooks/usePaginationFragment.js +1 -26
  77. package/lib/relay-hooks/usePreloadedQuery.js +0 -27
  78. package/lib/relay-hooks/useQueryLoader.js +0 -74
  79. package/lib/relay-hooks/useRefetchableFragment.js +0 -16
  80. package/lib/relay-hooks/useRefetchableFragmentNode.js +14 -97
  81. package/lib/relay-hooks/useRelayEnvironment.js +0 -11
  82. package/lib/relay-hooks/useStaticFragmentNodeWarning.js +0 -15
  83. package/lib/relay-hooks/useSubscribeToInvalidationState.js +0 -25
  84. package/lib/relay-hooks/useSubscription.js +0 -15
  85. package/lib/relay-hooks/useUnsafeRef_DEPRECATED.js +0 -17
  86. package/package.json +2 -2
  87. package/react-relay-hooks.js +2 -2
  88. package/react-relay-hooks.min.js +2 -2
  89. package/react-relay-legacy.js +2 -2
  90. package/react-relay-legacy.min.js +2 -2
  91. package/react-relay.js +2 -2
  92. package/react-relay.min.js +2 -2
  93. package/relay-hooks/EntryPointContainer.react.js.flow +5 -0
  94. package/relay-hooks/EntryPointTypes.flow.js.flow +20 -19
  95. package/relay-hooks/FragmentResource.js.flow +114 -26
  96. package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +4 -2
  97. package/relay-hooks/NestedRelayEntryPointBuilderUtils.js.flow +51 -0
  98. package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +7 -5
  99. package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +5 -0
  100. package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +5 -0
  101. package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +2 -0
  102. package/relay-hooks/loadEntryPoint.js.flow +4 -2
  103. package/relay-hooks/loadQuery.js.flow +21 -1
  104. package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +4 -2
  105. package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +2 -1
  106. package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +28 -10
  107. package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +3 -9
  108. package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +28 -57
  109. package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +19 -12
  110. package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +15 -31
  111. package/relay-hooks/useBlockingPaginationFragment.js.flow +2 -4
  112. package/relay-hooks/useClientQuery.js.flow +2 -2
  113. package/relay-hooks/useFragmentNode.js.flow +2 -2
  114. package/relay-hooks/useLoadMoreFunction.js.flow +15 -9
  115. package/relay-hooks/useMutation.js.flow +26 -9
  116. package/relay-hooks/usePaginationFragment.js.flow +2 -8
  117. package/relay-hooks/useQueryLoader.js.flow +2 -8
  118. package/relay-hooks/useRefetchableFragment.js.flow +3 -2
  119. package/relay-hooks/useRefetchableFragmentNode.js.flow +28 -13
@@ -1,14 +1,3 @@
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
- * @format
9
- * @oncall relay
10
- */
11
-
12
1
  'use strict';
13
2
 
14
3
  var preloadQuery_DEPRECATED = require('./preloadQuery_DEPRECATED');
@@ -26,7 +15,6 @@ function stableStringify(value) {
26
15
  return (_JSON$stringify = JSON.stringify(stableCopy(value))) !== null && _JSON$stringify !== void 0 ? _JSON$stringify : 'null';
27
16
  }
28
17
  function prepareEntryPoint(environmentProvider, entryPoint, entryPointParams) {
29
- // Start loading the code for the entrypoint
30
18
  var loadingPromise = null;
31
19
  if (entryPoint.root.getModuleIfRequired() == null) {
32
20
  loadingPromise = entryPoint.root.load();
@@ -71,7 +59,6 @@ function prepareEntryPoint(environmentProvider, entryPoint, entryPointParams) {
71
59
  loadingPromise = (_loadingPromise = loadingPromise) !== null && _loadingPromise !== void 0 ? _loadingPromise : entryPoint.root.load();
72
60
  throw loadingPromise;
73
61
  }
74
- // $FlowFixMe[incompatible-cast] - trust me Flow, its entryPoint component
75
62
  return component;
76
63
  },
77
64
  queries: preloadedQueries,
@@ -85,9 +72,6 @@ function LazyLoadEntryPointContainer_DEPRECATED(_ref) {
85
72
  environmentProvider = _ref.environmentProvider;
86
73
  var environment = useRelayEnvironment();
87
74
  var getPreloadProps = entryPoint.getPreloadProps;
88
- // IMPORTANT: Loading the component may suspend (throw), so the props
89
- // *must* be computed first to fetch the component's data-dependencies in
90
- // parallel with the component itself (the code).
91
75
  var entryPointParamsHash = stableStringify(entryPointParams);
92
76
  var _useMemo = useMemo(function () {
93
77
  return prepareEntryPoint(environmentProvider !== null && environmentProvider !== void 0 ? environmentProvider : {
@@ -95,8 +79,6 @@ function LazyLoadEntryPointContainer_DEPRECATED(_ref) {
95
79
  return environment;
96
80
  }
97
81
  }, entryPoint, entryPointParams);
98
- // NOTE: stableParams encodes the information from params
99
- // eslint-disable-next-line react-hooks/exhaustive-deps
100
82
  }, [environment, environmentProvider, getPreloadProps, entryPointParamsHash]),
101
83
  getComponent = _useMemo.getComponent,
102
84
  queries = _useMemo.queries,
@@ -1,92 +1,9 @@
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
- * @format
9
- * @oncall relay
10
- */
11
-
12
1
  'use strict';
13
2
 
14
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
15
4
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
16
5
  var React = require('react');
17
6
  var useMemo = React.useMemo;
18
-
19
- /**
20
- * Renders the results of a data-driven dependency fetched with the `@match`
21
- * directive. The `@match` directive can be used to specify a mapping of
22
- * result types to the containers used to render those types. The result
23
- * value is an opaque object that described which component was selected
24
- * and a reference to its data. Use <MatchContainer/> to render these
25
- * values.
26
- *
27
- * ## Example
28
- *
29
- * For example, consider a piece of media content that might be text or
30
- * an image, where for clients that don't support images the application
31
- * should fall back to rendering the image caption as text. @match can be
32
- * used to dynamically select whether to render a given media item as
33
- * an image or text (on the server) and then fetch the corresponding
34
- * React component and its data dependencies (information about the
35
- * image or about the text).
36
- *
37
- * ```
38
- * // Media.react.js
39
- *
40
- * // Define a React component that uses <MatchContainer /> to render the
41
- * // results of a @module selection
42
- * function Media(props) {
43
- * const {media, ...restProps} = props;
44
- *
45
- * const loader = moduleReference => {
46
- * // given the data returned by your server for the @module directive,
47
- * // return the React component (or throw a Suspense promise if
48
- * // it is loading asynchronously).
49
- * todo_returnModuleOrThrowPromise(moduleReference);
50
- * };
51
- * return <MatchContainer
52
- * loader={loader}
53
- * match={media.mediaAttachment}
54
- * props={restProps}
55
- * />;
56
- * }
57
- *
58
- * module.exports = createSuspenseFragmentContainer(
59
- * Media,
60
- * {
61
- * media: graphql`
62
- * fragment Media_media on Media {
63
- * # ...
64
- * mediaAttachment @match {
65
- * ...ImageContainer_image @module(name: "ImageContainer.react")
66
- * ...TextContainer_text @module(name: "TextContainer.react")
67
- * }
68
- * }
69
- * `
70
- * },
71
- * );
72
- * ```
73
- *
74
- * ## API
75
- *
76
- * MatchContainer accepts the following props:
77
- * - `match`: The results (an opaque object) of a `@match` field.
78
- * - `props`: Props that should be passed through to the dynamically
79
- * selected component. Note that any of the components listed in
80
- * `@module()` could be selected, so all components should accept
81
- * the value passed here.
82
- * - `loader`: A function to load a module given a reference (whatever
83
- * your server returns for the `js(moduleName: String)` field).
84
- *
85
- */
86
-
87
- // Note: this type is intentionally non-exact, it is expected that the
88
- // object may contain sibling fields.
89
-
90
7
  function MatchContainer(_ref2) {
91
8
  var _ref;
92
9
  var fallback = _ref2.fallback,
@@ -96,13 +13,6 @@ function MatchContainer(_ref2) {
96
13
  if (match != null && typeof match !== 'object') {
97
14
  throw new Error('MatchContainer: Expected `match` value to be an object or null/undefined.');
98
15
  }
99
- // NOTE: the MatchPointer type has a $fragmentSpreads field to ensure that only
100
- // an object that contains a FragmentSpread can be passed. If the fragment
101
- // spread matches, then the metadata fields below (__id, __fragments, etc.)
102
- // will be present. But they can be missing if all the fragment spreads use
103
- // @module and none of the types matched. The cast here is necessary because
104
- // fragment Flow types don't describe metadata fields, only the actual schema
105
- // fields the developer selected.
106
16
  var _ref3 = (_ref = match) !== null && _ref !== void 0 ? _ref : {},
107
17
  __id = _ref3.__id,
108
18
  __fragments = _ref3.__fragments,
@@ -114,8 +24,6 @@ function MatchContainer(_ref2) {
114
24
  }
115
25
  var LoadedContainer = __module_component != null ? loader(__module_component) : null;
116
26
  var fragmentProps = useMemo(function () {
117
- // TODO: Perform this transformation in RelayReader so that unchanged
118
- // output of subscriptions already has a stable identity.
119
27
  if (__fragmentPropName != null && __id != null && __fragments != null) {
120
28
  var fragProps = {};
121
29
  fragProps[__fragmentPropName] = {
@@ -128,8 +36,6 @@ function MatchContainer(_ref2) {
128
36
  return null;
129
37
  }, [__id, __fragments, __fragmentOwner, __fragmentPropName]);
130
38
  if (LoadedContainer != null && fragmentProps != null) {
131
- // $FlowFixMe[incompatible-type]
132
- // $FlowFixMe[cannot-spread-indexer]
133
39
  return /*#__PURE__*/React.createElement(LoadedContainer, (0, _extends2["default"])({}, props, fragmentProps));
134
40
  } else {
135
41
  return fallback !== null && fallback !== void 0 ? fallback : null;
@@ -0,0 +1,9 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.NestedRelayEntryPoint = NestedRelayEntryPoint;
7
+ function NestedRelayEntryPoint(params) {
8
+ return params;
9
+ }
@@ -1,18 +1,3 @@
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
- * @format
9
- * @oncall relay
10
- */
11
-
12
- // This contextual profiler can be used to wrap a react sub-tree. It will bind
13
- // the RelayProfiler during the render phase of these components. Allows
14
- // collecting metrics for a specific part of your application.
15
-
16
1
  'use strict';
17
2
 
18
3
  var React = require('react');
@@ -1,14 +1,3 @@
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
- * @format
9
- * @oncall relay
10
- */
11
-
12
1
  'use strict';
13
2
 
14
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
@@ -58,9 +47,6 @@ function createCacheEntry(cacheIdentifier, operation, operationAvailability, val
58
47
  var retention = environment.retain(operation);
59
48
  return {
60
49
  dispose: function dispose() {
61
- // Normally if this entry never commits, the request would've ended by the
62
- // time this timeout expires and the temporary retain is released. However,
63
- // we need to do this for live queries which remain open indefinitely.
64
50
  if (isLiveQuery && currentNetworkSubscription != null) {
65
51
  currentNetworkSubscription.unsubscribe();
66
52
  }
@@ -111,34 +97,17 @@ var QueryResourceImpl = /*#__PURE__*/function () {
111
97
  _proto.prepare = function prepare(operation, fetchObservable, maybeFetchPolicy, maybeRenderPolicy, observer, cacheBreaker, profilerContext) {
112
98
  var cacheIdentifier = getQueryCacheIdentifier(this._environment, operation, maybeFetchPolicy, maybeRenderPolicy, cacheBreaker);
113
99
  return this.prepareWithIdentifier(cacheIdentifier, operation, fetchObservable, maybeFetchPolicy, maybeRenderPolicy, observer, profilerContext);
114
- }
115
-
116
- /**
117
- * This function should be called during a Component's render function,
118
- * to either read an existing cached value for the query, or fetch the query
119
- * and suspend.
120
- */;
100
+ };
121
101
  _proto.prepareWithIdentifier = function prepareWithIdentifier(cacheIdentifier, operation, fetchObservable, maybeFetchPolicy, maybeRenderPolicy, observer, profilerContext) {
122
102
  var environment = this._environment;
123
103
  var fetchPolicy = maybeFetchPolicy !== null && maybeFetchPolicy !== void 0 ? maybeFetchPolicy : operationIsLiveQuery(operation) ? DEFAULT_LIVE_FETCH_POLICY : DEFAULT_FETCH_POLICY;
124
104
  var renderPolicy = maybeRenderPolicy !== null && maybeRenderPolicy !== void 0 ? maybeRenderPolicy : environment.UNSTABLE_getDefaultRenderPolicy();
125
-
126
- // 1. Check if there's a cached value for this operation, and reuse it if
127
- // it's available
128
105
  var cacheEntry = this._cache.get(cacheIdentifier);
129
106
  var temporaryRetainDisposable = null;
130
107
  var entryWasCached = cacheEntry != null;
131
108
  if (cacheEntry == null) {
132
- // 2. If a cached value isn't available, try fetching the operation.
133
- // _fetchAndSaveQuery will update the cache with either a Promise or
134
- // an Error to throw, or a QueryResult to return.
135
109
  cacheEntry = this._fetchAndSaveQuery(cacheIdentifier, operation, fetchObservable, fetchPolicy, renderPolicy, profilerContext, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, observer), {}, {
136
110
  unsubscribe: function unsubscribe(subscription) {
137
- // 4. If the request is cancelled, make sure to dispose
138
- // of the temporary retain; this will ensure that a promise
139
- // doesn't remain unnecessarily cached until the temporary retain
140
- // expires. Not clearing the temporary retain might cause the
141
- // query to incorrectly re-suspend.
142
111
  if (temporaryRetainDisposable != null) {
143
112
  temporaryRetainDisposable.dispose();
144
113
  }
@@ -147,12 +116,6 @@ var QueryResourceImpl = /*#__PURE__*/function () {
147
116
  }
148
117
  }));
149
118
  }
150
-
151
- // 3. Temporarily retain here in render phase. When the component reading
152
- // the operation is committed, we will transfer ownership of data retention
153
- // to the component.
154
- // In case the component never commits (mounts or updates) from this render,
155
- // this data retention hold will auto-release itself after a timeout.
156
119
  temporaryRetainDisposable = cacheEntry.temporaryRetain(environment);
157
120
  var cachedValue = cacheEntry.getValue();
158
121
  if (isPromise(cachedValue)) {
@@ -170,13 +133,7 @@ var QueryResourceImpl = /*#__PURE__*/function () {
170
133
  throw cachedValue;
171
134
  }
172
135
  return cachedValue;
173
- }
174
-
175
- /**
176
- * This function should be called during a component's commit phase
177
- * (e.g. inside useEffect), in order to retain the operation in the Relay store
178
- * and transfer ownership of the operation to the component lifecycle.
179
- */;
136
+ };
180
137
  _proto.retain = function retain(queryResult, profilerContext) {
181
138
  var environment = this._environment;
182
139
  var cacheIdentifier = queryResult.cacheIdentifier,
@@ -216,19 +173,12 @@ var QueryResourceImpl = /*#__PURE__*/function () {
216
173
  _proto._fetchAndSaveQuery = function _fetchAndSaveQuery(cacheIdentifier, operation, fetchObservable, fetchPolicy, renderPolicy, profilerContext, observer) {
217
174
  var _this2 = this;
218
175
  var environment = this._environment;
219
-
220
- // NOTE: Running `check` will write missing data to the store using any
221
- // missing data handlers specified on the environment;
222
- // We run it here first to make the handlers get a chance to populate
223
- // missing data.
224
176
  var queryAvailability = environment.check(operation);
225
177
  var queryStatus = queryAvailability.status;
226
178
  var hasFullQuery = queryStatus === 'available';
227
179
  var canPartialRender = hasFullQuery || renderPolicy === 'partial' && queryStatus !== 'stale';
228
180
  var shouldFetch;
229
181
  var shouldAllowRender;
230
- // Different definitions for Promise in our repos can cause this variable
231
- // to cause errors when synced elsewhere
232
182
  var resolveNetworkPromise = function resolveNetworkPromise() {};
233
183
  switch (fetchPolicy) {
234
184
  case 'store-only':
@@ -257,11 +207,6 @@ var QueryResourceImpl = /*#__PURE__*/function () {
257
207
  break;
258
208
  }
259
209
  }
260
-
261
- // NOTE: If this value is false, we will cache a promise for this
262
- // query, which means we will suspend here at this query root.
263
- // If it's true, we will cache the query resource and allow rendering to
264
- // continue.
265
210
  if (shouldAllowRender) {
266
211
  var queryResult = getQueryResult(operation, cacheIdentifier);
267
212
  var _cacheEntry = createCacheEntry(cacheIdentifier, operation, queryAvailability, queryResult, null, this._clearCacheEntry);
@@ -281,7 +226,6 @@ var QueryResourceImpl = /*#__PURE__*/function () {
281
226
  if (observerStart) {
282
227
  var subscriptionWithConditionalCancelation = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, subscription), {}, {
283
228
  unsubscribe: function unsubscribe() {
284
- // Only live queries should have their network requests canceled.
285
229
  if (operationIsLiveQuery(operation)) {
286
230
  subscription.unsubscribe();
287
231
  }
@@ -303,17 +247,9 @@ var QueryResourceImpl = /*#__PURE__*/function () {
303
247
  },
304
248
  error: function error(_error) {
305
249
  var cacheEntry = _this2._getOrCreateCacheEntry(cacheIdentifier, operation, queryAvailability, _error, networkSubscription);
306
-
307
- // If, this is the first thing we receive for the query,
308
- // before any other payload handled is error, we will cache and
309
- // re-throw that error later.
310
-
311
- // We will ignore errors for any incremental payloads we receive.
312
250
  if (cacheEntry.processedPayloadsCount === 0) {
313
251
  cacheEntry.setValue(_error);
314
252
  } else {
315
- // TODO:T92030819 Remove this warning and actually throw the network error
316
- // To complete this task we need to have a way of precisely tracking suspendable points
317
253
  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;
318
254
  }
319
255
  resolveNetworkPromise();
@@ -339,8 +275,6 @@ var QueryResourceImpl = /*#__PURE__*/function () {
339
275
  var networkPromise = new Promise(function (resolve) {
340
276
  resolveNetworkPromise = resolve;
341
277
  });
342
-
343
- // $FlowExpectedError[prop-missing] Expando to annotate Promises.
344
278
  networkPromise.displayName = 'Relay(' + operation.fragment.node.name + ')';
345
279
  _cacheEntry2 = createCacheEntry(cacheIdentifier, operation, queryAvailability, networkPromise, networkSubscription, this._clearCacheEntry);
346
280
  this._cache.set(cacheIdentifier, _cacheEntry2);
@@ -1,14 +1,3 @@
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
- * @format
9
- * @oncall relay
10
- */
11
-
12
1
  'use strict';
13
2
 
14
3
  var ReactRelayContext = require('./../ReactRelayContext');
@@ -1,26 +1,9 @@
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
- * @format
9
- * @oncall relay
10
- */
11
-
12
1
  'use strict';
13
2
 
14
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
15
4
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
16
5
  var invariant = require('invariant');
17
6
  var TEMPORARY_RETAIN_DURATION_MS = 5 * 60 * 1000;
18
-
19
- /**
20
- * Allows you to retain a resource as part of a component lifecycle accounting
21
- * for Suspense. You temporarily retain the resource during render, then
22
- * permanently retain it during commit and release it during unmount.
23
- */
24
7
  var SuspenseResource = /*#__PURE__*/function () {
25
8
  function SuspenseResource(retain) {
26
9
  var _this = this;
@@ -48,20 +31,11 @@ var SuspenseResource = /*#__PURE__*/function () {
48
31
  _proto.temporaryRetain = function temporaryRetain(environment) {
49
32
  var _this2 = this;
50
33
  var _this$_releaseTempora;
51
- // If we're executing in a server environment, there's no need
52
- // to create temporary retains, since the component will never commit.
53
34
  if (environment.isServer()) {
54
35
  return {
55
36
  dispose: function dispose() {}
56
37
  };
57
38
  }
58
-
59
- // temporaryRetain is called during the render phase. However,
60
- // given that we can't tell if this render will eventually commit or not,
61
- // we create a timer to autodispose of this retain in case the associated
62
- // component never commits.
63
- // If the component /does/ commit, permanentRetain will clear this timeout
64
- // and permanently retain the data.
65
39
  var retention = this._retain(environment);
66
40
  var releaseQueryTimeout = null;
67
41
  var releaseTemporaryRetain = function releaseTemporaryRetain() {
@@ -71,14 +45,6 @@ var SuspenseResource = /*#__PURE__*/function () {
71
45
  retention.dispose();
72
46
  };
73
47
  releaseQueryTimeout = setTimeout(releaseTemporaryRetain, TEMPORARY_RETAIN_DURATION_MS);
74
-
75
- // NOTE: Since temporaryRetain can be called multiple times, we release
76
- // the previous temporary retain after we re-establish a new one, since
77
- // we only ever need a single temporary retain until the permanent retain is
78
- // established.
79
- // temporaryRetain may be called multiple times by React during the render
80
- // phase, as well as multiple times by other query components that are
81
- // rendering the same query/variables.
82
48
  (_this$_releaseTempora = this._releaseTemporaryRetain) === null || _this$_releaseTempora === void 0 ? void 0 : _this$_releaseTempora.call(this);
83
49
  this._releaseTemporaryRetain = releaseTemporaryRetain;
84
50
  return {
@@ -1,20 +1,8 @@
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
- * @format
9
- * @oncall relay
10
- */
11
-
12
1
  'use strict';
13
2
 
14
3
  var _require = require('./loadQuery'),
15
4
  loadQuery = _require.loadQuery;
16
5
  function loadEntryPoint(environmentProvider, entryPoint, entryPointParams) {
17
- // Start loading the code for the entrypoint
18
6
  var loadingPromise = null;
19
7
  if (entryPoint.root.getModuleIfRequired() == null) {
20
8
  loadingPromise = entryPoint.root.load();
@@ -34,8 +22,6 @@ function loadEntryPoint(environmentProvider, entryPoint, entryPointParams) {
34
22
  parameters = _queries$queryPropNam.parameters,
35
23
  variables = _queries$queryPropNam.variables;
36
24
  var environment = environmentProvider.getEnvironment(environmentProviderOptions);
37
-
38
- // $FlowFixMe[underconstrained-implicit-instantiation]
39
25
  preloadedQueries[queryPropName] = loadQuery(environment, parameters, variables, {
40
26
  fetchPolicy: options === null || options === void 0 ? void 0 : options.fetchPolicy,
41
27
  networkCacheConfig: options === null || options === void 0 ? void 0 : options.networkCacheConfig,
@@ -84,18 +70,9 @@ function loadEntryPoint(environmentProvider, entryPoint, entryPointParams) {
84
70
  loadingPromise = (_loadingPromise = loadingPromise) !== null && _loadingPromise !== void 0 ? _loadingPromise : entryPoint.root.load();
85
71
  throw loadingPromise;
86
72
  }
87
-
88
- // On certain platforms, getting an es6 module with a default export from a JSResource will return an object like
89
- // {default: module}, so let's assume that if the "component" has a static property named "default"
90
- // that it's actually an es6 module wrapper, so unwrap it. This won't work for React classes with a static property named "default", but
91
- // that's probably a worthwhile trade-off.
92
- var component =
93
- // $FlowIgnore[prop-missing]
94
- componentModule["default"] != null ? componentModule["default"] : componentModule;
95
- // $FlowFixMe[incompatible-cast] - trust me Flow, its entryPoint component
73
+ var component = componentModule["default"] != null ? componentModule["default"] : componentModule;
96
74
  return component;
97
75
  },
98
- // $FlowFixMe[unsafe-getters-setters] - this has no side effects
99
76
  get isDisposed() {
100
77
  return isDisposed;
101
78
  },
@@ -1,14 +1,3 @@
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
- * @format
9
- * @oncall relay
10
- */
11
-
12
1
  'use strict';
13
2
 
14
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
@@ -30,37 +19,18 @@ var fetchKey = 100001;
30
19
  function useTrackLoadQueryInRender() {
31
20
  if (RenderDispatcher === null) {
32
21
  var _React$__SECRET_INTER, _React$__SECRET_INTER2;
33
- // Flow does not know of React internals (rightly so), but we need to
34
- // ensure here that this function isn't called inside render.
35
- RenderDispatcher = // $FlowFixMe[prop-missing]
36
- (_React$__SECRET_INTER = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED) === null || _React$__SECRET_INTER === void 0 ? void 0 : (_React$__SECRET_INTER2 = _React$__SECRET_INTER.ReactCurrentDispatcher) === null || _React$__SECRET_INTER2 === void 0 ? void 0 : _React$__SECRET_INTER2.current;
22
+ RenderDispatcher = (_React$__SECRET_INTER = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED) === null || _React$__SECRET_INTER === void 0 ? void 0 : (_React$__SECRET_INTER2 = _React$__SECRET_INTER.ReactCurrentDispatcher) === null || _React$__SECRET_INTER2 === void 0 ? void 0 : _React$__SECRET_INTER2.current;
37
23
  }
38
24
  }
39
25
  function loadQuery(environment, preloadableRequest, variables, options, environmentProviderOptions) {
40
26
  var _React$__SECRET_INTER3, _React$__SECRET_INTER4, _options$__nameForWar, _options$fetchPolicy;
41
- // This code ensures that we don't call loadQuery during render.
42
- var CurrentDispatcher = // $FlowFixMe[prop-missing]
43
- (_React$__SECRET_INTER3 = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED) === null || _React$__SECRET_INTER3 === void 0 ? void 0 : (_React$__SECRET_INTER4 = _React$__SECRET_INTER3.ReactCurrentDispatcher) === null || _React$__SECRET_INTER4 === void 0 ? void 0 : _React$__SECRET_INTER4.current;
27
+ var CurrentDispatcher = (_React$__SECRET_INTER3 = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED) === null || _React$__SECRET_INTER3 === void 0 ? void 0 : (_React$__SECRET_INTER4 = _React$__SECRET_INTER3.ReactCurrentDispatcher) === null || _React$__SECRET_INTER4 === void 0 ? void 0 : _React$__SECRET_INTER4.current;
44
28
  process.env.NODE_ENV !== "production" ? warning(RenderDispatcher == null || CurrentDispatcher !== RenderDispatcher, 'Relay: `%s` should not be called inside a React render function.', (_options$__nameForWar = options === null || options === void 0 ? void 0 : options.__nameForWarning) !== null && _options$__nameForWar !== void 0 ? _options$__nameForWar : 'loadQuery') : void 0;
45
-
46
- // Every time you call loadQuery, we will generate a new fetchKey.
47
- // This will ensure that every query reference that is created and
48
- // passed to usePreloadedQuery is independently evaluated,
49
- // even if they are for the same query/variables.
50
- // Specifically, we want to avoid a case where we try to refetch a
51
- // query by calling loadQuery a second time, and have the Suspense
52
- // cache in usePreloadedQuery reuse the cached result instead of
53
- // re-evaluating the new query ref and triggering a refetch if
54
- // necessary.
55
29
  fetchKey++;
56
30
  var fetchPolicy = (_options$fetchPolicy = options === null || options === void 0 ? void 0 : options.fetchPolicy) !== null && _options$fetchPolicy !== void 0 ? _options$fetchPolicy : 'store-or-network';
57
31
  var networkCacheConfig = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, options === null || options === void 0 ? void 0 : options.networkCacheConfig), {}, {
58
32
  force: true
59
33
  });
60
-
61
- // executeWithNetworkSource will retain and execute an operation
62
- // against the Relay store, given an Observable that would provide
63
- // the network events for the operation.
64
34
  var retainReference;
65
35
  var didExecuteNetworkSource = false;
66
36
  var executeWithNetworkSource = function executeWithNetworkSource(operation, networkObservable) {
@@ -70,53 +40,18 @@ function loadQuery(environment, preloadableRequest, variables, options, environm
70
40
  source: networkObservable
71
41
  });
72
42
  };
73
-
74
- // N.B. For loadQuery, we unconventionally want to return an Observable
75
- // that isn't lazily executed, meaning that we don't want to wait
76
- // until the returned Observable is subscribed to to actually start
77
- // fetching and executing an operation; i.e. we want to execute the
78
- // operation eagerly, when loadQuery is called.
79
- // For this reason, we use an intermediate executionSubject which
80
- // allows us to capture the events that occur during the eager execution
81
- // of the operation, and then replay them to the Observable we
82
- // ultimately return.
83
43
  var executionSubject = new ReplaySubject();
84
44
  var returnedObservable = Observable.create(function (sink) {
85
45
  return executionSubject.subscribe(sink);
86
46
  });
87
47
  var unsubscribeFromNetworkRequest;
88
48
  var networkError = null;
89
- // makeNetworkRequest will immediately start a raw network request if
90
- // one isn't already in flight and return an Observable that when
91
- // subscribed to will replay the network events that have occured so far,
92
- // as well as subsequent events.
93
49
  var didMakeNetworkRequest = false;
94
50
  var makeNetworkRequest = function makeNetworkRequest(params) {
95
- // N.B. this function is called synchronously or not at all
96
- // didMakeNetworkRequest is safe to rely on in the returned value
97
- // Even if the request gets deduped below, we still wan't to return an
98
- // observable that provides the replayed network events for the query,
99
- // so we set this to true before deduping, to guarantee that the
100
- // `source` observable is returned.
101
51
  didMakeNetworkRequest = true;
102
52
  var observable;
103
53
  var subject = new ReplaySubject();
104
54
  if (RelayFeatureFlags.ENABLE_LOAD_QUERY_REQUEST_DEDUPING === true) {
105
- // Here, we are calling fetchQueryDeduped at the network layer level,
106
- // which ensures that only a single network request is active for a given
107
- // (environment, identifier) pair.
108
- // Since network requests can be started /before/ we have the query ast
109
- // necessary to process the results, we need to dedupe the raw requests
110
- // separately from deduping the operation execution; specifically,
111
- // if `loadQuery` is called multiple times before the query ast is available,
112
- // we still want the network request to be deduped.
113
- // - If a duplicate active network request is found, it will return an
114
- // Observable that replays the events of the already active request.
115
- // - If no duplicate active network request is found, it will call the fetchFn
116
- // to start the request, and return an Observable that will replay
117
- // the events from the network request.
118
- // We provide an extra key to the identifier to distinguish deduping
119
- // of raw network requests vs deduping of operation executions.
120
55
  var identifier = 'raw-network-request-' + getRequestIdentifier(params, variables);
121
56
  observable = fetchQueryDeduped(environment, identifier, function () {
122
57
  var network = environment.getNetwork();
@@ -151,31 +86,8 @@ function loadQuery(environment, preloadableRequest, variables, options, environm
151
86
  var unsubscribeFromExecution;
152
87
  var executeDeduped = function executeDeduped(operation, fetchFn) {
153
88
  if (RelayFeatureFlags.ENABLE_LOAD_QUERY_REQUEST_DEDUPING === true) {
154
- // N.B. at this point, if we're calling execute with a query ast (OperationDescriptor),
155
- // we are guaranteed to have started a network request. We set this to
156
- // true here as well since `makeNetworkRequest` might get skipped in the case
157
- // where the query ast is already available and the query executions get deduped.
158
- // Even if the execution gets deduped below, we still wan't to return
159
- // an observable that provides the replayed network events for the query,
160
- // so we set this to true before deduping, to guarantee that the `source`
161
- // observable is returned.
162
89
  didMakeNetworkRequest = true;
163
90
  }
164
-
165
- // Here, we are calling fetchQueryDeduped, which ensures that only
166
- // a single operation is active for a given (environment, identifier) pair,
167
- // and also tracks the active state of the operation, which is necessary
168
- // for our Suspense infra to later be able to suspend (or not) on
169
- // active operations. Even though we already dedupe raw network requests,
170
- // we also need to dedupe and keep track operation execution for our Suspense
171
- // infra, and we also want to avoid processing responses more than once, for
172
- // the cases where `loadQuery` might be called multiple times after the query ast
173
- // is available.
174
- // - If a duplicate active operation is found, it will return an
175
- // Observable that replays the events of the already active operation.
176
- // - If no duplicate active operation is found, it will call the fetchFn
177
- // to execute the operation, and return an Observable that will provide
178
- // the events for executing the operation.
179
91
  var _fetchQueryDeduped$su = fetchQueryDeduped(environment, operation.request.identifier, fetchFn).subscribe({
180
92
  error: function error(err) {
181
93
  executionSubject.error(err);
@@ -195,15 +107,9 @@ function loadQuery(environment, preloadableRequest, variables, options, environm
195
107
  if (fetchPolicy === 'store-only') {
196
108
  return;
197
109
  }
198
-
199
- // N.B. If the fetch policy allows fulfillment from the store but the
200
- // environment already has the data for that operation cached in the store,
201
- // then we do nothing.
202
110
  var shouldFetch = fetchPolicy !== 'store-or-network' || environment.check(operation).status !== 'available';
203
111
  if (shouldFetch) {
204
112
  executeDeduped(operation, function () {
205
- // N.B. Since we have the operation synchronously available here,
206
- // we can immediately fetch and execute the operation.
207
113
  var networkObservable = makeNetworkRequest(concreteRequest.params);
208
114
  var executeObservable = executeWithNetworkSource(operation, networkObservable);
209
115
  return executeObservable;
@@ -223,15 +129,7 @@ function loadQuery(environment, preloadableRequest, variables, options, environm
223
129
  if (_module != null) {
224
130
  checkAvailabilityAndExecute(_module);
225
131
  } else {
226
- // If the module isn't synchronously available, we launch the
227
- // network request immediately if the fetchPolicy might produce
228
- // a network fetch, regardless of the state of the store cache. We
229
- // do this because we can't check if a query is cached without the
230
- // ast, and we know that if we don't have the query ast
231
- // available, then this query could've never been written to the
232
- // store in the first place, so it couldn't have been cached.
233
132
  var networkObservable = fetchPolicy === 'store-only' ? null : makeNetworkRequest(params);
234
- // $FlowFixMe[method-unbinding] added when improving typing for this parameters
235
133
  var _PreloadableQueryRegi = PreloadableQueryRegistry.onLoad(queryId, function (preloadedModule) {
236
134
  cancelOnLoadCallback();
237
135
  var operation = createOperationDescriptor(preloadedModule, variables, networkCacheConfig);
@@ -289,11 +187,9 @@ function loadQuery(environment, preloadableRequest, variables, options, environm
289
187
  cancelNetworkRequest: cancelNetworkRequest,
290
188
  fetchKey: fetchKey,
291
189
  id: queryId,
292
- // $FlowFixMe[unsafe-getters-setters] - this has no side effects
293
190
  get isDisposed() {
294
191
  return isDisposed || isReleased;
295
192
  },
296
- // $FlowFixMe[unsafe-getters-setters] - this has no side effects
297
193
  get networkError() {
298
194
  return networkError;
299
195
  },