react-relay 17.0.0 → 18.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) 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 +2 -2
  5. package/ReactRelayPaginationContainer.js.flow +2 -2
  6. package/ReactRelayQueryRenderer.js.flow +1 -1
  7. package/ReactRelayQueryRendererContext.js.flow +1 -1
  8. package/ReactRelayRefetchContainer.js.flow +2 -2
  9. package/ReactRelayTypes.js.flow +45 -18
  10. package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +2 -2
  11. package/buildReactRelayContainer.js.flow +6 -5
  12. package/hooks.js +1 -1
  13. package/index.js +1 -1
  14. package/legacy.js +1 -1
  15. package/lib/relay-hooks/getConnectionState.js +47 -0
  16. package/lib/relay-hooks/legacy/FragmentResource.js +2 -6
  17. package/lib/relay-hooks/loadEntryPoint.js +8 -5
  18. package/lib/relay-hooks/loadQuery.js +2 -14
  19. package/lib/relay-hooks/readFragmentInternal.js +2 -4
  20. package/lib/relay-hooks/useEntryPointLoader.js +5 -8
  21. package/lib/relay-hooks/useFragment.js +4 -7
  22. package/lib/relay-hooks/useFragmentInternal.js +6 -484
  23. package/lib/relay-hooks/useFragmentInternal_CURRENT.js +477 -0
  24. package/lib/relay-hooks/useFragmentInternal_EXPERIMENTAL.js +499 -0
  25. package/lib/relay-hooks/useLazyLoadQuery.js +2 -5
  26. package/lib/relay-hooks/useLoadMoreFunction.js +10 -43
  27. package/lib/relay-hooks/useLoadMoreFunction_EXPERIMENTAL.js +130 -0
  28. package/lib/relay-hooks/usePreloadedQuery.js +6 -9
  29. package/lib/relay-hooks/useQueryLoader.js +9 -3
  30. package/lib/relay-hooks/useQueryLoader_EXPERIMENTAL.js +120 -0
  31. package/multi-actor/ActorChange.js.flow +1 -1
  32. package/package.json +3 -3
  33. package/react-relay-hooks.js +2 -2
  34. package/react-relay-hooks.min.js +2 -2
  35. package/react-relay-legacy.js +1 -1
  36. package/react-relay-legacy.min.js +1 -1
  37. package/react-relay.js +2 -2
  38. package/react-relay.min.js +2 -2
  39. package/relay-hooks/EntryPointTypes.flow.js.flow +35 -12
  40. package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +8 -4
  41. package/relay-hooks/MatchContainer.js.flow +1 -1
  42. package/relay-hooks/ProfilerContext.js.flow +1 -1
  43. package/relay-hooks/__flowtests__/EntryPointTypes/ExtractQueryTypes-flowtest.js.flow +43 -0
  44. package/relay-hooks/getConnectionState.js.flow +97 -0
  45. package/relay-hooks/legacy/FragmentResource.js.flow +2 -13
  46. package/relay-hooks/loadEntryPoint.js.flow +10 -4
  47. package/relay-hooks/loadQuery.js.flow +4 -28
  48. package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +4 -1
  49. package/relay-hooks/readFragmentInternal.js.flow +1 -10
  50. package/relay-hooks/useEntryPointLoader.js.flow +3 -4
  51. package/relay-hooks/useFragment.js.flow +0 -5
  52. package/relay-hooks/useFragmentInternal.js.flow +19 -643
  53. package/relay-hooks/useFragmentInternal_CURRENT.js.flow +656 -0
  54. package/relay-hooks/useFragmentInternal_EXPERIMENTAL.js.flow +718 -0
  55. package/relay-hooks/useLazyLoadQuery.js.flow +0 -5
  56. package/relay-hooks/useLoadMoreFunction.js.flow +14 -80
  57. package/relay-hooks/useLoadMoreFunction_EXPERIMENTAL.js.flow +280 -0
  58. package/relay-hooks/usePaginationFragment.js.flow +1 -1
  59. package/relay-hooks/usePreloadedQuery.js.flow +0 -5
  60. package/relay-hooks/useQueryLoader.js.flow +28 -5
  61. package/relay-hooks/useQueryLoader_EXPERIMENTAL.js.flow +253 -0
