react-relay 16.2.0 → 18.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (93) hide show
  1. package/ReactRelayContainerUtils.js.flow +2 -2
  2. package/ReactRelayContext.js +1 -1
  3. package/ReactRelayContext.js.flow +1 -1
  4. package/ReactRelayFragmentContainer.js.flow +10 -8
  5. package/ReactRelayLocalQueryRenderer.js.flow +4 -1
  6. package/ReactRelayPaginationContainer.js.flow +4 -2
  7. package/ReactRelayQueryRenderer.js.flow +2 -2
  8. package/ReactRelayQueryRendererContext.js.flow +1 -1
  9. package/ReactRelayRefetchContainer.js.flow +2 -2
  10. package/ReactRelayTypes.js.flow +45 -18
  11. package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +2 -2
  12. package/buildReactRelayContainer.js.flow +10 -8
  13. package/getRootVariablesForFragments.js.flow +1 -0
  14. package/hooks.js +1 -1
  15. package/index.js +1 -1
  16. package/legacy.js +1 -1
  17. package/lib/ReactRelayFragmentContainer.js +2 -2
  18. package/lib/buildReactRelayContainer.js +3 -3
  19. package/lib/relay-hooks/legacy/FragmentResource.js +14 -16
  20. package/lib/relay-hooks/loadEntryPoint.js +8 -5
  21. package/lib/relay-hooks/loadQuery.js +2 -14
  22. package/lib/relay-hooks/{experimental/readFragmentInternal_EXPERIMENTAL.js → readFragmentInternal.js} +7 -5
  23. package/lib/relay-hooks/useEntryPointLoader.js +5 -8
  24. package/lib/relay-hooks/useFragment.js +7 -20
  25. package/lib/relay-hooks/useFragmentInternal.js +13 -0
  26. package/lib/relay-hooks/{experimental/useFragmentInternal_EXPERIMENTAL.js → useFragmentInternal_CURRENT.js} +12 -18
  27. package/lib/relay-hooks/useFragmentInternal_EXPERIMENTAL.js +520 -0
  28. package/lib/relay-hooks/useLazyLoadQuery.js +2 -5
  29. package/lib/relay-hooks/useLazyLoadQueryNode.js +2 -13
  30. package/lib/relay-hooks/usePaginationFragment.js +17 -13
  31. package/lib/relay-hooks/usePreloadedQuery.js +6 -9
  32. package/lib/relay-hooks/useQueryLoader.js +1 -3
  33. package/lib/relay-hooks/useRefetchableFragment.js +3 -12
  34. package/lib/relay-hooks/{experimental/useRefetchableFragmentInternal_EXPERIMENTAL.js → useRefetchableFragmentInternal.js} +7 -7
  35. package/multi-actor/ActorChange.js.flow +1 -1
  36. package/multi-actor/useRelayActorEnvironment.js.flow +1 -1
  37. package/package.json +3 -3
  38. package/react-relay-hooks.js +2 -2
  39. package/react-relay-hooks.min.js +2 -2
  40. package/react-relay-legacy.js +2 -2
  41. package/react-relay-legacy.min.js +2 -2
  42. package/react-relay.js +2 -2
  43. package/react-relay.min.js +2 -2
  44. package/relay-hooks/EntryPointTypes.flow.js.flow +49 -25
  45. package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +22 -5
  46. package/relay-hooks/MatchContainer.js.flow +1 -1
  47. package/relay-hooks/ProfilerContext.js.flow +1 -1
  48. package/relay-hooks/__flowtests__/EntryPointTypes/ExtractQueryTypes-flowtest.js.flow +43 -0
  49. package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +21 -0
  50. package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +19 -0
  51. package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +22 -0
  52. package/relay-hooks/legacy/FragmentResource.js.flow +13 -16
  53. package/relay-hooks/legacy/useBlockingPaginationFragment.js.flow +2 -2
  54. package/relay-hooks/legacy/useFragmentNode.js.flow +1 -1
  55. package/relay-hooks/legacy/useRefetchableFragmentNode.js.flow +2 -2
  56. package/relay-hooks/loadEntryPoint.js.flow +10 -4
  57. package/relay-hooks/loadQuery.js.flow +10 -33
  58. package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +4 -1
  59. package/relay-hooks/{experimental/readFragmentInternal_EXPERIMENTAL.js.flow → readFragmentInternal.js.flow} +6 -4
  60. package/relay-hooks/useClientQuery.js.flow +1 -1
  61. package/relay-hooks/useEntryPointLoader.js.flow +4 -5
  62. package/relay-hooks/useFetchTrackingRef.js.flow +1 -1
  63. package/relay-hooks/useFragment.js.flow +8 -25
  64. package/relay-hooks/useFragmentInternal.js.flow +45 -0
  65. package/relay-hooks/{experimental/useFragmentInternal_EXPERIMENTAL.js.flow → useFragmentInternal_CURRENT.js.flow} +14 -5
  66. package/relay-hooks/useFragmentInternal_EXPERIMENTAL.js.flow +764 -0
  67. package/relay-hooks/useIsMountedRef.js.flow +1 -1
  68. package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
  69. package/relay-hooks/useIsParentQueryActive.js.flow +5 -2
  70. package/relay-hooks/useLazyLoadQuery.js.flow +3 -7
  71. package/relay-hooks/useLazyLoadQueryNode.js.flow +3 -19
  72. package/relay-hooks/useLoadMoreFunction.js.flow +1 -1
  73. package/relay-hooks/useMemoOperationDescriptor.js.flow +1 -1
  74. package/relay-hooks/useMemoVariables.js.flow +1 -1
  75. package/relay-hooks/useMutation.js.flow +1 -1
  76. package/relay-hooks/usePaginationFragment.js.flow +62 -50
  77. package/relay-hooks/usePreloadedQuery.js.flow +2 -6
  78. package/relay-hooks/useQueryLoader.js.flow +3 -7
  79. package/relay-hooks/useRefetchableFragment.js.flow +7 -37
  80. package/relay-hooks/{experimental/useRefetchableFragmentInternal_EXPERIMENTAL.js.flow → useRefetchableFragmentInternal.js.flow} +11 -11
  81. package/relay-hooks/useRelayEnvironment.js.flow +1 -1
  82. package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -1
  83. package/relay-hooks/useSubscribeToInvalidationState.js.flow +1 -1
  84. package/relay-hooks/useSubscription.js.flow +1 -1
  85. package/relay-hooks/useUnsafeRef_DEPRECATED.js.flow +1 -1
  86. package/lib/relay-hooks/HooksImplementation.js +0 -15
  87. package/lib/relay-hooks/experimental/useFragment_EXPERIMENTAL.js +0 -26
  88. package/lib/relay-hooks/experimental/usePaginationFragment_EXPERIMENTAL.js +0 -127
  89. package/lib/relay-hooks/experimental/useRefetchableFragment_EXPERIMENTAL.js +0 -23
  90. package/relay-hooks/HooksImplementation.js.flow +0 -45
  91. package/relay-hooks/experimental/useFragment_EXPERIMENTAL.js.flow +0 -72
  92. package/relay-hooks/experimental/usePaginationFragment_EXPERIMENTAL.js.flow +0 -161
  93. package/relay-hooks/experimental/useRefetchableFragment_EXPERIMENTAL.js.flow +0 -49
