relay-runtime 1.7.0-rc.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/index.js +1 -1
- package/lib/ConvertToExecuteFunction.js +12 -75
- package/lib/DataChecker.js +400 -0
- package/lib/NormalizationNode.js +14 -0
- package/lib/ReaderNode.js +10 -0
- package/lib/RelayCombinedEnvironmentTypes.js +10 -0
- package/lib/RelayConcreteNode.js +12 -29
- package/lib/RelayConcreteVariables.js +17 -11
- package/lib/RelayConnectionHandler.js +98 -42
- package/lib/RelayConnectionInterface.js +5 -13
- package/lib/RelayCore.js +17 -14
- package/lib/RelayDeclarativeMutationConfig.js +69 -34
- package/lib/RelayDefaultHandleKey.js +1 -2
- package/lib/RelayDefaultHandlerProvider.js +6 -5
- package/lib/RelayError.js +6 -9
- package/lib/RelayInMemoryRecordSource.js +20 -22
- package/lib/RelayModernEnvironment.js +140 -229
- package/lib/RelayModernFragmentSpecResolver.js +110 -102
- package/lib/RelayModernGraphQLTag.js +53 -15
- package/lib/{RelayModernOperationSelector.js → RelayModernOperationDescriptor.js} +9 -8
- package/lib/RelayModernQueryExecutor.js +172 -0
- package/lib/RelayModernRecord.js +97 -38
- package/lib/RelayModernSelector.js +89 -33
- package/lib/RelayModernStore.js +301 -0
- package/lib/RelayNetwork.js +16 -28
- package/lib/RelayNetworkLogger.js +2 -3
- package/lib/RelayNetworkLoggerTransaction.js +32 -30
- package/lib/RelayNetworkTypes.js +1 -2
- package/lib/RelayObservable.js +127 -155
- package/lib/RelayProfiler.js +35 -22
- package/lib/RelayPublishQueue.js +144 -96
- package/lib/RelayQueryResponseCache.js +37 -21
- package/lib/RelayReader.js +194 -61
- package/lib/RelayRecordProxy.js +50 -31
- package/lib/RelayRecordSourceMutator.js +92 -51
- package/lib/RelayRecordSourceProxy.js +43 -35
- package/lib/RelayRecordSourceSelectorProxy.js +22 -21
- package/lib/RelayRecordState.js +1 -3
- package/lib/RelayReferenceMarker.js +110 -37
- package/lib/RelayResponseNormalizer.js +248 -82
- package/lib/RelayRuntimeTypes.js +1 -3
- package/lib/RelayStoreTypes.js +1 -2
- package/lib/RelayStoreUtils.js +37 -19
- package/lib/RelayViewerHandler.js +14 -10
- package/lib/applyRelayModernOptimisticMutation.js +8 -8
- package/lib/cloneRelayHandleSourceField.js +8 -9
- package/lib/commitLocalUpdate.js +1 -2
- package/lib/commitRelayModernMutation.js +21 -14
- package/lib/createRelayNetworkLogger.js +11 -9
- package/lib/deepFreeze.js +2 -3
- package/lib/fetchRelayModernQuery.js +10 -12
- package/lib/generateRelayClientID.js +4 -2
- package/lib/getRelayHandleKey.js +5 -6
- package/lib/hasOverlappingIDs.js +3 -2
- package/lib/index.js +59 -62
- package/lib/isPromise.js +1 -2
- package/lib/isRelayModernEnvironment.js +1 -3
- package/lib/isScalarAndEqual.js +1 -3
- package/lib/normalizePayload.js +17 -15
- package/lib/normalizeRelayPayload.js +9 -9
- package/lib/recycleNodesInto.js +25 -9
- package/lib/requestRelaySubscription.js +25 -58
- package/lib/simpleClone.js +2 -3
- package/lib/stableCopy.js +5 -3
- package/lib/validateMutation.js +146 -0
- package/package.json +3 -3
- package/relay-runtime.js +4 -0
- package/relay-runtime.min.js +9 -0
- package/lib/RelayDataLoader.js +0 -302
- package/lib/RelayMarkSweepStore.js +0 -242
- package/lib/deferrableFragmentKey.js +0 -20
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
3
|
*
|
|
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.
|
|
@@ -7,61 +7,73 @@
|
|
|
7
7
|
* strict-local
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
10
|
'use strict';
|
|
12
11
|
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
12
|
+
var _objectSpread2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/objectSpread"));
|
|
16
13
|
|
|
17
14
|
/**
|
|
18
15
|
* A cache for storing query responses, featuring:
|
|
19
16
|
* - `get` with TTL
|
|
20
17
|
* - cache size limiting, with least-recently *updated* entries purged first
|
|
21
18
|
*/
|
|
22
|
-
var RelayQueryResponseCache =
|
|
19
|
+
var RelayQueryResponseCache =
|
|
20
|
+
/*#__PURE__*/
|
|
21
|
+
function () {
|
|
23
22
|
function RelayQueryResponseCache(_ref) {
|
|
24
23
|
var size = _ref.size,
|
|
25
24
|
ttl = _ref.ttl;
|
|
26
|
-
(0,
|
|
27
|
-
|
|
28
|
-
!(size > 0) ? process.env.NODE_ENV !== 'production' ? require('fbjs/lib/invariant')(false, 'RelayQueryResponseCache: Expected the max cache size to be > 0, got ' + '`%s`.', size) : require('fbjs/lib/invariant')(false) : void 0;
|
|
29
|
-
!(ttl > 0) ? process.env.NODE_ENV !== 'production' ? require('fbjs/lib/invariant')(false, 'RelayQueryResponseCache: Expected the max ttl to be > 0, got `%s`.', ttl) : require('fbjs/lib/invariant')(false) : void 0;
|
|
25
|
+
!(size > 0) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayQueryResponseCache: Expected the max cache size to be > 0, got ' + '`%s`.', size) : require("fbjs/lib/invariant")(false) : void 0;
|
|
26
|
+
!(ttl > 0) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayQueryResponseCache: Expected the max ttl to be > 0, got `%s`.', ttl) : require("fbjs/lib/invariant")(false) : void 0;
|
|
30
27
|
this._responses = new Map();
|
|
31
28
|
this._size = size;
|
|
32
29
|
this._ttl = ttl;
|
|
33
30
|
}
|
|
34
31
|
|
|
35
|
-
RelayQueryResponseCache.prototype
|
|
32
|
+
var _proto = RelayQueryResponseCache.prototype;
|
|
33
|
+
|
|
34
|
+
_proto.clear = function clear() {
|
|
36
35
|
this._responses.clear();
|
|
37
36
|
};
|
|
38
37
|
|
|
39
|
-
|
|
38
|
+
_proto.get = function get(queryID, variables) {
|
|
40
39
|
var _this = this;
|
|
41
40
|
|
|
42
41
|
var cacheKey = getCacheKey(queryID, variables);
|
|
42
|
+
|
|
43
43
|
this._responses.forEach(function (response, key) {
|
|
44
44
|
if (!isCurrent(response.fetchTime, _this._ttl)) {
|
|
45
|
-
_this._responses[
|
|
45
|
+
_this._responses["delete"](key);
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
|
+
|
|
48
49
|
var response = this._responses.get(cacheKey);
|
|
49
|
-
|
|
50
|
+
|
|
51
|
+
return response != null ? // $FlowFixMe
|
|
52
|
+
(0, _objectSpread2["default"])({}, response.payload, {
|
|
53
|
+
extensions: (0, _objectSpread2["default"])({}, response.payload.extensions, {
|
|
54
|
+
cacheTimestamp: response.fetchTime
|
|
55
|
+
})
|
|
56
|
+
}) : null;
|
|
50
57
|
};
|
|
51
58
|
|
|
52
|
-
|
|
59
|
+
_proto.set = function set(queryID, variables, payload) {
|
|
53
60
|
var fetchTime = Date.now();
|
|
54
61
|
var cacheKey = getCacheKey(queryID, variables);
|
|
55
|
-
|
|
62
|
+
|
|
63
|
+
this._responses["delete"](cacheKey); // deletion resets key ordering
|
|
64
|
+
|
|
65
|
+
|
|
56
66
|
this._responses.set(cacheKey, {
|
|
57
67
|
fetchTime: fetchTime,
|
|
58
68
|
payload: payload
|
|
59
|
-
});
|
|
60
|
-
|
|
69
|
+
}); // Purge least-recently updated key when max size reached
|
|
70
|
+
|
|
71
|
+
|
|
61
72
|
if (this._responses.size > this._size) {
|
|
62
73
|
var firstKey = this._responses.keys().next();
|
|
74
|
+
|
|
63
75
|
if (!firstKey.done) {
|
|
64
|
-
this._responses[
|
|
76
|
+
this._responses["delete"](firstKey.value);
|
|
65
77
|
}
|
|
66
78
|
}
|
|
67
79
|
};
|
|
@@ -70,13 +82,17 @@ var RelayQueryResponseCache = function () {
|
|
|
70
82
|
}();
|
|
71
83
|
|
|
72
84
|
function getCacheKey(queryID, variables) {
|
|
73
|
-
return JSON.stringify(require(
|
|
85
|
+
return JSON.stringify(require("./stableCopy")({
|
|
86
|
+
queryID: queryID,
|
|
87
|
+
variables: variables
|
|
88
|
+
}));
|
|
74
89
|
}
|
|
75
|
-
|
|
76
90
|
/**
|
|
77
91
|
* Determine whether a response fetched at `fetchTime` is still valid given
|
|
78
92
|
* some `ttl`.
|
|
79
93
|
*/
|
|
94
|
+
|
|
95
|
+
|
|
80
96
|
function isCurrent(fetchTime, ttl) {
|
|
81
97
|
return fetchTime + ttl >= Date.now();
|
|
82
98
|
}
|
package/lib/RelayReader.js
CHANGED
|
@@ -1,171 +1,304 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
3
|
*
|
|
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
|
+
* strict-local
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
10
|
'use strict';
|
|
12
11
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var _extends4 = _interopRequireDefault(require('babel-runtime/helpers/extends'));
|
|
16
|
-
|
|
17
|
-
var _classCallCheck3 = _interopRequireDefault(require('babel-runtime/helpers/classCallCheck'));
|
|
12
|
+
function read(recordSource, selector, owner) {
|
|
13
|
+
var _owner;
|
|
18
14
|
|
|
19
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
20
|
-
|
|
21
|
-
function read(recordSource, selector) {
|
|
22
15
|
var dataID = selector.dataID,
|
|
23
16
|
node = selector.node,
|
|
24
17
|
variables = selector.variables;
|
|
25
|
-
|
|
26
|
-
var reader = new RelayReader(recordSource, variables);
|
|
18
|
+
var reader = new RelayReader(recordSource, variables, (_owner = owner) !== null && _owner !== void 0 ? _owner : null);
|
|
27
19
|
return reader.read(node, dataID);
|
|
28
20
|
}
|
|
29
|
-
|
|
30
21
|
/**
|
|
31
22
|
* @private
|
|
32
23
|
*/
|
|
33
24
|
|
|
34
|
-
var RelayReader = function () {
|
|
35
|
-
function RelayReader(recordSource, variables) {
|
|
36
|
-
(0, _classCallCheck3['default'])(this, RelayReader);
|
|
37
25
|
|
|
26
|
+
var RelayReader =
|
|
27
|
+
/*#__PURE__*/
|
|
28
|
+
function () {
|
|
29
|
+
function RelayReader(recordSource, variables, owner) {
|
|
38
30
|
this._recordSource = recordSource;
|
|
39
31
|
this._seenRecords = {};
|
|
32
|
+
this._isMissingData = false;
|
|
40
33
|
this._variables = variables;
|
|
34
|
+
this._owner = owner;
|
|
41
35
|
}
|
|
42
36
|
|
|
43
|
-
RelayReader.prototype
|
|
37
|
+
var _proto = RelayReader.prototype;
|
|
38
|
+
|
|
39
|
+
_proto.read = function read(node, dataID) {
|
|
44
40
|
var data = this._traverse(node, dataID, null);
|
|
41
|
+
|
|
45
42
|
return {
|
|
46
43
|
data: data,
|
|
47
44
|
dataID: dataID,
|
|
48
45
|
node: node,
|
|
49
46
|
seenRecords: this._seenRecords,
|
|
50
|
-
variables: this._variables
|
|
47
|
+
variables: this._variables,
|
|
48
|
+
isMissingData: this._isMissingData,
|
|
49
|
+
owner: this._owner
|
|
51
50
|
};
|
|
52
51
|
};
|
|
53
52
|
|
|
54
|
-
|
|
53
|
+
_proto._traverse = function _traverse(node, dataID, prevData) {
|
|
55
54
|
var record = this._recordSource.get(dataID);
|
|
55
|
+
|
|
56
56
|
this._seenRecords[dataID] = record;
|
|
57
|
+
|
|
57
58
|
if (record == null) {
|
|
59
|
+
if (record === undefined) {
|
|
60
|
+
this._isMissingData = true;
|
|
61
|
+
}
|
|
62
|
+
|
|
58
63
|
return record;
|
|
59
64
|
}
|
|
65
|
+
|
|
60
66
|
var data = prevData || {};
|
|
67
|
+
|
|
61
68
|
this._traverseSelections(node.selections, record, data);
|
|
69
|
+
|
|
62
70
|
return data;
|
|
63
71
|
};
|
|
64
72
|
|
|
65
|
-
|
|
66
|
-
!this._variables.hasOwnProperty(name) ? process.env.NODE_ENV !==
|
|
73
|
+
_proto._getVariableValue = function _getVariableValue(name) {
|
|
74
|
+
!this._variables.hasOwnProperty(name) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayReader(): Undefined variable `%s`.', name) : require("fbjs/lib/invariant")(false) : void 0;
|
|
67
75
|
return this._variables[name];
|
|
68
76
|
};
|
|
69
77
|
|
|
70
|
-
|
|
78
|
+
_proto._traverseSelections = function _traverseSelections(selections, record, data) {
|
|
71
79
|
var _this = this;
|
|
72
80
|
|
|
73
81
|
selections.forEach(function (selection) {
|
|
74
|
-
if (selection.kind === require(
|
|
82
|
+
if (selection.kind === require("./RelayConcreteNode").SCALAR_FIELD) {
|
|
75
83
|
_this._readScalar(selection, record, data);
|
|
76
|
-
} else if (selection.kind === require(
|
|
84
|
+
} else if (selection.kind === require("./RelayConcreteNode").LINKED_FIELD) {
|
|
77
85
|
if (selection.plural) {
|
|
78
86
|
_this._readPluralLink(selection, record, data);
|
|
79
87
|
} else {
|
|
80
88
|
_this._readLink(selection, record, data);
|
|
81
89
|
}
|
|
82
|
-
} else if (selection.kind === require(
|
|
90
|
+
} else if (selection.kind === require("./RelayConcreteNode").CONDITION) {
|
|
83
91
|
var conditionValue = _this._getVariableValue(selection.condition);
|
|
92
|
+
|
|
84
93
|
if (conditionValue === selection.passingValue) {
|
|
85
94
|
_this._traverseSelections(selection.selections, record, data);
|
|
86
95
|
}
|
|
87
|
-
} else if (selection.kind === require(
|
|
88
|
-
var typeName = require(
|
|
96
|
+
} else if (selection.kind === require("./RelayConcreteNode").INLINE_FRAGMENT) {
|
|
97
|
+
var typeName = require("./RelayModernRecord").getType(record);
|
|
98
|
+
|
|
89
99
|
if (typeName != null && typeName === selection.type) {
|
|
90
100
|
_this._traverseSelections(selection.selections, record, data);
|
|
91
101
|
}
|
|
92
|
-
} else if (selection.kind === require(
|
|
102
|
+
} else if (selection.kind === require("./RelayConcreteNode").FRAGMENT_SPREAD) {
|
|
93
103
|
_this._createFragmentPointer(selection, record, data, _this._variables);
|
|
94
|
-
} else if (selection.kind === require(
|
|
95
|
-
_this.
|
|
104
|
+
} else if (selection.kind === require("./RelayConcreteNode").MATCH_FIELD) {
|
|
105
|
+
_this._readMatchField(selection, record, data);
|
|
96
106
|
} else {
|
|
97
|
-
!false ? process.env.NODE_ENV !==
|
|
107
|
+
!false ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayReader(): Unexpected ast kind `%s`.', selection.kind) : require("fbjs/lib/invariant")(false) : void 0;
|
|
98
108
|
}
|
|
99
109
|
});
|
|
100
110
|
};
|
|
101
111
|
|
|
102
|
-
|
|
103
|
-
var
|
|
104
|
-
|
|
105
|
-
var
|
|
112
|
+
_proto._readScalar = function _readScalar(field, record, data) {
|
|
113
|
+
var _field$alias;
|
|
114
|
+
|
|
115
|
+
var applicationName = (_field$alias = field.alias) !== null && _field$alias !== void 0 ? _field$alias : field.name;
|
|
116
|
+
|
|
117
|
+
var storageKey = require("./RelayStoreUtils").getStorageKey(field, this._variables);
|
|
118
|
+
|
|
119
|
+
var value = require("./RelayModernRecord").getValue(record, storageKey);
|
|
120
|
+
|
|
121
|
+
if (value === undefined) {
|
|
122
|
+
this._isMissingData = true;
|
|
123
|
+
}
|
|
124
|
+
|
|
106
125
|
data[applicationName] = value;
|
|
107
126
|
};
|
|
108
127
|
|
|
109
|
-
|
|
110
|
-
var
|
|
111
|
-
|
|
112
|
-
var
|
|
128
|
+
_proto._readLink = function _readLink(field, record, data) {
|
|
129
|
+
var _field$alias2;
|
|
130
|
+
|
|
131
|
+
var applicationName = (_field$alias2 = field.alias) !== null && _field$alias2 !== void 0 ? _field$alias2 : field.name;
|
|
132
|
+
|
|
133
|
+
var storageKey = require("./RelayStoreUtils").getStorageKey(field, this._variables);
|
|
134
|
+
|
|
135
|
+
var linkedID = require("./RelayModernRecord").getLinkedRecordID(record, storageKey);
|
|
113
136
|
|
|
114
137
|
if (linkedID == null) {
|
|
115
138
|
data[applicationName] = linkedID;
|
|
139
|
+
|
|
140
|
+
if (linkedID === undefined) {
|
|
141
|
+
this._isMissingData = true;
|
|
142
|
+
}
|
|
143
|
+
|
|
116
144
|
return;
|
|
117
145
|
}
|
|
118
146
|
|
|
119
147
|
var prevData = data[applicationName];
|
|
120
|
-
!(prevData == null || typeof prevData === 'object') ? process.env.NODE_ENV !==
|
|
148
|
+
!(prevData == null || typeof prevData === 'object') ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayReader(): Expected data for field `%s` on record `%s` ' + 'to be an object, got `%s`.', applicationName, require("./RelayModernRecord").getDataID(record), prevData) : require("fbjs/lib/invariant")(false) : void 0;
|
|
121
149
|
data[applicationName] = this._traverse(field, linkedID, prevData);
|
|
122
150
|
};
|
|
123
151
|
|
|
124
|
-
|
|
152
|
+
_proto._readPluralLink = function _readPluralLink(field, record, data) {
|
|
125
153
|
var _this2 = this;
|
|
126
154
|
|
|
127
|
-
var
|
|
128
|
-
|
|
129
|
-
var
|
|
155
|
+
var _field$alias3;
|
|
156
|
+
|
|
157
|
+
var applicationName = (_field$alias3 = field.alias) !== null && _field$alias3 !== void 0 ? _field$alias3 : field.name;
|
|
158
|
+
|
|
159
|
+
var storageKey = require("./RelayStoreUtils").getStorageKey(field, this._variables);
|
|
160
|
+
|
|
161
|
+
var linkedIDs = require("./RelayModernRecord").getLinkedRecordIDs(record, storageKey);
|
|
130
162
|
|
|
131
163
|
if (linkedIDs == null) {
|
|
132
164
|
data[applicationName] = linkedIDs;
|
|
165
|
+
|
|
166
|
+
if (linkedIDs === undefined) {
|
|
167
|
+
this._isMissingData = true;
|
|
168
|
+
}
|
|
169
|
+
|
|
133
170
|
return;
|
|
134
171
|
}
|
|
135
172
|
|
|
136
173
|
var prevData = data[applicationName];
|
|
137
|
-
!(prevData == null || Array.isArray(prevData)) ? process.env.NODE_ENV !==
|
|
174
|
+
!(prevData == null || Array.isArray(prevData)) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayReader(): Expected data for field `%s` on record `%s` ' + 'to be an array, got `%s`.', applicationName, require("./RelayModernRecord").getDataID(record), prevData) : require("fbjs/lib/invariant")(false) : void 0;
|
|
138
175
|
var linkedArray = prevData || [];
|
|
139
176
|
linkedIDs.forEach(function (linkedID, nextIndex) {
|
|
140
177
|
if (linkedID == null) {
|
|
178
|
+
if (linkedID === undefined) {
|
|
179
|
+
_this2._isMissingData = true;
|
|
180
|
+
}
|
|
181
|
+
|
|
141
182
|
linkedArray[nextIndex] = linkedID;
|
|
142
183
|
return;
|
|
143
184
|
}
|
|
185
|
+
|
|
144
186
|
var prevItem = linkedArray[nextIndex];
|
|
145
|
-
!(prevItem == null || typeof prevItem === 'object') ? process.env.NODE_ENV !==
|
|
146
|
-
|
|
147
|
-
linkedArray[nextIndex] = linkedItem;
|
|
187
|
+
!(prevItem == null || typeof prevItem === 'object') ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayReader(): Expected data for field `%s` on record `%s` ' + 'to be an object, got `%s`.', applicationName, require("./RelayModernRecord").getDataID(record), prevItem) : require("fbjs/lib/invariant")(false) : void 0;
|
|
188
|
+
linkedArray[nextIndex] = _this2._traverse(field, linkedID, prevItem);
|
|
148
189
|
});
|
|
149
190
|
data[applicationName] = linkedArray;
|
|
150
191
|
};
|
|
192
|
+
/**
|
|
193
|
+
* Reads a ReaderMatchField, which was generated from using the @match
|
|
194
|
+
* directive
|
|
195
|
+
*/
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
_proto._readMatchField = function _readMatchField(field, record, data) {
|
|
199
|
+
var _field$alias4;
|
|
151
200
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
201
|
+
var applicationName = (_field$alias4 = field.alias) !== null && _field$alias4 !== void 0 ? _field$alias4 : field.name;
|
|
202
|
+
|
|
203
|
+
var storageKey = require("./RelayStoreUtils").getStorageKey(field, this._variables);
|
|
204
|
+
|
|
205
|
+
var linkedID = require("./RelayModernRecord").getLinkedRecordID(record, storageKey);
|
|
206
|
+
|
|
207
|
+
if (linkedID == null) {
|
|
208
|
+
data[applicationName] = linkedID;
|
|
209
|
+
|
|
210
|
+
if (linkedID === undefined) {
|
|
211
|
+
this._isMissingData = true;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return;
|
|
156
215
|
}
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
216
|
+
|
|
217
|
+
var prevData = data[applicationName];
|
|
218
|
+
!(prevData == null || typeof prevData === 'object') ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayReader(): Expected data for field `%s` on record `%s` ' + 'to be an object, got `%s`.', applicationName, require("./RelayModernRecord").getDataID(record), prevData) : require("fbjs/lib/invariant")(false) : void 0; // Instead of recursing into the traversal again, let's manually traverse
|
|
219
|
+
// one level to get the record associated with the match field
|
|
220
|
+
|
|
221
|
+
var linkedRecord = this._recordSource.get(linkedID);
|
|
222
|
+
|
|
223
|
+
this._seenRecords[linkedID] = linkedRecord;
|
|
224
|
+
|
|
225
|
+
if (linkedRecord == null) {
|
|
226
|
+
if (linkedRecord === undefined) {
|
|
227
|
+
this._isMissingData = true;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
data[applicationName] = linkedRecord;
|
|
231
|
+
return;
|
|
232
|
+
} // Determine the concrete type for the match field record. The type of a
|
|
233
|
+
// match field must be a union type (i.e. abstract type), so here we
|
|
234
|
+
// read the concrete type on the record, which should be the type resolved
|
|
235
|
+
// by the server in the response.
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
var concreteType = require("./RelayModernRecord").getType(linkedRecord);
|
|
239
|
+
|
|
240
|
+
!(typeof concreteType === 'string') ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayReader(): Expected to be able to resolve concrete type for ' + 'field `%s` on record `%s`', applicationName, require("./RelayModernRecord").getDataID(linkedRecord)) : require("fbjs/lib/invariant")(false) : void 0; // If we can't find a match provided in the directive for the concrete
|
|
241
|
+
// type, return null as the result
|
|
242
|
+
|
|
243
|
+
var match = field.matchesByType[concreteType];
|
|
244
|
+
|
|
245
|
+
if (match == null) {
|
|
246
|
+
data[applicationName] = null;
|
|
247
|
+
return;
|
|
248
|
+
} // Determine the component module from the store: if the field is missing
|
|
249
|
+
// it means we don't know what component to render the match with.
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
var matchComponent = require("./RelayModernRecord").getValue(linkedRecord, require("./RelayStoreUtils").MATCH_COMPONENT_KEY);
|
|
253
|
+
|
|
254
|
+
if (matchComponent == null) {
|
|
255
|
+
if (matchComponent === undefined) {
|
|
256
|
+
this._isMissingData = true;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
data[applicationName] = null;
|
|
260
|
+
return;
|
|
261
|
+
} // Otherwise, read the fragment and module associated to the concrete
|
|
262
|
+
// type, and put that data with the result:
|
|
263
|
+
// - For the matched fragment, create the relevant fragment pointer and add
|
|
264
|
+
// the expected fragmentPropName
|
|
265
|
+
// - For the matched module, create a reference to the module
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
var matchResult = {};
|
|
269
|
+
|
|
270
|
+
this._createFragmentPointer({
|
|
271
|
+
kind: 'FragmentSpread',
|
|
272
|
+
name: match.fragmentName,
|
|
273
|
+
args: null
|
|
274
|
+
}, linkedRecord, matchResult, this._variables);
|
|
275
|
+
|
|
276
|
+
matchResult[require("./RelayStoreUtils").FRAGMENT_PROP_NAME_KEY] = match.fragmentPropName;
|
|
277
|
+
matchResult[require("./RelayStoreUtils").MODULE_KEY] = matchComponent; // Attach the match result to the data being read
|
|
278
|
+
|
|
279
|
+
data[applicationName] = matchResult;
|
|
160
280
|
};
|
|
161
281
|
|
|
162
|
-
|
|
163
|
-
var
|
|
164
|
-
|
|
165
|
-
|
|
282
|
+
_proto._createFragmentPointer = function _createFragmentPointer(fragmentSpread, record, data, variables) {
|
|
283
|
+
var fragmentPointers = data[require("./RelayStoreUtils").FRAGMENTS_KEY];
|
|
284
|
+
|
|
285
|
+
if (fragmentPointers == null) {
|
|
286
|
+
fragmentPointers = data[require("./RelayStoreUtils").FRAGMENTS_KEY] = {};
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
!(typeof fragmentPointers === 'object' && fragmentPointers) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayReader: Expected fragment spread data to be an object, got `%s`.', fragmentPointers) : require("fbjs/lib/invariant")(false) : void 0;
|
|
290
|
+
|
|
291
|
+
if (data[require("./RelayStoreUtils").ID_KEY] == null) {
|
|
292
|
+
data[require("./RelayStoreUtils").ID_KEY] = require("./RelayModernRecord").getDataID(record);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
fragmentPointers[fragmentSpread.name] = fragmentSpread.args ? require("./RelayStoreUtils").getArgumentValues(fragmentSpread.args, variables) : {};
|
|
296
|
+
data[require("./RelayStoreUtils").FRAGMENT_OWNER_KEY] = this._owner;
|
|
166
297
|
};
|
|
167
298
|
|
|
168
299
|
return RelayReader;
|
|
169
300
|
}();
|
|
170
301
|
|
|
171
|
-
module.exports = {
|
|
302
|
+
module.exports = {
|
|
303
|
+
read: read
|
|
304
|
+
};
|
package/lib/RelayRecordProxy.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
3
|
*
|
|
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.
|
|
@@ -7,99 +7,118 @@
|
|
|
7
7
|
* strict-local
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
10
|
'use strict';
|
|
12
11
|
|
|
13
|
-
var _classCallCheck3 = _interopRequireDefault(require('babel-runtime/helpers/classCallCheck'));
|
|
14
|
-
|
|
15
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
16
|
-
|
|
17
12
|
/**
|
|
18
13
|
* @internal
|
|
19
14
|
*
|
|
20
15
|
* A helper class for manipulating a given record from a record source via an
|
|
21
16
|
* imperative/OO-style API.
|
|
22
17
|
*/
|
|
23
|
-
var RelayRecordProxy =
|
|
18
|
+
var RelayRecordProxy =
|
|
19
|
+
/*#__PURE__*/
|
|
20
|
+
function () {
|
|
24
21
|
function RelayRecordProxy(source, mutator, dataID) {
|
|
25
|
-
(0, _classCallCheck3['default'])(this, RelayRecordProxy);
|
|
26
|
-
|
|
27
22
|
this._dataID = dataID;
|
|
28
23
|
this._mutator = mutator;
|
|
29
24
|
this._source = source;
|
|
30
25
|
}
|
|
31
26
|
|
|
32
|
-
RelayRecordProxy.prototype
|
|
27
|
+
var _proto = RelayRecordProxy.prototype;
|
|
28
|
+
|
|
29
|
+
_proto.copyFieldsFrom = function copyFieldsFrom(source) {
|
|
33
30
|
this._mutator.copyFields(source.getDataID(), this._dataID);
|
|
34
31
|
};
|
|
35
32
|
|
|
36
|
-
|
|
33
|
+
_proto.getDataID = function getDataID() {
|
|
37
34
|
return this._dataID;
|
|
38
35
|
};
|
|
39
36
|
|
|
40
|
-
|
|
37
|
+
_proto.getType = function getType() {
|
|
41
38
|
var type = this._mutator.getType(this._dataID);
|
|
42
|
-
|
|
39
|
+
|
|
40
|
+
!(type != null) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayRecordProxy: Cannot get the type of deleted record `%s`.', this._dataID) : require("fbjs/lib/invariant")(false) : void 0;
|
|
43
41
|
return type;
|
|
44
42
|
};
|
|
45
43
|
|
|
46
|
-
|
|
47
|
-
var storageKey = require(
|
|
44
|
+
_proto.getValue = function getValue(name, args) {
|
|
45
|
+
var storageKey = require("./RelayStoreUtils").getStableStorageKey(name, args);
|
|
46
|
+
|
|
48
47
|
return this._mutator.getValue(this._dataID, storageKey);
|
|
49
48
|
};
|
|
50
49
|
|
|
51
|
-
|
|
52
|
-
!isValidLeafValue(value) ? process.env.NODE_ENV !==
|
|
53
|
-
|
|
50
|
+
_proto.setValue = function setValue(value, name, args) {
|
|
51
|
+
!isValidLeafValue(value) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayRecordProxy#setValue(): Expected a scalar or array of scalars, ' + 'got `%s`.', JSON.stringify(value)) : require("fbjs/lib/invariant")(false) : void 0;
|
|
52
|
+
|
|
53
|
+
var storageKey = require("./RelayStoreUtils").getStableStorageKey(name, args);
|
|
54
|
+
|
|
54
55
|
this._mutator.setValue(this._dataID, storageKey, value);
|
|
56
|
+
|
|
55
57
|
return this;
|
|
56
58
|
};
|
|
57
59
|
|
|
58
|
-
|
|
59
|
-
var storageKey = require(
|
|
60
|
+
_proto.getLinkedRecord = function getLinkedRecord(name, args) {
|
|
61
|
+
var storageKey = require("./RelayStoreUtils").getStableStorageKey(name, args);
|
|
62
|
+
|
|
60
63
|
var linkedID = this._mutator.getLinkedRecordID(this._dataID, storageKey);
|
|
64
|
+
|
|
61
65
|
return linkedID != null ? this._source.get(linkedID) : linkedID;
|
|
62
66
|
};
|
|
63
67
|
|
|
64
|
-
|
|
65
|
-
!(record instanceof RelayRecordProxy) ? process.env.NODE_ENV !==
|
|
66
|
-
|
|
68
|
+
_proto.setLinkedRecord = function setLinkedRecord(record, name, args) {
|
|
69
|
+
!(record instanceof RelayRecordProxy) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayRecordProxy#setLinkedRecord(): Expected a record, got `%s`.', record) : require("fbjs/lib/invariant")(false) : void 0;
|
|
70
|
+
|
|
71
|
+
var storageKey = require("./RelayStoreUtils").getStableStorageKey(name, args);
|
|
72
|
+
|
|
67
73
|
var linkedID = record.getDataID();
|
|
74
|
+
|
|
68
75
|
this._mutator.setLinkedRecordID(this._dataID, storageKey, linkedID);
|
|
76
|
+
|
|
69
77
|
return this;
|
|
70
78
|
};
|
|
71
79
|
|
|
72
|
-
|
|
80
|
+
_proto.getOrCreateLinkedRecord = function getOrCreateLinkedRecord(name, typeName, args) {
|
|
73
81
|
var linkedRecord = this.getLinkedRecord(name, args);
|
|
82
|
+
|
|
74
83
|
if (!linkedRecord) {
|
|
75
|
-
var storageKey = require(
|
|
76
|
-
|
|
84
|
+
var storageKey = require("./RelayStoreUtils").getStableStorageKey(name, args);
|
|
85
|
+
|
|
86
|
+
var clientID = require("./generateRelayClientID")(this.getDataID(), storageKey);
|
|
87
|
+
|
|
77
88
|
linkedRecord = this._source.create(clientID, typeName);
|
|
78
89
|
this.setLinkedRecord(linkedRecord, name, args);
|
|
79
90
|
}
|
|
91
|
+
|
|
80
92
|
return linkedRecord;
|
|
81
93
|
};
|
|
82
94
|
|
|
83
|
-
|
|
95
|
+
_proto.getLinkedRecords = function getLinkedRecords(name, args) {
|
|
84
96
|
var _this = this;
|
|
85
97
|
|
|
86
|
-
var storageKey = require(
|
|
98
|
+
var storageKey = require("./RelayStoreUtils").getStableStorageKey(name, args);
|
|
99
|
+
|
|
87
100
|
var linkedIDs = this._mutator.getLinkedRecordIDs(this._dataID, storageKey);
|
|
101
|
+
|
|
88
102
|
if (linkedIDs == null) {
|
|
89
103
|
return linkedIDs;
|
|
90
104
|
}
|
|
105
|
+
|
|
91
106
|
return linkedIDs.map(function (linkedID) {
|
|
92
107
|
return linkedID != null ? _this._source.get(linkedID) : linkedID;
|
|
93
108
|
});
|
|
94
109
|
};
|
|
95
110
|
|
|
96
|
-
|
|
97
|
-
!Array.isArray(records) ? process.env.NODE_ENV !==
|
|
98
|
-
|
|
111
|
+
_proto.setLinkedRecords = function setLinkedRecords(records, name, args) {
|
|
112
|
+
!Array.isArray(records) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayRecordProxy#setLinkedRecords(): Expected records to be an array, got `%s`.', records) : require("fbjs/lib/invariant")(false) : void 0;
|
|
113
|
+
|
|
114
|
+
var storageKey = require("./RelayStoreUtils").getStableStorageKey(name, args);
|
|
115
|
+
|
|
99
116
|
var linkedIDs = records.map(function (record) {
|
|
100
117
|
return record && record.getDataID();
|
|
101
118
|
});
|
|
119
|
+
|
|
102
120
|
this._mutator.setLinkedRecordIDs(this._dataID, storageKey, linkedIDs);
|
|
121
|
+
|
|
103
122
|
return this;
|
|
104
123
|
};
|
|
105
124
|
|