@@ -0,0 +1,499 @@
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
+ handlePotentialSnapshotErrors(environment, state.snapshot.errorResponseFields);
120
+ } else if (state.kind === 'plural') {
121
+ var _iterator5 = (0, _createForOfIteratorHelper2["default"])(state.snapshots),
122
+ _step5;
123
+ try {
124
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
125
+ var snapshot = _step5.value;
126
+ handlePotentialSnapshotErrors(environment, snapshot.errorResponseFields);
127
+ }
128
+ } catch (err) {
129
+ _iterator5.e(err);
130
+ } finally {
131
+ _iterator5.f();
132
+ }
133
+ }
134
+ }
135
+ function handleMissedUpdates(environment, state) {
136
+ if (state.kind === 'bailout') {
137
+ return null;
138
+ }
139
+ var currentEpoch = environment.getStore().getEpoch();
140
+ if (currentEpoch === state.epoch) {
141
+ return null;
142
+ }
143
+ if (state.kind === 'singular') {
144
+ var currentSnapshot = environment.lookup(state.snapshot.selector);
145
+ var updatedData = recycleNodesInto(state.snapshot.data, currentSnapshot.data);
146
+ var updatedCurrentSnapshot = {
147
+ data: updatedData,
148
+ isMissingData: currentSnapshot.isMissingData,
149
+ missingClientEdges: currentSnapshot.missingClientEdges,
150
+ missingLiveResolverFields: currentSnapshot.missingLiveResolverFields,
151
+ seenRecords: currentSnapshot.seenRecords,
152
+ selector: currentSnapshot.selector,
153
+ errorResponseFields: currentSnapshot.errorResponseFields
154
+ };
155
+ return [updatedData !== state.snapshot.data, {
156
+ kind: 'singular',
157
+ snapshot: updatedCurrentSnapshot,
158
+ epoch: currentEpoch,
159
+ selector: state.selector,
160
+ environment: state.environment
161
+ }];
162
+ } else {
163
+ var didMissUpdates = false;
164
+ var currentSnapshots = [];
165
+ for (var index = 0; index < state.snapshots.length; index++) {
166
+ var snapshot = state.snapshots[index];
167
+ var _currentSnapshot = environment.lookup(snapshot.selector);
168
+ var _updatedData = recycleNodesInto(snapshot.data, _currentSnapshot.data);
169
+ var _updatedCurrentSnapshot = {
170
+ data: _updatedData,
171
+ isMissingData: _currentSnapshot.isMissingData,
172
+ missingClientEdges: _currentSnapshot.missingClientEdges,
173
+ missingLiveResolverFields: _currentSnapshot.missingLiveResolverFields,
174
+ seenRecords: _currentSnapshot.seenRecords,
175
+ selector: _currentSnapshot.selector,
176
+ errorResponseFields: _currentSnapshot.errorResponseFields
177
+ };
178
+ if (_updatedData !== snapshot.data) {
179
+ didMissUpdates = true;
180
+ }
181
+ currentSnapshots.push(_updatedCurrentSnapshot);
182
+ }
183
+ !(currentSnapshots.length === state.snapshots.length) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Expected same number of snapshots') : invariant(false) : void 0;
184
+ return [didMissUpdates, {
185
+ kind: 'plural',
186
+ snapshots: currentSnapshots,
187
+ epoch: currentEpoch,
188
+ selector: state.selector,
189
+ environment: state.environment
190
+ }];
191
+ }
192
+ }
193
+ function handleMissingClientEdge(environment, parentFragmentNode, parentFragmentRef, missingClientEdgeRequestInfo, queryOptions) {
194
+ var originalVariables = getVariablesFromFragment(parentFragmentNode, parentFragmentRef);
195
+ var variables = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, originalVariables), {}, {
196
+ id: missingClientEdgeRequestInfo.clientEdgeDestinationID
197
+ });
198
+ var queryOperationDescriptor = createOperationDescriptor(missingClientEdgeRequestInfo.request, variables, queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.networkCacheConfig);
199
+ var QueryResource = getQueryResourceForEnvironment(environment);
200
+ var queryResult = QueryResource.prepare(queryOperationDescriptor, fetchQueryInternal(environment, queryOperationDescriptor), queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.fetchPolicy);
201
+ return [queryResult, getPromiseForActiveRequest(environment, queryOperationDescriptor.request)];
202
+ }
203
+ function subscribeToSnapshot(environment, state, setState) {
204
+ if (state.kind === 'bailout') {
205
+ return function () {};
206
+ } else if (state.kind === 'singular') {
207
+ var disposable = environment.subscribe(state.snapshot, function (latestSnapshot) {
208
+ setState(function (prevState) {
209
+ var nextState = null;
210
+ if (prevState.kind !== 'singular' || prevState.snapshot.selector !== latestSnapshot.selector || prevState.environment !== environment) {
211
+ var updates = handleMissedUpdates(prevState.environment, prevState);
212
+ if (updates != null) {
213
+ var dataChanged = updates[0],
214
+ updatedState = updates[1];
215
+ environment.__log({
216
+ name: 'useFragment.subscription.missedUpdates',
217
+ hasDataChanges: dataChanged
218
+ });
219
+ nextState = dataChanged ? updatedState : prevState;
220
+ } else {
221
+ nextState = prevState;
222
+ }
223
+ } else {
224
+ nextState = {
225
+ kind: 'singular',
226
+ snapshot: latestSnapshot,
227
+ epoch: environment.getStore().getEpoch(),
228
+ selector: state.selector,
229
+ environment: state.environment
230
+ };
231
+ }
232
+ return nextState;
233
+ });
234
+ });
235
+ return function () {
236
+ disposable.dispose();
237
+ };
238
+ } else {
239
+ var disposables = state.snapshots.map(function (snapshot, index) {
240
+ return environment.subscribe(snapshot, function (latestSnapshot) {
241
+ setState(function (prevState) {
242
+ var _prevState$snapshots$;
243
+ var nextState = null;
244
+ if (prevState.kind !== 'plural' || ((_prevState$snapshots$ = prevState.snapshots[index]) === null || _prevState$snapshots$ === void 0 ? void 0 : _prevState$snapshots$.selector) !== latestSnapshot.selector || prevState.environment !== environment) {
245
+ var updates = handleMissedUpdates(prevState.environment, prevState);
246
+ if (updates != null) {
247
+ var dataChanged = updates[0],
248
+ updatedState = updates[1];
249
+ environment.__log({
250
+ name: 'useFragment.subscription.missedUpdates',
251
+ hasDataChanges: dataChanged
252
+ });
253
+ nextState = dataChanged ? updatedState : prevState;
254
+ } else {
255
+ nextState = prevState;
256
+ }
257
+ } else {
258
+ var updated = (0, _toConsumableArray2["default"])(prevState.snapshots);
259
+ updated[index] = latestSnapshot;
260
+ nextState = {
261
+ kind: 'plural',
262
+ snapshots: updated,
263
+ epoch: environment.getStore().getEpoch(),
264
+ selector: state.selector,
265
+ environment: state.environment
266
+ };
267
+ }
268
+ return nextState;
269
+ });
270
+ });
271
+ });
272
+ return function () {
273
+ var _iterator6 = (0, _createForOfIteratorHelper2["default"])(disposables),
274
+ _step6;
275
+ try {
276
+ for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
277
+ var d = _step6.value;
278
+ d.dispose();
279
+ }
280
+ } catch (err) {
281
+ _iterator6.e(err);
282
+ } finally {
283
+ _iterator6.f();
284
+ }
285
+ };
286
+ }
287
+ }
288
+ function getFragmentState(environment, fragmentSelector) {
289
+ if (fragmentSelector == null) {
290
+ return {
291
+ kind: 'bailout',
292
+ environment: environment
293
+ };
294
+ } else if (fragmentSelector.kind === 'PluralReaderSelector') {
295
+ return {
296
+ kind: 'plural',
297
+ snapshots: fragmentSelector.selectors.map(function (s) {
298
+ return environment.lookup(s);
299
+ }),
300
+ epoch: environment.getStore().getEpoch(),
301
+ selector: fragmentSelector,
302
+ environment: environment
303
+ };
304
+ } else {
305
+ return {
306
+ kind: 'singular',
307
+ snapshot: environment.lookup(fragmentSelector),
308
+ epoch: environment.getStore().getEpoch(),
309
+ selector: fragmentSelector,
310
+ environment: environment
311
+ };
312
+ }
313
+ }
314
+ function useFragmentInternal_EXPERIMENTAL(fragmentNode, fragmentRef, hookDisplayName, queryOptions) {
315
+ var _fragmentNode$metadat, _fragmentNode$metadat2;
316
+ var fragmentSelector = useMemo(function () {
317
+ return getSelector(fragmentNode, fragmentRef);
318
+ }, [fragmentNode, fragmentRef]);
319
+ var isPlural = (fragmentNode === null || fragmentNode === void 0 ? void 0 : (_fragmentNode$metadat = fragmentNode.metadata) === null || _fragmentNode$metadat === void 0 ? void 0 : _fragmentNode$metadat.plural) === true;
320
+ if (isPlural) {
321
+ !(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;
322
+ } else {
323
+ !!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;
324
+ }
325
+ !(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;
326
+ var environment = useRelayEnvironment();
327
+ var _useState = useState(function () {
328
+ return getFragmentState(environment, fragmentSelector);
329
+ }),
330
+ _state = _useState[0],
331
+ setState = _useState[1];
332
+ var state = _state;
333
+ var previousEnvironment = state.environment;
334
+ if (!areEqualSelectors(fragmentSelector, state.selector) || environment !== state.environment) {
335
+ var newState = getFragmentState(environment, fragmentSelector);
336
+ setState(newState);
337
+ state = newState;
338
+ }
339
+ var committedFragmentSelectorRef = useRef(false);
340
+ useEffect(function () {
341
+ committedFragmentSelectorRef.current = fragmentSelector;
342
+ }, [fragmentSelector]);
343
+ if (((_fragmentNode$metadat2 = fragmentNode.metadata) === null || _fragmentNode$metadat2 === void 0 ? void 0 : _fragmentNode$metadat2.hasClientEdges) === true) {
344
+ var _useMemo = useMemo(function () {
345
+ var missingClientEdges = getMissingClientEdges(state);
346
+ var clientEdgeQueries;
347
+ var activeRequestPromises = [];
348
+ if (missingClientEdges !== null && missingClientEdges !== void 0 && missingClientEdges.length) {
349
+ clientEdgeQueries = [];
350
+ var _iterator7 = (0, _createForOfIteratorHelper2["default"])(missingClientEdges),
351
+ _step7;
352
+ try {
353
+ for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
354
+ var edge = _step7.value;
355
+ var _handleMissingClientE = handleMissingClientEdge(environment, fragmentNode, fragmentRef, edge, queryOptions),
356
+ queryResult = _handleMissingClientE[0],
357
+ requestPromise = _handleMissingClientE[1];
358
+ clientEdgeQueries.push(queryResult);
359
+ if (requestPromise != null) {
360
+ activeRequestPromises.push(requestPromise);
361
+ }
362
+ }
363
+ } catch (err) {
364
+ _iterator7.e(err);
365
+ } finally {
366
+ _iterator7.f();
367
+ }
368
+ }
369
+ return [clientEdgeQueries, activeRequestPromises];
370
+ }, [state, environment, fragmentNode, fragmentRef, queryOptions]),
371
+ clientEdgeQueries = _useMemo[0],
372
+ activeRequestPromises = _useMemo[1];
373
+ if (activeRequestPromises.length) {
374
+ throw Promise.all(activeRequestPromises);
375
+ }
376
+ useEffect(function () {
377
+ var QueryResource = getQueryResourceForEnvironment(environment);
378
+ if (clientEdgeQueries !== null && clientEdgeQueries !== void 0 && clientEdgeQueries.length) {
379
+ var disposables = [];
380
+ var _iterator8 = (0, _createForOfIteratorHelper2["default"])(clientEdgeQueries),
381
+ _step8;
382
+ try {
383
+ for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
384
+ var query = _step8.value;
385
+ disposables.push(QueryResource.retain(query));
386
+ }
387
+ } catch (err) {
388
+ _iterator8.e(err);
389
+ } finally {
390
+ _iterator8.f();
391
+ }
392
+ return function () {
393
+ for (var _i = 0, _disposables = disposables; _i < _disposables.length; _i++) {
394
+ var disposable = _disposables[_i];
395
+ disposable.dispose();
396
+ }
397
+ };
398
+ }
399
+ }, [environment, clientEdgeQueries]);
400
+ }
401
+ if (isMissingData(state)) {
402
+ var suspendingLiveResolvers = getSuspendingLiveResolver(state);
403
+ if (suspendingLiveResolvers != null && suspendingLiveResolvers.length > 0) {
404
+ throw Promise.all(suspendingLiveResolvers.map(function (_ref) {
405
+ var liveStateID = _ref.liveStateID;
406
+ return environment.getStore().getLiveResolverPromise(liveStateID);
407
+ }));
408
+ }
409
+ if (RelayFeatureFlags.ENABLE_RELAY_OPERATION_TRACKER_SUSPENSE || environment !== previousEnvironment || !committedFragmentSelectorRef.current || !areEqualSelectors(committedFragmentSelectorRef.current, fragmentSelector)) {
410
+ !(fragmentSelector != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'refinement, see invariants above') : invariant(false) : void 0;
411
+ var fragmentOwner = fragmentSelector.kind === 'PluralReaderSelector' ? fragmentSelector.selectors[0].owner : fragmentSelector.owner;
412
+ var pendingOperationsResult = getPendingOperationsForFragment(environment, fragmentNode, fragmentOwner);
413
+ if (pendingOperationsResult) {
414
+ throw pendingOperationsResult.promise;
415
+ }
416
+ }
417
+ }
418
+ handlePotentialSnapshotErrorsForState(environment, state);
419
+ var storeSubscriptionRef = useRef(null);
420
+ useEffect(function () {
421
+ var storeSubscription = storeSubscriptionRef.current;
422
+ if (storeSubscription != null) {
423
+ if (state.environment === storeSubscription.environment && state.selector === storeSubscription.selector) {
424
+ return;
425
+ } else {
426
+ storeSubscription.dispose();
427
+ }
428
+ }
429
+ if (state.kind === 'bailout') {
430
+ return;
431
+ }
432
+ var stateForSubscription = state;
433
+ var updates = handleMissedUpdates(state.environment, state);
434
+ if (updates !== null) {
435
+ var didMissUpdates = updates[0],
436
+ updatedState = updates[1];
437
+ if (didMissUpdates) {
438
+ setState(updatedState);
439
+ return;
440
+ }
441
+ stateForSubscription = updatedState;
442
+ }
443
+ var dispose = subscribeToSnapshot(state.environment, stateForSubscription, setState);
444
+ storeSubscriptionRef.current = {
445
+ dispose: dispose,
446
+ selector: state.selector,
447
+ environment: state.environment
448
+ };
449
+ }, [state]);
450
+ useEffect(function () {
451
+ if (storeSubscriptionRef.current == null && state.kind !== 'bailout') {
452
+ var dispose = subscribeToSnapshot(state.environment, state, setState);
453
+ storeSubscriptionRef.current = {
454
+ dispose: dispose,
455
+ selector: state.selector,
456
+ environment: state.environment
457
+ };
458
+ }
459
+ return function () {
460
+ var _storeSubscriptionRef;
461
+ (_storeSubscriptionRef = storeSubscriptionRef.current) === null || _storeSubscriptionRef === void 0 ? void 0 : _storeSubscriptionRef.dispose();
462
+ storeSubscriptionRef.current = null;
463
+ };
464
+ }, []);
465
+ var data;
466
+ if (isPlural) {
467
+ var fragmentRefIsNullish = fragmentRef == null;
468
+ data = useMemo(function () {
469
+ if (state.kind === 'bailout') {
470
+ return fragmentRefIsNullish ? null : [];
471
+ } else {
472
+ !(state.kind === 'plural') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Expected state to be plural because fragment is plural') : invariant(false) : void 0;
473
+ return state.snapshots.map(function (s) {
474
+ return s.data;
475
+ });
476
+ }
477
+ }, [state, fragmentRefIsNullish]);
478
+ } else if (state.kind === 'bailout') {
479
+ data = null;
480
+ } else {
481
+ !(state.kind === 'singular') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Expected state to be singular because fragment is singular') : invariant(false) : void 0;
482
+ data = state.snapshot.data;
483
+ }
484
+ if (RelayFeatureFlags.LOG_MISSING_RECORDS_IN_PROD || process.env.NODE_ENV !== "production") {
485
+ if (fragmentRef != null && (data === undefined || Array.isArray(data) && data.length > 0 && data.every(function (d) {
486
+ return d === undefined;
487
+ }))) {
488
+ 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;
489
+ }
490
+ }
491
+ if (process.env.NODE_ENV !== "production") {
492
+ useDebugValue({
493
+ fragment: fragmentNode.name,
494
+ data: data
495
+ });
496
+ }
497
+ return data;
498
+ }
499
+ 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
@@ -2,9 +2,11 @@
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
4
4
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
5
+ var getConnectionState = require('./getConnectionState');
5
6
  var useFetchTrackingRef = require('./useFetchTrackingRef');