@@ -0,0 +1,13 @@
1
+ 'use strict';
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
4
+ var _useFragmentInternal_CURRENT = _interopRequireDefault(require("./useFragmentInternal_CURRENT"));
5
+ var _useFragmentInternal_EXPERIMENTAL = _interopRequireDefault(require("./useFragmentInternal_EXPERIMENTAL"));
6
+ var _relayRuntime = require("relay-runtime");
7
+ function useFragmentInternal(fragmentNode, fragmentRef, hookDisplayName, queryOptions) {
8
+ if (_relayRuntime.RelayFeatureFlags.ENABLE_USE_FRAGMENT_EXPERIMENTAL) {
9
+ return (0, _useFragmentInternal_EXPERIMENTAL["default"])(fragmentNode, fragmentRef, hookDisplayName, queryOptions);
10
+ }
11
+ return (0, _useFragmentInternal_CURRENT["default"])(fragmentNode, fragmentRef, hookDisplayName, queryOptions);
12
+ }
13
+ module.exports = useFragmentInternal;
@@ -4,9 +4,9 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
4
4
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
5
5
  var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
6
6
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
7
- var _require = require('../QueryResource'),
7
+ var _require = require('./QueryResource'),
8
8
  getQueryResourceForEnvironment = _require.getQueryResourceForEnvironment;
9
- var useRelayEnvironment = require('../useRelayEnvironment');
9
+ var useRelayEnvironment = require('./useRelayEnvironment');
10
10
  var invariant = require('invariant');
11
11
  var _require2 = require('react'),
12
12
  useDebugValue = _require2.useDebugValue,
@@ -116,14 +116,16 @@ function getSuspendingLiveResolver(state) {
116
116
  }
117
117
  function handlePotentialSnapshotErrorsForState(environment, state) {
118
118
  if (state.kind === 'singular') {
119
- handlePotentialSnapshotErrors(environment, state.snapshot.missingRequiredFields, state.snapshot.relayResolverErrors, state.snapshot.errorResponseFields);
119
+ var _state$snapshot$selec, _state$snapshot$selec2;
120
+ handlePotentialSnapshotErrors(environment, state.snapshot.missingRequiredFields, state.snapshot.relayResolverErrors, state.snapshot.errorResponseFields, (_state$snapshot$selec = (_state$snapshot$selec2 = state.snapshot.selector.node.metadata) === null || _state$snapshot$selec2 === void 0 ? void 0 : _state$snapshot$selec2.throwOnFieldError) !== null && _state$snapshot$selec !== void 0 ? _state$snapshot$selec : false);
120
121
  } else if (state.kind === 'plural') {
121
122
  var _iterator5 = (0, _createForOfIteratorHelper2["default"])(state.snapshots),
122
123
  _step5;
123
124
  try {
124
125
  for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
126
+ var _snapshot$selector$no, _snapshot$selector$no2;
125
127
  var snapshot = _step5.value;
126
- handlePotentialSnapshotErrors(environment, snapshot.missingRequiredFields, snapshot.relayResolverErrors, snapshot.errorResponseFields);
128
+ handlePotentialSnapshotErrors(environment, snapshot.missingRequiredFields, snapshot.relayResolverErrors, snapshot.errorResponseFields, (_snapshot$selector$no = (_snapshot$selector$no2 = snapshot.selector.node.metadata) === null || _snapshot$selector$no2 === void 0 ? void 0 : _snapshot$selector$no2.throwOnFieldError) !== null && _snapshot$selector$no !== void 0 ? _snapshot$selector$no : false);
127
129
  }
128
130
  } catch (err) {
129
131
  _iterator5.e(err);
@@ -300,7 +302,7 @@ function getFragmentState(environment, fragmentSelector) {
300
302
  };
301
303
  }
302
304
  }
