react-relay 2.0.0-rc.2 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/index.js +2 -2
- package/lib/ReactRelayContext.js +6 -3
- package/lib/ReactRelayFragmentContainer.js +48 -46
- package/lib/ReactRelayFragmentMockRenderer.js +5 -1
- package/lib/ReactRelayPaginationContainer.js +102 -68
- package/lib/ReactRelayQueryFetcher.js +54 -28
- package/lib/ReactRelayQueryRenderer.js +28 -20
- package/lib/ReactRelayRefetchContainer.js +70 -58
- package/lib/ReactRelayTestMocker.js +56 -43
- package/lib/ReactRelayTypes.js +1 -1
- package/lib/RelayContext.js +8 -2
- package/lib/assertFragmentMap.js +9 -7
- package/lib/buildReactRelayContainer.js +32 -23
- package/lib/index.js +41 -0
- package/lib/isRelayEnvironment.js +1 -1
- package/lib/isRelayVariables.js +1 -1
- package/lib/readContext.js +7 -4
- package/package.json +4 -4
- package/react-relay.js +2 -2
- package/react-relay.min.js +2 -2
- package/classic.js +0 -10
- package/compat.js +0 -10
- package/lib/ConcreteQuery.js +0 -10
- package/lib/GraphQLQueryRunner.js +0 -264
- package/lib/GraphQLRange.js +0 -1124
- package/lib/GraphQLSegment.js +0 -743
- package/lib/GraphQLStoreChangeEmitter.js +0 -141
- package/lib/GraphQLStoreQueryResolver.js +0 -288
- package/lib/GraphQLStoreRangeUtils.js +0 -126
- package/lib/QueryBuilder.js +0 -228
- package/lib/ReactRelayClassicExports.js +0 -29
- package/lib/ReactRelayCompatContainerBuilder.js +0 -175
- package/lib/ReactRelayCompatPublic.js +0 -28
- package/lib/ReactRelayContainerProfiler.js +0 -30
- package/lib/ReactRelayFragmentContainer-flowtest.js +0 -201
- package/lib/ReactRelayPaginationContainer-flowtest.js +0 -213
- package/lib/ReactRelayPublic.js +0 -29
- package/lib/ReactRelayRefetchContainer-flowtest.js +0 -191
- package/lib/RelayCacheProcessor.js +0 -196
- package/lib/RelayChangeTracker.js +0 -83
- package/lib/RelayClassicContainerUtils.js +0 -49
- package/lib/RelayClassicCore.js +0 -34
- package/lib/RelayClassicRecordState.js +0 -31
- package/lib/RelayCompatContainer.js +0 -25
- package/lib/RelayCompatEnvironment.js +0 -27
- package/lib/RelayCompatMutations.js +0 -133
- package/lib/RelayCompatPaginationContainer.js +0 -27
- package/lib/RelayCompatRefetchContainer.js +0 -27
- package/lib/RelayCompatTypes.js +0 -10
- package/lib/RelayContainer.js +0 -889
- package/lib/RelayContainerComparators.js +0 -75
- package/lib/RelayContainerProxy.js +0 -21
- package/lib/RelayDefaultNetworkLayer.js +0 -192
- package/lib/RelayEnvironment.js +0 -449
- package/lib/RelayEnvironmentTypes.js +0 -10
- package/lib/RelayFetchMode.js +0 -17
- package/lib/RelayFragmentPointer.js +0 -161
- package/lib/RelayFragmentReference.js +0 -249
- package/lib/RelayFragmentSpecResolver.js +0 -305
- package/lib/RelayGraphQLMutation.js +0 -288
- package/lib/RelayGraphQLTag.js +0 -42
- package/lib/RelayInternalTypes.js +0 -15
- package/lib/RelayInternals.js +0 -24
- package/lib/RelayMetaRoute.js +0 -35
- package/lib/RelayMockRenderer.js +0 -71
- package/lib/RelayModern-flowtest.js +0 -342
- package/lib/RelayModernFlowtest_badref.graphql.js +0 -10
- package/lib/RelayModernFlowtest_notref.graphql.js +0 -10
- package/lib/RelayModernFlowtest_user.graphql.js +0 -10
- package/lib/RelayModernFlowtest_users.graphql.js +0 -10
- package/lib/RelayMutation.js +0 -322
- package/lib/RelayMutationDebugPrinter.js +0 -47
- package/lib/RelayMutationQuery.js +0 -558
- package/lib/RelayMutationQueue.js +0 -530
- package/lib/RelayMutationRequest.js +0 -103
- package/lib/RelayMutationTracker.js +0 -113
- package/lib/RelayMutationTransaction.js +0 -92
- package/lib/RelayMutationTransactionStatus.js +0 -55
- package/lib/RelayNetworkDebug.js +0 -131
- package/lib/RelayNetworkLayer.js +0 -185
- package/lib/RelayNodeInterface.js +0 -104
- package/lib/RelayOperationDescriptor.js +0 -40
- package/lib/RelayOptimisticMutationUtils.js +0 -208
- package/lib/RelayPendingQueryTracker.js +0 -166
- package/lib/RelayPropTypes.js +0 -57
- package/lib/RelayPublic.js +0 -44
- package/lib/RelayQL.js +0 -128
- package/lib/RelayQuery.js +0 -1584
- package/lib/RelayQueryCaching.js +0 -33
- package/lib/RelayQueryConfig.js +0 -58
- package/lib/RelayQueryPath.js +0 -204
- package/lib/RelayQueryRequest.js +0 -103
- package/lib/RelayQueryTracker.js +0 -86
- package/lib/RelayQueryTransform.js +0 -91
- package/lib/RelayQueryVisitor.js +0 -93
- package/lib/RelayQueryWriter.js +0 -573
- package/lib/RelayReadyState.js +0 -83
- package/lib/RelayReadyStateRenderer.js +0 -145
- package/lib/RelayRecord.js +0 -75
- package/lib/RelayRecordStatusMap.js +0 -57
- package/lib/RelayRecordStore.js +0 -433
- package/lib/RelayRecordWriter.js +0 -601
- package/lib/RelayRefQueryDescriptor.js +0 -27
- package/lib/RelayRenderer.js +0 -268
- package/lib/RelayRootContainer.js +0 -125
- package/lib/RelayRoute.js +0 -92
- package/lib/RelayRouteFragment.js +0 -44
- package/lib/RelaySelector.js +0 -201
- package/lib/RelayShallowMock.js +0 -69
- package/lib/RelayStaticContainer.js +0 -38
- package/lib/RelayStore.js +0 -12
- package/lib/RelayStoreConstants.js +0 -20
- package/lib/RelayStoreData.js +0 -660
- package/lib/RelayTaskQueue.js +0 -189
- package/lib/RelayTypes.js +0 -13
- package/lib/RelayVariable.js +0 -32
- package/lib/RelayVariables.js +0 -92
- package/lib/buildRQL.js +0 -160
- package/lib/callsFromGraphQL.js +0 -74
- package/lib/callsToGraphQL.js +0 -34
- package/lib/checkRelayQueryData.js +0 -250
- package/lib/createRelayQuery.js +0 -17
- package/lib/dedent.js +0 -49
- package/lib/diffRelayQuery.js +0 -757
- package/lib/directivesToGraphQL.js +0 -39
- package/lib/filterRelayQuery.js +0 -29
- package/lib/findRelayQueryLeaves.js +0 -293
- package/lib/flattenRelayQuery.js +0 -121
- package/lib/flattenSplitRelayQueries.js +0 -44
- package/lib/forEachRootCallArg.js +0 -40
- package/lib/fromGraphQL.js +0 -48
- package/lib/generateClientEdgeID.js +0 -22
- package/lib/generateClientID.js +0 -27
- package/lib/generateConcreteFragmentID.js +0 -30
- package/lib/generateForceIndex.js +0 -24
- package/lib/generateRQLFieldAlias.js +0 -39
- package/lib/getRangeBehavior.js +0 -58
- package/lib/getRelayQueries.js +0 -83
- package/lib/intersectRelayQuery.js +0 -149
- package/lib/isClassicRelayContext.js +0 -20
- package/lib/isClassicRelayEnvironment.js +0 -20
- package/lib/isCompatibleRelayFragmentType.js +0 -27
- package/lib/isRelayContainer.js +0 -16
- package/lib/makeLegacyStringishComponentRef.js +0 -52
- package/lib/printRelayOSSQuery.js +0 -329
- package/lib/printRelayQuery.js +0 -26
- package/lib/rangeOperationToMetadataKey.js +0 -25
- package/lib/readRelayQueryData.js +0 -551
- package/lib/relayUnstableBatchedUpdates.js +0 -12
- package/lib/relayUnstableBatchedUpdates.native.js +0 -11
- package/lib/restoreRelayCacheData.js +0 -188
- package/lib/serializeRelayQueryCall.js +0 -42
- package/lib/splitDeferredRelayQueries.js +0 -298
- package/lib/stableStringify.js +0 -85
- package/lib/testEditDistance.js +0 -112
- package/lib/throwFailedPromise.js +0 -26
- package/lib/toGraphQL.js +0 -94
- package/lib/transformRelayQueryPayload.js +0 -145
- package/lib/validateMutationConfig.js +0 -117
- package/lib/validateRelayReadQuery.js +0 -112
- package/lib/writeRelayQueryPayload.js +0 -44
- package/lib/writeRelayUpdatePayload.js +0 -513
- package/react-relay-classic.js +0 -4
- package/react-relay-classic.min.js +0 -9
- package/react-relay-compat.js +0 -4
- package/react-relay-compat.min.js +0 -9
package/index.js
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
/**
|
2
|
-
* Relay
|
2
|
+
* Relay v5.0.0
|
3
3
|
*
|
4
4
|
* Copyright (c) 2013-present, Facebook, Inc.
|
5
5
|
*
|
@@ -7,4 +7,4 @@
|
|
7
7
|
* LICENSE file in the root directory of this source tree.
|
8
8
|
*/
|
9
9
|
|
10
|
-
module.exports = require('./lib/
|
10
|
+
module.exports = require('./lib/index.js');
|
package/lib/ReactRelayContext.js
CHANGED
@@ -4,11 +4,14 @@
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*
|
7
|
-
*
|
7
|
+
*
|
8
8
|
* @format
|
9
9
|
*/
|
10
10
|
'use strict';
|
11
11
|
|
12
|
-
var
|
12
|
+
var React = require("react");
|
13
13
|
|
14
|
-
|
14
|
+
var _require = require("relay-runtime"),
|
15
|
+
createRelayContext = _require.__internal.createRelayContext;
|
16
|
+
|
17
|
+
module.exports = createRelayContext(React);
|
@@ -4,20 +4,37 @@
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
6
6
|
*
|
7
|
-
*
|
7
|
+
*
|
8
8
|
* @format
|
9
9
|
*/
|
10
10
|
'use strict';
|
11
11
|
|
12
|
-
var
|
12
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
13
13
|
|
14
|
-
var
|
14
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread"));
|
15
15
|
|
16
|
-
var
|
16
|
+
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
17
17
|
|
18
|
-
var _assertThisInitialized2 =
|
18
|
+
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
19
19
|
|
20
|
-
var
|
20
|
+
var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
|
21
|
+
|
22
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
23
|
+
|
24
|
+
var React = require("react");
|
25
|
+
|
26
|
+
var areEqual = require("fbjs/lib/areEqual");
|
27
|
+
|
28
|
+
var buildReactRelayContainer = require("./buildReactRelayContainer");
|
29
|
+
|
30
|
+
var _require = require("./ReactRelayContainerUtils"),
|
31
|
+
getContainerName = _require.getContainerName;
|
32
|
+
|
33
|
+
var _require2 = require("./RelayContext"),
|
34
|
+
assertRelayContext = _require2.assertRelayContext;
|
35
|
+
|
36
|
+
var _require3 = require("relay-runtime"),
|
37
|
+
isScalarAndEqual = _require3.isScalarAndEqual;
|
21
38
|
|
22
39
|
/**
|
23
40
|
* Composes a React component class, returning a new class that intercepts
|
@@ -25,38 +42,32 @@ var _defineProperty2 = require("@babel/runtime/helpers/interopRequireDefault")(r
|
|
25
42
|
* updates.
|
26
43
|
*/
|
27
44
|
function createContainerWithFragments(Component, fragments) {
|
28
|
-
var
|
45
|
+
var _class, _temp;
|
29
46
|
|
30
|
-
var
|
47
|
+
var containerName = getContainerName(Component);
|
48
|
+
return _temp = _class =
|
31
49
|
/*#__PURE__*/
|
32
50
|
function (_React$Component) {
|
33
|
-
(0, _inheritsLoose2["default"])(
|
51
|
+
(0, _inheritsLoose2["default"])(_class, _React$Component);
|
34
52
|
|
35
|
-
function
|
53
|
+
function _class(props) {
|
36
54
|
var _this;
|
37
55
|
|
38
56
|
_this = _React$Component.call(this, props) || this;
|
39
|
-
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(
|
40
|
-
var profiler = require("relay-runtime").RelayProfiler.profile('ReactRelayFragmentContainer.handleFragmentDataUpdate');
|
41
|
-
|
57
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "_handleFragmentDataUpdate", function () {
|
42
58
|
var resolverFromThisUpdate = _this.state.resolver;
|
43
59
|
|
44
60
|
_this.setState(function (updatedState) {
|
45
|
-
// If this event belongs to the current data source, update.
|
46
|
-
|
47
|
-
|
48
|
-
return {
|
61
|
+
return (// If this event belongs to the current data source, update.
|
62
|
+
// Otherwise we should ignore it.
|
63
|
+
resolverFromThisUpdate === updatedState.resolver ? {
|
49
64
|
data: updatedState.resolver.resolve(),
|
50
65
|
relayProp: getRelayProp(updatedState.relayProp.environment)
|
51
|
-
}
|
52
|
-
|
53
|
-
|
54
|
-
return null;
|
55
|
-
}, profiler.stop);
|
66
|
+
} : null
|
67
|
+
);
|
68
|
+
});
|
56
69
|
});
|
57
|
-
|
58
|
-
var relayContext = require("./RelayContext").assertRelayContext(props.__relayContext);
|
59
|
-
|
70
|
+
var relayContext = assertRelayContext(props.__relayContext);
|
60
71
|
var createFragmentSpecResolver = relayContext.environment.unstable_internal.createFragmentSpecResolver; // Do not provide a subscription/callback here.
|
61
72
|
// It is possible for this render to be interrupted or aborted,
|
62
73
|
// In which case the subscription would cause a leak.
|
@@ -79,13 +90,11 @@ function createContainerWithFragments(Component, fragments) {
|
|
79
90
|
*/
|
80
91
|
|
81
92
|
|
82
|
-
|
93
|
+
_class.getDerivedStateFromProps = function getDerivedStateFromProps(nextProps, prevState) {
|
83
94
|
// Any props change could impact the query, so we mirror props in state.
|
84
95
|
// This is an unusual pattern, but necessary for this container usecase.
|
85
96
|
var prevProps = prevState.prevProps;
|
86
|
-
|
87
|
-
var relayContext = require("./RelayContext").assertRelayContext(nextProps.__relayContext);
|
88
|
-
|
97
|
+
var relayContext = assertRelayContext(nextProps.__relayContext);
|
89
98
|
var _relayContext$environ = relayContext.environment.unstable_internal,
|
90
99
|
createFragmentSpecResolver = _relayContext$environ.createFragmentSpecResolver,
|
91
100
|
getDataIDsFromObject = _relayContext$environ.getDataIDsFromObject;
|
@@ -97,7 +106,7 @@ function createContainerWithFragments(Component, fragments) {
|
|
97
106
|
// - Existing references are based on old variables.
|
98
107
|
// - Pending fetches are for the previous records.
|
99
108
|
|
100
|
-
if (prevState.prevPropsContext.environment !== relayContext.environment || prevState.prevPropsContext.variables !== relayContext.variables || !
|
109
|
+
if (prevState.prevPropsContext.environment !== relayContext.environment || prevState.prevPropsContext.variables !== relayContext.variables || !areEqual(prevIDs, nextIDs)) {
|
101
110
|
// Do not provide a subscription/callback here.
|
102
111
|
// It is possible for this render to be interrupted or aborted,
|
103
112
|
// In which case the subscription would cause a leak.
|
@@ -127,7 +136,7 @@ function createContainerWithFragments(Component, fragments) {
|
|
127
136
|
return null;
|
128
137
|
};
|
129
138
|
|
130
|
-
var _proto =
|
139
|
+
var _proto = _class.prototype;
|
131
140
|
|
132
141
|
_proto.componentDidMount = function componentDidMount() {
|
133
142
|
this._subscribeToNewResolver();
|
@@ -167,18 +176,18 @@ function createContainerWithFragments(Component, fragments) {
|
|
167
176
|
return true;
|
168
177
|
}
|
169
178
|
} else {
|
170
|
-
if (!fragments.hasOwnProperty(_key) && !
|
179
|
+
if (!fragments.hasOwnProperty(_key) && !isScalarAndEqual(nextProps[_key], this.props[_key])) {
|
171
180
|
return true;
|
172
181
|
}
|
173
182
|
}
|
174
183
|
}
|
175
184
|
|
176
185
|
return false;
|
177
|
-
}
|
186
|
+
}
|
178
187
|
/**
|
179
188
|
* Render new data for the existing props/context.
|
180
189
|
*/
|
181
|
-
|
190
|
+
;
|
182
191
|
|
183
192
|
_proto._rerenderIfStoreHasChanged = function _rerenderIfStoreHasChanged() {
|
184
193
|
var _this$state = this.state,
|
@@ -207,20 +216,14 @@ function createContainerWithFragments(Component, fragments) {
|
|
207
216
|
componentRef = _this$props.componentRef,
|
208
217
|
_ = _this$props.__relayContext,
|
209
218
|
props = (0, _objectWithoutPropertiesLoose2["default"])(_this$props, ["componentRef", "__relayContext"]);
|
210
|
-
return
|
219
|
+
return React.createElement(Component, (0, _objectSpread2["default"])({}, props, this.state.data, {
|
211
220
|
ref: componentRef,
|
212
221
|
relay: this.state.relayProp
|
213
222
|
}));
|
214
223
|
};
|
215
224
|
|
216
|
-
return
|
217
|
-
}(
|
218
|
-
|
219
|
-
(0, _defineProperty2["default"])(Container, "displayName", containerName);
|
220
|
-
|
221
|
-
require("./ReactRelayContainerProfiler").profileContainer(Container, 'ReactRelayFragmentContainer');
|
222
|
-
|
223
|
-
return Container;
|
225
|
+
return _class;
|
226
|
+
}(React.Component), (0, _defineProperty2["default"])(_class, "displayName", containerName), _temp;
|
224
227
|
}
|
225
228
|
|
226
229
|
function getRelayProp(environment) {
|
@@ -238,10 +241,9 @@ function getRelayProp(environment) {
|
|
238
241
|
|
239
242
|
|
240
243
|
function createContainer(Component, fragmentSpec) {
|
241
|
-
return
|
244
|
+
return buildReactRelayContainer(Component, fragmentSpec, createContainerWithFragments);
|
242
245
|
}
|
243
246
|
|
244
247
|
module.exports = {
|
245
|
-
createContainer: createContainer
|
246
|
-
createContainerWithFragments: createContainerWithFragments
|
248
|
+
createContainer: createContainer
|
247
249
|
};
|
@@ -9,8 +9,12 @@
|
|
9
9
|
*/
|
10
10
|
'use strict';
|
11
11
|
|
12
|
+
var React = require("react");
|
13
|
+
|
14
|
+
var ReactRelayContext = require("./ReactRelayContext");
|
15
|
+
|
12
16
|
function ReactRelayFragmentMockRenderer(props) {
|
13
|
-
return
|
17
|
+
return React.createElement(ReactRelayContext.Provider, {
|
14
18
|
value: {
|
15
19
|
environment: props.environment,
|
16
20
|
variables: {}
|
@@ -9,17 +9,48 @@
|
|
9
9
|
*/
|
10
10
|
'use strict';
|
11
11
|
|
12
|
-
var
|
12
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
13
13
|
|
14
|
-
var
|
14
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
15
15
|
|
16
|
-
var
|
16
|
+
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
17
17
|
|
18
|
-
var _assertThisInitialized2 =
|
18
|
+
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
19
19
|
|
20
|
-
var
|
20
|
+
var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
|
21
21
|
|
22
|
-
var
|
22
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
23
|
+
|
24
|
+
var _objectSpread3 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread"));
|
25
|
+
|
26
|
+
var React = require("react");
|
27
|
+
|
28
|
+
var ReactRelayContext = require("./ReactRelayContext");
|
29
|
+
|
30
|
+
var ReactRelayQueryFetcher = require("./ReactRelayQueryFetcher");
|
31
|
+
|
32
|
+
var areEqual = require("fbjs/lib/areEqual");
|
33
|
+
|
34
|
+
var buildReactRelayContainer = require("./buildReactRelayContainer");
|
35
|
+
|
36
|
+
var forEachObject = require("fbjs/lib/forEachObject");
|
37
|
+
|
38
|
+
var invariant = require("fbjs/lib/invariant");
|
39
|
+
|
40
|
+
var warning = require("fbjs/lib/warning");
|
41
|
+
|
42
|
+
var _require = require("./ReactRelayContainerUtils"),
|
43
|
+
getComponentName = _require.getComponentName,
|
44
|
+
getContainerName = _require.getContainerName;
|
45
|
+
|
46
|
+
var _require2 = require("./RelayContext"),
|
47
|
+
assertRelayContext = _require2.assertRelayContext;
|
48
|
+
|
49
|
+
var _require3 = require("relay-runtime"),
|
50
|
+
ConnectionInterface = _require3.ConnectionInterface,
|
51
|
+
Observable = _require3.Observable,
|
52
|
+
getFragmentOwners = _require3.getFragmentOwners,
|
53
|
+
isScalarAndEqual = _require3.isScalarAndEqual;
|
23
54
|
|
24
55
|
var FORWARD = 'forward';
|
25
56
|
|
@@ -156,7 +187,7 @@ var FORWARD = 'forward';
|
|
156
187
|
*/
|
157
188
|
function createGetConnectionFromProps(metadata) {
|
158
189
|
var path = metadata.path;
|
159
|
-
!path ? process.env.NODE_ENV !== "production" ?
|
190
|
+
!path ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayPaginationContainer: Unable to synthesize a ' + 'getConnectionFromProps function.') : invariant(false) : void 0;
|
160
191
|
return function (props) {
|
161
192
|
var data = props[metadata.fragmentName];
|
162
193
|
|
@@ -174,7 +205,7 @@ function createGetConnectionFromProps(metadata) {
|
|
174
205
|
|
175
206
|
function createGetFragmentVariables(metadata) {
|
176
207
|
var countVariable = metadata.count;
|
177
|
-
!countVariable ? process.env.NODE_ENV !== "production" ?
|
208
|
+
!countVariable ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayPaginationContainer: Unable to synthesize a ' + 'getFragmentVariables function.') : invariant(false) : void 0;
|
178
209
|
return function (prevVars, totalCount) {
|
179
210
|
return (0, _objectSpread3["default"])({}, prevVars, (0, _defineProperty2["default"])({}, countVariable, totalCount));
|
180
211
|
};
|
@@ -195,15 +226,15 @@ function findConnectionMetadata(fragments) {
|
|
195
226
|
}
|
196
227
|
|
197
228
|
if (connectionMetadata) {
|
198
|
-
!(connectionMetadata.length === 1) ? process.env.NODE_ENV !== "production" ?
|
199
|
-
!!foundConnectionMetadata ? process.env.NODE_ENV !== "production" ?
|
229
|
+
!(connectionMetadata.length === 1) ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayPaginationContainer: Only a single @connection is ' + 'supported, `%s` has %s.', fragmentName, connectionMetadata.length) : invariant(false) : void 0;
|
230
|
+
!!foundConnectionMetadata ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayPaginationContainer: Only a single fragment with ' + '@connection is supported.') : invariant(false) : void 0;
|
200
231
|
foundConnectionMetadata = (0, _objectSpread3["default"])({}, connectionMetadata[0], {
|
201
232
|
fragmentName: fragmentName
|
202
233
|
});
|
203
234
|
}
|
204
235
|
}
|
205
236
|
|
206
|
-
!(!isRelayModern || foundConnectionMetadata !== null) ? process.env.NODE_ENV !== "production" ?
|
237
|
+
!(!isRelayModern || foundConnectionMetadata !== null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayPaginationContainer: A @connection directive must be present.') : invariant(false) : void 0;
|
207
238
|
return foundConnectionMetadata || {};
|
208
239
|
}
|
209
240
|
|
@@ -218,41 +249,38 @@ function toObserver(observerOrCallback) {
|
|
218
249
|
}
|
219
250
|
|
220
251
|
function createContainerWithFragments(Component, fragments, connectionConfig) {
|
221
|
-
var
|
222
|
-
|
223
|
-
var containerName = require("./ReactRelayContainerUtils").getContainerName(Component);
|
252
|
+
var _class, _temp;
|
224
253
|
|
254
|
+
var componentName = getComponentName(Component);
|
255
|
+
var containerName = getContainerName(Component);
|
225
256
|
var metadata = findConnectionMetadata(fragments);
|
226
257
|
var getConnectionFromProps = connectionConfig.getConnectionFromProps || createGetConnectionFromProps(metadata);
|
227
258
|
var direction = connectionConfig.direction || metadata.direction;
|
228
|
-
!direction ? process.env.NODE_ENV !== "production" ?
|
259
|
+
!direction ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayPaginationContainer: Unable to infer direction of the ' + 'connection, possibly because both first and last are provided.') : invariant(false) : void 0;
|
229
260
|
var getFragmentVariables = connectionConfig.getFragmentVariables || createGetFragmentVariables(metadata);
|
230
|
-
|
231
|
-
var Container =
|
261
|
+
return _temp = _class =
|
232
262
|
/*#__PURE__*/
|
233
263
|
function (_React$Component) {
|
234
|
-
(0, _inheritsLoose2["default"])(
|
264
|
+
(0, _inheritsLoose2["default"])(_class, _React$Component);
|
235
265
|
|
236
|
-
function
|
266
|
+
function _class(props) {
|
237
267
|
var _this;
|
238
268
|
|
239
269
|
_this = _React$Component.call(this, props) || this;
|
240
|
-
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(
|
241
|
-
var profiler = require("relay-runtime").RelayProfiler.profile('ReactRelayPaginationContainer.handleFragmentDataUpdate');
|
242
|
-
|
270
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "_handleFragmentDataUpdate", function () {
|
243
271
|
_this.setState({
|
244
272
|
data: _this._resolver.resolve()
|
245
|
-
}
|
273
|
+
});
|
246
274
|
});
|
247
|
-
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(
|
275
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "_hasMore", function () {
|
248
276
|
var connectionData = _this._getConnectionData();
|
249
277
|
|
250
278
|
return !!(connectionData && connectionData.hasMore && connectionData.cursor);
|
251
279
|
});
|
252
|
-
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(
|
280
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "_isLoading", function () {
|
253
281
|
return !!_this._refetchSubscription;
|
254
282
|
});
|
255
|
-
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(
|
283
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "_refetchConnection", function (totalCount, observerOrCallback, refetchVariables) {
|
256
284
|
if (!_this._canFetchPage('refetchConnection')) {
|
257
285
|
return {
|
258
286
|
dispose: function dispose() {}
|
@@ -274,7 +302,7 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
274
302
|
dispose: fetch.unsubscribe
|
275
303
|
};
|
276
304
|
});
|
277
|
-
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(
|
305
|
+
(0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "_loadMore", function (pageSize, observerOrCallback, options) {
|
278
306
|
if (!_this._canFetchPage('loadMore')) {
|
279
307
|
return {
|
280
308
|
dispose: function dispose() {}
|
@@ -286,10 +314,9 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
286
314
|
var connectionData = _this._getConnectionData();
|
287
315
|
|
288
316
|
if (!connectionData) {
|
289
|
-
|
317
|
+
Observable.create(function (sink) {
|
290
318
|
return sink.complete();
|
291
319
|
}).subscribe(observer);
|
292
|
-
|
293
320
|
return null;
|
294
321
|
}
|
295
322
|
|
@@ -299,12 +326,12 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
299
326
|
return _this._refetchConnection(totalCount, observerOrCallback);
|
300
327
|
}
|
301
328
|
|
302
|
-
var _ConnectionInterface$ =
|
329
|
+
var _ConnectionInterface$ = ConnectionInterface.get(),
|
303
330
|
END_CURSOR = _ConnectionInterface$.END_CURSOR,
|
304
331
|
START_CURSOR = _ConnectionInterface$.START_CURSOR;
|
305
332
|
|
306
333
|
var cursor = connectionData.cursor;
|
307
|
-
process.env.NODE_ENV !== "production" ?
|
334
|
+
process.env.NODE_ENV !== "production" ? warning(cursor, 'ReactRelayPaginationContainer: Cannot `loadMore` without valid `%s` (got `%s`)', direction === FORWARD ? END_CURSOR : START_CURSOR, cursor) : void 0;
|
308
335
|
var paginatingVariables = {
|
309
336
|
count: pageSize,
|
310
337
|
cursor: cursor,
|
@@ -317,9 +344,7 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
317
344
|
dispose: fetch.unsubscribe
|
318
345
|
};
|
319
346
|
});
|
320
|
-
|
321
|
-
var relayContext = require("./RelayContext").assertRelayContext(props.__relayContext);
|
322
|
-
|
347
|
+
var relayContext = assertRelayContext(props.__relayContext);
|
323
348
|
var createFragmentSpecResolver = relayContext.environment.unstable_internal.createFragmentSpecResolver;
|
324
349
|
_this._isARequestInFlight = false;
|
325
350
|
_this._refetchSubscription = null;
|
@@ -342,11 +367,10 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
342
367
|
*/
|
343
368
|
|
344
369
|
|
345
|
-
var _proto =
|
370
|
+
var _proto = _class.prototype;
|
346
371
|
|
347
372
|
_proto.UNSAFE_componentWillReceiveProps = function UNSAFE_componentWillReceiveProps(nextProps) {
|
348
|
-
var relayContext =
|
349
|
-
|
373
|
+
var relayContext = assertRelayContext(nextProps.__relayContext);
|
350
374
|
var _relayContext$environ = relayContext.environment.unstable_internal,
|
351
375
|
createFragmentSpecResolver = _relayContext$environ.createFragmentSpecResolver,
|
352
376
|
getDataIDsFromObject = _relayContext$environ.getDataIDsFromObject;
|
@@ -357,7 +381,7 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
357
381
|
// - Existing references are based on old variables.
|
358
382
|
// - Pending fetches are for the previous records.
|
359
383
|
|
360
|
-
if (relayContext.environment !== this.state.prevContext.environment || relayContext.variables !== this.state.prevContext.variables || !
|
384
|
+
if (relayContext.environment !== this.state.prevContext.environment || relayContext.variables !== this.state.prevContext.variables || !areEqual(prevIDs, nextIDs)) {
|
361
385
|
this._cleanup(); // Child containers rely on context.relay being mutated (for gDSFP).
|
362
386
|
|
363
387
|
|
@@ -404,7 +428,7 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
404
428
|
return true;
|
405
429
|
}
|
406
430
|
} else {
|
407
|
-
if (!fragments.hasOwnProperty(_key) && !
|
431
|
+
if (!fragments.hasOwnProperty(_key) && !isScalarAndEqual(nextProps[_key], this.props[_key])) {
|
408
432
|
return true;
|
409
433
|
}
|
410
434
|
}
|
@@ -421,11 +445,11 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
421
445
|
refetchConnection: this._refetchConnection,
|
422
446
|
environment: relayContext.environment
|
423
447
|
};
|
424
|
-
}
|
448
|
+
}
|
425
449
|
/**
|
426
450
|
* Render new data for the existing props/context.
|
427
451
|
*/
|
428
|
-
|
452
|
+
;
|
429
453
|
|
430
454
|
_proto._getConnectionData = function _getConnectionData() {
|
431
455
|
// Extract connection data and verify there are more edges to fetch
|
@@ -439,7 +463,7 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
439
463
|
return null;
|
440
464
|
}
|
441
465
|
|
442
|
-
var _ConnectionInterface$2 =
|
466
|
+
var _ConnectionInterface$2 = ConnectionInterface.get(),
|
443
467
|
EDGES = _ConnectionInterface$2.EDGES,
|
444
468
|
PAGE_INFO = _ConnectionInterface$2.PAGE_INFO,
|
445
469
|
HAS_NEXT_PAGE = _ConnectionInterface$2.HAS_NEXT_PAGE,
|
@@ -447,7 +471,7 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
447
471
|
END_CURSOR = _ConnectionInterface$2.END_CURSOR,
|
448
472
|
START_CURSOR = _ConnectionInterface$2.START_CURSOR;
|
449
473
|
|
450
|
-
!(typeof connectionData === 'object') ? process.env.NODE_ENV !== "production" ?
|
474
|
+
!(typeof connectionData === 'object') ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayPaginationContainer: Expected `getConnectionFromProps()` in `%s`' + 'to return `null` or a plain object with %s and %s properties, got `%s`.', componentName, EDGES, PAGE_INFO, connectionData) : invariant(false) : void 0;
|
451
475
|
var edges = connectionData[EDGES];
|
452
476
|
var pageInfo = connectionData[PAGE_INFO];
|
453
477
|
|
@@ -455,13 +479,13 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
455
479
|
return null;
|
456
480
|
}
|
457
481
|
|
458
|
-
!Array.isArray(edges) ? process.env.NODE_ENV !== "production" ?
|
459
|
-
!(typeof pageInfo === 'object') ? process.env.NODE_ENV !== "production" ?
|
482
|
+
!Array.isArray(edges) ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayPaginationContainer: Expected `getConnectionFromProps()` in `%s`' + 'to return an object with %s: Array, got `%s`.', componentName, EDGES, edges) : invariant(false) : void 0;
|
483
|
+
!(typeof pageInfo === 'object') ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayPaginationContainer: Expected `getConnectionFromProps()` in `%s`' + 'to return an object with %s: Object, got `%s`.', componentName, PAGE_INFO, pageInfo) : invariant(false) : void 0;
|
460
484
|
var hasMore = direction === FORWARD ? pageInfo[HAS_NEXT_PAGE] : pageInfo[HAS_PREV_PAGE];
|
461
485
|
var cursor = direction === FORWARD ? pageInfo[END_CURSOR] : pageInfo[START_CURSOR];
|
462
486
|
|
463
487
|
if (typeof hasMore !== 'boolean' || edges.length !== 0 && typeof cursor === 'undefined') {
|
464
|
-
process.env.NODE_ENV !== "production" ?
|
488
|
+
process.env.NODE_ENV !== "production" ? warning(false, 'ReactRelayPaginationContainer: Cannot paginate without %s fields in `%s`. ' + 'Be sure to fetch %s (got `%s`) and %s (got `%s`).', PAGE_INFO, componentName, direction === FORWARD ? HAS_NEXT_PAGE : HAS_PREV_PAGE, hasMore, direction === FORWARD ? END_CURSOR : START_CURSOR, cursor) : void 0;
|
465
489
|
return null;
|
466
490
|
}
|
467
491
|
|
@@ -474,7 +498,7 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
474
498
|
|
475
499
|
_proto._getQueryFetcher = function _getQueryFetcher() {
|
476
500
|
if (!this._queryFetcher) {
|
477
|
-
this._queryFetcher = new
|
501
|
+
this._queryFetcher = new ReactRelayQueryFetcher();
|
478
502
|
}
|
479
503
|
|
480
504
|
return this._queryFetcher;
|
@@ -482,7 +506,7 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
482
506
|
|
483
507
|
_proto._canFetchPage = function _canFetchPage(method) {
|
484
508
|
if (this._isUnmounted) {
|
485
|
-
process.env.NODE_ENV !== "production" ?
|
509
|
+
process.env.NODE_ENV !== "production" ? warning(false, 'ReactRelayPaginationContainer: Unexpected call of `%s` ' + 'on unmounted container `%s`. It looks like some instances ' + 'of your container still trying to fetch data but they already ' + 'unmounted. Please make sure you clear all timers, intervals, async ' + 'calls, etc that may trigger `%s` call.', method, containerName, method) : void 0;
|
486
510
|
return false;
|
487
511
|
}
|
488
512
|
|
@@ -492,7 +516,7 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
492
516
|
_proto._fetchPage = function _fetchPage(paginatingVariables, observer, options) {
|
493
517
|
var _this2 = this;
|
494
518
|
|
495
|
-
var _assertRelayContext =
|
519
|
+
var _assertRelayContext = assertRelayContext(this.props.__relayContext),
|
496
520
|
environment = _assertRelayContext.environment;
|
497
521
|
|
498
522
|
var _environment$unstable = environment.unstable_internal,
|
@@ -504,15 +528,32 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
504
528
|
__relayContext = _this$props2.__relayContext,
|
505
529
|
restProps = (0, _objectWithoutPropertiesLoose2["default"])(_this$props2, ["componentRef", "__relayContext"]);
|
506
530
|
var props = (0, _objectSpread3["default"])({}, restProps, this.state.data);
|
507
|
-
var rootVariables
|
508
|
-
var fragmentVariables
|
531
|
+
var rootVariables;
|
532
|
+
var fragmentVariables;
|
533
|
+
var fragmentOwners = getFragmentOwners(fragments, restProps); // NOTE: rootVariables are spread down below in a couple of places,
|
534
|
+
// so we compute them here from the fragment owners.
|
535
|
+
// For extra safety, we make sure the rootVariables include the
|
536
|
+
// variables from all owners in this fragmentSpec, even though they
|
537
|
+
// should all point to the same owner
|
538
|
+
|
539
|
+
forEachObject(fragments, function (__, key) {
|
540
|
+
var _ref, _fragmentOwner$, _ref2;
|
541
|
+
|
542
|
+
var fragmentOwner = fragmentOwners[key];
|
543
|
+
var fragmentOwnerVariables = Array.isArray(fragmentOwner) ? (_ref = (_fragmentOwner$ = fragmentOwner[0]) === null || _fragmentOwner$ === void 0 ? void 0 : _fragmentOwner$.variables) !== null && _ref !== void 0 ? _ref : {} : (_ref2 = fragmentOwner === null || fragmentOwner === void 0 ? void 0 : fragmentOwner.variables) !== null && _ref2 !== void 0 ? _ref2 : {};
|
544
|
+
rootVariables = (0, _objectSpread3["default"])({}, rootVariables, fragmentOwnerVariables);
|
545
|
+
});
|
546
|
+
fragmentVariables = getVariablesFromObject( // NOTE: We pass empty operationVariables because we want to prefer
|
547
|
+
// the variables from the fragment owner
|
548
|
+
{}, fragments, restProps, fragmentOwners);
|
509
549
|
fragmentVariables = (0, _objectSpread3["default"])({}, rootVariables, fragmentVariables, this._refetchVariables);
|
510
550
|
var fetchVariables = connectionConfig.getVariables(props, {
|
511
551
|
count: paginatingVariables.count,
|
512
552
|
cursor: paginatingVariables.cursor
|
513
553
|
}, fragmentVariables);
|
514
|
-
!(typeof fetchVariables === 'object' && fetchVariables !== null) ? process.env.NODE_ENV !== "production" ?
|
554
|
+
!(typeof fetchVariables === 'object' && fetchVariables !== null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'ReactRelayPaginationContainer: Expected `getVariables()` to ' + 'return an object, got `%s` in `%s`.', fetchVariables, componentName) : invariant(false) : void 0;
|
515
555
|
fetchVariables = (0, _objectSpread3["default"])({}, fetchVariables, this._refetchVariables);
|
556
|
+
fragmentVariables = (0, _objectSpread3["default"])({}, fetchVariables, fragmentVariables);
|
516
557
|
var cacheConfig = options ? {
|
517
558
|
force: !!options.force
|
518
559
|
} : undefined;
|
@@ -531,7 +572,7 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
531
572
|
|
532
573
|
var prevData = _this2._resolver.resolve();
|
533
574
|
|
534
|
-
_this2._resolver.setVariables(getFragmentVariables(fragmentVariables, paginatingVariables.totalCount));
|
575
|
+
_this2._resolver.setVariables(getFragmentVariables(fragmentVariables, paginatingVariables.totalCount), operation.node);
|
535
576
|
|
536
577
|
var nextData = _this2._resolver.resolve(); // Workaround slightly different handling for connection in different
|
537
578
|
// core implementations:
|
@@ -544,7 +585,7 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
544
585
|
// TODO #14894725: remove PaginationContainer equal check
|
545
586
|
|
546
587
|
|
547
|
-
if (!
|
588
|
+
if (!areEqual(prevData, nextData)) {
|
548
589
|
_this2.setState({
|
549
590
|
data: nextData,
|
550
591
|
contextForChildren: {
|
@@ -571,7 +612,7 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
571
612
|
cacheConfig: cacheConfig,
|
572
613
|
preservePreviousReferences: true
|
573
614
|
}).mergeMap(function (payload) {
|
574
|
-
return
|
615
|
+
return Observable.create(function (sink) {
|
575
616
|
onNext(payload, function () {
|
576
617
|
sink.next(); // pass void to public observer's `next`
|
577
618
|
|
@@ -611,22 +652,16 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
611
652
|
componentRef = _this$props3.componentRef,
|
612
653
|
__relayContext = _this$props3.__relayContext,
|
613
654
|
props = (0, _objectWithoutPropertiesLoose2["default"])(_this$props3, ["componentRef", "__relayContext"]);
|
614
|
-
return
|
655
|
+
return React.createElement(ReactRelayContext.Provider, {
|
615
656
|
value: this.state.contextForChildren
|
616
|
-
},
|
657
|
+
}, React.createElement(Component, (0, _extends2["default"])({}, props, this.state.data, {
|
617
658
|
ref: componentRef,
|
618
659
|
relay: this.state.relayProp
|
619
660
|
})));
|
620
661
|
};
|
621
662
|
|
622
|
-
return
|
623
|
-
}(
|
624
|
-
|
625
|
-
(0, _defineProperty2["default"])(Container, "displayName", containerName);
|
626
|
-
|
627
|
-
require("./ReactRelayContainerProfiler").profileContainer(Container, 'ReactRelayPaginationContainer');
|
628
|
-
|
629
|
-
return Container;
|
663
|
+
return _class;
|
664
|
+
}(React.Component), (0, _defineProperty2["default"])(_class, "displayName", containerName), _temp;
|
630
665
|
}
|
631
666
|
/**
|
632
667
|
* Wrap the basic `createContainer()` function with logic to adapt to the
|
@@ -638,12 +673,11 @@ function createContainerWithFragments(Component, fragments, connectionConfig) {
|
|
638
673
|
|
639
674
|
|
640
675
|
function createContainer(Component, fragmentSpec, connectionConfig) {
|
641
|
-
return
|
676
|
+
return buildReactRelayContainer(Component, fragmentSpec, function (ComponentClass, fragments) {
|
642
677
|
return createContainerWithFragments(ComponentClass, fragments, connectionConfig);
|
643
678
|
});
|
644
679
|
}
|
645
680
|
|
646
681
|
module.exports = {
|
647
|
-
createContainer: createContainer
|
648
|
-
createContainerWithFragments: createContainerWithFragments
|
682
|
+
createContainer: createContainer
|
649
683
|
};
|