react-relay 16.2.0 → 17.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/ReactRelayContext.js +1 -1
- package/ReactRelayFragmentContainer.js.flow +8 -6
- package/ReactRelayLocalQueryRenderer.js.flow +4 -1
- package/ReactRelayPaginationContainer.js.flow +2 -0
- package/ReactRelayQueryRenderer.js.flow +1 -1
- package/buildReactRelayContainer.js.flow +5 -3
- package/getRootVariablesForFragments.js.flow +1 -0
- package/hooks.js +1 -1
- package/index.js +1 -1
- package/legacy.js +1 -1
- package/lib/ReactRelayFragmentContainer.js +2 -2
- package/lib/buildReactRelayContainer.js +3 -3
- package/lib/relay-hooks/legacy/FragmentResource.js +14 -16
- package/lib/relay-hooks/{experimental/readFragmentInternal_EXPERIMENTAL.js → readFragmentInternal.js} +7 -5
- package/lib/relay-hooks/useFragment.js +3 -13
- package/lib/relay-hooks/{experimental/useFragmentInternal_EXPERIMENTAL.js → useFragmentInternal.js} +9 -7
- package/lib/relay-hooks/useLazyLoadQueryNode.js +2 -13
- package/lib/relay-hooks/usePaginationFragment.js +17 -13
- package/lib/relay-hooks/useRefetchableFragment.js +3 -12
- package/lib/relay-hooks/{experimental/useRefetchableFragmentInternal_EXPERIMENTAL.js → useRefetchableFragmentInternal.js} +7 -7
- package/multi-actor/useRelayActorEnvironment.js.flow +1 -1
- 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 +2 -2
- package/react-relay-legacy.min.js +2 -2
- package/react-relay.js +2 -2
- package/react-relay.min.js +2 -2
- package/relay-hooks/EntryPointTypes.flow.js.flow +14 -13
- package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +14 -1
- package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +21 -0
- package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +19 -0
- package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +22 -0
- package/relay-hooks/legacy/FragmentResource.js.flow +13 -16
- package/relay-hooks/legacy/useBlockingPaginationFragment.js.flow +2 -2
- package/relay-hooks/legacy/useFragmentNode.js.flow +1 -1
- package/relay-hooks/legacy/useRefetchableFragmentNode.js.flow +2 -2
- package/relay-hooks/loadQuery.js.flow +9 -8
- package/relay-hooks/{experimental/readFragmentInternal_EXPERIMENTAL.js.flow → readFragmentInternal.js.flow} +6 -4
- package/relay-hooks/useClientQuery.js.flow +1 -1
- package/relay-hooks/useEntryPointLoader.js.flow +1 -1
- package/relay-hooks/useFetchTrackingRef.js.flow +1 -1
- package/relay-hooks/useFragment.js.flow +8 -20
- package/relay-hooks/{experimental/useFragmentInternal_EXPERIMENTAL.js.flow → useFragmentInternal.js.flow} +14 -5
- package/relay-hooks/useIsMountedRef.js.flow +1 -1
- package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
- package/relay-hooks/useIsParentQueryActive.js.flow +5 -2
- package/relay-hooks/useLazyLoadQuery.js.flow +3 -2
- package/relay-hooks/useLazyLoadQueryNode.js.flow +3 -19
- package/relay-hooks/useLoadMoreFunction.js.flow +1 -1
- package/relay-hooks/useMemoOperationDescriptor.js.flow +1 -1
- package/relay-hooks/useMemoVariables.js.flow +1 -1
- package/relay-hooks/useMutation.js.flow +1 -1
- package/relay-hooks/usePaginationFragment.js.flow +62 -50
- package/relay-hooks/usePreloadedQuery.js.flow +2 -1
- package/relay-hooks/useQueryLoader.js.flow +2 -5
- package/relay-hooks/useRefetchableFragment.js.flow +7 -37
- package/relay-hooks/{experimental/useRefetchableFragmentInternal_EXPERIMENTAL.js.flow → useRefetchableFragmentInternal.js.flow} +11 -11
- package/relay-hooks/useRelayEnvironment.js.flow +1 -1
- package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -1
- package/relay-hooks/useSubscribeToInvalidationState.js.flow +1 -1
- package/relay-hooks/useSubscription.js.flow +1 -1
- package/relay-hooks/useUnsafeRef_DEPRECATED.js.flow +1 -1
- package/lib/relay-hooks/HooksImplementation.js +0 -15
- package/lib/relay-hooks/experimental/useFragment_EXPERIMENTAL.js +0 -26
- package/lib/relay-hooks/experimental/usePaginationFragment_EXPERIMENTAL.js +0 -127
- package/lib/relay-hooks/experimental/useRefetchableFragment_EXPERIMENTAL.js +0 -23
- package/relay-hooks/HooksImplementation.js.flow +0 -45
- package/relay-hooks/experimental/useFragment_EXPERIMENTAL.js.flow +0 -72
- package/relay-hooks/experimental/usePaginationFragment_EXPERIMENTAL.js.flow +0 -161
- package/relay-hooks/experimental/useRefetchableFragment_EXPERIMENTAL.js.flow +0 -49
package/ReactRelayContext.js
CHANGED
@@ -242,12 +242,14 @@ function createContainerWithFragments<
|
|
242
242
|
// eslint-disable-next-line no-unused-vars
|
243
243
|
const {componentRef, __relayContext, __rootIsQueryRenderer, ...props} =
|
244
244
|
this.props;
|
245
|
-
return
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
245
|
+
return (
|
246
|
+
<Component
|
247
|
+
{...props}
|
248
|
+
{...this.state.data}
|
249
|
+
ref={componentRef}
|
250
|
+
relay={this.state.relayProp}
|
251
|
+
/>
|
252
|
+
);
|
251
253
|
}
|
252
254
|
};
|
253
255
|
}
|
@@ -40,14 +40,17 @@ const queryRendererContext: ReactRelayQueryRendererContextType = {
|
|
40
40
|
rootIsQueryRenderer: true,
|
41
41
|
};
|
42
42
|
|
43
|
-
|
43
|
+
hook useDeepCompare<T: {...}>(value: T): T {
|
44
44
|
const latestValue = React.useRef(value);
|
45
|
+
// $FlowFixMe[react-rule-unsafe-ref]
|
45
46
|
if (!areEqual(latestValue.current, value)) {
|
46
47
|
if (__DEV__) {
|
47
48
|
deepFreeze(value);
|
48
49
|
}
|
50
|
+
// $FlowFixMe[react-rule-unsafe-ref]
|
49
51
|
latestValue.current = value;
|
50
52
|
}
|
53
|
+
// $FlowFixMe[react-rule-unsafe-ref]
|
51
54
|
return latestValue.current;
|
52
55
|
}
|
53
56
|
|
@@ -595,7 +595,9 @@ function createContainerWithFragments<
|
|
595
595
|
PAGE_INFO,
|
596
596
|
connectionData,
|
597
597
|
);
|
598
|
+
// $FlowFixMe[invalid-computed-prop]
|
598
599
|
const edges = connectionData[EDGES];
|
600
|
+
// $FlowFixMe[invalid-computed-prop]
|
599
601
|
const pageInfo = connectionData[PAGE_INFO];
|
600
602
|
if (edges == null || pageInfo == null) {
|
601
603
|
return null;
|
@@ -378,7 +378,7 @@ function fetchQueryAndComputeStateFromProps(
|
|
378
378
|
requestCacheKey: ?string,
|
379
379
|
): Partial<State> {
|
380
380
|
const {environment, query, variables, cacheConfig} = props;
|
381
|
-
const genericEnvironment =
|
381
|
+
const genericEnvironment: IEnvironment = environment;
|
382
382
|
if (query) {
|
383
383
|
const request = getRequest(query);
|
384
384
|
const operation = createOperationDescriptor(
|
@@ -52,12 +52,13 @@ function buildReactRelayContainer<TBase: React$ComponentType<any>>(
|
|
52
52
|
const Container = createContainerWithFragments(ComponentClass, fragments);
|
53
53
|
Container.displayName = containerName;
|
54
54
|
|
55
|
-
function
|
55
|
+
function ForwardRef(
|
56
56
|
props: any,
|
57
57
|
ref:
|
58
58
|
| ((null | React$ElementRef<TBase>) => mixed)
|
59
59
|
| {-current: null | React$ElementRef<TBase>, ...},
|
60
60
|
) {
|
61
|
+
// $FlowFixMe[react-rule-hook]
|
61
62
|
const context = useContext(ReactRelayContext);
|
62
63
|
invariant(
|
63
64
|
context != null,
|
@@ -66,6 +67,7 @@ function buildReactRelayContainer<TBase: React$ComponentType<any>>(
|
|
66
67
|
containerName,
|
67
68
|
containerName,
|
68
69
|
);
|
70
|
+
// $FlowFixMe[react-rule-hook]
|
69
71
|
const queryRendererContext = useContext(ReactRelayQueryRendererContext);
|
70
72
|
|
71
73
|
return (
|
@@ -79,8 +81,8 @@ function buildReactRelayContainer<TBase: React$ComponentType<any>>(
|
|
79
81
|
/>
|
80
82
|
);
|
81
83
|
}
|
82
|
-
|
83
|
-
const ForwardContainer = React.forwardRef(
|
84
|
+
ForwardRef.displayName = containerName;
|
85
|
+
const ForwardContainer = React.forwardRef(ForwardRef);
|
84
86
|
|
85
87
|
if (__DEV__) {
|
86
88
|
// Used by RelayModernTestUtils
|
@@ -25,6 +25,7 @@ function getRootVariablesForFragments<TProps: {...}>(
|
|
25
25
|
// should all point to the same owner
|
26
26
|
Object.keys(fragments).forEach(key => {
|
27
27
|
const fragmentNode = fragments[key];
|
28
|
+
// $FlowFixMe[invalid-computed-prop]
|
28
29
|
const fragmentRef = props[key];
|
29
30
|
const selector = getSelector(fragmentNode, fragmentRef);
|
30
31
|
const fragmentOwnerVariables =
|
package/hooks.js
CHANGED
package/index.js
CHANGED
package/legacy.js
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
4
|
-
var
|
4
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
5
5
|
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
6
6
|
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
7
7
|
var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
|
@@ -141,7 +141,7 @@ function createContainerWithFragments(Component, fragments) {
|
|
141
141
|
__relayContext = _this$props.__relayContext,
|
142
142
|
__rootIsQueryRenderer = _this$props.__rootIsQueryRenderer,
|
143
143
|
props = (0, _objectWithoutPropertiesLoose2["default"])(_this$props, _excluded);
|
144
|
-
return React.createElement(Component, (0,
|
144
|
+
return /*#__PURE__*/React.createElement(Component, (0, _extends2["default"])({}, props, this.state.data, {
|
145
145
|
ref: componentRef,
|
146
146
|
relay: this.state.relayProp
|
147
147
|
}));
|
@@ -22,7 +22,7 @@ function buildReactRelayContainer(ComponentClass, fragmentSpec, createContainerW
|
|
22
22
|
}
|
23
23
|
var Container = createContainerWithFragments(ComponentClass, fragments);
|
24
24
|
Container.displayName = containerName;
|
25
|
-
function
|
25
|
+
function ForwardRef(props, ref) {
|
26
26
|
var _queryRendererContext;
|
27
27
|
var context = useContext(ReactRelayContext);
|
28
28
|
!(context != null) ? process.env.NODE_ENV !== "production" ? invariant(false, '`%s` tried to render a context that was not valid this means that ' + '`%s` was rendered outside of a query renderer.', containerName, containerName) : invariant(false) : void 0;
|
@@ -33,8 +33,8 @@ function buildReactRelayContainer(ComponentClass, fragmentSpec, createContainerW
|
|
33
33
|
componentRef: props.componentRef || ref
|
34
34
|
}));
|
35
35
|
}
|
36
|
-
|
37
|
-
var ForwardContainer = React.forwardRef(
|
36
|
+
ForwardRef.displayName = containerName;
|
37
|
+
var ForwardContainer = React.forwardRef(ForwardRef);
|
38
38
|
if (process.env.NODE_ENV !== "production") {
|
39
39
|
ForwardContainer.__ComponentClass = ComponentClass;
|
40
40
|
ForwardContainer.displayName = containerName;
|
@@ -131,9 +131,7 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
|
|
131
131
|
function FragmentResourceImpl(environment) {
|
132
132
|
this._environment = environment;
|
133
133
|
this._cache = LRUCache.create(CACHE_CAPACITY);
|
134
|
-
|
135
|
-
this._clientEdgeQueryResultsCache = new ClientEdgeQueryResultsCache(environment);
|
136
|
-
}
|
134
|
+
this._clientEdgeQueryResultsCache = new ClientEdgeQueryResultsCache(environment);
|
137
135
|
}
|
138
136
|
var _proto2 = FragmentResourceImpl.prototype;
|
139
137
|
_proto2.read = function read(fragmentNode, fragmentRef, componentDisplayName, fragmentKey) {
|
@@ -216,7 +214,7 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
|
|
216
214
|
return fragmentResult;
|
217
215
|
}
|
218
216
|
var clientEdgeRequests = null;
|
219
|
-
if (
|
217
|
+
if (((_fragmentNode$metadat2 = fragmentNode.metadata) === null || _fragmentNode$metadat2 === void 0 ? void 0 : _fragmentNode$metadat2.hasClientEdges) === true && hasMissingClientEdges(snapshot)) {
|
220
218
|
clientEdgeRequests = [];
|
221
219
|
var queryResource = getQueryResourceForEnvironment(this._environment);
|
222
220
|
var queryResults = [];
|
@@ -237,7 +235,7 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
|
|
237
235
|
this._clientEdgeQueryResultsCache.recordQueryResults(fragmentIdentifier, queryResults);
|
238
236
|
}
|
239
237
|
var clientEdgePromises = [];
|
240
|
-
if (
|
238
|
+
if (clientEdgeRequests) {
|
241
239
|
clientEdgePromises = clientEdgeRequests.map(function (request) {
|
242
240
|
return getPromiseForActiveRequest(_this3._environment, request);
|
243
241
|
}).filter(Boolean);
|
@@ -311,10 +309,12 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
|
|
311
309
|
var _this4 = this;
|
312
310
|
if (Array.isArray(snapshot)) {
|
313
311
|
snapshot.forEach(function (s) {
|
314
|
-
|
312
|
+
var _s$selector$node$meta, _s$selector$node$meta2;
|
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);
|
315
314
|
});
|
316
315
|
} else {
|
317
|
-
|
316
|
+
var _snapshot$selector$no, _snapshot$selector$no2;
|
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);
|
318
318
|
}
|
319
319
|
};
|
320
320
|
_proto2.readSpec = function readSpec(fragmentNodes, fragmentRefs, componentDisplayName) {
|
@@ -326,6 +326,7 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
|
|
326
326
|
};
|
327
327
|
_proto2.subscribe = function subscribe(fragmentResult, callback) {
|
328
328
|
var _this5 = this;
|
329
|
+
var _this$_clientEdgeQuer, _this$_clientEdgeQuer2;
|
329
330
|
var environment = this._environment;
|
330
331
|
var cacheKey = fragmentResult.cacheKey;
|
331
332
|
var renderedSnapshot = fragmentResult.snapshot;
|
@@ -370,15 +371,12 @@ var FragmentResourceImpl = /*#__PURE__*/function () {
|
|
370
371
|
callback();
|
371
372
|
}));
|
372
373
|
}
|
373
|
-
|
374
|
-
|
375
|
-
var
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
disposables.push(queryResource.retain(queryResult));
|
380
|
-
});
|
381
|
-
}
|
374
|
+
var clientEdgeQueryResults = (_this$_clientEdgeQuer = (_this$_clientEdgeQuer2 = this._clientEdgeQueryResultsCache) === null || _this$_clientEdgeQuer2 === void 0 ? void 0 : _this$_clientEdgeQuer2.get(cacheKey)) !== null && _this$_clientEdgeQuer !== void 0 ? _this$_clientEdgeQuer : undefined;
|
375
|
+
if (clientEdgeQueryResults !== null && clientEdgeQueryResults !== void 0 && clientEdgeQueryResults.length) {
|
376
|
+
var queryResource = getQueryResourceForEnvironment(this._environment);
|
377
|
+
clientEdgeQueryResults.forEach(function (queryResult) {
|
378
|
+
disposables.push(queryResource.retain(queryResult));
|
379
|
+
});
|
382
380
|
}
|
383
381
|
return {
|
384
382
|
dispose: function dispose() {
|
@@ -3,7 +3,7 @@
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
4
4
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
5
5
|
var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
|
6
|
-
var _require = require('
|
6
|
+
var _require = require('./QueryResource'),
|
7
7
|
getQueryResourceForEnvironment = _require.getQueryResourceForEnvironment;
|
8
8
|
var invariant = require('invariant');
|
9
9
|
var _require2 = require('relay-runtime'),
|
@@ -66,14 +66,16 @@ function getMissingClientEdges(state) {
|
|
66
66
|
}
|
67
67
|
function handlePotentialSnapshotErrorsForState(environment, state) {
|
68
68
|
if (state.kind === 'singular') {
|
69
|
-
|
69
|
+
var _state$snapshot$selec, _state$snapshot$selec2;
|
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);
|
70
71
|
} else if (state.kind === 'plural') {
|
71
72
|
var _iterator3 = (0, _createForOfIteratorHelper2["default"])(state.snapshots),
|
72
73
|
_step3;
|
73
74
|
try {
|
74
75
|
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
76
|
+
var _snapshot$selector$no, _snapshot$selector$no2;
|
75
77
|
var snapshot = _step3.value;
|
76
|
-
handlePotentialSnapshotErrors(environment, snapshot.missingRequiredFields, snapshot.relayResolverErrors, snapshot.errorResponseFields);
|
78
|
+
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);
|
77
79
|
}
|
78
80
|
} catch (err) {
|
79
81
|
_iterator3.e(err);
|
@@ -118,7 +120,7 @@ function getFragmentState(environment, fragmentSelector) {
|
|
118
120
|
};
|
119
121
|
}
|
120
122
|
}
|
121
|
-
function
|
123
|
+
function readFragmentInternal(environment, fragmentNode, fragmentRef, hookDisplayName, queryOptions, fragmentKey) {
|
122
124
|
var _fragmentNode$metadat, _fragmentNode$metadat2;
|
123
125
|
var fragmentSelector = getSelector(fragmentNode, fragmentRef);
|
124
126
|
var isPlural = (fragmentNode === null || fragmentNode === void 0 ? void 0 : (_fragmentNode$metadat = fragmentNode.metadata) === null || _fragmentNode$metadat === void 0 ? void 0 : _fragmentNode$metadat.plural) === true;
|
@@ -179,4 +181,4 @@ function readFragmentInternal_EXPERIMENTAL(environment, fragmentNode, fragmentRe
|
|
179
181
|
clientEdgeQueries: clientEdgeQueries
|
180
182
|
};
|
181
183
|
}
|
182
|
-
module.exports =
|
184
|
+
module.exports = readFragmentInternal;
|
@@ -1,20 +1,18 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
var HooksImplementation = require('./HooksImplementation');
|
4
|
-
var useFragmentNode = require('./legacy/useFragmentNode');
|
5
3
|
var _require = require('./loadQuery'),
|
6
4
|
useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
|
5
|
+
var useFragmentInternal = require('./useFragmentInternal');
|
7
6
|
var useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
|
8
7
|
var _require2 = require('react'),
|
9
8
|
useDebugValue = _require2.useDebugValue;
|
10
9
|
var _require3 = require('relay-runtime'),
|
11
10
|
getFragment = _require3.getFragment;
|
12
|
-
function
|
11
|
+
function useFragment(fragment, key) {
|
13
12
|
useTrackLoadQueryInRender();
|
14
13
|
var fragmentNode = getFragment(fragment);
|
15
14
|
useStaticFragmentNodeWarning(fragmentNode, 'first argument of useFragment()');
|
16
|
-
var
|
17
|
-
data = _useFragmentNode.data;
|
15
|
+
var data = useFragmentInternal(fragmentNode, key, 'useFragment()');
|
18
16
|
if (process.env.NODE_ENV !== "production") {
|
19
17
|
useDebugValue({
|
20
18
|
fragment: fragmentNode.name,
|
@@ -23,12 +21,4 @@ function useFragment_LEGACY(fragment, key) {
|
|
23
21
|
}
|
24
22
|
return data;
|
25
23
|
}
|
26
|
-
function useFragment(fragment, key) {
|
27
|
-
var impl = HooksImplementation.get();
|
28
|
-
if (impl) {
|
29
|
-
return impl.useFragment(fragment, key);
|
30
|
-
} else {
|
31
|
-
return useFragment_LEGACY(fragment, key);
|
32
|
-
}
|
33
|
-
}
|
34
24
|
module.exports = useFragment;
|
package/lib/relay-hooks/{experimental/useFragmentInternal_EXPERIMENTAL.js → useFragmentInternal.js}
RENAMED
@@ -4,9 +4,9 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
4
4
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
5
5
|
var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
|
6
6
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
7
|
-
var _require = require('
|
7
|
+
var _require = require('./QueryResource'),
|
8
8
|
getQueryResourceForEnvironment = _require.getQueryResourceForEnvironment;
|
9
|
-
var useRelayEnvironment = require('
|
9
|
+
var useRelayEnvironment = require('./useRelayEnvironment');
|
10
10
|
var invariant = require('invariant');
|
11
11
|
var _require2 = require('react'),
|
12
12
|
useDebugValue = _require2.useDebugValue,
|
@@ -116,14 +116,16 @@ function getSuspendingLiveResolver(state) {
|
|
116
116
|
}
|
117
117
|
function handlePotentialSnapshotErrorsForState(environment, state) {
|
118
118
|
if (state.kind === 'singular') {
|
119
|
-
|
119
|
+
var _state$snapshot$selec, _state$snapshot$selec2;
|
120
|
+
handlePotentialSnapshotErrors(environment, state.snapshot.missingRequiredFields, state.snapshot.relayResolverErrors, state.snapshot.errorResponseFields, (_state$snapshot$selec = (_state$snapshot$selec2 = state.snapshot.selector.node.metadata) === null || _state$snapshot$selec2 === void 0 ? void 0 : _state$snapshot$selec2.throwOnFieldError) !== null && _state$snapshot$selec !== void 0 ? _state$snapshot$selec : false);
|
120
121
|
} else if (state.kind === 'plural') {
|
121
122
|
var _iterator5 = (0, _createForOfIteratorHelper2["default"])(state.snapshots),
|
122
123
|
_step5;
|
123
124
|
try {
|
124
125
|
for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
|
126
|
+
var _snapshot$selector$no, _snapshot$selector$no2;
|
125
127
|
var snapshot = _step5.value;
|
126
|
-
handlePotentialSnapshotErrors(environment, snapshot.missingRequiredFields, snapshot.relayResolverErrors, snapshot.errorResponseFields);
|
128
|
+
handlePotentialSnapshotErrors(environment, snapshot.missingRequiredFields, snapshot.relayResolverErrors, snapshot.errorResponseFields, (_snapshot$selector$no = (_snapshot$selector$no2 = snapshot.selector.node.metadata) === null || _snapshot$selector$no2 === void 0 ? void 0 : _snapshot$selector$no2.throwOnFieldError) !== null && _snapshot$selector$no !== void 0 ? _snapshot$selector$no : false);
|
127
129
|
}
|
128
130
|
} catch (err) {
|
129
131
|
_iterator5.e(err);
|
@@ -300,7 +302,7 @@ function getFragmentState(environment, fragmentSelector) {
|
|
300
302
|
};
|
301
303
|
}
|
302
304
|
}
|
303
|
-
function
|
305
|
+
function useFragmentInternal(fragmentNode, fragmentRef, hookDisplayName, queryOptions) {
|
304
306
|
var _fragmentNode$metadat, _fragmentNode$metadat2;
|
305
307
|
var fragmentSelector = useMemo(function () {
|
306
308
|
return getSelector(fragmentNode, fragmentRef);
|
@@ -416,7 +418,7 @@ function useFragmentInternal_EXPERIMENTAL(fragmentNode, fragmentRef, hookDisplay
|
|
416
418
|
return environment.getStore().getLiveResolverPromise(liveStateID);
|
417
419
|
}));
|
418
420
|
}
|
419
|
-
if (environment !== previousEnvironment || !committedFragmentSelectorRef.current || !areEqualSelectors(committedFragmentSelectorRef.current, fragmentSelector)) {
|
421
|
+
if (RelayFeatureFlags.ENABLE_RELAY_OPERATION_TRACKER_SUSPENSE || environment !== previousEnvironment || !committedFragmentSelectorRef.current || !areEqualSelectors(committedFragmentSelectorRef.current, fragmentSelector)) {
|
420
422
|
!(fragmentSelector != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'refinement, see invariants above') : invariant(false) : void 0;
|
421
423
|
var fragmentOwner = fragmentSelector.kind === 'PluralReaderSelector' ? fragmentSelector.selectors[0].owner : fragmentSelector.owner;
|
422
424
|
var pendingOperationsResult = getPendingOperationsForFragment(environment, fragmentNode, fragmentOwner);
|
@@ -486,4 +488,4 @@ function useFragmentInternal_EXPERIMENTAL(fragmentNode, fragmentRef, hookDisplay
|
|
486
488
|
}
|
487
489
|
return data;
|
488
490
|
}
|
489
|
-
module.exports =
|
491
|
+
module.exports = useFragmentInternal;
|
@@ -1,12 +1,11 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
var HooksImplementation = require('./HooksImplementation');
|
4
|
-
var useFragmentNode = require('./legacy/useFragmentNode');
|
5
3
|
var ProfilerContext = require('./ProfilerContext');
|
6
4
|
var _require = require('./QueryResource'),
|
7
5
|
getQueryCacheIdentifier = _require.getQueryCacheIdentifier,
|
8
6
|
getQueryResourceForEnvironment = _require.getQueryResourceForEnvironment;
|
9
7
|
var useFetchTrackingRef = require('./useFetchTrackingRef');
|
8
|
+
var useFragmentInternal = require('./useFragmentInternal');
|
10
9
|
var useRelayEnvironment = require('./useRelayEnvironment');
|
11
10
|
var React = require('react');
|
12
11
|
var useContext = React.useContext,
|
@@ -62,17 +61,7 @@ function useLazyLoadQueryNode(_ref) {
|
|
62
61
|
});
|
63
62
|
var fragmentNode = preparedQueryResult.fragmentNode,
|
64
63
|
fragmentRef = preparedQueryResult.fragmentRef;
|
65
|
-
var data =
|
64
|
+
var data = useFragmentInternal(fragmentNode, fragmentRef, componentDisplayName);
|
66
65
|
return data;
|
67
66
|
}
|
68
|
-
function useFragmentNodeImpl(fragment, key, componentDisplayName) {
|
69
|
-
var impl = HooksImplementation.get();
|
70
|
-
if (impl && impl.useFragment__internal) {
|
71
|
-
return impl.useFragment__internal(fragment, key, componentDisplayName);
|
72
|
-
} else {
|
73
|
-
var _useFragmentNode = useFragmentNode(fragment, key, componentDisplayName),
|
74
|
-
data = _useFragmentNode.data;
|
75
|
-
return data;
|
76
|
-
}
|
77
|
-
}
|
78
67
|
module.exports = useLazyLoadQueryNode;
|
@@ -2,9 +2,9 @@
|
|
2
2
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
4
4
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
5
|
-
var HooksImplementation = require('./HooksImplementation');
|
6
|
-
var useRefetchableFragmentNode = require('./legacy/useRefetchableFragmentNode');
|
7
5
|
var useLoadMoreFunction = require('./useLoadMoreFunction');
|
6
|
+
var useRefetchableFragmentInternal = require('./useRefetchableFragmentInternal');
|
7
|
+
var useRelayEnvironment = require('./useRelayEnvironment');
|
8
8
|
var useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
|
9
9
|
var _require = require('react'),
|
10
10
|
useCallback = _require.useCallback,
|
@@ -14,7 +14,7 @@ var _require2 = require('relay-runtime'),
|
|
14
14
|
getFragment = _require2.getFragment,
|
15
15
|
getFragmentIdentifier = _require2.getFragmentIdentifier,
|
16
16
|
getPaginationMetadata = _require2.getPaginationMetadata;
|
17
|
-
function
|
17
|
+
function usePaginationFragment(fragmentInput, parentFragmentRef) {
|
18
18
|
var fragmentNode = getFragment(fragmentInput);
|
19
19
|
useStaticFragmentNodeWarning(fragmentNode, 'first argument of usePaginationFragment()');
|
20
20
|
var componentDisplayName = 'usePaginationFragment()';
|
@@ -22,7 +22,7 @@ function usePaginationFragment_LEGACY(fragmentInput, parentFragmentRef) {
|
|
22
22
|
connectionPathInFragmentData = _getPaginationMetadat.connectionPathInFragmentData,
|
23
23
|
paginationRequest = _getPaginationMetadat.paginationRequest,
|
24
24
|
paginationMetadata = _getPaginationMetadat.paginationMetadata;
|
25
|
-
var _useRefetchableFragme =
|
25
|
+
var _useRefetchableFragme = useRefetchableFragmentInternal(fragmentNode, parentFragmentRef, componentDisplayName),
|
26
26
|
fragmentData = _useRefetchableFragme.fragmentData,
|
27
27
|
fragmentRef = _useRefetchableFragme.fragmentRef,
|
28
28
|
refetch = _useRefetchableFragme.refetch;
|
@@ -86,9 +86,21 @@ function usePaginationFragment_LEGACY(fragmentInput, parentFragmentRef) {
|
|
86
86
|
};
|
87
87
|
}
|
88
88
|
function useLoadMore(args) {
|
89
|
+
var environment = useRelayEnvironment();
|
89
90
|
var _useState = useState(false),
|
90
91
|
isLoadingMore = _useState[0],
|
91
|
-
|
92
|
+
reallySetIsLoadingMore = _useState[1];
|
93
|
+
var setIsLoadingMore = function setIsLoadingMore(value) {
|
94
|
+
var _environment$getSched;
|
95
|
+
var schedule = (_environment$getSched = environment.getScheduler()) === null || _environment$getSched === void 0 ? void 0 : _environment$getSched.schedule;
|
96
|
+
if (schedule) {
|
97
|
+
schedule(function () {
|
98
|
+
reallySetIsLoadingMore(value);
|
99
|
+
});
|
100
|
+
} else {
|
101
|
+
reallySetIsLoadingMore(value);
|
102
|
+
}
|
103
|
+
};
|
92
104
|
var observer = {
|
93
105
|
start: function start() {
|
94
106
|
return setIsLoadingMore(true);
|
@@ -112,12 +124,4 @@ function useLoadMore(args) {
|
|
112
124
|
disposeFetch = _useLoadMoreFunction[2];
|
113
125
|
return [loadMore, hasMore, isLoadingMore, disposeFetch];
|
114
126
|
}
|
115
|
-
function usePaginationFragment(fragmentInput, parentFragmentRef) {
|
116
|
-
var impl = HooksImplementation.get();
|
117
|
-
if (impl) {
|
118
|
-
return impl.usePaginationFragment(fragmentInput, parentFragmentRef);
|
119
|
-
} else {
|
120
|
-
return usePaginationFragment_LEGACY(fragmentInput, parentFragmentRef);
|
121
|
-
}
|
122
|
-
}
|
123
127
|
module.exports = usePaginationFragment;
|
@@ -1,16 +1,15 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
-
var
|
4
|
-
var useRefetchableFragmentNode = require('./legacy/useRefetchableFragmentNode');
|
3
|
+
var useRefetchableFragmentInternal = require('./useRefetchableFragmentInternal');
|
5
4
|
var useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
|
6
5
|
var _require = require('react'),
|
7
6
|
useDebugValue = _require.useDebugValue;
|
8
7
|
var _require2 = require('relay-runtime'),
|
9
8
|
getFragment = _require2.getFragment;
|
10
|
-
function
|
9
|
+
function useRefetchableFragment(fragmentInput, fragmentRef) {
|
11
10
|
var fragmentNode = getFragment(fragmentInput);
|
12
11
|
useStaticFragmentNodeWarning(fragmentNode, 'first argument of useRefetchableFragment()');
|
13
|
-
var _useRefetchableFragme =
|
12
|
+
var _useRefetchableFragme = useRefetchableFragmentInternal(fragmentNode, fragmentRef, 'useRefetchableFragment()'),
|
14
13
|
fragmentData = _useRefetchableFragme.fragmentData,
|
15
14
|
refetch = _useRefetchableFragme.refetch;
|
16
15
|
if (process.env.NODE_ENV !== "production") {
|
@@ -21,12 +20,4 @@ function useRefetchableFragment_LEGACY(fragmentInput, fragmentRef) {
|
|
21
20
|
}
|
22
21
|
return [fragmentData, refetch];
|
23
22
|
}
|
24
|
-
function useRefetchableFragment(fragmentInput, parentFragmentRef) {
|
25
|
-
var impl = HooksImplementation.get();
|
26
|
-
if (impl) {
|
27
|
-
return impl.useRefetchableFragment(fragmentInput, parentFragmentRef);
|
28
|
-
} else {
|
29
|
-
return useRefetchableFragment_LEGACY(fragmentInput, parentFragmentRef);
|
30
|
-
}
|
31
|
-
}
|
32
23
|
module.exports = useRefetchableFragment;
|
@@ -2,14 +2,14 @@
|
|
2
2
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
|
4
4
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
5
|
-
var ProfilerContext = require('
|
6
|
-
var _require = require('
|
5
|
+
var ProfilerContext = require('./ProfilerContext');
|
6
|
+
var _require = require('./QueryResource'),
|
7
7
|
getQueryResourceForEnvironment = _require.getQueryResourceForEnvironment;
|
8
|
-
var
|
9
|
-
var
|
10
|
-
var
|
11
|
-
var
|
12
|
-
var
|
8
|
+
var readFragmentInternal = require('./readFragmentInternal');
|
9
|
+
var useFragmentInternal = require('./useFragmentInternal');
|
10
|
+
var useIsMountedRef = require('./useIsMountedRef');
|
11
|
+
var useQueryLoader = require('./useQueryLoader');
|
12
|
+
var useRelayEnvironment = require('./useRelayEnvironment');
|
13
13
|
var invariant = require('invariant');
|
14
14
|
var _require2 = require('react'),
|
15
15
|
useCallback = _require2.useCallback,
|
@@ -20,7 +20,7 @@ const ReactRelayContext = require('./../ReactRelayContext');
|
|
20
20
|
const invariant = require('invariant');
|
21
21
|
const {useContext} = require('react');
|
22
22
|
|
23
|
-
|
23
|
+
hook useRelayActorEnvironment(
|
24
24
|
actorIdentifier: ActorIdentifier,
|
25
25
|
): IActorEnvironment {
|
26
26
|
const context = useContext(ReactRelayContext);
|
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "react-relay",
|
3
3
|
"description": "A framework for building GraphQL-driven React applications.",
|
4
|
-
"version": "
|
4
|
+
"version": "17.0.0",
|
5
5
|
"keywords": [
|
6
6
|
"graphql",
|
7
7
|
"relay",
|
@@ -20,7 +20,7 @@
|
|
20
20
|
"fbjs": "^3.0.2",
|
21
21
|
"invariant": "^2.2.4",
|
22
22
|
"nullthrows": "^1.1.1",
|
23
|
-
"relay-runtime": "
|
23
|
+
"relay-runtime": "17.0.0"
|
24
24
|
},
|
25
25
|
"peerDependencies": {
|
26
26
|
"react": "^16.9.0 || ^17 || ^18"
|