6
7
  var useIsMountedRef = require('./useIsMountedRef');
7
8
  var useIsOperationNodeActive = require('./useIsOperationNodeActive');
9
+ var useLoadMoreFunction_EXPERIMENTAL = require('./useLoadMoreFunction_EXPERIMENTAL');
8
10
  var useRelayEnvironment = require('./useRelayEnvironment');
9
11
  var invariant = require('invariant');
10
12
  var _require = require('react'),
@@ -13,14 +15,19 @@ var _require = require('react'),
13
15
  useState = _require.useState;
14
16
  var _require2 = require('relay-runtime'),
15
17
  fetchQuery = _require2.__internal.fetchQuery,
16
- ConnectionInterface = _require2.ConnectionInterface,
18
+ RelayFeatureFlags = _require2.RelayFeatureFlags,
17
19
  createOperationDescriptor = _require2.createOperationDescriptor,
18
20
  getPaginationVariables = _require2.getPaginationVariables,
19
21
  getRefetchMetadata = _require2.getRefetchMetadata,
20
- getSelector = _require2.getSelector,
21
- getValueAtPath = _require2.getValueAtPath;
22
+ getSelector = _require2.getSelector;
22
23
  var warning = require("fbjs/lib/warning");
23
24
  function useLoadMoreFunction(args) {
25
+ if (RelayFeatureFlags.ENABLE_ACTIVITY_COMPATIBILITY) {
26
+ return useLoadMoreFunction_EXPERIMENTAL(args);
27
+ }
28
+ return useLoadMoreFunction_CURRENT(args);
29
+ }
30
+ function useLoadMoreFunction_CURRENT(args) {
24
31
  var direction = args.direction,
25
32
  fragmentNode = args.fragmentNode,
26
33
  fragmentRef = args.fragmentRef,
@@ -121,44 +128,4 @@ function useLoadMoreFunction(args) {
121
128
  }, [environment, identifierValue, direction, cursor, startFetch, disposeFetch, completeFetch, isFetchingRef, isParentQueryActive, fragmentData, fragmentNode.name, fragmentRef, componentDisplayName]);
