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.
- package/ReactRelayContainerUtils.js.flow +2 -2
- package/ReactRelayContext.js +1 -1
- package/ReactRelayContext.js.flow +1 -1
- package/ReactRelayFragmentContainer.js.flow +2 -2
- package/ReactRelayPaginationContainer.js.flow +2 -2
- package/ReactRelayQueryRenderer.js.flow +1 -1
- package/ReactRelayQueryRendererContext.js.flow +1 -1
- package/ReactRelayRefetchContainer.js.flow +2 -2
- package/ReactRelayTypes.js.flow +45 -18
- package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +2 -2
- package/buildReactRelayContainer.js.flow +6 -5
- 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/loadEntryPoint.js +8 -5
- package/lib/relay-hooks/loadQuery.js +2 -14
- package/lib/relay-hooks/readFragmentInternal.js +2 -4
- package/lib/relay-hooks/useEntryPointLoader.js +5 -8
- package/lib/relay-hooks/useFragment.js +4 -7
- package/lib/relay-hooks/useFragmentInternal.js +6 -484
- package/lib/relay-hooks/useFragmentInternal_CURRENT.js +477 -0
- package/lib/relay-hooks/useFragmentInternal_EXPERIMENTAL.js +499 -0
- package/lib/relay-hooks/useLazyLoadQuery.js +2 -5
- package/lib/relay-hooks/useLoadMoreFunction.js +10 -43
- package/lib/relay-hooks/useLoadMoreFunction_EXPERIMENTAL.js +130 -0
- package/lib/relay-hooks/usePreloadedQuery.js +6 -9
- package/lib/relay-hooks/useQueryLoader.js +9 -3
- package/lib/relay-hooks/useQueryLoader_EXPERIMENTAL.js +120 -0
- package/multi-actor/ActorChange.js.flow +1 -1
- package/package.json +3 -3
- 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/EntryPointTypes.flow.js.flow +35 -12
- package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +8 -4
- package/relay-hooks/MatchContainer.js.flow +1 -1
- package/relay-hooks/ProfilerContext.js.flow +1 -1
- package/relay-hooks/__flowtests__/EntryPointTypes/ExtractQueryTypes-flowtest.js.flow +43 -0
- package/relay-hooks/getConnectionState.js.flow +97 -0
- package/relay-hooks/legacy/FragmentResource.js.flow +2 -13
- package/relay-hooks/loadEntryPoint.js.flow +10 -4
- package/relay-hooks/loadQuery.js.flow +4 -28
- package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +4 -1
- package/relay-hooks/readFragmentInternal.js.flow +1 -10
- package/relay-hooks/useEntryPointLoader.js.flow +3 -4
- package/relay-hooks/useFragment.js.flow +0 -5
- package/relay-hooks/useFragmentInternal.js.flow +19 -643
- package/relay-hooks/useFragmentInternal_CURRENT.js.flow +656 -0
- package/relay-hooks/useFragmentInternal_EXPERIMENTAL.js.flow +718 -0
- package/relay-hooks/useLazyLoadQuery.js.flow +0 -5
- package/relay-hooks/useLoadMoreFunction.js.flow +14 -80
- package/relay-hooks/useLoadMoreFunction_EXPERIMENTAL.js.flow +280 -0
- package/relay-hooks/usePaginationFragment.js.flow +1 -1
- package/relay-hooks/usePreloadedQuery.js.flow +0 -5
- package/relay-hooks/useQueryLoader.js.flow +28 -5
- package/relay-hooks/useQueryLoader_EXPERIMENTAL.js.flow +253 -0
@@ -1,491 +1,13 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
4
|
-
var
|
5
|
-
var
|
6
|
-
var
|
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
|
-
}];
|
164
|
-
} else {
|
165
|
-
var didMissUpdates = false;
|
166
|
-
var currentSnapshots = [];
|
167
|
-
for (var index = 0; index < state.snapshots.length; index++) {
|
168
|
-
var snapshot = state.snapshots[index];
|
169
|
-
var _currentSnapshot = environment.lookup(snapshot.selector);
|
170
|
-
var _updatedData = recycleNodesInto(snapshot.data, _currentSnapshot.data);
|
171
|
-
var _updatedCurrentSnapshot = {
|
172
|
-
data: _updatedData,
|
173
|
-
isMissingData: _currentSnapshot.isMissingData,
|
174
|
-
missingClientEdges: _currentSnapshot.missingClientEdges,
|
175
|
-
missingLiveResolverFields: _currentSnapshot.missingLiveResolverFields,
|
176
|
-
seenRecords: _currentSnapshot.seenRecords,
|
177
|
-
selector: _currentSnapshot.selector,
|
178
|
-
missingRequiredFields: _currentSnapshot.missingRequiredFields,
|
179
|
-
relayResolverErrors: _currentSnapshot.relayResolverErrors,
|
180
|
-
errorResponseFields: _currentSnapshot.errorResponseFields
|
181
|
-
};
|
182
|
-
if (_updatedData !== snapshot.data) {
|
183
|
-
didMissUpdates = true;
|
184
|
-
}
|
185
|
-
currentSnapshots.push(_updatedCurrentSnapshot);
|
186
|
-
}
|
187
|
-
!(currentSnapshots.length === state.snapshots.length) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Expected same number of snapshots') : invariant(false) : void 0;
|
188
|
-
return [didMissUpdates, {
|
189
|
-
kind: 'plural',
|
190
|
-
snapshots: currentSnapshots,
|
191
|
-
epoch: currentEpoch
|
192
|
-
}];
|
193
|
-
}
|
194
|
-
}
|
195
|
-
function handleMissingClientEdge(environment, parentFragmentNode, parentFragmentRef, missingClientEdgeRequestInfo, queryOptions) {
|
196
|
-
var originalVariables = getVariablesFromFragment(parentFragmentNode, parentFragmentRef);
|
197
|
-
var variables = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, originalVariables), {}, {
|
198
|
-
id: missingClientEdgeRequestInfo.clientEdgeDestinationID
|
199
|
-
});
|
200
|
-
var queryOperationDescriptor = createOperationDescriptor(missingClientEdgeRequestInfo.request, variables, queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.networkCacheConfig);
|
201
|
-
var QueryResource = getQueryResourceForEnvironment(environment);
|
202
|
-
var queryResult = QueryResource.prepare(queryOperationDescriptor, fetchQueryInternal(environment, queryOperationDescriptor), queryOptions === null || queryOptions === void 0 ? void 0 : queryOptions.fetchPolicy);
|
203
|
-
return [queryResult, getPromiseForActiveRequest(environment, queryOperationDescriptor.request)];
|
204
|
-
}
|
205
|
-
function subscribeToSnapshot(environment, state, setState, hasPendingStateChanges) {
|
206
|
-
if (state.kind === 'bailout') {
|
207
|
-
return function () {};
|
208
|
-
} else if (state.kind === 'singular') {
|
209
|
-
var disposable = environment.subscribe(state.snapshot, function (latestSnapshot) {
|
210
|
-
setState(function (prevState) {
|
211
|
-
if (prevState.kind !== 'singular' || prevState.snapshot.selector !== latestSnapshot.selector) {
|
212
|
-
var updates = handleMissedUpdates(environment, prevState);
|
213
|
-
if (updates != null) {
|
214
|
-
var dataChanged = updates[0],
|
215
|
-
nextState = updates[1];
|
216
|
-
environment.__log({
|
217
|
-
name: 'useFragment.subscription.missedUpdates',
|
218
|
-
hasDataChanges: dataChanged
|
219
|
-
});
|
220
|
-
hasPendingStateChanges.current = dataChanged;
|
221
|
-
return dataChanged ? nextState : prevState;
|
222
|
-
} else {
|
223
|
-
return prevState;
|
224
|
-
}
|
225
|
-
}
|
226
|
-
hasPendingStateChanges.current = true;
|
227
|
-
return {
|
228
|
-
kind: 'singular',
|
229
|
-
snapshot: latestSnapshot,
|
230
|
-
epoch: environment.getStore().getEpoch()
|
231
|
-
};
|
232
|
-
});
|
233
|
-
});
|
234
|
-
return function () {
|
235
|
-
disposable.dispose();
|
236
|
-
};
|
237
|
-
} else {
|
238
|
-
var disposables = state.snapshots.map(function (snapshot, index) {
|
239
|
-
return environment.subscribe(snapshot, function (latestSnapshot) {
|
240
|
-
setState(function (prevState) {
|
241
|
-
var _prevState$snapshots$;
|
242
|
-
if (prevState.kind !== 'plural' || ((_prevState$snapshots$ = prevState.snapshots[index]) === null || _prevState$snapshots$ === void 0 ? void 0 : _prevState$snapshots$.selector) !== latestSnapshot.selector) {
|
243
|
-
var updates = handleMissedUpdates(environment, prevState);
|
244
|
-
if (updates != null) {
|
245
|
-
var dataChanged = updates[0],
|
246
|
-
nextState = updates[1];
|
247
|
-
environment.__log({
|
248
|
-
name: 'useFragment.subscription.missedUpdates',
|
249
|
-
hasDataChanges: dataChanged
|
250
|
-
});
|
251
|
-
hasPendingStateChanges.current = hasPendingStateChanges.current || dataChanged;
|
252
|
-
return dataChanged ? nextState : prevState;
|
253
|
-
} else {
|
254
|
-
return prevState;
|
255
|
-
}
|
256
|
-
}
|
257
|
-
var updated = (0, _toConsumableArray2["default"])(prevState.snapshots);
|
258
|
-
updated[index] = latestSnapshot;
|
259
|
-
hasPendingStateChanges.current = true;
|
260
|
-
return {
|
261
|
-
kind: 'plural',
|
262
|
-
snapshots: updated,
|
263
|
-
epoch: environment.getStore().getEpoch()
|
264
|
-
};
|
265
|
-
});
|
266
|
-
});
|
267
|
-
});
|
268
|
-
return function () {
|
269
|
-
var _iterator6 = (0, _createForOfIteratorHelper2["default"])(disposables),
|
270
|
-
_step6;
|
271
|
-
try {
|
272
|
-
for (_iterator6.s(); !(_step6 = _iterator6.n()).done;) {
|
273
|
-
var d = _step6.value;
|
274
|
-
d.dispose();
|
275
|
-
}
|
276
|
-
} catch (err) {
|
277
|
-
_iterator6.e(err);
|
278
|
-
} finally {
|
279
|
-
_iterator6.f();
|
280
|
-
}
|
281
|
-
};
|
282
|
-
}
|
283
|
-
}
|
284
|
-
function getFragmentState(environment, fragmentSelector) {
|
285
|
-
if (fragmentSelector == null) {
|
286
|
-
return {
|
287
|
-
kind: 'bailout'
|
288
|
-
};
|
289
|
-
} else if (fragmentSelector.kind === 'PluralReaderSelector') {
|
290
|
-
return {
|
291
|
-
kind: 'plural',
|
292
|
-
snapshots: fragmentSelector.selectors.map(function (s) {
|
293
|
-
return environment.lookup(s);
|
294
|
-
}),
|
295
|
-
epoch: environment.getStore().getEpoch()
|
296
|
-
};
|
297
|
-
} else {
|
298
|
-
return {
|
299
|
-
kind: 'singular',
|
300
|
-
snapshot: environment.lookup(fragmentSelector),
|
301
|
-
epoch: environment.getStore().getEpoch()
|
302
|
-
};
|
303
|
-
}
|
304
|
-
}
|
4
|
+
var _useFragmentInternal_CURRENT = _interopRequireDefault(require("./useFragmentInternal_CURRENT"));
|
5
|
+
var _useFragmentInternal_EXPERIMENTAL = _interopRequireDefault(require("./useFragmentInternal_EXPERIMENTAL"));
|
6
|
+
var _relayRuntime = require("relay-runtime");
|
305
7
|
function useFragmentInternal(fragmentNode, fragmentRef, hookDisplayName, queryOptions) {
|
306
|
-
|
307
|
-
|
308
|
-
return getSelector(fragmentNode, fragmentRef);
|
309
|
-
}, [fragmentNode, fragmentRef]);
|
310
|
-
var isPlural = (fragmentNode === null || fragmentNode === void 0 ? void 0 : (_fragmentNode$metadat = fragmentNode.metadata) === null || _fragmentNode$metadat === void 0 ? void 0 : _fragmentNode$metadat.plural) === true;
|
311
|
-
if (isPlural) {
|
312
|
-
!(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;
|
313
|
-
} else {
|
314
|
-
!!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;
|
315
|
-
}
|
316
|
-
!(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;
|
317
|
-
var environment = useRelayEnvironment();
|
318
|
-
var _useState = useState(function () {
|
319
|
-
return getFragmentState(environment, fragmentSelector);
|
320
|
-
}),
|
321
|
-
_state = _useState[0],
|
322
|
-
setState = _useState[1];
|
323
|
-
var state = _state;
|
324
|
-
var _useState2 = useState(state),
|
325
|
-
_subscribedState = _useState2[0],
|
326
|
-
setSubscribedState = _useState2[1];
|
327
|
-
var subscribedState = _subscribedState;
|
328
|
-
var _useState3 = useState(fragmentSelector),
|
329
|
-
previousFragmentSelector = _useState3[0],
|
330
|
-
setPreviousFragmentSelector = _useState3[1];
|
331
|
-
var _useState4 = useState(environment),
|
332
|
-
previousEnvironment = _useState4[0],
|
333
|
-
setPreviousEnvironment = _useState4[1];
|
334
|
-
if (!areEqualSelectors(fragmentSelector, previousFragmentSelector) || environment !== previousEnvironment) {
|
335
|
-
setPreviousFragmentSelector(fragmentSelector);
|
336
|
-
setPreviousEnvironment(environment);
|
337
|
-
var newState = getFragmentState(environment, fragmentSelector);
|
338
|
-
setState(newState);
|
339
|
-
setSubscribedState(newState);
|
340
|
-
state = newState;
|
341
|
-
subscribedState = newState;
|
342
|
-
}
|
343
|
-
var committedFragmentSelectorRef = useRef(false);
|
344
|
-
useEffect(function () {
|
345
|
-
committedFragmentSelectorRef.current = fragmentSelector;
|
346
|
-
}, [fragmentSelector]);
|
347
|
-
if (((_fragmentNode$metadat2 = fragmentNode.metadata) === null || _fragmentNode$metadat2 === void 0 ? void 0 : _fragmentNode$metadat2.hasClientEdges) === true) {
|
348
|
-
var _useMemo = useMemo(function () {
|
349
|
-
var missingClientEdges = getMissingClientEdges(state);
|
350
|
-
var clientEdgeQueries;
|
351
|
-
var activeRequestPromises = [];
|
352
|
-
if (missingClientEdges !== null && missingClientEdges !== void 0 && missingClientEdges.length) {
|
353
|
-
clientEdgeQueries = [];
|
354
|
-
var _iterator7 = (0, _createForOfIteratorHelper2["default"])(missingClientEdges),
|
355
|
-
_step7;
|
356
|
-
try {
|
357
|
-
for (_iterator7.s(); !(_step7 = _iterator7.n()).done;) {
|
358
|
-
var edge = _step7.value;
|
359
|
-
var _handleMissingClientE = handleMissingClientEdge(environment, fragmentNode, fragmentRef, edge, queryOptions),
|
360
|
-
queryResult = _handleMissingClientE[0],
|
361
|
-
requestPromise = _handleMissingClientE[1];
|
362
|
-
clientEdgeQueries.push(queryResult);
|
363
|
-
if (requestPromise != null) {
|
364
|
-
activeRequestPromises.push(requestPromise);
|
365
|
-
}
|
366
|
-
}
|
367
|
-
} catch (err) {
|
368
|
-
_iterator7.e(err);
|
369
|
-
} finally {
|
370
|
-
_iterator7.f();
|
371
|
-
}
|
372
|
-
}
|
373
|
-
return [clientEdgeQueries, activeRequestPromises];
|
374
|
-
}, [state, environment, fragmentNode, fragmentRef, queryOptions]),
|
375
|
-
clientEdgeQueries = _useMemo[0],
|
376
|
-
activeRequestPromises = _useMemo[1];
|
377
|
-
if (activeRequestPromises.length) {
|
378
|
-
throw Promise.all(activeRequestPromises);
|
379
|
-
}
|
380
|
-
useEffect(function () {
|
381
|
-
var QueryResource = getQueryResourceForEnvironment(environment);
|
382
|
-
if (clientEdgeQueries !== null && clientEdgeQueries !== void 0 && clientEdgeQueries.length) {
|
383
|
-
var disposables = [];
|
384
|
-
var _iterator8 = (0, _createForOfIteratorHelper2["default"])(clientEdgeQueries),
|
385
|
-
_step8;
|
386
|
-
try {
|
387
|
-
for (_iterator8.s(); !(_step8 = _iterator8.n()).done;) {
|
388
|
-
var query = _step8.value;
|
389
|
-
disposables.push(QueryResource.retain(query));
|
390
|
-
}
|
391
|
-
} catch (err) {
|
392
|
-
_iterator8.e(err);
|
393
|
-
} finally {
|
394
|
-
_iterator8.f();
|
395
|
-
}
|
396
|
-
return function () {
|
397
|
-
var _iterator9 = (0, _createForOfIteratorHelper2["default"])(disposables),
|
398
|
-
_step9;
|
399
|
-
try {
|
400
|
-
for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
|
401
|
-
var disposable = _step9.value;
|
402
|
-
disposable.dispose();
|
403
|
-
}
|
404
|
-
} catch (err) {
|
405
|
-
_iterator9.e(err);
|
406
|
-
} finally {
|
407
|
-
_iterator9.f();
|
408
|
-
}
|
409
|
-
};
|
410
|
-
}
|
411
|
-
}, [environment, clientEdgeQueries]);
|
412
|
-
}
|
413
|
-
if (isMissingData(state)) {
|
414
|
-
var suspendingLiveResolvers = getSuspendingLiveResolver(state);
|
415
|
-
if (suspendingLiveResolvers != null && suspendingLiveResolvers.length > 0) {
|
416
|
-
throw Promise.all(suspendingLiveResolvers.map(function (_ref) {
|
417
|
-
var liveStateID = _ref.liveStateID;
|
418
|
-
return environment.getStore().getLiveResolverPromise(liveStateID);
|
419
|
-
}));
|
420
|
-
}
|
421
|
-
if (RelayFeatureFlags.ENABLE_RELAY_OPERATION_TRACKER_SUSPENSE || environment !== previousEnvironment || !committedFragmentSelectorRef.current || !areEqualSelectors(committedFragmentSelectorRef.current, fragmentSelector)) {
|
422
|
-
!(fragmentSelector != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'refinement, see invariants above') : invariant(false) : void 0;
|
423
|
-
var fragmentOwner = fragmentSelector.kind === 'PluralReaderSelector' ? fragmentSelector.selectors[0].owner : fragmentSelector.owner;
|
424
|
-
var pendingOperationsResult = getPendingOperationsForFragment(environment, fragmentNode, fragmentOwner);
|
425
|
-
if (pendingOperationsResult) {
|
426
|
-
throw pendingOperationsResult.promise;
|
427
|
-
}
|
428
|
-
}
|
429
|
-
}
|
430
|
-
handlePotentialSnapshotErrorsForState(environment, state);
|
431
|
-
var hasPendingStateChanges = useRef(false);
|
432
|
-
useEffect(function () {
|
433
|
-
var currentState = subscribedState;
|
434
|
-
var updates = handleMissedUpdates(environment, subscribedState);
|
435
|
-
if (updates !== null) {
|
436
|
-
var didMissUpdates = updates[0],
|
437
|
-
updatedState = updates[1];
|
438
|
-
if (didMissUpdates) {
|
439
|
-
setState(updatedState);
|
440
|
-
}
|
441
|
-
currentState = updatedState;
|
442
|
-
}
|
443
|
-
return subscribeToSnapshot(environment, currentState, setState, hasPendingStateChanges);
|
444
|
-
}, [environment, subscribedState]);
|
445
|
-
if (hasPendingStateChanges.current) {
|
446
|
-
var updates = handleMissedUpdates(environment, state);
|
447
|
-
if (updates != null) {
|
448
|
-
var hasStateUpdates = updates[0],
|
449
|
-
updatedState = updates[1];
|
450
|
-
if (hasStateUpdates) {
|
451
|
-
setState(updatedState);
|
452
|
-
state = updatedState;
|
453
|
-
}
|
454
|
-
}
|
455
|
-
hasPendingStateChanges.current = false;
|
456
|
-
}
|
457
|
-
var data;
|
458
|
-
if (isPlural) {
|
459
|
-
var fragmentRefIsNullish = fragmentRef == null;
|
460
|
-
data = useMemo(function () {
|
461
|
-
if (state.kind === 'bailout') {
|
462
|
-
return fragmentRefIsNullish ? null : [];
|
463
|
-
} else {
|
464
|
-
!(state.kind === 'plural') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Expected state to be plural because fragment is plural') : invariant(false) : void 0;
|
465
|
-
return state.snapshots.map(function (s) {
|
466
|
-
return s.data;
|
467
|
-
});
|
468
|
-
}
|
469
|
-
}, [state, fragmentRefIsNullish]);
|
470
|
-
} else if (state.kind === 'bailout') {
|
471
|
-
data = null;
|
472
|
-
} else {
|
473
|
-
!(state.kind === 'singular') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Expected state to be singular because fragment is singular') : invariant(false) : void 0;
|
474
|
-
data = state.snapshot.data;
|
475
|
-
}
|
476
|
-
if (RelayFeatureFlags.LOG_MISSING_RECORDS_IN_PROD || process.env.NODE_ENV !== "production") {
|
477
|
-
if (fragmentRef != null && (data === undefined || Array.isArray(data) && data.length > 0 && data.every(function (d) {
|
478
|
-
return d === undefined;
|
479
|
-
}))) {
|
480
|
-
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;
|
481
|
-
}
|
482
|
-
}
|
483
|
-
if (process.env.NODE_ENV !== "production") {
|
484
|
-
useDebugValue({
|
485
|
-
fragment: fragmentNode.name,
|
486
|
-
data: data
|
487
|
-
});
|
8
|
+
if (_relayRuntime.RelayFeatureFlags.ENABLE_ACTIVITY_COMPATIBILITY) {
|
9
|
+
return (0, _useFragmentInternal_EXPERIMENTAL["default"])(fragmentNode, fragmentRef, hookDisplayName, queryOptions);
|
488
10
|
}
|
489
|
-
return
|
11
|
+
return (0, _useFragmentInternal_CURRENT["default"])(fragmentNode, fragmentRef, hookDisplayName, queryOptions);
|
490
12
|
}
|
491
13
|
module.exports = useFragmentInternal;
|