303
- function useFragmentInternal_EXPERIMENTAL(fragmentNode, fragmentRef, hookDisplayName, queryOptions) {
305
+ function useFragmentInternal(fragmentNode, fragmentRef, hookDisplayName, queryOptions) {
304
306
  var _fragmentNode$metadat, _fragmentNode$metadat2;
305
307
  var fragmentSelector = useMemo(function () {
306
308
  return getSelector(fragmentNode, fragmentRef);
@@ -392,17 +394,9 @@ function useFragmentInternal_EXPERIMENTAL(fragmentNode, fragmentRef, hookDisplay
392
394
  _iterator8.f();
393
395
  }
394
396
  return function () {
395
- var _iterator9 = (0, _createForOfIteratorHelper2["default"])(disposables),
396
- _step9;
397
- try {
398
- for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
399
- var disposable = _step9.value;
400
- disposable.dispose();
401
- }
402
- } catch (err) {
403
- _iterator9.e(err);
404
- } finally {
405
- _iterator9.f();
397
+ for (var _i = 0, _disposables = disposables; _i < _disposables.length; _i++) {
398
+ var disposable = _disposables[_i];
399
+ disposable.dispose();
406
400
  }
407
401
  };
408
402
  }
@@ -416,7 +410,7 @@ function useFragmentInternal_EXPERIMENTAL(fragmentNode, fragmentRef, hookDisplay
416
410
  return environment.getStore().getLiveResolverPromise(liveStateID);
417
411
  }));
418
412
  }
