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
@@ -1,145 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
3
|
-
*
|
4
|
-
* This source code is licensed under the MIT license found in the
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
6
|
-
*
|
7
|
-
*
|
8
|
-
* @format
|
9
|
-
*/
|
10
|
-
'use strict';
|
11
|
-
|
12
|
-
var _objectSpread2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/objectSpread"));
|
13
|
-
|
14
|
-
var _inheritsLoose2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/inheritsLoose"));
|
15
|
-
|
16
|
-
/**
|
17
|
-
* @public
|
18
|
-
*
|
19
|
-
* RelayReadyStateRenderer synchronously renders a container and query config
|
20
|
-
* given `readyState`. The `readyState` must be an accurate representation of
|
21
|
-
* the data that currently resides in the supplied `environment`. If you need
|
22
|
-
* data to be fetched in addition to rendering, please use `RelayRenderer`.
|
23
|
-
*
|
24
|
-
* If `readyState` is not supplied, the previously rendered `readyState` will
|
25
|
-
* continue to be rendered (or null if there is no previous `readyState`).
|
26
|
-
*/
|
27
|
-
var RelayReadyStateRenderer =
|
28
|
-
/*#__PURE__*/
|
29
|
-
function (_React$Component) {
|
30
|
-
(0, _inheritsLoose2["default"])(RelayReadyStateRenderer, _React$Component);
|
31
|
-
|
32
|
-
// TODO t16225453
|
33
|
-
function RelayReadyStateRenderer(props, context) {
|
34
|
-
var _this;
|
35
|
-
|
36
|
-
_this = _React$Component.call(this, props, context) || this;
|
37
|
-
_this._relay = {
|
38
|
-
environment: props.environment,
|
39
|
-
variables: props.queryConfig.params,
|
40
|
-
route: props.queryConfig
|
41
|
-
};
|
42
|
-
_this.state = {
|
43
|
-
getContainerProps: createContainerPropsFactory()
|
44
|
-
};
|
45
|
-
return _this;
|
46
|
-
}
|
47
|
-
|
48
|
-
var _proto = RelayReadyStateRenderer.prototype;
|
49
|
-
|
50
|
-
_proto.UNSAFE_componentWillReceiveProps = function UNSAFE_componentWillReceiveProps(nextProps) {
|
51
|
-
if (this.props.environment !== nextProps.environment || this.props.queryConfig !== nextProps.queryConfig) {
|
52
|
-
this._relay = {
|
53
|
-
environment: nextProps.environment,
|
54
|
-
variables: nextProps.queryConfig.params,
|
55
|
-
route: nextProps.queryConfig
|
56
|
-
};
|
57
|
-
}
|
58
|
-
};
|
59
|
-
/**
|
60
|
-
* Avoid updating when we have fetched data but are still not ready.
|
61
|
-
*/
|
62
|
-
|
63
|
-
|
64
|
-
_proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps) {
|
65
|
-
var prevProps = this.props;
|
66
|
-
|
67
|
-
if (prevProps.Container !== nextProps.Container || prevProps.environment !== nextProps.environment || prevProps.queryConfig !== nextProps.queryConfig || prevProps.render !== nextProps.render || prevProps.retry !== nextProps.retry) {
|
68
|
-
return true;
|
69
|
-
}
|
70
|
-
|
71
|
-
var prevReadyState = prevProps.readyState;
|
72
|
-
var nextReadyState = nextProps.readyState;
|
73
|
-
|
74
|
-
if (prevReadyState == null || nextReadyState == null) {
|
75
|
-
return true;
|
76
|
-
}
|
77
|
-
|
78
|
-
if (prevReadyState.aborted !== nextReadyState.aborted || prevReadyState.done !== nextReadyState.done || prevReadyState.error !== nextReadyState.error || prevReadyState.ready !== nextReadyState.ready || prevReadyState.stale !== nextReadyState.stale) {
|
79
|
-
return true;
|
80
|
-
}
|
81
|
-
|
82
|
-
return nextReadyState.ready;
|
83
|
-
};
|
84
|
-
|
85
|
-
_proto.render = function render() {
|
86
|
-
var children;
|
87
|
-
var shouldUpdate = false;
|
88
|
-
var _this$props = this.props,
|
89
|
-
readyState = _this$props.readyState,
|
90
|
-
render = _this$props.render;
|
91
|
-
|
92
|
-
if (readyState) {
|
93
|
-
if (render) {
|
94
|
-
children = render({
|
95
|
-
done: readyState.done,
|
96
|
-
error: readyState.error,
|
97
|
-
events: readyState.events,
|
98
|
-
props: readyState.ready ? this.state.getContainerProps(this.props) : null,
|
99
|
-
retry: this.props.retry,
|
100
|
-
stale: readyState.stale
|
101
|
-
});
|
102
|
-
} else if (readyState.ready) {
|
103
|
-
var Container = this.props.Container;
|
104
|
-
children = require("react").createElement(Container, this.state.getContainerProps(this.props));
|
105
|
-
}
|
106
|
-
|
107
|
-
shouldUpdate = true;
|
108
|
-
}
|
109
|
-
|
110
|
-
if (children === undefined) {
|
111
|
-
children = null;
|
112
|
-
shouldUpdate = false;
|
113
|
-
}
|
114
|
-
|
115
|
-
return require("react").createElement(require("./ReactRelayContext").Provider, {
|
116
|
-
value: this._relay
|
117
|
-
}, require("react").createElement(require("./RelayStaticContainer"), {
|
118
|
-
shouldUpdate: shouldUpdate
|
119
|
-
}, children));
|
120
|
-
};
|
121
|
-
|
122
|
-
return RelayReadyStateRenderer;
|
123
|
-
}(require("react").Component);
|
124
|
-
|
125
|
-
function createContainerPropsFactory() {
|
126
|
-
var prevProps;
|
127
|
-
var querySet;
|
128
|
-
return function (nextProps) {
|
129
|
-
if (!querySet || !prevProps || prevProps.Container !== nextProps.Container || prevProps.queryConfig !== nextProps.queryConfig) {
|
130
|
-
querySet = require("./getRelayQueries")(nextProps.Container, nextProps.queryConfig);
|
131
|
-
}
|
132
|
-
|
133
|
-
var containerProps = (0, _objectSpread2["default"])({}, nextProps.queryConfig.params, require("fbjs/lib/mapObject")(querySet, function (query) {
|
134
|
-
return createFragmentPointerForRoot(nextProps.environment, query);
|
135
|
-
}));
|
136
|
-
prevProps = nextProps;
|
137
|
-
return containerProps;
|
138
|
-
};
|
139
|
-
}
|
140
|
-
|
141
|
-
function createFragmentPointerForRoot(environment, query) {
|
142
|
-
return query ? require("./RelayFragmentPointer").createForRoot(environment.getStoreData().getQueuedStore(), query) : null;
|
143
|
-
}
|
144
|
-
|
145
|
-
module.exports = RelayReadyStateRenderer;
|
package/lib/RelayRecord.js
DELETED
@@ -1,75 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
3
|
-
*
|
4
|
-
* This source code is licensed under the MIT license found in the
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
6
|
-
*
|
7
|
-
*
|
8
|
-
* @format
|
9
|
-
*/
|
10
|
-
'use strict';
|
11
|
-
|
12
|
-
var _objectSpread2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/objectSpread"));
|
13
|
-
|
14
|
-
var MetadataKey = {
|
15
|
-
DATA_ID: '__dataID__',
|
16
|
-
FILTER_CALLS: '__filterCalls__',
|
17
|
-
FORCE_INDEX: '__forceIndex__',
|
18
|
-
MUTATION_IDS: '__mutationIDs__',
|
19
|
-
MUTATION_STATUS: '__mutationStatus__',
|
20
|
-
PATH: '__path__',
|
21
|
-
RANGE: '__range__',
|
22
|
-
RESOLVED_DEFERRED_FRAGMENTS: '__resolvedDeferredFragments__',
|
23
|
-
RESOLVED_FRAGMENT_MAP: '__resolvedFragmentMap__',
|
24
|
-
RESOLVED_FRAGMENT_MAP_GENERATION: '__resolvedFragmentMapGeneration__',
|
25
|
-
STATUS: '__status__'
|
26
|
-
};
|
27
|
-
var metadataKeyLookup = {};
|
28
|
-
Object.keys(MetadataKey).forEach(function (name) {
|
29
|
-
metadataKeyLookup[MetadataKey[name]] = true;
|
30
|
-
});
|
31
|
-
/**
|
32
|
-
* Records are plain objects with special metadata properties.
|
33
|
-
*/
|
34
|
-
|
35
|
-
var RelayRecord = {
|
36
|
-
MetadataKey: MetadataKey,
|
37
|
-
create: function create(dataID) {
|
38
|
-
return {
|
39
|
-
__dataID__: dataID
|
40
|
-
};
|
41
|
-
},
|
42
|
-
createWithFields: function createWithFields(dataID, fields) {
|
43
|
-
return (0, _objectSpread2["default"])({
|
44
|
-
__dataID__: dataID
|
45
|
-
}, fields);
|
46
|
-
},
|
47
|
-
isRecord: function isRecord(maybeRecord) {
|
48
|
-
return typeof maybeRecord === 'object' && maybeRecord != null && !Array.isArray(maybeRecord) && typeof maybeRecord.__dataID__ === 'string';
|
49
|
-
},
|
50
|
-
getRecord: function getRecord(maybeRecord) {
|
51
|
-
if (RelayRecord.isRecord(maybeRecord)) {
|
52
|
-
return maybeRecord;
|
53
|
-
} else {
|
54
|
-
return null;
|
55
|
-
}
|
56
|
-
},
|
57
|
-
getDataID: function getDataID(record) {
|
58
|
-
return record.__dataID__;
|
59
|
-
},
|
60
|
-
getDataIDForObject: function getDataIDForObject(maybeRecord) {
|
61
|
-
return maybeRecord.__dataID__;
|
62
|
-
},
|
63
|
-
|
64
|
-
/**
|
65
|
-
* Checks whether the given ID was created on the client, as opposed to an ID
|
66
|
-
* that's understood by the server as well.
|
67
|
-
*/
|
68
|
-
isClientID: function isClientID(dataID) {
|
69
|
-
return dataID.indexOf('client:') === 0;
|
70
|
-
},
|
71
|
-
isMetadataKey: function isMetadataKey(key) {
|
72
|
-
return metadataKeyLookup.hasOwnProperty(key);
|
73
|
-
}
|
74
|
-
};
|
75
|
-
module.exports = RelayRecord;
|
@@ -1,57 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
3
|
-
*
|
4
|
-
* This source code is licensed under the MIT license found in the
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
6
|
-
*
|
7
|
-
*
|
8
|
-
* @format
|
9
|
-
*/
|
10
|
-
'use strict';
|
11
|
-
/**
|
12
|
-
* Record might contain data from optimistic update.
|
13
|
-
*/
|
14
|
-
|
15
|
-
var OPTIMISTIC_MASK = 0x01;
|
16
|
-
/**
|
17
|
-
* The subtree of data from this record contains partial data.
|
18
|
-
*/
|
19
|
-
|
20
|
-
var PARTIAL_MASK = 0x04;
|
21
|
-
|
22
|
-
function set(status, value, mask) {
|
23
|
-
status = status || 0;
|
24
|
-
|
25
|
-
if (value) {
|
26
|
-
return status | mask; // eslint-disable-line no-bitwise
|
27
|
-
} else {
|
28
|
-
return status & ~mask; // eslint-disable-line no-bitwise
|
29
|
-
}
|
30
|
-
}
|
31
|
-
|
32
|
-
function check(status, mask) {
|
33
|
-
return ((status || 0) & mask) !== 0; // eslint-disable-line no-bitwise
|
34
|
-
}
|
35
|
-
/**
|
36
|
-
* A set of functions for modifying `__status__` on records inside of
|
37
|
-
* RelayStore.
|
38
|
-
*/
|
39
|
-
|
40
|
-
|
41
|
-
var RelayRecordStatusMap = {
|
42
|
-
setOptimisticStatus: function setOptimisticStatus(status, value) {
|
43
|
-
return set(status, value, OPTIMISTIC_MASK);
|
44
|
-
},
|
45
|
-
isOptimisticStatus: function isOptimisticStatus(status) {
|
46
|
-
return check(status, OPTIMISTIC_MASK);
|
47
|
-
},
|
48
|
-
// Should only be used on records read out from RelayRecordStore
|
49
|
-
// by `readRelayQueryData`.
|
50
|
-
setPartialStatus: function setPartialStatus(status, value) {
|
51
|
-
return set(status, value, PARTIAL_MASK);
|
52
|
-
},
|
53
|
-
isPartialStatus: function isPartialStatus(status) {
|
54
|
-
return check(status, PARTIAL_MASK);
|
55
|
-
}
|
56
|
-
};
|
57
|
-
module.exports = RelayRecordStatusMap;
|
package/lib/RelayRecordStore.js
DELETED
@@ -1,433 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* Copyright (c) Facebook, Inc. and its affiliates.
|
3
|
-
*
|
4
|
-
* This source code is licensed under the MIT license found in the
|
5
|
-
* LICENSE file in the root directory of this source tree.
|
6
|
-
*
|
7
|
-
*
|
8
|
-
* @format
|
9
|
-
*/
|
10
|
-
'use strict';
|
11
|
-
|
12
|
-
var EMPTY = '';
|
13
|
-
|
14
|
-
var FILTER_CALLS = require("./RelayRecord").MetadataKey.FILTER_CALLS,
|
15
|
-
FORCE_INDEX = require("./RelayRecord").MetadataKey.FORCE_INDEX,
|
16
|
-
MUTATION_IDS = require("./RelayRecord").MetadataKey.MUTATION_IDS,
|
17
|
-
PATH = require("./RelayRecord").MetadataKey.PATH,
|
18
|
-
RANGE = require("./RelayRecord").MetadataKey.RANGE,
|
19
|
-
RESOLVED_FRAGMENT_MAP = require("./RelayRecord").MetadataKey.RESOLVED_FRAGMENT_MAP;
|
20
|
-
/**
|
21
|
-
* @internal
|
22
|
-
*
|
23
|
-
* `RelayRecordStore` is the central repository for all data fetched by the
|
24
|
-
* client. Data is stored as a map from IDs to Records. Records are shapes of
|
25
|
-
* data with globally unique "data IDs".
|
26
|
-
*/
|
27
|
-
|
28
|
-
|
29
|
-
var RelayRecordStore =
|
30
|
-
/*#__PURE__*/
|
31
|
-
function () {
|
32
|
-
function RelayRecordStore(records, rootCallMaps, nodeConnectionMap) {
|
33
|
-
this._cachedRecords = records.cachedRecords;
|
34
|
-
this._cachedRootCallMap = rootCallMaps && rootCallMaps.cachedRootCallMap || {};
|
35
|
-
this._queuedRecords = records.queuedRecords;
|
36
|
-
this._nodeConnectionMap = nodeConnectionMap || {};
|
37
|
-
this._records = records.records;
|
38
|
-
this._rootCallMap = rootCallMaps && rootCallMaps.rootCallMap || {};
|
39
|
-
this._storage = [];
|
40
|
-
|
41
|
-
if (this._queuedRecords) {
|
42
|
-
this._storage.push(this._queuedRecords);
|
43
|
-
}
|
44
|
-
|
45
|
-
if (this._records) {
|
46
|
-
this._storage.push(this._records);
|
47
|
-
}
|
48
|
-
|
49
|
-
if (this._cachedRecords) {
|
50
|
-
this._storage.push(this._cachedRecords);
|
51
|
-
}
|
52
|
-
}
|
53
|
-
/**
|
54
|
-
* Get the data ID associated with a storage key (and optionally an
|
55
|
-
* identifying argument value) for a root query.
|
56
|
-
*/
|
57
|
-
|
58
|
-
|
59
|
-
var _proto = RelayRecordStore.prototype;
|
60
|
-
|
61
|
-
_proto.getDataID = function getDataID(storageKey, identifyingArgValue) {
|
62
|
-
if (require("./RelayNodeInterface").isNodeRootCall(storageKey)) {
|
63
|
-
!(identifyingArgValue != null) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayRecordStore.getDataID(): Argument to `%s()` ' + 'cannot be null or undefined.', storageKey) : require("fbjs/lib/invariant")(false) : void 0;
|
64
|
-
return identifyingArgValue;
|
65
|
-
}
|
66
|
-
|
67
|
-
if (identifyingArgValue == null) {
|
68
|
-
identifyingArgValue = EMPTY;
|
69
|
-
}
|
70
|
-
|
71
|
-
if (this._rootCallMap.hasOwnProperty(storageKey) && this._rootCallMap[storageKey].hasOwnProperty(identifyingArgValue)) {
|
72
|
-
return this._rootCallMap[storageKey][identifyingArgValue];
|
73
|
-
} else if (this._cachedRootCallMap.hasOwnProperty(storageKey)) {
|
74
|
-
return this._cachedRootCallMap[storageKey][identifyingArgValue];
|
75
|
-
}
|
76
|
-
};
|
77
|
-
/**
|
78
|
-
* Returns the status of the record stored at `dataID`.
|
79
|
-
*/
|
80
|
-
|
81
|
-
|
82
|
-
_proto.getRecordState = function getRecordState(dataID) {
|
83
|
-
var record = this._getRecord(dataID);
|
84
|
-
|
85
|
-
if (record === null) {
|
86
|
-
return require("./RelayClassicRecordState").NONEXISTENT;
|
87
|
-
} else if (record === undefined) {
|
88
|
-
return require("./RelayClassicRecordState").UNKNOWN;
|
89
|
-
}
|
90
|
-
|
91
|
-
return require("./RelayClassicRecordState").EXISTENT;
|
92
|
-
};
|
93
|
-
/**
|
94
|
-
* Returns the path to a non-refetchable record.
|
95
|
-
*/
|
96
|
-
|
97
|
-
|
98
|
-
_proto.getPathToRecord = function getPathToRecord(dataID) {
|
99
|
-
var path = this._getField(dataID, PATH);
|
100
|
-
|
101
|
-
return path;
|
102
|
-
};
|
103
|
-
/**
|
104
|
-
* Returns whether a given record is affected by an optimistic update.
|
105
|
-
*/
|
106
|
-
|
107
|
-
|
108
|
-
_proto.hasOptimisticUpdate = function hasOptimisticUpdate(dataID) {
|
109
|
-
var queuedRecords = this._queuedRecords;
|
110
|
-
return queuedRecords ? queuedRecords.hasOwnProperty(dataID) : false;
|
111
|
-
};
|
112
|
-
/**
|
113
|
-
* Returns a list of client mutation IDs for queued mutations whose optimistic
|
114
|
-
* updates are affecting the record corresponding the given dataID. Returns
|
115
|
-
* null if the record isn't affected by any optimistic updates.
|
116
|
-
*/
|
117
|
-
|
118
|
-
|
119
|
-
_proto.getClientMutationIDs = function getClientMutationIDs(dataID) {
|
120
|
-
var queuedRecords = this._queuedRecords;
|
121
|
-
|
122
|
-
if (queuedRecords) {
|
123
|
-
var record = queuedRecords[dataID];
|
124
|
-
|
125
|
-
if (record) {
|
126
|
-
return record[MUTATION_IDS];
|
127
|
-
}
|
128
|
-
}
|
129
|
-
|
130
|
-
return null;
|
131
|
-
};
|
132
|
-
/**
|
133
|
-
* Check whether a given record has received data for a deferred fragment.
|
134
|
-
*/
|
135
|
-
|
136
|
-
|
137
|
-
_proto.hasFragmentData = function hasFragmentData(dataID, fragmentID) {
|
138
|
-
var resolvedFragmentMap = this._getField(dataID, RESOLVED_FRAGMENT_MAP);
|
139
|
-
|
140
|
-
!(typeof resolvedFragmentMap === 'object' || resolvedFragmentMap == null) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayRecordStore.hasFragmentData(): Expected the map of ' + 'resolved deferred fragments associated with record `%s` to be null or ' + 'an object. Found a(n) `%s`.', dataID, typeof resolvedFragmentMap) : require("fbjs/lib/invariant")(false) : void 0;
|
141
|
-
return !!(resolvedFragmentMap && resolvedFragmentMap[fragmentID]);
|
142
|
-
};
|
143
|
-
|
144
|
-
_proto.getType = function getType(dataID) {
|
145
|
-
// `__typename` property is typed as `string`
|
146
|
-
return this._getField(dataID, '__typename');
|
147
|
-
};
|
148
|
-
/**
|
149
|
-
* Returns the value of the field for the given dataID.
|
150
|
-
*/
|
151
|
-
|
152
|
-
|
153
|
-
_proto.getField = function getField(dataID, storageKey) {
|
154
|
-
return this._getField(dataID, storageKey);
|
155
|
-
};
|
156
|
-
/**
|
157
|
-
* Returns the Data ID of a linked record (eg the ID of the `address` record
|
158
|
-
* in `actor{address}`).
|
159
|
-
*/
|
160
|
-
|
161
|
-
|
162
|
-
_proto.getLinkedRecordID = function getLinkedRecordID(dataID, storageKey) {
|
163
|
-
var field = this._getField(dataID, storageKey);
|
164
|
-
|
165
|
-
if (field == null) {
|
166
|
-
return field;
|
167
|
-
}
|
168
|
-
|
169
|
-
var record = require("./RelayRecord").getRecord(field);
|
170
|
-
|
171
|
-
!record ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayRecordStore.getLinkedRecordID(): Expected field `%s` for record ' + '`%s` to have a linked record.', storageKey, dataID) : require("fbjs/lib/invariant")(false) : void 0;
|
172
|
-
return require("./RelayRecord").getDataID(record);
|
173
|
-
};
|
174
|
-
/**
|
175
|
-
* Returns an array of Data ID for a plural linked field (eg the actor IDs of
|
176
|
-
* the `likers` in `story{likers}`).
|
177
|
-
*/
|
178
|
-
|
179
|
-
|
180
|
-
_proto.getLinkedRecordIDs = function getLinkedRecordIDs(dataID, storageKey) {
|
181
|
-
var field = this._getField(dataID, storageKey);
|
182
|
-
|
183
|
-
if (field == null) {
|
184
|
-
return field;
|
185
|
-
}
|
186
|
-
|
187
|
-
!Array.isArray(field) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayRecordStore.getLinkedRecordIDs(): Expected field `%s` for ' + 'record `%s` to have an array of linked records.', storageKey, dataID) : require("fbjs/lib/invariant")(false) : void 0;
|
188
|
-
return field.map(function (element, ii) {
|
189
|
-
var record = require("./RelayRecord").getRecord(element);
|
190
|
-
|
191
|
-
!record ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayRecordStore.getLinkedRecordIDs(): Expected element at index %s ' + 'in field `%s` for record `%s` to be a linked record.', ii, storageKey, dataID) : require("fbjs/lib/invariant")(false) : void 0;
|
192
|
-
return require("./RelayRecord").getDataID(record);
|
193
|
-
});
|
194
|
-
};
|
195
|
-
/**
|
196
|
-
* Gets the connectionIDs for all the connections that contain the given
|
197
|
-
* record as a `node`, or null if the record does not appear as a `node` in
|
198
|
-
* any connection.
|
199
|
-
*/
|
200
|
-
|
201
|
-
|
202
|
-
_proto.getConnectionIDsForRecord = function getConnectionIDsForRecord(dataID) {
|
203
|
-
var connectionIDs = this._nodeConnectionMap[dataID];
|
204
|
-
|
205
|
-
if (connectionIDs) {
|
206
|
-
return Object.keys(connectionIDs);
|
207
|
-
}
|
208
|
-
|
209
|
-
return null;
|
210
|
-
};
|
211
|
-
/**
|
212
|
-
* Gets the connectionIDs for all variations of calls for the given base
|
213
|
-
* schema name (Ex: `posts.orderby(recent)` and `posts.orderby(likes)`).
|
214
|
-
*/
|
215
|
-
|
216
|
-
|
217
|
-
_proto.getConnectionIDsForField = function getConnectionIDsForField(dataID, schemaName) {
|
218
|
-
// ignore queued records because not all range fields may be present there
|
219
|
-
var record = this._records[dataID];
|
220
|
-
|
221
|
-
if (record == null) {
|
222
|
-
return record;
|
223
|
-
}
|
224
|
-
|
225
|
-
var connectionIDs;
|
226
|
-
|
227
|
-
require("fbjs/lib/forEachObject")(record, function (datum, key) {
|
228
|
-
if (datum && getFieldNameFromKey(key) === schemaName) {
|
229
|
-
// $FlowFixMe(site=www,mobile) forEachObject is only typed in www
|
230
|
-
var connectionID = require("./RelayRecord").getDataIDForObject(datum);
|
231
|
-
|
232
|
-
if (connectionID) {
|
233
|
-
connectionIDs = connectionIDs || [];
|
234
|
-
connectionIDs.push(connectionID);
|
235
|
-
}
|
236
|
-
}
|
237
|
-
});
|
238
|
-
|
239
|
-
return connectionIDs;
|
240
|
-
};
|
241
|
-
/**
|
242
|
-
* Get the force index associated with the range at `connectionID`.
|
243
|
-
*/
|
244
|
-
|
245
|
-
|
246
|
-
_proto.getRangeForceIndex = function getRangeForceIndex(connectionID) {
|
247
|
-
var forceIndex = this._getField(connectionID, FORCE_INDEX);
|
248
|
-
|
249
|
-
if (forceIndex === null) {
|
250
|
-
return -1;
|
251
|
-
}
|
252
|
-
|
253
|
-
return forceIndex || 0;
|
254
|
-
};
|
255
|
-
/**
|
256
|
-
* Get the condition calls that were used to fetch the given connection.
|
257
|
-
* Ex: for a field `photos.orderby(recent)`, this would be
|
258
|
-
* [{name: 'orderby', value: 'recent'}]
|
259
|
-
*/
|
260
|
-
|
261
|
-
|
262
|
-
_proto.getRangeFilterCalls = function getRangeFilterCalls(connectionID) {
|
263
|
-
return this._getField(connectionID, FILTER_CALLS);
|
264
|
-
};
|
265
|
-
/**
|
266
|
-
* Returns range information for the given connection field:
|
267
|
-
* - `filteredEdges`: any edges already fetched for the given `calls`.
|
268
|
-
* - `diffCalls`: an array of calls describing the difference
|
269
|
-
* between the given `calls` and already fetched data. Includes conditional
|
270
|
-
* calls (`orderby`) and range/offset calls (`first`, `after`).
|
271
|
-
* - `filterCalls`: the subset of `calls` that are condition calls
|
272
|
-
* (`orderby`).
|
273
|
-
*/
|
274
|
-
|
275
|
-
|
276
|
-
_proto.getRangeMetadata = function getRangeMetadata(connectionID, calls) {
|
277
|
-
var _this = this;
|
278
|
-
|
279
|
-
if (connectionID == null) {
|
280
|
-
return connectionID;
|
281
|
-
}
|
282
|
-
|
283
|
-
var range = this._getField(connectionID, RANGE);
|
284
|
-
|
285
|
-
if (range == null) {
|
286
|
-
if (range === null) {
|
287
|
-
process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(false, 'RelayRecordStore.getRangeMetadata(): Expected range to exist if ' + '`edges` has been fetched.') : void 0;
|
288
|
-
}
|
289
|
-
|
290
|
-
return undefined;
|
291
|
-
}
|
292
|
-
|
293
|
-
var filterCalls = getFilterCalls(calls); // Edges can only be fetched if a range call (first/last/find) is given.
|
294
|
-
// Otherwise return diffCalls/filterCalls with empty edges.
|
295
|
-
|
296
|
-
if (calls.length === filterCalls.length) {
|
297
|
-
return {
|
298
|
-
diffCalls: calls,
|
299
|
-
filterCalls: filterCalls,
|
300
|
-
pageInfo: undefined,
|
301
|
-
requestedEdgeIDs: [],
|
302
|
-
filteredEdges: []
|
303
|
-
};
|
304
|
-
}
|
305
|
-
|
306
|
-
var queuedRecord = this._queuedRecords ? this._queuedRecords[connectionID] : null;
|
307
|
-
var rangeInfo = range.retrieveRangeInfoForQuery(calls, queuedRecord);
|
308
|
-
var diffCalls = rangeInfo.diffCalls;
|
309
|
-
var pageInfo = rangeInfo.pageInfo,
|
310
|
-
requestedEdgeIDs = rangeInfo.requestedEdgeIDs;
|
311
|
-
|
312
|
-
if (diffCalls && diffCalls.length) {
|
313
|
-
diffCalls = filterCalls.concat(diffCalls);
|
314
|
-
} else {
|
315
|
-
diffCalls = [];
|
316
|
-
}
|
317
|
-
|
318
|
-
var filteredEdges;
|
319
|
-
|
320
|
-
if (requestedEdgeIDs) {
|
321
|
-
var _ConnectionInterface$ = require("relay-runtime").ConnectionInterface.get(),
|
322
|
-
NODE = _ConnectionInterface$.NODE;
|
323
|
-
|
324
|
-
filteredEdges = requestedEdgeIDs.map(function (edgeID) {
|
325
|
-
return {
|
326
|
-
edgeID: edgeID,
|
327
|
-
nodeID: _this.getLinkedRecordID(edgeID, NODE)
|
328
|
-
};
|
329
|
-
}).filter(function (edge) {
|
330
|
-
return _this._getRecord(edge.nodeID);
|
331
|
-
});
|
332
|
-
} else {
|
333
|
-
filteredEdges = [];
|
334
|
-
}
|
335
|
-
|
336
|
-
return {
|
337
|
-
diffCalls: diffCalls,
|
338
|
-
filterCalls: filterCalls,
|
339
|
-
pageInfo: pageInfo,
|
340
|
-
requestedEdgeIDs: requestedEdgeIDs,
|
341
|
-
filteredEdges: filteredEdges
|
342
|
-
};
|
343
|
-
};
|
344
|
-
/**
|
345
|
-
* Returns whether there is a range at `connectionID`.
|
346
|
-
*/
|
347
|
-
|
348
|
-
|
349
|
-
_proto.hasRange = function hasRange(connectionID) {
|
350
|
-
return !!this._getField(connectionID, RANGE);
|
351
|
-
};
|
352
|
-
/**
|
353
|
-
* Completely removes the record identified by `dataID` from the store.
|
354
|
-
* This is only used by garbage collection.
|
355
|
-
*/
|
356
|
-
|
357
|
-
|
358
|
-
_proto.removeRecord = function removeRecord(dataID) {
|
359
|
-
delete this._records[dataID];
|
360
|
-
|
361
|
-
if (this._queuedRecords) {
|
362
|
-
delete this._queuedRecords[dataID];
|
363
|
-
}
|
364
|
-
|
365
|
-
if (this._cachedRecords) {
|
366
|
-
delete this._cachedRecords[dataID];
|
367
|
-
}
|
368
|
-
|
369
|
-
delete this._nodeConnectionMap[dataID];
|
370
|
-
};
|
371
|
-
/**
|
372
|
-
* Gets the first version of the record from the available caches.
|
373
|
-
*/
|
374
|
-
|
375
|
-
|
376
|
-
_proto._getRecord = function _getRecord(dataID) {
|
377
|
-
if (this._queuedRecords && this._queuedRecords.hasOwnProperty(dataID)) {
|
378
|
-
return this._queuedRecords[dataID];
|
379
|
-
} else if (this._records.hasOwnProperty(dataID)) {
|
380
|
-
return this._records[dataID];
|
381
|
-
} else if (this._cachedRecords) {
|
382
|
-
return this._cachedRecords[dataID];
|
383
|
-
}
|
384
|
-
};
|
385
|
-
/**
|
386
|
-
* Get the value of the field from the first version of the record for which
|
387
|
-
* the field is defined, returning `null` if the record has been deleted or
|
388
|
-
* `undefined` if the record has not been fetched.
|
389
|
-
*/
|
390
|
-
|
391
|
-
|
392
|
-
_proto._getField = function _getField(dataID, storageKey) {
|
393
|
-
var storage = this._storage;
|
394
|
-
|
395
|
-
for (var ii = 0; ii < storage.length; ii++) {
|
396
|
-
var record = storage[ii][dataID];
|
397
|
-
|
398
|
-
if (record === null) {
|
399
|
-
return null;
|
400
|
-
} else if (record && record.hasOwnProperty(storageKey)) {
|
401
|
-
return record[storageKey];
|
402
|
-
}
|
403
|
-
}
|
404
|
-
|
405
|
-
return undefined;
|
406
|
-
};
|
407
|
-
|
408
|
-
return RelayRecordStore;
|
409
|
-
}();
|
410
|
-
/**
|
411
|
-
* Filter calls to only those that specify conditions on the returned results
|
412
|
-
* (ex: `orderby(TOP_STORIES)`), removing generic calls (ex: `first`, `find`).
|
413
|
-
*/
|
414
|
-
|
415
|
-
|
416
|
-
function getFilterCalls(calls) {
|
417
|
-
return calls.filter(function (call) {
|
418
|
-
return !require("relay-runtime").ConnectionInterface.isConnectionCall(call);
|
419
|
-
});
|
420
|
-
}
|
421
|
-
/**
|
422
|
-
* Returns the field name based on the object key used to store the data in
|
423
|
-
* nodeData. It returns the field name without any calls. For example, the
|
424
|
-
* field name for 'profile_picture{size:"50"}' will be 'profile_picture'
|
425
|
-
*/
|
426
|
-
|
427
|
-
|
428
|
-
function getFieldNameFromKey(key) {
|
429
|
-
// This is based on the GraphQL spec for what constitutes a valid field name.
|
430
|
-
return key.split(/(?![_A-Za-z][_0-9A-Za-z]*)/, 1)[0];
|
431
|
-
}
|
432
|
-
|
433
|
-
module.exports = RelayRecordStore;
|