122
129
  return [loadMore, hasMore, disposeFetch];
123
130
  }
124
- function getConnectionState(direction, fragmentNode, fragmentData, connectionPathInFragmentData) {
125
- var _pageInfo$END_CURSOR, _pageInfo$START_CURSO;
126
- var _ConnectionInterface$ = ConnectionInterface.get(),
127
- EDGES = _ConnectionInterface$.EDGES,
128
- PAGE_INFO = _ConnectionInterface$.PAGE_INFO,
129
- HAS_NEXT_PAGE = _ConnectionInterface$.HAS_NEXT_PAGE,
130
- HAS_PREV_PAGE = _ConnectionInterface$.HAS_PREV_PAGE,
131
- END_CURSOR = _ConnectionInterface$.END_CURSOR,
132
- START_CURSOR = _ConnectionInterface$.START_CURSOR;
133
- var connection = getValueAtPath(fragmentData, connectionPathInFragmentData);
134
- if (connection == null) {
135
- return {
136
- cursor: null,
137
- hasMore: false
138
- };
139
- }
140
- !(typeof connection === 'object') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected connection in fragment `%s` to have been `null`, or ' + 'a plain object with %s and %s properties. Instead got `%s`.', fragmentNode.name, EDGES, PAGE_INFO, connection) : invariant(false) : void 0;
141
- var edges = connection[EDGES];
142
- var pageInfo = connection[PAGE_INFO];
143
- if (edges == null || pageInfo == null) {
144
- return {
145
- cursor: null,
146
- hasMore: false
147
- };
148
- }
149
- !Array.isArray(edges) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected connection in fragment `%s` to have a plural `%s` field. ' + 'Instead got `%s`.', fragmentNode.name, EDGES, edges) : invariant(false) : void 0;
150
- !(typeof pageInfo === 'object') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected connection in fragment `%s` to have a `%s` field. ' + 'Instead got `%s`.', fragmentNode.name, PAGE_INFO, pageInfo) : invariant(false) : void 0;
151
- var cursor = direction === 'forward' ? (_pageInfo$END_CURSOR = pageInfo[END_CURSOR]) !== null && _pageInfo$END_CURSOR !== void 0 ? _pageInfo$END_CURSOR : null : (_pageInfo$START_CURSO = pageInfo[START_CURSOR]) !== null && _pageInfo$START_CURSO !== void 0 ? _pageInfo$START_CURSO : null;
152
- !(cursor === null || typeof cursor === 'string') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected page info for connection in fragment `%s` to have a ' + 'valid `%s`. Instead got `%s`.', fragmentNode.name, START_CURSOR, cursor) : invariant(false) : void 0;
153
- var hasMore;
154
- if (direction === 'forward') {
155
- hasMore = cursor != null && pageInfo[HAS_NEXT_PAGE] === true;
156
- } else {
157
- hasMore = cursor != null && pageInfo[HAS_PREV_PAGE] === true;
158
- }
159
- return {
160
- cursor: cursor,
161
- hasMore: hasMore
162
- };
163
- }
164
131
  module.exports = useLoadMoreFunction;