419
- if (environment !== previousEnvironment || !committedFragmentSelectorRef.current || !areEqualSelectors(committedFragmentSelectorRef.current, fragmentSelector)) {
413
+ if (RelayFeatureFlags.ENABLE_RELAY_OPERATION_TRACKER_SUSPENSE || environment !== previousEnvironment || !committedFragmentSelectorRef.current || !areEqualSelectors(committedFragmentSelectorRef.current, fragmentSelector)) {
420
414
  !(fragmentSelector != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'refinement, see invariants above') : invariant(false) : void 0;
421
415
  var fragmentOwner = fragmentSelector.kind === 'PluralReaderSelector' ? fragmentSelector.selectors[0].owner : fragmentSelector.owner;
422
416
  var pendingOperationsResult = getPendingOperationsForFragment(environment, fragmentNode, fragmentOwner);
@@ -486,4 +480,4 @@ function useFragmentInternal_EXPERIMENTAL(fragmentNode, fragmentRef, hookDisplay
486
480
  }
487
481
  return data;
488
482
  }
489
- module.exports = useFragmentInternal_EXPERIMENTAL;
483
+ module.exports = useFragmentInternal;
@@ -0,0 +1,520 @@
1
+ 'use strict';
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
4
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
5
+ var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
6
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
7
+ var _require = require('./QueryResource'),
8
+ getQueryResourceForEnvironment = _require.getQueryResourceForEnvironment;
9
+ var useRelayEnvironment = require('./useRelayEnvironment');
10
+ var invariant = require('invariant');
11
+ var _require2 = require('react'),
12
+ useDebugValue = _require2.useDebugValue,
13
+ useEffect = _require2.useEffect,
14
+ useMemo = _require2.useMemo,
15
+ useRef = _require2.useRef,
16
+ useState = _require2.useState;
17
+ var _require3 = require('relay-runtime'),
18
+ _require3$__internal = _require3.__internal,
19
+ fetchQueryInternal = _require3$__internal.fetchQuery,
20
+ getPromiseForActiveRequest = _require3$__internal.getPromiseForActiveRequest,
21
+ RelayFeatureFlags = _require3.RelayFeatureFlags,
22
+ areEqualSelectors = _require3.areEqualSelectors,
23
+ createOperationDescriptor = _require3.createOperationDescriptor,
24
+ getPendingOperationsForFragment = _require3.getPendingOperationsForFragment,
25
+ getSelector = _require3.getSelector,
26
+ getVariablesFromFragment = _require3.getVariablesFromFragment,
27
+ handlePotentialSnapshotErrors = _require3.handlePotentialSnapshotErrors,
28
+ recycleNodesInto = _require3.recycleNodesInto;
29
+ var warning = require("fbjs/lib/warning");
30
+ function isMissingData(state) {
31
+ if (state.kind === 'bailout') {
32
+ return false;
33
+ } else if (state.kind === 'singular') {
34
+ return state.snapshot.isMissingData;
35
+ } else {
36
+ return state.snapshots.some(function (s) {
37
+ return s.isMissingData;
38
+ });
39
+ }
40
+ }
41
+ function getMissingClientEdges(state) {
42
+ if (state.kind === 'bailout') {
43
+ return null;
44
+ } else if (state.kind === 'singular') {
45
+ var _state$snapshot$missi;
46
+ return (_state$snapshot$missi = state.snapshot.missingClientEdges) !== null && _state$snapshot$missi !== void 0 ? _state$snapshot$missi : null;
47
+ } else {
48
+ var edges = null;
49
+ var _iterator = (0, _createForOfIteratorHelper2["default"])(state.snapshots),
50
+ _step;
51
+ try {
52
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
53
+ var snapshot = _step.value;
54
+ if (snapshot.missingClientEdges) {
55
+ var _edges;
56
+ edges = (_edges = edges) !== null && _edges !== void 0 ? _edges : [];
57
+ var _iterator2 = (0, _createForOfIteratorHelper2["default"])(snapshot.missingClientEdges),
58
+ _step2;
59
+ try {
60
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
61
+ var edge = _step2.value;
62
+ edges.push(edge);
63
+ }
64
+ } catch (err) {
65
+ _iterator2.e(err);
66
+ } finally {
67
+ _iterator2.f();
68
+ }
69
+ }
70
+ }
71
+ } catch (err) {
72
+ _iterator.e(err);
73
+ } finally {
74
+ _iterator.f();
75
+ }
76
+ return edges;
77
+ }
78
+ }
79
+ function getSuspendingLiveResolver(state) {
80
+ if (state.kind === 'bailout') {
81
+ return null;
82
+ } else if (state.kind === 'singular') {
83
+ var _state$snapshot$missi2;
84
+ return (_state$snapshot$missi2 = state.snapshot.missingLiveResolverFields) !== null && _state$snapshot$missi2 !== void 0 ? _state$snapshot$missi2 : null;
85
+ } else {
86
+ var missingFields = null;
87
+ var _iterator3 = (0, _createForOfIteratorHelper2["default"])(state.snapshots),
88
+ _step3;
89
+ try {
90
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
91
+ var snapshot = _step3.value;
92
+ if (snapshot.missingLiveResolverFields) {
93
+ var _missingFields;
94
+ missingFields = (_missingFields = missingFields) !== null && _missingFields !== void 0 ? _missingFields : [];
95
+ var _iterator4 = (0, _createForOfIteratorHelper2["default"])(snapshot.missingLiveResolverFields),
96
+ _step4;
97
+ try {
98
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
99
+ var edge = _step4.value;
100
+ missingFields.push(edge);
101
+ }
102
+ } catch (err) {
103
+ _iterator4.e(err);
104
+ } finally {
105
+ _iterator4.f();
106
+ }
107
+ }
108
+ }
109
+ } catch (err) {
110
+ _iterator3.e(err);
111
+ } finally {
112
+ _iterator3.f();
113
+ }
114
+ return missingFields;
115
+ }
116
+ }
117
+ function handlePotentialSnapshotErrorsForState(environment, state) {
118
+ if (state.kind === 'singular') {
119
+ var _state$snapshot$selec, _state$snapshot$selec2;
120
+ handlePotentialSnapshotErrors(environment, state.snapshot.missingRequiredFields, state.snapshot.relayResolverErrors, state.snapshot.errorResponseFields, (_state$snapshot$selec = (_state$snapshot$selec2 = state.snapshot.selector.node.metadata) === null || _state$snapshot$selec2 === void 0 ? void 0 : _state$snapshot$selec2.throwOnFieldError) !== null && _state$snapshot$selec !== void 0 ? _state$snapshot$selec : false);
121
+ } else if (state.kind === 'plural') {
122
+ var _iterator5 = (0, _createForOfIteratorHelper2["default"])(state.snapshots),
123
+ _step5;
124
+ try {
125
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
126
+ var _snapshot$selector$no, _snapshot$selector$no2;
127
+ var snapshot = _step5.value;
128
+ handlePotentialSnapshotErrors(environment, snapshot.missingRequiredFields, snapshot.relayResolverErrors, snapshot.errorResponseFields, (_snapshot$selector$no = (_snapshot$selector$no2 = snapshot.selector.node.metadata) === null || _snapshot$selector$no2 === void 0 ? void 0 : _snapshot$selector$no2.throwOnFieldError) !== null && _snapshot$selector$no !== void 0 ? _snapshot$selector$no : false);
129
+ }
130
+ } catch (err) {
131
+ _iterator5.e(err);
132
+ } finally {
133
+ _iterator5.f();
134
+ }
135
+ }
136
+ }
137
+ function handleMissedUpdates(environment, state) {
138
+ if (state.kind === 'bailout') {
139
+ return null;
140
+ }
141
+ var currentEpoch = environment.getStore().getEpoch();
142
+ if (currentEpoch === state.epoch) {
143
+ return null;
144
+ }
145
+ if (state.kind === 'singular') {
146
+ var currentSnapshot = environment.lookup(state.snapshot.selector);
147
+ var updatedData = recycleNodesInto(state.snapshot.data, currentSnapshot.data);
148
+ var updatedCurrentSnapshot = {
149
+ data: updatedData,
150
+ isMissingData: currentSnapshot.isMissingData,
151
+ missingClientEdges: currentSnapshot.missingClientEdges,
152
+ missingLiveResolverFields: currentSnapshot.missingLiveResolverFields,
153
+ seenRecords: currentSnapshot.seenRecords,
154
+ selector: currentSnapshot.selector,
155
+ missingRequiredFields: currentSnapshot.missingRequiredFields,
156
+ relayResolverErrors: currentSnapshot.relayResolverErrors,
157
+ errorResponseFields: currentSnapshot.errorResponseFields
158
+ };
159
+ return [updatedData !== state.snapshot.data, {
160
+ kind: 'singular',
161
+ snapshot: updatedCurrentSnapshot,
162
+ epoch: currentEpoch,
163
+ selector: state.selector,
164
+ environment: state.environment
165
+ }];
166
+ } else {
167
+ var didMissUpdates = false;
168
+ var currentSnapshots = [];
169
+ for (var index = 0; index < state.snapshots.length; index++) {
170
+ var snapshot = state.snapshots[index];
171
+ var _currentSnapshot = environment.lookup(snapshot.selector);
172
+ var _updatedData = recycleNodesInto(snapshot.data, _currentSnapshot.data);
173
+ var _updatedCurrentSnapshot = {
174
+ data: _updatedData,
175
+ isMissingData: _currentSnapshot.isMissingData,
176
+ missingClientEdges: _currentSnapshot.missingClientEdges,
177
+ missingLiveResolverFields: _currentSnapshot.missingLiveResolverFields,
178
+ seenRecords: _currentSnapshot.seenRecords,
179
+ selector: _currentSnapshot.selector,
180
+ missingRequiredFields: _currentSnapshot.missingRequiredFields,
181
+ relayResolverErrors: _currentSnapshot.relayResolverErrors,
182
+ errorResponseFields: _currentSnapshot.errorResponseFields
183
+ };
184
+ if (_updatedData !== snapshot.data) {
185
+ didMissUpdates = true;
186
+ }
187
+ currentSnapshots.push(_updatedCurrentSnapshot);
188
+ }
189
+ !(currentSnapshots.length === state.snapshots.length) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Expected same number of snapshots') : invariant(false) : void 0;
190
+ return [didMissUpdates, {
191
+ kind: 'plural',
192
+ snapshots: currentSnapshots,
193
+ epoch: currentEpoch,
194
+ selector: state.selector,
195
+ environment: state.environment
196
+ }];
197
+ }
198
+ }
199
+ function handleMissingClientEdge(environment, parentFragmentNode, parentFragmentRef, missingClientEdgeRequestInfo, queryOptions) {
200
+ var originalVariables = getVariablesFromFragment(parentFragmentNode, parentFragmentRef);
201
+ var variables = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, originalVariables), {}, {
202
+ id: missingClientEdgeRequestInfo.clientEdgeDestinationID
203
+ });
204
+ var queryOperationDescriptor = createOperationDescriptor(missingClientEdgeRequestInfo.request, variables, queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.networkCacheConfig);
205
+ var QueryResource = getQueryResourceForEnvironment(environment);
206
+ var queryResult = QueryResource.prepare(queryOperationDescriptor, fetchQueryInternal(environment, queryOperationDescriptor), queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.fetchPolicy);
207
+ return [queryResult, getPromiseForActiveRequest(environment, queryOperationDescriptor.request)];
208
+ }
209
+ function subscribeToSnapshot(environment, state, setState, pendingStateRef) {
210
+ if (state.kind === 'bailout') {
211
+ return function () {};
212
+ } else if (state.kind === 'singular') {
213
+ var disposable = environment.subscribe(state.snapshot, function (latestSnapshot) {
214
+ setState(function (prevState) {
215
+ var nextState = null;
216
+ if (prevState.kind !== 'singular' || prevState.snapshot.selector !== latestSnapshot.selector || prevState.environment !== environment) {
217
+ var updates = handleMissedUpdates(prevState.environment, prevState);
218
+ if (updates != null) {
219
+ var dataChanged = updates[0],
220
+ updatedState = updates[1];
221
+ environment.__log({
222
+ name: 'useFragment.subscription.missedUpdates',
223
+ hasDataChanges: dataChanged
224
+ });
225
+ nextState = dataChanged ? updatedState : prevState;
226
+ } else {
227
+ nextState = prevState;
228
+ }
229
+ } else {
230
+ nextState = {
231
+ kind: 'singular',
232
+ snapshot: latestSnapshot,
233
+ epoch: environment.getStore().getEpoch(),
234
+ selector: state.selector,
235
+ environment: state.environment
236
+ };
237
+ }
238
+ pendingStateRef.current = nextState.kind === 'singular' ? nextState.epoch : null;
239
+ return nextState;
240
+ });
241
+ });
242
+ return function () {
243
+ disposable.dispose();
244
+ };
245
+ } else {
246
+ var disposables = state.snapshots.map(function (snapshot, index) {
247
+ return environment.subscribe(snapshot, function (latestSnapshot) {
248
+ setState(function (prevState) {
249
+ var _prevState$snapshots$;
250
+ var nextState = null;
251
+ if (prevState.kind !== 'plural' || ((_prevState$snapshots$ = prevState.snapshots[index]) === null || _prevState$snapshots$ === void 0 ? void 0 : _prevState$snapshots$.selector) !== latestSnapshot.selector || prevState.environment !== environment) {
252
+ var updates = handleMissedUpdates(prevState.environment, prevState);
253
+ if (updates != null) {
254
+ var dataChanged = updates[0],
255
+ updatedState = updates[1];
256
+ environment.__log({
257
+ name: 'useFragment.subscription.missedUpdates',
258
+ hasDataChanges: dataChanged
259
+ });
260
+ nextState = dataChanged ? updatedState : prevState;
261
+ } else {
262
+ nextState = prevState;
263
+ }
264
+ } else {
265
+ var updated = (0, _toConsumableArray2["default"])(prevState.snapshots);
266
+ updated[index] = latestSnapshot;
267
+ nextState = {
268
+ kind: 'plural',
269
+ snapshots: updated,
270
+ epoch: environment.getStore().getEpoch(),
271
+ selector: state.selector,
272
+ environment: state.environment
273
+ };
274
+ }
275
+ pendingStateRef.current = nextState.kind === 'plural' ? nextState.epoch : null;
276
+ return nextState;
277
+ });
278
+ });
279
+ });
280
+ return function () {
281
+ var _iterator6 = (0, _createForOfIteratorHelper2["default"])(disposables),
282
+ _step6;
283
+ try {
284
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
285
+ var d = _step6.value;
286
+ d.dispose();
287
+ }
288
+ } catch (err) {
289
+ _iterator6.e(err);
290
+ } finally {
291
+ _iterator6.f();
292
+ }
293
+ };
294
+ }
295
+ }
296
+ function getFragmentState(environment, fragmentSelector) {
297
+ if (fragmentSelector == null) {
298
+ return {
299
+ kind: 'bailout',
300
+ environment: environment
301
+ };
302
+ } else if (fragmentSelector.kind === 'PluralReaderSelector') {
303
+ return {
304
+ kind: 'plural',
305
+ snapshots: fragmentSelector.selectors.map(function (s) {
306
+ return environment.lookup(s);
307
+ }),
308
+ epoch: environment.getStore().getEpoch(),
309
+ selector: fragmentSelector,
310
+ environment: environment
311
+ };
312
+ } else {
313
+ return {
314
+ kind: 'singular',
315
+ snapshot: environment.lookup(fragmentSelector),
316
+ epoch: environment.getStore().getEpoch(),
317
+ selector: fragmentSelector,
318
+ environment: environment
319
+ };
320
+ }
321
+ }
322
+ function useFragmentInternal_EXPERIMENTAL(fragmentNode, fragmentRef, hookDisplayName, queryOptions) {
323
+ var _fragmentNode$metadat, _fragmentNode$metadat2;
324
+ var fragmentSelector = useMemo(function () {
325
+ return getSelector(fragmentNode, fragmentRef);
326
+ }, [fragmentNode, fragmentRef]);
327
+ var isPlural = (fragmentNode === null || fragmentNode === void 0 ? void 0 : (_fragmentNode$metadat = fragmentNode.metadata) === null || _fragmentNode$metadat === void 0 ? void 0 : _fragmentNode$metadat.plural) === true;
328
+ if (isPlural) {
329
+ !(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.', fragmentNode.name, typeof fragmentRef, fragmentNode.name) : invariant(false) : void 0;
330
+ } else {
331
+ !!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.', fragmentNode.name, typeof fragmentRef, fragmentNode.name) : invariant(false) : void 0;
332
+ }
333
+ !(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, hookDisplayName) : invariant(false) : void 0;
334
+ var environment = useRelayEnvironment();
335
+ var _useState = useState(function () {
336
+ return getFragmentState(environment, fragmentSelector);
337
+ }),
338
+ _state = _useState[0],
339
+ setState = _useState[1];
340
+ var state = _state;
341
+ var previousEnvironment = state.environment;
342
+ if (!areEqualSelectors(fragmentSelector, state.selector) || environment !== state.environment) {
343
+ var newState = getFragmentState(environment, fragmentSelector);
344
+ setState(newState);
345
+ state = newState;
346
+ }
347
+ var committedFragmentSelectorRef = useRef(false);
348
+ useEffect(function () {
349
+ committedFragmentSelectorRef.current = fragmentSelector;
350
+ }, [fragmentSelector]);
351
+ if (((_fragmentNode$metadat2 = fragmentNode.metadata) === null || _fragmentNode$metadat2 === void 0 ? void 0 : _fragmentNode$metadat2.hasClientEdges) === true) {
352
+ var _useMemo = useMemo(function () {
353
+ var missingClientEdges = getMissingClientEdges(state);
354
+ var clientEdgeQueries;
355
+ var activeRequestPromises = [];
356
+ if (missingClientEdges !== null && missingClientEdges !== void 0 && missingClientEdges.length) {
357
+ clientEdgeQueries = [];
358
+ var _iterator7 = (0, _createForOfIteratorHelper2["default"])(missingClientEdges),
359
+ _step7;
360
+ try {
361
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
362
+ var edge = _step7.value;
363
+ var _handleMissingClientE = handleMissingClientEdge(environment, fragmentNode, fragmentRef, edge, queryOptions),
364
+ queryResult = _handleMissingClientE[0],
365
+ requestPromise = _handleMissingClientE[1];
366
+ clientEdgeQueries.push(queryResult);
367
+ if (requestPromise != null) {
368
+ activeRequestPromises.push(requestPromise);
369
+ }
370
+ }
371
+ } catch (err) {
372
+ _iterator7.e(err);
373
+ } finally {
374
+ _iterator7.f();
375
+ }
376
+ }
377
+ return [clientEdgeQueries, activeRequestPromises];
378
+ }, [state, environment, fragmentNode, fragmentRef, queryOptions]),
379
+ clientEdgeQueries = _useMemo[0],
380
+ activeRequestPromises = _useMemo[1];
381
+ if (activeRequestPromises.length) {
382
+ throw Promise.all(activeRequestPromises);
383
+ }
384
+ useEffect(function () {
385
+ var QueryResource = getQueryResourceForEnvironment(environment);
386
+ if (clientEdgeQueries !== null && clientEdgeQueries !== void 0 && clientEdgeQueries.length) {
387
+ var disposables = [];
388
+ var _iterator8 = (0, _createForOfIteratorHelper2["default"])(clientEdgeQueries),
389
+ _step8;
390
+ try {
391
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
392
+ var query = _step8.value;
393
+ disposables.push(QueryResource.retain(query));
394
+ }
395
+ } catch (err) {
396
+ _iterator8.e(err);
397
+ } finally {
398
+ _iterator8.f();
399
+ }
400
+ return function () {
401
+ for (var _i = 0, _disposables = disposables; _i < _disposables.length; _i++) {
402
+ var disposable = _disposables[_i];
403
+ disposable.dispose();
404
+ }
405
+ };
406
+ }
407
+ }, [environment, clientEdgeQueries]);
408
+ }
409
+ if (isMissingData(state)) {
410
+ var suspendingLiveResolvers = getSuspendingLiveResolver(state);
411
+ if (suspendingLiveResolvers != null && suspendingLiveResolvers.length > 0) {
412
+ throw Promise.all(suspendingLiveResolvers.map(function (_ref) {
413
+ var liveStateID = _ref.liveStateID;
414
+ return environment.getStore().getLiveResolverPromise(liveStateID);
415
+ }));
416
+ }
417
+ if (RelayFeatureFlags.ENABLE_RELAY_OPERATION_TRACKER_SUSPENSE || environment !== previousEnvironment || !committedFragmentSelectorRef.current || !areEqualSelectors(committedFragmentSelectorRef.current, fragmentSelector)) {
418
+ !(fragmentSelector != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'refinement, see invariants above') : invariant(false) : void 0;
419
+ var fragmentOwner = fragmentSelector.kind === 'PluralReaderSelector' ? fragmentSelector.selectors[0].owner : fragmentSelector.owner;
420
+ var pendingOperationsResult = getPendingOperationsForFragment(environment, fragmentNode, fragmentOwner);
421
+ if (pendingOperationsResult) {
422
+ throw pendingOperationsResult.promise;
423
+ }
424
+ }
425
+ }
426
+ handlePotentialSnapshotErrorsForState(environment, state);
427
+ var pendingStateEpochRef = useRef(null);
428
+ var storeSubscriptionRef = useRef(null);
429
+ useEffect(function () {
430
+ var storeSubscription = storeSubscriptionRef.current;
431
+ if (storeSubscription != null) {
432
+ if (state.environment === storeSubscription.environment && state.selector === storeSubscription.selector) {
433
+ return;
434
+ } else {
435
+ storeSubscription.dispose();
436
+ }
437
+ }
438
+ if (state.kind === 'bailout') {
439
+ return;
440
+ }
441
+ var stateForSubscription = state;
442
+ var updates = handleMissedUpdates(state.environment, state);
443
+ if (updates !== null) {
444
+ var didMissUpdates = updates[0],
445
+ updatedState = updates[1];
446
+ if (didMissUpdates) {
447
+ setState(updatedState);
448
+ return;
449
+ }
450
+ stateForSubscription = updatedState;
451
+ }
452
+ var dispose = subscribeToSnapshot(state.environment, stateForSubscription, setState, pendingStateEpochRef);
453
+ storeSubscriptionRef.current = {
454
+ dispose: dispose,
455
+ selector: state.selector,
456
+ environment: state.environment
457
+ };
458
+ }, [state]);
459
+ useEffect(function () {
460
+ if (storeSubscriptionRef.current == null && state.kind !== 'bailout') {
461
+ var dispose = subscribeToSnapshot(state.environment, state, setState, pendingStateEpochRef);
462
+ storeSubscriptionRef.current = {
463
+ dispose: dispose,
464
+ selector: state.selector,
465
+ environment: state.environment
466
+ };
467
+ }
468
+ return function () {
469
+ var _storeSubscriptionRef;
470
+ (_storeSubscriptionRef = storeSubscriptionRef.current) === null || _storeSubscriptionRef === void 0 ? void 0 : _storeSubscriptionRef.dispose();
471
+ storeSubscriptionRef.current = null;
472
+ };
473
+ }, []);
474
+ if (pendingStateEpochRef.current !== null && pendingStateEpochRef.current !== state.epoch) {
475
+ var updates = handleMissedUpdates(environment, state);
476
+ if (updates != null) {
477
+ var hasStateUpdates = updates[0],
478
+ updatedState = updates[1];
479
+ if (hasStateUpdates) {
480
+ setState(updatedState);
481
+ state = updatedState;
482
+ }
483
+ }
484
+ }
485
+ pendingStateEpochRef.current = null;
486
+ var data;
487
+ if (isPlural) {
488
+ var fragmentRefIsNullish = fragmentRef == null;
489
+ data = useMemo(function () {
490
+ if (state.kind === 'bailout') {
491
+ return fragmentRefIsNullish ? null : [];
492
+ } else {
493
+ !(state.kind === 'plural') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Expected state to be plural because fragment is plural') : invariant(false) : void 0;
494
+ return state.snapshots.map(function (s) {
495
+ return s.data;
496
+ });
497
+ }
498
+ }, [state, fragmentRefIsNullish]);
499
+ } else if (state.kind === 'bailout') {
500
+ data = null;
501
+ } else {
502
+ !(state.kind === 'singular') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Expected state to be singular because fragment is singular') : invariant(false) : void 0;
503
+ data = state.snapshot.data;
504
+ }
505
+ if (RelayFeatureFlags.LOG_MISSING_RECORDS_IN_PROD || process.env.NODE_ENV !== "production") {
506
+ if (fragmentRef != null && (data === undefined || Array.isArray(data) && data.length > 0 && data.every(function (d) {
507
+ return d === undefined;
508
+ }))) {
509
+ 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;
510
+ }
511
+ }
512
+ if (process.env.NODE_ENV !== "production") {
513
+ useDebugValue({
514
+ fragment: fragmentNode.name,
515
+ data: data
516
+ });
517
+ }
518
+ return data;
519
+ }
520
+ module.exports = useFragmentInternal_EXPERIMENTAL;
@@ -1,14 +1,11 @@
1
1
  'use strict';
