react-relay 18.0.0 → 18.1.0
Sign up to get free protection for your applications and to get access to all the features.
- package/ReactRelayContext.js +1 -1
- package/buildReactRelayContainer.js.flow +1 -0
- package/hooks.js +1 -1
- package/index.js +1 -1
- package/legacy.js +1 -1
- package/lib/relay-hooks/getConnectionState.js +47 -0
- package/lib/relay-hooks/legacy/FragmentResource.js +2 -6
- package/lib/relay-hooks/readFragmentInternal.js +2 -4
- package/lib/relay-hooks/useFragmentInternal.js +1 -1
- package/lib/relay-hooks/useFragmentInternal_CURRENT.js +2 -8
- package/lib/relay-hooks/useFragmentInternal_EXPERIMENTAL.js +5 -26
- package/lib/relay-hooks/useLoadMoreFunction.js +10 -43
- package/lib/relay-hooks/useLoadMoreFunction_EXPERIMENTAL.js +130 -0
- package/lib/relay-hooks/useQueryLoader.js +8 -0
- package/lib/relay-hooks/useQueryLoader_EXPERIMENTAL.js +120 -0
- package/package.json +2 -2
- package/react-relay-hooks.js +2 -2
- package/react-relay-hooks.min.js +2 -2
- package/react-relay-legacy.js +1 -1
- package/react-relay-legacy.min.js +1 -1
- package/react-relay.js +2 -2
- package/react-relay.min.js +2 -2
- package/relay-hooks/getConnectionState.js.flow +97 -0
- package/relay-hooks/legacy/FragmentResource.js.flow +2 -13
- package/relay-hooks/readFragmentInternal.js.flow +1 -10
- package/relay-hooks/useFragmentInternal.js.flow +1 -1
- package/relay-hooks/useFragmentInternal_CURRENT.js.flow +2 -15
- package/relay-hooks/useFragmentInternal_EXPERIMENTAL.js.flow +3 -49
- package/relay-hooks/useLoadMoreFunction.js.flow +14 -80
- package/relay-hooks/useLoadMoreFunction_EXPERIMENTAL.js.flow +280 -0
- package/relay-hooks/useQueryLoader.js.flow +27 -3
- package/relay-hooks/useQueryLoader_EXPERIMENTAL.js.flow +253 -0
package/ReactRelayContext.js
CHANGED
package/hooks.js
CHANGED
package/index.js
CHANGED
package/legacy.js
CHANGED
@@ -0,0 +1,47 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
var invariant = require('invariant');
|
4
|
+
var _require = require('relay-runtime'),
|
5
|
+
ConnectionInterface = _require.ConnectionInterface,
|
6
|
+
getValueAtPath = _require.getValueAtPath;
|
7
|
+
function getConnectionState(direction, fragmentNode, fragmentData, connectionPathInFragmentData) {
|
8
|
+
var _pageInfo$END_CURSOR, _pageInfo$START_CURSO;
|
9
|
+
var _ConnectionInterface$ = ConnectionInterface.get(),
|
10
|
+
EDGES = _ConnectionInterface$.EDGES,
|
11
|
+
PAGE_INFO = _ConnectionInterface$.PAGE_INFO,
|
12
|
+
HAS_NEXT_PAGE = _ConnectionInterface$.HAS_NEXT_PAGE,
|
13
|
+
HAS_PREV_PAGE = _ConnectionInterface$.HAS_PREV_PAGE,
|
14
|
+
END_CURSOR = _ConnectionInterface$.END_CURSOR,
|
15
|
+
START_CURSOR = _ConnectionInterface$.START_CURSOR;
|
16
|
+
var connection = getValueAtPath(fragmentData, connectionPathInFragmentData);
|
17
|
+
if (connection == null) {
|
18
|
+
return {
|
19
|
+
cursor: null,
|
20
|
+
hasMore: false
|
21
|
+
};
|
22
|
+
}
|
23
|
+
!(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;
|
24
|
+
var edges = connection[EDGES];
|
25
|
+
var pageInfo = connection[PAGE_INFO];
|
26
|
+
if (edges == null || pageInfo == null) {
|
27
|
+
return {
|
28
|
+
cursor: null,
|
29
|
+
hasMore: false
|
30
|
+
};
|
31
|
+
}
|
32
|
+
!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;
|
33
|
+
!(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;
|
34
|
+
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;
|
35
|
+
!(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;
|
36
|
+
var hasMore;
|
37
|
+
if (direction === 'forward') {
|
38
|
+
hasMore = cursor != null && pageInfo[HAS_NEXT_PAGE] === true;
|
39
|
+
} else {
|
40
|
+
hasMore = cursor != null && pageInfo[HAS_PREV_PAGE] === true;
|
41
|
+
}
|
42
|
+
return {
|
43
|
+
cursor: cursor,
|
44
|
+
hasMore: hasMore
|
45
|
+
};
|
46
|
+
}
|
47
|
+
module.exports = getConnectionState;
|
@@ -309,12 +309,10 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
|
|
309
309
|
var _this4 = this;
|
310
310
|
if (Array.isArray(snapshot)) {
|
311
311
|
snapshot.forEach(function (s) {
|
312
|
-
|
313
|
-
handlePotentialSnapshotErrors(_this4._environment, s.missingRequiredFields, s.relayResolverErrors, s.errorResponseFields, (_s$selector$node$meta = (_s$selector$node$meta2 = s.selector.node.metadata) === null || _s$selector$node$meta2 === void 0 ? void 0 : _s$selector$node$meta2.throwOnFieldError) !== null && _s$selector$node$meta !== void 0 ? _s$selector$node$meta : false);
|
312
|
+
handlePotentialSnapshotErrors(_this4._environment, s.errorResponseFields);
|
314
313
|
});
|
315
314
|
} else {
|
316
|
-
|
317
|
-
handlePotentialSnapshotErrors(this._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);
|
315
|
+
handlePotentialSnapshotErrors(this._environment, snapshot.errorResponseFields);
|
318
316
|
}
|
319
317
|
};
|
320
318
|
_proto2.readSpec = function readSpec(fragmentNodes, fragmentRefs, componentDisplayName) {
|
@@ -456,8 +454,6 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
|
|
456
454
|
missingLiveResolverFields: currentSnapshot.missingLiveResolverFields,
|
457
455
|
seenRecords: currentSnapshot.seenRecords,
|
458
456
|
selector: currentSnapshot.selector,
|
459
|
-
missingRequiredFields: currentSnapshot.missingRequiredFields,
|
460
|
-
relayResolverErrors: currentSnapshot.relayResolverErrors,
|
461
457
|
errorResponseFields: currentSnapshot.errorResponseFields
|
462
458
|
};
|
463
459
|
if (updatedData !== renderData) {
|
@@ -66,16 +66,14 @@ function getMissingClientEdges(state) {
|
|
66
66
|
}
|
67
67
|
function handlePotentialSnapshotErrorsForState(environment, state) {
|
68
68
|
if (state.kind === 'singular') {
|
69
|
-
|
70
|
-
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);
|
69
|
+
handlePotentialSnapshotErrors(environment, state.snapshot.errorResponseFields);
|
71
70
|
} else if (state.kind === 'plural') {
|
72
71
|
var _iterator3 = (0, _createForOfIteratorHelper2["default"])(state.snapshots),
|
73
72
|
_step3;
|
74
73
|
try {
|
75
74
|
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
76
|
-
var _snapshot$selector$no, _snapshot$selector$no2;
|
77
75
|
var snapshot = _step3.value;
|
78
|
-
handlePotentialSnapshotErrors(environment, snapshot.
|
76
|
+
handlePotentialSnapshotErrors(environment, snapshot.errorResponseFields);
|
79
77
|
}
|
80
78
|
} catch (err) {
|
81
79
|
_iterator3.e(err);
|
@@ -5,7 +5,7 @@ var _useFragmentInternal_CURRENT = _interopRequireDefault(require("./useFragment
|
|
5
5
|
var _useFragmentInternal_EXPERIMENTAL = _interopRequireDefault(require("./useFragmentInternal_EXPERIMENTAL"));
|
6
6
|
var _relayRuntime = require("relay-runtime");
|
7
7
|
function useFragmentInternal(fragmentNode, fragmentRef, hookDisplayName, queryOptions) {
|
8
|
-
if (_relayRuntime.RelayFeatureFlags.
|
8
|
+
if (_relayRuntime.RelayFeatureFlags.ENABLE_ACTIVITY_COMPATIBILITY) {
|
9
9
|
return (0, _useFragmentInternal_EXPERIMENTAL["default"])(fragmentNode, fragmentRef, hookDisplayName, queryOptions);
|
10
10
|
}
|
11
11
|
return (0, _useFragmentInternal_CURRENT["default"])(fragmentNode, fragmentRef, hookDisplayName, queryOptions);
|
@@ -116,16 +116,14 @@ function getSuspendingLiveResolver(state) {
|
|
116
116
|
}
|
117
117
|
function handlePotentialSnapshotErrorsForState(environment, state) {
|
118
118
|
if (state.kind === 'singular') {
|
119
|
-
|
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);
|
119
|
+
handlePotentialSnapshotErrors(environment, state.snapshot.errorResponseFields);
|
121
120
|
} else if (state.kind === 'plural') {
|
122
121
|
var _iterator5 = (0, _createForOfIteratorHelper2["default"])(state.snapshots),
|
123
122
|
_step5;
|
124
123
|
try {
|
125
124
|
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
126
|
-
var _snapshot$selector$no, _snapshot$selector$no2;
|
127
125
|
var snapshot = _step5.value;
|
128
|
-
handlePotentialSnapshotErrors(environment, snapshot.
|
126
|
+
handlePotentialSnapshotErrors(environment, snapshot.errorResponseFields);
|
129
127
|
}
|
130
128
|
} catch (err) {
|
131
129
|
_iterator5.e(err);
|
@@ -152,8 +150,6 @@ function handleMissedUpdates(environment, state) {
|
|
152
150
|
missingLiveResolverFields: currentSnapshot.missingLiveResolverFields,
|
153
151
|
seenRecords: currentSnapshot.seenRecords,
|
154
152
|
selector: currentSnapshot.selector,
|
155
|
-
missingRequiredFields: currentSnapshot.missingRequiredFields,
|
156
|
-
relayResolverErrors: currentSnapshot.relayResolverErrors,
|
157
153
|
errorResponseFields: currentSnapshot.errorResponseFields
|
158
154
|
};
|
159
155
|
return [updatedData !== state.snapshot.data, {
|
@@ -175,8 +171,6 @@ function handleMissedUpdates(environment, state) {
|
|
175
171
|
missingLiveResolverFields: _currentSnapshot.missingLiveResolverFields,
|
176
172
|
seenRecords: _currentSnapshot.seenRecords,
|
177
173
|
selector: _currentSnapshot.selector,
|
178
|
-
missingRequiredFields: _currentSnapshot.missingRequiredFields,
|
179
|
-
relayResolverErrors: _currentSnapshot.relayResolverErrors,
|
180
174
|
errorResponseFields: _currentSnapshot.errorResponseFields
|
181
175
|
};
|
182
176
|
if (_updatedData !== snapshot.data) {
|
@@ -116,16 +116,14 @@ function getSuspendingLiveResolver(state) {
|
|
116
116
|
}
|
117
117
|
function handlePotentialSnapshotErrorsForState(environment, state) {
|
118
118
|
if (state.kind === 'singular') {
|
119
|
-
|
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);
|
119
|
+
handlePotentialSnapshotErrors(environment, state.snapshot.errorResponseFields);
|
121
120
|
} else if (state.kind === 'plural') {
|
122
121
|
var _iterator5 = (0, _createForOfIteratorHelper2["default"])(state.snapshots),
|
123
122
|
_step5;
|
124
123
|
try {
|
125
124
|
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
126
|
-
var _snapshot$selector$no, _snapshot$selector$no2;
|
127
125
|
var snapshot = _step5.value;
|
128
|
-
handlePotentialSnapshotErrors(environment, snapshot.
|
126
|
+
handlePotentialSnapshotErrors(environment, snapshot.errorResponseFields);
|
129
127
|
}
|
130
128
|
} catch (err) {
|
131
129
|
_iterator5.e(err);
|
@@ -152,8 +150,6 @@ function handleMissedUpdates(environment, state) {
|
|
152
150
|
missingLiveResolverFields: currentSnapshot.missingLiveResolverFields,
|
153
151
|
seenRecords: currentSnapshot.seenRecords,
|
154
152
|
selector: currentSnapshot.selector,
|
155
|
-
missingRequiredFields: currentSnapshot.missingRequiredFields,
|
156
|
-
relayResolverErrors: currentSnapshot.relayResolverErrors,
|
157
153
|
errorResponseFields: currentSnapshot.errorResponseFields
|
158
154
|
};
|
159
155
|
return [updatedData !== state.snapshot.data, {
|
@@ -177,8 +173,6 @@ function handleMissedUpdates(environment, state) {
|
|
177
173
|
missingLiveResolverFields: _currentSnapshot.missingLiveResolverFields,
|
178
174
|
seenRecords: _currentSnapshot.seenRecords,
|
179
175
|
selector: _currentSnapshot.selector,
|
180
|
-
missingRequiredFields: _currentSnapshot.missingRequiredFields,
|
181
|
-
relayResolverErrors: _currentSnapshot.relayResolverErrors,
|
182
176
|
errorResponseFields: _currentSnapshot.errorResponseFields
|
183
177
|
};
|
184
178
|
if (_updatedData !== snapshot.data) {
|
@@ -206,7 +200,7 @@ function handleMissingClientEdge(environment, parentFragmentNode, parentFragment
|
|
206
200
|
var queryResult = QueryResource.prepare(queryOperationDescriptor, fetchQueryInternal(environment, queryOperationDescriptor), queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.fetchPolicy);
|
207
201
|
return [queryResult, getPromiseForActiveRequest(environment, queryOperationDescriptor.request)];
|
208
202
|
}
|
209
|
-
function subscribeToSnapshot(environment, state, setState
|
203
|
+
function subscribeToSnapshot(environment, state, setState) {
|
210
204
|
if (state.kind === 'bailout') {
|
211
205
|
return function () {};
|
212
206
|
} else if (state.kind === 'singular') {
|
@@ -235,7 +229,6 @@ function subscribeToSnapshot(environment, state, setState, pendingStateRef) {
|
|
235
229
|
environment: state.environment
|
236
230
|
};
|
237
231
|
}
|
238
|
-
pendingStateRef.current = nextState.kind === 'singular' ? nextState.epoch : null;
|
239
232
|
return nextState;
|
240
233
|
});
|
241
234
|
});
|
@@ -272,7 +265,6 @@ function subscribeToSnapshot(environment, state, setState, pendingStateRef) {
|
|
272
265
|
environment: state.environment
|
273
266
|
};
|
274
267
|
}
|
275
|
-
pendingStateRef.current = nextState.kind === 'plural' ? nextState.epoch : null;
|
276
268
|
return nextState;
|
277
269
|
});
|
278
270
|
});
|
@@ -424,7 +416,6 @@ function useFragmentInternal_EXPERIMENTAL(fragmentNode, fragmentRef, hookDisplay
|
|
424
416
|
}
|
425
417
|
}
|
426
418
|
handlePotentialSnapshotErrorsForState(environment, state);
|
427
|
-
var pendingStateEpochRef = useRef(null);
|
428
419
|
var storeSubscriptionRef = useRef(null);
|
429
420
|
useEffect(function () {
|
430
421
|
var storeSubscription = storeSubscriptionRef.current;
|
@@ -449,7 +440,7 @@ function useFragmentInternal_EXPERIMENTAL(fragmentNode, fragmentRef, hookDisplay
|
|
449
440
|
}
|
450
441
|
stateForSubscription = updatedState;
|
451
442
|
}
|
452
|
-
var dispose = subscribeToSnapshot(state.environment, stateForSubscription, setState
|
443
|
+
var dispose = subscribeToSnapshot(state.environment, stateForSubscription, setState);
|
453
444
|
storeSubscriptionRef.current = {
|
454
445
|
dispose: dispose,
|
455
446
|
selector: state.selector,
|
@@ -458,7 +449,7 @@ function useFragmentInternal_EXPERIMENTAL(fragmentNode, fragmentRef, hookDisplay
|
|
458
449
|
}, [state]);
|
459
450
|
useEffect(function () {
|
460
451
|
if (storeSubscriptionRef.current == null && state.kind !== 'bailout') {
|
461
|
-
var dispose = subscribeToSnapshot(state.environment, state, setState
|
452
|
+
var dispose = subscribeToSnapshot(state.environment, state, setState);
|
462
453
|
storeSubscriptionRef.current = {
|
463
454
|
dispose: dispose,
|
464
455
|
selector: state.selector,
|
@@ -471,18 +462,6 @@ function useFragmentInternal_EXPERIMENTAL(fragmentNode, fragmentRef, hookDisplay
|
|
471
462
|
storeSubscriptionRef.current = null;
|
472
463
|
};
|
473
464
|
}, []);
|
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
465
|
var data;
|
487
466
|
if (isPlural) {
|
488
467
|
var fragmentRefIsNullish = fragmentRef == null;
|
@@ -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
|
-
|
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;
|
@@ -0,0 +1,130 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
4
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
5
|
+
var getConnectionState = require('./getConnectionState');
|
6
|
+
var useIsMountedRef = require('./useIsMountedRef');
|
7
|
+
var useIsOperationNodeActive = require('./useIsOperationNodeActive');
|
8
|
+
var useRelayEnvironment = require('./useRelayEnvironment');
|
9
|
+
var invariant = require('invariant');
|
10
|
+
var _require = require('react'),
|
11
|
+
useCallback = _require.useCallback,
|
12
|
+
useRef = _require.useRef,
|
13
|
+
useState = _require.useState;
|
14
|
+
var _require2 = require('relay-runtime'),
|
15
|
+
fetchQuery = _require2.__internal.fetchQuery,
|
16
|
+
createOperationDescriptor = _require2.createOperationDescriptor,
|
17
|
+
getPaginationVariables = _require2.getPaginationVariables,
|
18
|
+
getRefetchMetadata = _require2.getRefetchMetadata,
|
19
|
+
getSelector = _require2.getSelector;
|
20
|
+
var warning = require("fbjs/lib/warning");
|
21
|
+
function useLoadMoreFunction_EXPERIMENTAL(args) {
|
22
|
+
var direction = args.direction,
|
23
|
+
fragmentNode = args.fragmentNode,
|
24
|
+
fragmentRef = args.fragmentRef,
|
25
|
+
fragmentIdentifier = args.fragmentIdentifier,
|
26
|
+
fragmentData = args.fragmentData,
|
27
|
+
connectionPathInFragmentData = args.connectionPathInFragmentData,
|
28
|
+
paginationRequest = args.paginationRequest,
|
29
|
+
paginationMetadata = args.paginationMetadata,
|
30
|
+
componentDisplayName = args.componentDisplayName,
|
31
|
+
observer = args.observer,
|
32
|
+
onReset = args.onReset;
|
33
|
+
var environment = useRelayEnvironment();
|
34
|
+
var _getRefetchMetadata = getRefetchMetadata(fragmentNode, componentDisplayName),
|
35
|
+
identifierInfo = _getRefetchMetadata.identifierInfo;
|
36
|
+
var identifierValue = (identifierInfo === null || identifierInfo === void 0 ? void 0 : identifierInfo.identifierField) != null && fragmentData != null && typeof fragmentData === 'object' ? fragmentData[identifierInfo.identifierField] : null;
|
37
|
+
var fetchStatusRef = useRef({
|
38
|
+
kind: 'none'
|
39
|
+
});
|
40
|
+
var _useState = useState(environment),
|
41
|
+
mirroredEnvironment = _useState[0],
|
42
|
+
setMirroredEnvironment = _useState[1];
|
43
|
+
var _useState2 = useState(fragmentIdentifier),
|
44
|
+
mirroredFragmentIdentifier = _useState2[0],
|
45
|
+
setMirroredFragmentIdentifier = _useState2[1];
|
46
|
+
var isParentQueryActive = useIsOperationNodeActive(fragmentNode, fragmentRef);
|
47
|
+
var forceDisposeFn = useCallback(function () {
|
48
|
+
if (fetchStatusRef.current.kind === 'fetching') {
|
49
|
+
fetchStatusRef.current.subscription.unsubscribe();
|
50
|
+
}
|
51
|
+
fetchStatusRef.current = {
|
52
|
+
kind: 'none'
|
53
|
+
};
|
54
|
+
}, []);
|
55
|
+
var shouldReset = environment !== mirroredEnvironment || fragmentIdentifier !== mirroredFragmentIdentifier;
|
56
|
+
if (shouldReset) {
|
57
|
+
forceDisposeFn();
|
58
|
+
onReset();
|
59
|
+
setMirroredEnvironment(environment);
|
60
|
+
setMirroredFragmentIdentifier(fragmentIdentifier);
|
61
|
+
}
|
62
|
+
var _getConnectionState = getConnectionState(direction, fragmentNode, fragmentData, connectionPathInFragmentData),
|
63
|
+
cursor = _getConnectionState.cursor,
|
64
|
+
hasMore = _getConnectionState.hasMore;
|
65
|
+
var isMountedRef = useIsMountedRef();
|
66
|
+
var loadMore = useCallback(function (count, options) {
|
67
|
+
var onComplete = options === null || options === void 0 ? void 0 : options.onComplete;
|
68
|
+
if (isMountedRef.current !== true) {
|
69
|
+
process.env.NODE_ENV !== "production" ? warning(false, 'Relay: Unexpected fetch on unmounted component for fragment ' + '`%s` in `%s`. It looks like some instances of your component are ' + 'still trying to fetch data but they already unmounted. ' + 'Please make sure you clear all timers, intervals, ' + 'async calls, etc that may trigger a fetch.', fragmentNode.name, componentDisplayName) : void 0;
|
70
|
+
return {
|
71
|
+
dispose: function dispose() {}
|
72
|
+
};
|
73
|
+
}
|
74
|
+
var fragmentSelector = getSelector(fragmentNode, fragmentRef);
|
75
|
+
if (fetchStatusRef.current.kind === 'fetching' || fragmentData == null || isParentQueryActive) {
|
76
|
+
if (fragmentSelector == null) {
|
77
|
+
process.env.NODE_ENV !== "production" ? warning(false, 'Relay: Unexpected fetch while using a null fragment ref ' + 'for fragment `%s` in `%s`. When fetching more items, we expect ' + "initial fragment data to be non-null. Please make sure you're " + 'passing a valid fragment ref to `%s` before paginating.', fragmentNode.name, componentDisplayName, componentDisplayName) : void 0;
|
78
|
+
}
|
79
|
+
if (onComplete) {
|
80
|
+
onComplete(null);
|
81
|
+
}
|
82
|
+
return {
|
83
|
+
dispose: function dispose() {}
|
84
|
+
};
|
85
|
+
}
|
86
|
+
!(fragmentSelector != null && fragmentSelector.kind !== 'PluralReaderSelector') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected to be able to find a non-plural fragment owner for ' + "fragment `%s` when using `%s`. If you're seeing this, " + 'this is likely a bug in Relay.', fragmentNode.name, componentDisplayName) : invariant(false) : void 0;
|
87
|
+
var parentVariables = fragmentSelector.owner.variables;
|
88
|
+
var fragmentVariables = fragmentSelector.variables;
|
89
|
+
var extraVariables = options === null || options === void 0 ? void 0 : options.UNSTABLE_extraVariables;
|
90
|
+
var baseVariables = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, parentVariables), fragmentVariables);
|
91
|
+
var paginationVariables = getPaginationVariables(direction, count, cursor, baseVariables, (0, _objectSpread2["default"])({}, extraVariables), paginationMetadata);
|
92
|
+
if (identifierInfo != null) {
|
93
|
+
if (typeof identifierValue !== 'string') {
|
94
|
+
process.env.NODE_ENV !== "production" ? warning(false, 'Relay: Expected result to have a string ' + '`%s` in order to refetch, got `%s`.', identifierInfo.identifierField, identifierValue) : void 0;
|
95
|
+
}
|
96
|
+
paginationVariables[identifierInfo.identifierQueryVariableName] = identifierValue;
|
97
|
+
}
|
98
|
+
var paginationQuery = createOperationDescriptor(paginationRequest, paginationVariables, {
|
99
|
+
force: true
|
100
|
+
});
|
101
|
+
fetchQuery(environment, paginationQuery).subscribe((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, observer), {}, {
|
102
|
+
start: function start(subscription) {
|
103
|
+
fetchStatusRef.current = {
|
104
|
+
kind: 'fetching',
|
105
|
+
subscription: subscription
|
106
|
+
};
|
107
|
+
observer.start && observer.start(subscription);
|
108
|
+
},
|
109
|
+
complete: function complete() {
|
110
|
+
fetchStatusRef.current = {
|
111
|
+
kind: 'none'
|
112
|
+
};
|
113
|
+
observer.complete && observer.complete();
|
114
|
+
onComplete && onComplete(null);
|
115
|
+
},
|
116
|
+
error: function error(_error) {
|
117
|
+
fetchStatusRef.current = {
|
118
|
+
kind: 'none'
|
119
|
+
};
|
120
|
+
observer.complete && observer.complete();
|
121
|
+
onComplete && onComplete(_error);
|
122
|
+
}
|
123
|
+
}));
|
124
|
+
return {
|
125
|
+
dispose: function dispose() {}
|
126
|
+
};
|
127
|
+
}, [environment, identifierValue, direction, cursor, isParentQueryActive, fragmentData, fragmentNode.name, fragmentRef, componentDisplayName]);
|
128
|
+
return [loadMore, hasMore, forceDisposeFn];
|
129
|
+
}
|
130
|
+
module.exports = useLoadMoreFunction_EXPERIMENTAL;
|
@@ -5,6 +5,7 @@ var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime
|
|
5
5
|
var _require = require('./loadQuery'),
|
6
6
|
loadQuery = _require.loadQuery;
|
7
7
|
var useIsMountedRef = require('./useIsMountedRef');
|
8
|
+
var useQueryLoader_EXPERIMENTAL = require('./useQueryLoader_EXPERIMENTAL');
|
8
9
|
var useRelayEnvironment = require('./useRelayEnvironment');
|
9
10
|
var _require2 = require('react'),
|
10
11
|
useCallback = _require2.useCallback,
|
@@ -12,6 +13,7 @@ var _require2 = require('react'),
|
|
12
13
|
useRef = _require2.useRef,
|
13
14
|
useState = _require2.useState;
|
14
15
|
var _require3 = require('relay-runtime'),
|
16
|
+
RelayFeatureFlags = _require3.RelayFeatureFlags,
|
15
17
|
getRequest = _require3.getRequest;
|
16
18
|
var initialNullQueryReferenceState = {
|
17
19
|
kind: 'NullQueryReference'
|
@@ -24,6 +26,12 @@ function requestIsLiveQuery(preloadableRequest) {
|
|
24
26
|
return request.params.metadata.live !== undefined;
|
25
27
|
}
|
26
28
|
function useQueryLoader(preloadableRequest, initialQueryReference) {
|
29
|
+
if (RelayFeatureFlags.ENABLE_ACTIVITY_COMPATIBILITY) {
|
30
|
+
return useQueryLoader_EXPERIMENTAL(preloadableRequest, initialQueryReference);
|
31
|
+
}
|
32
|
+
return useQueryLoader_CURRENT(preloadableRequest, initialQueryReference);
|
33
|
+
}
|
34
|
+
function useQueryLoader_CURRENT(preloadableRequest, initialQueryReference) {
|
27
35
|
var initialQueryReferenceInternal = initialQueryReference !== null && initialQueryReference !== void 0 ? initialQueryReference : initialNullQueryReferenceState;
|
28
36
|
var environment = useRelayEnvironment();
|
29
37
|
var isMountedRef = useIsMountedRef();
|
@@ -0,0 +1,120 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
4
|
+
var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
|
5
|
+
var _require = require('./loadQuery'),
|
6
|
+
loadQuery = _require.loadQuery;
|
7
|
+
var useIsMountedRef = require('./useIsMountedRef');
|
8
|
+
var useRelayEnvironment = require('./useRelayEnvironment');
|
9
|
+
var _require2 = require('react'),
|
10
|
+
useCallback = _require2.useCallback,
|
11
|
+
useEffect = _require2.useEffect,
|
12
|
+
useInsertionEffect = _require2.useInsertionEffect,
|
13
|
+
useRef = _require2.useRef,
|
14
|
+
useState = _require2.useState;
|
15
|
+
var _require3 = require('relay-runtime'),
|
16
|
+
getRequest = _require3.getRequest;
|
17
|
+
var initialNullQueryReferenceState = {
|
18
|
+
kind: 'NullQueryReference'
|
19
|
+
};
|
20
|
+
function requestIsLiveQuery(preloadableRequest) {
|
21
|
+
if (preloadableRequest.kind === 'PreloadableConcreteRequest') {
|
22
|
+
return preloadableRequest.params.metadata.live !== undefined;
|
23
|
+
}
|
24
|
+
var request = getRequest(preloadableRequest);
|
25
|
+
return request.params.metadata.live !== undefined;
|
26
|
+
}
|
27
|
+
var CLEANUP_TIMEOUT = 1000 * 60 * 5;
|
28
|
+
function useQueryLoader_EXPERIMENTAL(preloadableRequest, initialQueryReference) {
|
29
|
+
var initialQueryReferenceInternal = initialQueryReference !== null && initialQueryReference !== void 0 ? initialQueryReference : initialNullQueryReferenceState;
|
30
|
+
var environment = useRelayEnvironment();
|
31
|
+
var isMountedRef = useIsMountedRef();
|
32
|
+
var undisposedQueryReferencesRef = useRef(null);
|
33
|
+
if (undisposedQueryReferencesRef.current == null) {
|
34
|
+
undisposedQueryReferencesRef.current = new Set([initialQueryReferenceInternal]);
|
35
|
+
}
|
36
|
+
var _useState = useState(function () {
|
37
|
+
return initialQueryReferenceInternal;
|
38
|
+
}),
|
39
|
+
queryReference = _useState[0],
|
40
|
+
setQueryReference = _useState[1];
|
41
|
+
var _useState2 = useState(function () {
|
42
|
+
return initialQueryReferenceInternal;
|
43
|
+
}),
|
44
|
+
previousInitialQueryReference = _useState2[0],
|
45
|
+
setPreviousInitialQueryReference = _useState2[1];
|
46
|
+
if (initialQueryReferenceInternal !== previousInitialQueryReference) {
|
47
|
+
var _undisposedQueryRefer;
|
48
|
+
(_undisposedQueryRefer = undisposedQueryReferencesRef.current) === null || _undisposedQueryRefer === void 0 ? void 0 : _undisposedQueryRefer.add(initialQueryReferenceInternal);
|
49
|
+
setPreviousInitialQueryReference(initialQueryReferenceInternal);
|
50
|
+
setQueryReference(initialQueryReferenceInternal);
|
51
|
+
}
|
52
|
+
var disposeQuery = useCallback(function () {
|
53
|
+
if (isMountedRef.current) {
|
54
|
+
var _undisposedQueryRefer2;
|
55
|
+
(_undisposedQueryRefer2 = undisposedQueryReferencesRef.current) === null || _undisposedQueryRefer2 === void 0 ? void 0 : _undisposedQueryRefer2.add(initialNullQueryReferenceState);
|
56
|
+
setQueryReference(initialNullQueryReferenceState);
|
57
|
+
}
|
58
|
+
}, [isMountedRef]);
|
59
|
+
var queryLoaderCallback = useCallback(function (variables, options) {
|
60
|
+
var _options$__environmen, _undisposedQueryRefer3;
|
61
|
+
if (!isMountedRef.current) {
|
62
|
+
return;
|
63
|
+
}
|
64
|
+
var mergedOptions = options != null && options.hasOwnProperty('__environment') ? {
|
65
|
+
fetchPolicy: options.fetchPolicy,
|
66
|
+
networkCacheConfig: options.networkCacheConfig,
|
67
|
+
__nameForWarning: options.__nameForWarning
|
68
|
+
} : options;
|
69
|
+
var updatedQueryReference = loadQuery((_options$__environmen = options === null || options === void 0 ? void 0 : options.__environment) !== null && _options$__environmen !== void 0 ? _options$__environmen : environment, preloadableRequest, variables, mergedOptions);
|
70
|
+
(_undisposedQueryRefer3 = undisposedQueryReferencesRef.current) === null || _undisposedQueryRefer3 === void 0 ? void 0 : _undisposedQueryRefer3.add(updatedQueryReference);
|
71
|
+
setQueryReference(updatedQueryReference);
|
72
|
+
}, [environment, preloadableRequest, setQueryReference, isMountedRef]);
|
73
|
+
var disposeAllRemainingQueryReferences = useCallback(function disposeAllRemainingQueryReferences(preloadableRequest, currentQueryReference) {
|
74
|
+
var _undisposedQueryRefer4;
|
75
|
+
var undisposedQueryReferences = (_undisposedQueryRefer4 = undisposedQueryReferencesRef.current) !== null && _undisposedQueryRefer4 !== void 0 ? _undisposedQueryRefer4 : new Set();
|
76
|
+
var _iterator = (0, _createForOfIteratorHelper2["default"])(undisposedQueryReferences),
|
77
|
+
_step;
|
78
|
+
try {
|
79
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
80
|
+
var undisposedQueryReference = _step.value;
|
81
|
+
if (undisposedQueryReference === currentQueryReference) {
|
82
|
+
continue;
|
83
|
+
}
|
84
|
+
if (undisposedQueryReference.kind !== 'NullQueryReference') {
|
85
|
+
if (requestIsLiveQuery(preloadableRequest)) {
|
86
|
+
undisposedQueryReference.dispose && undisposedQueryReference.dispose();
|
87
|
+
} else {
|
88
|
+
undisposedQueryReference.releaseQuery && undisposedQueryReference.releaseQuery();
|
89
|
+
}
|
90
|
+
}
|
91
|
+
}
|
92
|
+
} catch (err) {
|
93
|
+
_iterator.e(err);
|
94
|
+
} finally {
|
95
|
+
_iterator.f();
|
96
|
+
}
|
97
|
+
}, []);
|
98
|
+
var cleanupTimerRef = useRef(null);
|
99
|
+
useEffect(function () {
|
100
|
+
disposeAllRemainingQueryReferences(preloadableRequest, queryReference);
|
101
|
+
if (cleanupTimerRef.current != null) {
|
102
|
+
clearTimeout(cleanupTimerRef.current);
|
103
|
+
cleanupTimerRef.current = null;
|
104
|
+
}
|
105
|
+
return function () {
|
106
|
+
cleanupTimerRef.current = setTimeout(function () {
|
107
|
+
disposeAllRemainingQueryReferences(preloadableRequest, null);
|
108
|
+
}, CLEANUP_TIMEOUT);
|
109
|
+
};
|
110
|
+
}, [preloadableRequest, queryReference]);
|
111
|
+
useInsertionEffect(function () {
|
112
|
+
return function () {
|
113
|
+
cleanupTimerRef.current && clearTimeout(cleanupTimerRef.current);
|
114
|
+
cleanupTimerRef.current = null;
|
115
|
+
disposeAllRemainingQueryReferences(preloadableRequest, null);
|
116
|
+
};
|
117
|
+
}, [preloadableRequest]);
|
118
|
+
return [queryReference.kind === 'NullQueryReference' ? null : queryReference, queryLoaderCallback, disposeQuery];
|
119
|
+
}
|
120
|
+
module.exports = useQueryLoader_EXPERIMENTAL;
|