2
2
 
3
- var _require = require('./loadQuery'),
4
- useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
5
3
  var useLazyLoadQueryNode = require('./useLazyLoadQueryNode');
6
4
  var useMemoOperationDescriptor = require('./useMemoOperationDescriptor');
7
5
  var useRelayEnvironment = require('./useRelayEnvironment');
8
- var _require2 = require('relay-runtime'),
9
- fetchQuery = _require2.__internal.fetchQuery;
6
+ var _require = require('relay-runtime'),
7
+ fetchQuery = _require.__internal.fetchQuery;
10
8
  function useLazyLoadQuery(gqlQuery, variables, options) {
11
- useTrackLoadQueryInRender();
12
9
  var environment = useRelayEnvironment();
13
10
  var query = useMemoOperationDescriptor(gqlQuery, variables, options && options.networkCacheConfig ? options.networkCacheConfig : {
14
11
  force: true
@@ -1,12 +1,11 @@
1
1
  'use strict';
2
2
 
3
- var HooksImplementation = require('./HooksImplementation');
4
- var useFragmentNode = require('./legacy/useFragmentNode');
5
3
  var ProfilerContext = require('./ProfilerContext');
6
4
  var _require = require('./QueryResource'),
7
5
  getQueryCacheIdentifier = _require.getQueryCacheIdentifier,
8
6
  getQueryResourceForEnvironment = _require.getQueryResourceForEnvironment;
9
7
  var useFetchTrackingRef = require('./useFetchTrackingRef');
8
+ var useFragmentInternal = require('./useFragmentInternal');
10
9
  var useRelayEnvironment = require('./useRelayEnvironment');
11
10
  var React = require('react');
12
11
  var useContext = React.useContext,
@@ -62,17 +61,7 @@ function useLazyLoadQueryNode(_ref) {
62
61
  });
63
62
  var fragmentNode = preparedQueryResult.fragmentNode,
64
63
  fragmentRef = preparedQueryResult.fragmentRef;
65
- var data = useFragmentNodeImpl(fragmentNode, fragmentRef, componentDisplayName);
64
+ var data = useFragmentInternal(fragmentNode, fragmentRef, componentDisplayName);
66
65
  return data;
67
66
  }
68
- function useFragmentNodeImpl(fragment, key, componentDisplayName) {
69
- var impl = HooksImplementation.get();
70
- if (impl && impl.useFragment__internal) {
71
- return impl.useFragment__internal(fragment, key, componentDisplayName);
72
- } else {
73
- var _useFragmentNode = useFragmentNode(fragment, key, componentDisplayName),
74
- data = _useFragmentNode.data;
75
- return data;
76
- }
77
- }
78
67
  module.exports = useLazyLoadQueryNode;