relay-runtime 2.0.0-rc.2 → 5.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/index.js +1 -1
- package/lib/{generateRelayClientID.js → ClientID.js} +10 -3
- package/lib/ConvertToExecuteFunction.js +6 -4
- package/lib/DataChecker.js +88 -69
- package/lib/NormalizationNode.js +1 -1
- package/lib/ReaderNode.js +1 -1
- package/lib/RelayCombinedEnvironmentTypes.js +1 -1
- package/lib/RelayConcreteNode.js +5 -2
- package/lib/RelayConcreteVariables.js +15 -9
- package/lib/RelayConnectionHandler.js +27 -20
- package/lib/RelayConnectionInterface.js +4 -2
- package/lib/RelayCore.js +48 -15
- package/lib/RelayDeclarativeMutationConfig.js +16 -15
- package/lib/RelayDefaultHandleKey.js +1 -1
- package/lib/RelayDefaultHandlerProvider.js +7 -6
- package/lib/RelayDefaultMissingFieldHandlers.js +26 -0
- package/lib/RelayError.js +7 -2
- package/lib/RelayFeatureFlags.js +16 -0
- package/lib/RelayInMemoryRecordSource.js +8 -2
- package/lib/RelayModernEnvironment.js +159 -237
- package/lib/RelayModernFragmentOwner.js +72 -0
- package/lib/RelayModernFragmentSpecResolver.js +66 -15
- package/lib/RelayModernGraphQLTag.js +9 -5
- package/lib/RelayModernOperationDescriptor.js +9 -6
- package/lib/RelayModernQueryExecutor.js +791 -0
- package/lib/RelayModernRecord.js +44 -24
- package/lib/RelayModernSelector.js +208 -82
- package/lib/RelayModernStore.js +66 -34
- package/lib/RelayNetwork.js +14 -7
- package/lib/RelayNetworkLogger.js +6 -2
- package/lib/RelayNetworkLoggerTransaction.js +8 -4
- package/lib/RelayNetworkTypes.js +1 -1
- package/lib/RelayObservable.js +72 -41
- package/lib/RelayOperationTracker.js +265 -0
- package/lib/RelayProfiler.js +10 -6
- package/lib/RelayPublishQueue.js +66 -47
- package/lib/RelayQueryResponseCache.js +11 -5
- package/lib/RelayReader.js +135 -126
- package/lib/RelayRecordProxy.js +24 -20
- package/lib/RelayRecordSourceMutator.js +88 -25
- package/lib/RelayRecordSourceProxy.js +38 -19
- package/lib/RelayRecordSourceSelectorProxy.js +10 -7
- package/lib/RelayRecordState.js +1 -1
- package/lib/RelayReferenceMarker.js +66 -55
- package/lib/RelayReplaySubject.js +134 -0
- package/lib/RelayResponseNormalizer.js +245 -134
- package/lib/RelayRuntimeTypes.js +1 -1
- package/lib/RelayStoreUtils.js +55 -16
- package/lib/RelayViewerHandler.js +8 -50
- package/lib/StoreInspector.js +171 -0
- package/lib/applyRelayModernOptimisticMutation.js +8 -2
- package/lib/cloneRelayHandleSourceField.js +17 -7
- package/lib/commitLocalUpdate.js +1 -1
- package/lib/commitRelayModernMutation.js +33 -13
- package/lib/createRelayContext.js +27 -0
- package/lib/createRelayNetworkLogger.js +8 -2
- package/lib/deepFreeze.js +1 -1
- package/lib/defaultGetDataID.js +24 -0
- package/lib/fetchQueryInternal.js +232 -0
- package/lib/fetchRelayModernQuery.js +5 -3
- package/lib/getFragmentIdentifier.js +52 -0
- package/lib/getFragmentSpecIdentifier.js +26 -0
- package/lib/getRelayHandleKey.js +8 -2
- package/lib/getRequestParametersIdentifier.js +26 -0
- package/lib/hasOverlappingIDs.js +1 -1
- package/lib/index.js +155 -53
- package/lib/isPromise.js +1 -1
- package/lib/isScalarAndEqual.js +1 -1
- package/lib/normalizeRelayPayload.js +19 -10
- package/lib/recycleNodesInto.js +23 -5
- package/lib/requestRelaySubscription.js +9 -3
- package/lib/validateMutation.js +13 -6
- package/package.json +2 -2
- package/relay-runtime.js +2 -2
- package/relay-runtime.min.js +2 -2
- package/lib/normalizePayload.js +0 -37
- package/lib/simpleClone.js +0 -27
|
@@ -4,12 +4,25 @@
|
|
|
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
|
+
|
|
14
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread"));
|
|
15
|
+
|
|
16
|
+
var RelayModernRecord = require("./RelayModernRecord");
|
|
17
|
+
|
|
18
|
+
var invariant = require("fbjs/lib/invariant");
|
|
19
|
+
|
|
20
|
+
var _require = require("./RelayRecordState"),
|
|
21
|
+
EXISTENT = _require.EXISTENT;
|
|
22
|
+
|
|
23
|
+
var _require2 = require("./RelayStoreUtils"),
|
|
24
|
+
UNPUBLISH_FIELD_SENTINEL = _require2.UNPUBLISH_FIELD_SENTINEL,
|
|
25
|
+
UNPUBLISH_RECORD_SENTINEL = _require2.UNPUBLISH_RECORD_SENTINEL;
|
|
13
26
|
|
|
14
27
|
/**
|
|
15
28
|
* @internal
|
|
@@ -40,9 +53,61 @@ function () {
|
|
|
40
53
|
this._sink = sink;
|
|
41
54
|
this.__sources = [sink, base];
|
|
42
55
|
}
|
|
56
|
+
/**
|
|
57
|
+
* **UNSTABLE**
|
|
58
|
+
* This method is likely to be removed in an upcoming release
|
|
59
|
+
* and should not be relied upon.
|
|
60
|
+
* TODO T41593196: Remove unstable_getRawRecordWithChanges
|
|
61
|
+
*/
|
|
62
|
+
|
|
43
63
|
|
|
44
64
|
var _proto = RelayRecordSourceMutator.prototype;
|
|
45
65
|
|
|
66
|
+
_proto.unstable_getRawRecordWithChanges = function unstable_getRawRecordWithChanges(dataID) {
|
|
67
|
+
var baseRecord = this._base.get(dataID);
|
|
68
|
+
|
|
69
|
+
var sinkRecord = this._sink.get(dataID);
|
|
70
|
+
|
|
71
|
+
if (sinkRecord === undefined) {
|
|
72
|
+
if (baseRecord == null) {
|
|
73
|
+
return baseRecord;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
var nextRecord = RelayModernRecord.clone(baseRecord);
|
|
77
|
+
|
|
78
|
+
if (process.env.NODE_ENV !== "production") {
|
|
79
|
+
// Prevent mutation of a record from outside the store.
|
|
80
|
+
RelayModernRecord.freeze(nextRecord);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return nextRecord;
|
|
84
|
+
} else if (sinkRecord === null) {
|
|
85
|
+
return null;
|
|
86
|
+
} else if (sinkRecord === UNPUBLISH_RECORD_SENTINEL) {
|
|
87
|
+
return undefined;
|
|
88
|
+
} else if (baseRecord != null) {
|
|
89
|
+
var _nextRecord = RelayModernRecord.update(baseRecord, sinkRecord);
|
|
90
|
+
|
|
91
|
+
if (process.env.NODE_ENV !== "production") {
|
|
92
|
+
if (_nextRecord !== baseRecord) {
|
|
93
|
+
// Prevent mutation of a record from outside the store.
|
|
94
|
+
RelayModernRecord.freeze(_nextRecord);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
return _nextRecord;
|
|
99
|
+
} else {
|
|
100
|
+
var _nextRecord2 = RelayModernRecord.clone(sinkRecord);
|
|
101
|
+
|
|
102
|
+
if (process.env.NODE_ENV !== "production") {
|
|
103
|
+
// Prevent mutation of a record from outside the store.
|
|
104
|
+
RelayModernRecord.freeze(_nextRecord2);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
return _nextRecord2;
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
46
111
|
_proto._createBackupRecord = function _createBackupRecord(dataID) {
|
|
47
112
|
var backup = this._backup;
|
|
48
113
|
|
|
@@ -63,14 +128,14 @@ function () {
|
|
|
63
128
|
if (backup) {
|
|
64
129
|
var backupRecord = backup.get(dataID);
|
|
65
130
|
|
|
66
|
-
if (backupRecord && backupRecord !==
|
|
131
|
+
if (backupRecord && backupRecord !== UNPUBLISH_RECORD_SENTINEL) {
|
|
67
132
|
var copy = null;
|
|
68
133
|
|
|
69
134
|
for (var key in record) {
|
|
70
135
|
if (record.hasOwnProperty(key)) {
|
|
71
136
|
if (!(key in backupRecord)) {
|
|
72
137
|
copy = copy || (0, _objectSpread2["default"])({}, backupRecord);
|
|
73
|
-
copy[key] =
|
|
138
|
+
copy[key] = UNPUBLISH_FIELD_SENTINEL;
|
|
74
139
|
}
|
|
75
140
|
}
|
|
76
141
|
}
|
|
@@ -86,11 +151,9 @@ function () {
|
|
|
86
151
|
if (backup) {
|
|
87
152
|
var backupRecord = backup.get(dataID);
|
|
88
153
|
|
|
89
|
-
if (backupRecord && backupRecord !==
|
|
154
|
+
if (backupRecord && backupRecord !== UNPUBLISH_RECORD_SENTINEL && !(storageKey in backupRecord)) {
|
|
90
155
|
var copy = (0, _objectSpread2["default"])({}, backupRecord);
|
|
91
|
-
|
|
92
|
-
require("./RelayModernRecord").setValue(copy, storageKey, require("./RelayStoreUtils").UNPUBLISH_FIELD_SENTINEL);
|
|
93
|
-
|
|
156
|
+
RelayModernRecord.setValue(copy, storageKey, UNPUBLISH_FIELD_SENTINEL);
|
|
94
157
|
backup.set(dataID, copy);
|
|
95
158
|
}
|
|
96
159
|
}
|
|
@@ -102,8 +165,8 @@ function () {
|
|
|
102
165
|
if (!sinkRecord) {
|
|
103
166
|
var baseRecord = this._base.get(dataID);
|
|
104
167
|
|
|
105
|
-
!baseRecord ? process.env.NODE_ENV !== "production" ?
|
|
106
|
-
sinkRecord =
|
|
168
|
+
!baseRecord ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayRecordSourceMutator: Cannot modify non-existent record `%s`.', dataID) : invariant(false) : void 0;
|
|
169
|
+
sinkRecord = RelayModernRecord.create(dataID, RelayModernRecord.getType(baseRecord));
|
|
107
170
|
|
|
108
171
|
this._sink.set(dataID, sinkRecord);
|
|
109
172
|
}
|
|
@@ -116,41 +179,41 @@ function () {
|
|
|
116
179
|
|
|
117
180
|
var baseSource = this._base.get(sourceID);
|
|
118
181
|
|
|
119
|
-
!(sinkSource || baseSource) ? process.env.NODE_ENV !== "production" ?
|
|
182
|
+
!(sinkSource || baseSource) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayRecordSourceMutator#copyFields(): Cannot copy fields from ' + 'non-existent record `%s`.', sourceID) : invariant(false) : void 0;
|
|
120
183
|
|
|
121
184
|
this._createBackupRecord(sinkID);
|
|
122
185
|
|
|
123
186
|
var sink = this._getSinkRecord(sinkID);
|
|
124
187
|
|
|
125
188
|
if (baseSource) {
|
|
126
|
-
|
|
189
|
+
RelayModernRecord.copyFields(baseSource, sink);
|
|
127
190
|
}
|
|
128
191
|
|
|
129
192
|
if (sinkSource) {
|
|
130
|
-
|
|
193
|
+
RelayModernRecord.copyFields(sinkSource, sink);
|
|
131
194
|
}
|
|
132
195
|
|
|
133
196
|
this._setSentinelFieldsInBackupRecord(sinkID, sink);
|
|
134
197
|
};
|
|
135
198
|
|
|
136
199
|
_proto.copyFieldsFromRecord = function copyFieldsFromRecord(record, sinkID) {
|
|
137
|
-
this.
|
|
200
|
+
this._createBackupRecord(sinkID);
|
|
138
201
|
|
|
139
202
|
var sink = this._getSinkRecord(sinkID);
|
|
140
203
|
|
|
141
|
-
|
|
204
|
+
RelayModernRecord.copyFields(record, sink);
|
|
142
205
|
|
|
143
206
|
this._setSentinelFieldsInBackupRecord(sinkID, sink);
|
|
144
207
|
};
|
|
145
208
|
|
|
146
209
|
_proto.create = function create(dataID, typeName) {
|
|
147
|
-
!(this._base.getStatus(dataID) !==
|
|
210
|
+
!(this._base.getStatus(dataID) !== EXISTENT && this._sink.getStatus(dataID) !== EXISTENT) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayRecordSourceMutator#create(): Cannot create a record with id ' + '`%s`, this record already exists.', dataID) : invariant(false) : void 0;
|
|
148
211
|
|
|
149
212
|
if (this._backup) {
|
|
150
|
-
this._backup.set(dataID,
|
|
213
|
+
this._backup.set(dataID, UNPUBLISH_RECORD_SENTINEL);
|
|
151
214
|
}
|
|
152
215
|
|
|
153
|
-
var record =
|
|
216
|
+
var record = RelayModernRecord.create(dataID, typeName);
|
|
154
217
|
|
|
155
218
|
this._sink.set(dataID, record);
|
|
156
219
|
};
|
|
@@ -170,7 +233,7 @@ function () {
|
|
|
170
233
|
var record = this.__sources[ii].get(dataID);
|
|
171
234
|
|
|
172
235
|
if (record) {
|
|
173
|
-
return
|
|
236
|
+
return RelayModernRecord.getType(record);
|
|
174
237
|
} else if (record === null) {
|
|
175
238
|
return null;
|
|
176
239
|
}
|
|
@@ -182,7 +245,7 @@ function () {
|
|
|
182
245
|
var record = this.__sources[ii].get(dataID);
|
|
183
246
|
|
|
184
247
|
if (record) {
|
|
185
|
-
var value =
|
|
248
|
+
var value = RelayModernRecord.getValue(record, storageKey);
|
|
186
249
|
|
|
187
250
|
if (value !== undefined) {
|
|
188
251
|
return value;
|
|
@@ -198,7 +261,7 @@ function () {
|
|
|
198
261
|
|
|
199
262
|
var sinkRecord = this._getSinkRecord(dataID);
|
|
200
263
|
|
|
201
|
-
|
|
264
|
+
RelayModernRecord.setValue(sinkRecord, storageKey, value);
|
|
202
265
|
|
|
203
266
|
this._setSentinelFieldInBackupRecord(dataID, storageKey);
|
|
204
267
|
};
|
|
@@ -208,7 +271,7 @@ function () {
|
|
|
208
271
|
var record = this.__sources[ii].get(dataID);
|
|
209
272
|
|
|
210
273
|
if (record) {
|
|
211
|
-
var linkedID =
|
|
274
|
+
var linkedID = RelayModernRecord.getLinkedRecordID(record, storageKey);
|
|
212
275
|
|
|
213
276
|
if (linkedID !== undefined) {
|
|
214
277
|
return linkedID;
|
|
@@ -224,7 +287,7 @@ function () {
|
|
|
224
287
|
|
|
225
288
|
var sinkRecord = this._getSinkRecord(dataID);
|
|
226
289
|
|
|
227
|
-
|
|
290
|
+
RelayModernRecord.setLinkedRecordID(sinkRecord, storageKey, linkedID);
|
|
228
291
|
|
|
229
292
|
this._setSentinelFieldInBackupRecord(dataID, storageKey);
|
|
230
293
|
};
|
|
@@ -234,7 +297,7 @@ function () {
|
|
|
234
297
|
var record = this.__sources[ii].get(dataID);
|
|
235
298
|
|
|
236
299
|
if (record) {
|
|
237
|
-
var linkedIDs =
|
|
300
|
+
var linkedIDs = RelayModernRecord.getLinkedRecordIDs(record, storageKey);
|
|
238
301
|
|
|
239
302
|
if (linkedIDs !== undefined) {
|
|
240
303
|
return linkedIDs;
|
|
@@ -250,7 +313,7 @@ function () {
|
|
|
250
313
|
|
|
251
314
|
var sinkRecord = this._getSinkRecord(dataID);
|
|
252
315
|
|
|
253
|
-
|
|
316
|
+
RelayModernRecord.setLinkedRecordIDs(sinkRecord, storageKey, linkedIDs);
|
|
254
317
|
|
|
255
318
|
this._setSentinelFieldInBackupRecord(dataID, storageKey);
|
|
256
319
|
};
|
|
@@ -9,6 +9,24 @@
|
|
|
9
9
|
*/
|
|
10
10
|
'use strict';
|
|
11
11
|
|
|
12
|
+
var RelayModernRecord = require("./RelayModernRecord");
|
|
13
|
+
|
|
14
|
+
var RelayRecordProxy = require("./RelayRecordProxy");
|
|
15
|
+
|
|
16
|
+
var RelayRecordSourceSelectorProxy = require("./RelayRecordSourceSelectorProxy");
|
|
17
|
+
|
|
18
|
+
var invariant = require("fbjs/lib/invariant");
|
|
19
|
+
|
|
20
|
+
var normalizeRelayPayload = require("./normalizeRelayPayload");
|
|
21
|
+
|
|
22
|
+
var _require = require("./RelayRecordState"),
|
|
23
|
+
EXISTENT = _require.EXISTENT,
|
|
24
|
+
NONEXISTENT = _require.NONEXISTENT;
|
|
25
|
+
|
|
26
|
+
var _require2 = require("./RelayStoreUtils"),
|
|
27
|
+
ROOT_ID = _require2.ROOT_ID,
|
|
28
|
+
ROOT_TYPE = _require2.ROOT_TYPE;
|
|
29
|
+
|
|
12
30
|
/**
|
|
13
31
|
* @internal
|
|
14
32
|
*
|
|
@@ -17,10 +35,11 @@
|
|
|
17
35
|
var RelayRecordSourceProxy =
|
|
18
36
|
/*#__PURE__*/
|
|
19
37
|
function () {
|
|
20
|
-
function RelayRecordSourceProxy(mutator, handlerProvider) {
|
|
38
|
+
function RelayRecordSourceProxy(mutator, getDataID, handlerProvider) {
|
|
21
39
|
this.__mutator = mutator;
|
|
22
40
|
this._handlerProvider = handlerProvider || null;
|
|
23
41
|
this._proxies = {};
|
|
42
|
+
this._getDataID = getDataID;
|
|
24
43
|
}
|
|
25
44
|
|
|
26
45
|
var _proto = RelayRecordSourceProxy.prototype;
|
|
@@ -32,19 +51,17 @@ function () {
|
|
|
32
51
|
dataIDs.forEach(function (dataID) {
|
|
33
52
|
var status = source.getStatus(dataID);
|
|
34
53
|
|
|
35
|
-
if (status ===
|
|
54
|
+
if (status === EXISTENT) {
|
|
36
55
|
var sourceRecord = source.get(dataID);
|
|
37
56
|
|
|
38
57
|
if (sourceRecord) {
|
|
39
|
-
if (_this.__mutator.getStatus(dataID) !==
|
|
40
|
-
_this.create(dataID,
|
|
58
|
+
if (_this.__mutator.getStatus(dataID) !== EXISTENT) {
|
|
59
|
+
_this.create(dataID, RelayModernRecord.getType(sourceRecord));
|
|
41
60
|
}
|
|
42
61
|
|
|
43
62
|
_this.__mutator.copyFieldsFromRecord(sourceRecord, dataID);
|
|
44
|
-
|
|
45
|
-
delete _this._proxies[dataID];
|
|
46
63
|
}
|
|
47
|
-
} else if (status ===
|
|
64
|
+
} else if (status === NONEXISTENT) {
|
|
48
65
|
_this["delete"](dataID);
|
|
49
66
|
}
|
|
50
67
|
});
|
|
@@ -53,7 +70,7 @@ function () {
|
|
|
53
70
|
fieldPayloads.forEach(function (fieldPayload) {
|
|
54
71
|
var handler = _this._handlerProvider && _this._handlerProvider(fieldPayload.handle);
|
|
55
72
|
|
|
56
|
-
!handler ? process.env.NODE_ENV !== "production" ?
|
|
73
|
+
!handler ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayModernEnvironment: Expected a handler to be provided for handle `%s`.', fieldPayload.handle) : invariant(false) : void 0;
|
|
57
74
|
handler.update(_this, fieldPayload);
|
|
58
75
|
});
|
|
59
76
|
}
|
|
@@ -61,15 +78,17 @@ function () {
|
|
|
61
78
|
|
|
62
79
|
_proto.commitPayload = function commitPayload(operation, response) {
|
|
63
80
|
if (!response) {
|
|
64
|
-
return new
|
|
81
|
+
return new RelayRecordSourceSelectorProxy(this, operation.fragment);
|
|
65
82
|
}
|
|
66
83
|
|
|
67
|
-
var _normalizeRelayPayloa =
|
|
84
|
+
var _normalizeRelayPayloa = normalizeRelayPayload(operation.root, response, null, {
|
|
85
|
+
getDataID: this._getDataID
|
|
86
|
+
}),
|
|
68
87
|
source = _normalizeRelayPayloa.source,
|
|
69
88
|
fieldPayloads = _normalizeRelayPayloa.fieldPayloads;
|
|
70
89
|
|
|
71
90
|
this.publishSource(source, fieldPayloads);
|
|
72
|
-
return new
|
|
91
|
+
return new RelayRecordSourceSelectorProxy(this, operation.fragment);
|
|
73
92
|
};
|
|
74
93
|
|
|
75
94
|
_proto.create = function create(dataID, typeName) {
|
|
@@ -78,12 +97,12 @@ function () {
|
|
|
78
97
|
delete this._proxies[dataID];
|
|
79
98
|
var record = this.get(dataID); // For flow
|
|
80
99
|
|
|
81
|
-
!record ? process.env.NODE_ENV !== "production" ?
|
|
100
|
+
!record ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayRecordSourceProxy#create(): Expected the created record to exist.') : invariant(false) : void 0;
|
|
82
101
|
return record;
|
|
83
102
|
};
|
|
84
103
|
|
|
85
104
|
_proto["delete"] = function _delete(dataID) {
|
|
86
|
-
!(dataID !==
|
|
105
|
+
!(dataID !== ROOT_ID) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayRecordSourceProxy#delete(): Cannot delete the root record.') : invariant(false) : void 0;
|
|
87
106
|
delete this._proxies[dataID];
|
|
88
107
|
|
|
89
108
|
this.__mutator["delete"](dataID);
|
|
@@ -93,10 +112,10 @@ function () {
|
|
|
93
112
|
if (!this._proxies.hasOwnProperty(dataID)) {
|
|
94
113
|
var status = this.__mutator.getStatus(dataID);
|
|
95
114
|
|
|
96
|
-
if (status ===
|
|
97
|
-
this._proxies[dataID] = new
|
|
115
|
+
if (status === EXISTENT) {
|
|
116
|
+
this._proxies[dataID] = new RelayRecordProxy(this, this.__mutator, dataID);
|
|
98
117
|
} else {
|
|
99
|
-
this._proxies[dataID] = status ===
|
|
118
|
+
this._proxies[dataID] = status === NONEXISTENT ? null : undefined;
|
|
100
119
|
}
|
|
101
120
|
}
|
|
102
121
|
|
|
@@ -104,13 +123,13 @@ function () {
|
|
|
104
123
|
};
|
|
105
124
|
|
|
106
125
|
_proto.getRoot = function getRoot() {
|
|
107
|
-
var root = this.get(
|
|
126
|
+
var root = this.get(ROOT_ID);
|
|
108
127
|
|
|
109
128
|
if (!root) {
|
|
110
|
-
root = this.create(
|
|
129
|
+
root = this.create(ROOT_ID, ROOT_TYPE);
|
|
111
130
|
}
|
|
112
131
|
|
|
113
|
-
!(root && root.getType() ===
|
|
132
|
+
!(root && root.getType() === ROOT_TYPE) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayRecordSourceProxy#getRoot(): Expected the source to contain a ' + 'root record.') : invariant(false) : void 0;
|
|
114
133
|
return root;
|
|
115
134
|
};
|
|
116
135
|
|
|
@@ -4,11 +4,16 @@
|
|
|
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 invariant = require("fbjs/lib/invariant");
|
|
13
|
+
|
|
14
|
+
var _require = require("./RelayStoreUtils"),
|
|
15
|
+
getStorageKey = _require.getStorageKey;
|
|
16
|
+
|
|
12
17
|
/**
|
|
13
18
|
* @internal
|
|
14
19
|
*
|
|
@@ -47,24 +52,22 @@ function () {
|
|
|
47
52
|
var field = selector.node.selections.find(function (selection) {
|
|
48
53
|
return selection.kind === 'LinkedField' && selection.name === fieldName;
|
|
49
54
|
});
|
|
50
|
-
!(field && field.kind === 'LinkedField') ? process.env.NODE_ENV !== "production" ?
|
|
51
|
-
!(field.plural === plural) ? process.env.NODE_ENV !== "production" ?
|
|
55
|
+
!(field && field.kind === 'LinkedField') ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayRecordSourceSelectorProxy#getRootField(): Cannot find root ' + 'field `%s`, no such field is defined on GraphQL document `%s`.', fieldName, selector.node.name) : invariant(false) : void 0;
|
|
56
|
+
!(field.plural === plural) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayRecordSourceSelectorProxy#getRootField(): Expected root field ' + '`%s` to be %s.', fieldName, plural ? 'plural' : 'singular') : invariant(false) : void 0;
|
|
52
57
|
return field;
|
|
53
58
|
};
|
|
54
59
|
|
|
55
60
|
_proto.getRootField = function getRootField(fieldName) {
|
|
56
61
|
var field = this._getRootField(this._readSelector, fieldName, false);
|
|
57
62
|
|
|
58
|
-
var storageKey =
|
|
59
|
-
|
|
63
|
+
var storageKey = getStorageKey(field, this._readSelector.variables);
|
|
60
64
|
return this.getRoot().getLinkedRecord(storageKey);
|
|
61
65
|
};
|
|
62
66
|
|
|
63
67
|
_proto.getPluralRootField = function getPluralRootField(fieldName) {
|
|
64
68
|
var field = this._getRootField(this._readSelector, fieldName, true);
|
|
65
69
|
|
|
66
|
-
var storageKey =
|
|
67
|
-
|
|
70
|
+
var storageKey = getStorageKey(field, this._readSelector.variables);
|
|
68
71
|
return this.getRoot().getLinkedRecords(storageKey);
|
|
69
72
|
};
|
|
70
73
|
|
package/lib/RelayRecordState.js
CHANGED
|
@@ -4,11 +4,35 @@
|
|
|
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 RelayConcreteNode = require("./RelayConcreteNode");
|
|
13
|
+
|
|
14
|
+
var RelayModernRecord = require("./RelayModernRecord");
|
|
15
|
+
|
|
16
|
+
var RelayStoreUtils = require("./RelayStoreUtils");
|
|
17
|
+
|
|
18
|
+
var cloneRelayHandleSourceField = require("./cloneRelayHandleSourceField");
|
|
19
|
+
|
|
20
|
+
var invariant = require("fbjs/lib/invariant");
|
|
21
|
+
|
|
22
|
+
var CONDITION = RelayConcreteNode.CONDITION,
|
|
23
|
+
CLIENT_EXTENSION = RelayConcreteNode.CLIENT_EXTENSION,
|
|
24
|
+
DEFER = RelayConcreteNode.DEFER,
|
|
25
|
+
FRAGMENT_SPREAD = RelayConcreteNode.FRAGMENT_SPREAD,
|
|
26
|
+
INLINE_FRAGMENT = RelayConcreteNode.INLINE_FRAGMENT,
|
|
27
|
+
LINKED_FIELD = RelayConcreteNode.LINKED_FIELD,
|
|
28
|
+
MODULE_IMPORT = RelayConcreteNode.MODULE_IMPORT,
|
|
29
|
+
LINKED_HANDLE = RelayConcreteNode.LINKED_HANDLE,
|
|
30
|
+
SCALAR_FIELD = RelayConcreteNode.SCALAR_FIELD,
|
|
31
|
+
SCALAR_HANDLE = RelayConcreteNode.SCALAR_HANDLE,
|
|
32
|
+
STREAM = RelayConcreteNode.STREAM;
|
|
33
|
+
var getStorageKey = RelayStoreUtils.getStorageKey,
|
|
34
|
+
getModuleOperationKey = RelayStoreUtils.getModuleOperationKey;
|
|
35
|
+
|
|
12
36
|
function mark(recordSource, selector, references, operationLoader) {
|
|
13
37
|
var dataID = selector.dataID,
|
|
14
38
|
node = selector.node,
|
|
@@ -52,7 +76,7 @@ function () {
|
|
|
52
76
|
};
|
|
53
77
|
|
|
54
78
|
_proto._getVariableValue = function _getVariableValue(name) {
|
|
55
|
-
!this._variables.hasOwnProperty(name) ? process.env.NODE_ENV !== "production" ?
|
|
79
|
+
!this._variables.hasOwnProperty(name) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReferenceMarker(): Undefined variable `%s`.', name) : invariant(false) : void 0;
|
|
56
80
|
return this._variables[name];
|
|
57
81
|
};
|
|
58
82
|
|
|
@@ -62,7 +86,7 @@ function () {
|
|
|
62
86
|
selections.forEach(function (selection) {
|
|
63
87
|
/* eslint-disable no-fallthrough */
|
|
64
88
|
switch (selection.kind) {
|
|
65
|
-
case
|
|
89
|
+
case LINKED_FIELD:
|
|
66
90
|
if (selection.plural) {
|
|
67
91
|
_this._traversePluralLink(selection, record);
|
|
68
92
|
} else {
|
|
@@ -71,7 +95,7 @@ function () {
|
|
|
71
95
|
|
|
72
96
|
break;
|
|
73
97
|
|
|
74
|
-
case
|
|
98
|
+
case CONDITION:
|
|
75
99
|
var conditionValue = _this._getVariableValue(selection.condition);
|
|
76
100
|
|
|
77
101
|
if (conditionValue === selection.passingValue) {
|
|
@@ -80,8 +104,8 @@ function () {
|
|
|
80
104
|
|
|
81
105
|
break;
|
|
82
106
|
|
|
83
|
-
case
|
|
84
|
-
var typeName =
|
|
107
|
+
case INLINE_FRAGMENT:
|
|
108
|
+
var typeName = RelayModernRecord.getType(record);
|
|
85
109
|
|
|
86
110
|
if (typeName != null && typeName === selection.type) {
|
|
87
111
|
_this._traverseSelections(selection.selections, record);
|
|
@@ -89,10 +113,10 @@ function () {
|
|
|
89
113
|
|
|
90
114
|
break;
|
|
91
115
|
|
|
92
|
-
case
|
|
93
|
-
!false ? process.env.NODE_ENV !== "production" ?
|
|
116
|
+
case FRAGMENT_SPREAD:
|
|
117
|
+
!false ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReferenceMarker(): Unexpected fragment spread `...%s`, ' + 'expected all fragments to be inlined.', selection.name) : invariant(false) : void 0;
|
|
94
118
|
|
|
95
|
-
case
|
|
119
|
+
case LINKED_HANDLE:
|
|
96
120
|
// The selections for a "handle" field are the same as those of the
|
|
97
121
|
// original linked field where the handle was applied. Reference marking
|
|
98
122
|
// therefore requires traversing the original field selections against
|
|
@@ -102,7 +126,7 @@ function () {
|
|
|
102
126
|
// the concrete structure to allow shared subtrees, and have the linked
|
|
103
127
|
// handle directly refer to the same selections as the LinkedField that
|
|
104
128
|
// it was split from.
|
|
105
|
-
var handleField =
|
|
129
|
+
var handleField = cloneRelayHandleSourceField(selection, selections, _this._variables);
|
|
106
130
|
|
|
107
131
|
if (handleField.plural) {
|
|
108
132
|
_this._traversePluralLink(handleField, record);
|
|
@@ -112,68 +136,56 @@ function () {
|
|
|
112
136
|
|
|
113
137
|
break;
|
|
114
138
|
|
|
115
|
-
case
|
|
116
|
-
case
|
|
139
|
+
case DEFER:
|
|
140
|
+
case STREAM:
|
|
141
|
+
_this._traverseSelections(selection.selections, record);
|
|
142
|
+
|
|
143
|
+
break;
|
|
144
|
+
|
|
145
|
+
case SCALAR_FIELD:
|
|
146
|
+
case SCALAR_HANDLE:
|
|
117
147
|
break;
|
|
118
148
|
|
|
119
|
-
case
|
|
120
|
-
_this.
|
|
149
|
+
case MODULE_IMPORT:
|
|
150
|
+
_this._traverseModuleImport(selection, record);
|
|
151
|
+
|
|
152
|
+
break;
|
|
153
|
+
|
|
154
|
+
case CLIENT_EXTENSION:
|
|
155
|
+
_this._traverseSelections(selection.selections, record);
|
|
121
156
|
|
|
122
157
|
break;
|
|
123
158
|
|
|
124
159
|
default:
|
|
125
160
|
selection;
|
|
126
|
-
!false ? process.env.NODE_ENV !== "production" ?
|
|
161
|
+
!false ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReferenceMarker: Unknown AST node `%s`.', selection) : invariant(false) : void 0;
|
|
127
162
|
}
|
|
128
163
|
});
|
|
129
164
|
};
|
|
130
165
|
|
|
131
|
-
_proto.
|
|
132
|
-
var
|
|
133
|
-
|
|
134
|
-
var
|
|
135
|
-
|
|
136
|
-
if (linkedID == null) {
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
this._references.add(linkedID);
|
|
166
|
+
_proto._traverseModuleImport = function _traverseModuleImport(moduleImport, record) {
|
|
167
|
+
var operationLoader = this._operationLoader;
|
|
168
|
+
!(operationLoader !== null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReferenceMarker: Expected an operationLoader to be configured when using `@module`.') : invariant(false) : void 0;
|
|
169
|
+
var operationKey = getModuleOperationKey(moduleImport.documentName);
|
|
170
|
+
var operationReference = RelayModernRecord.getValue(record, operationKey);
|
|
141
171
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
if (linkedRecord == null) {
|
|
172
|
+
if (operationReference == null) {
|
|
145
173
|
return;
|
|
146
174
|
}
|
|
147
175
|
|
|
148
|
-
var
|
|
149
|
-
|
|
150
|
-
var match = field.matchesByType[typeName];
|
|
151
|
-
|
|
152
|
-
if (match != null) {
|
|
153
|
-
var operationLoader = this._operationLoader;
|
|
154
|
-
!(operationLoader !== null) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayReferenceMarker: Expected an operationLoader to be configured when using `@match`.') : require("fbjs/lib/invariant")(false) : void 0;
|
|
176
|
+
var operation = operationLoader.get(operationReference);
|
|
155
177
|
|
|
156
|
-
|
|
178
|
+
if (operation != null) {
|
|
179
|
+
this._traverseSelections(operation.selections, record);
|
|
180
|
+
} // Otherwise, if the operation is not available, we assume that the data
|
|
181
|
+
// cannot have been processed yet and therefore isn't in the store to
|
|
182
|
+
// begin with.
|
|
157
183
|
|
|
158
|
-
if (operationReference == null) {
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
var operation = operationLoader.get(operationReference);
|
|
163
|
-
|
|
164
|
-
if (operation != null) {
|
|
165
|
-
this._traverseSelections(operation.selections, linkedRecord);
|
|
166
|
-
} // If the operation is not available, we assume that the data cannot have been
|
|
167
|
-
// processed yet and therefore isn't in the store to begin with.
|
|
168
|
-
|
|
169
|
-
} else {// TODO: warn: store is corrupt: the field should be null if the typename did not match
|
|
170
|
-
}
|
|
171
184
|
};
|
|
172
185
|
|
|
173
186
|
_proto._traverseLink = function _traverseLink(field, record) {
|
|
174
|
-
var storageKey =
|
|
175
|
-
|
|
176
|
-
var linkedID = require("./RelayModernRecord").getLinkedRecordID(record, storageKey);
|
|
187
|
+
var storageKey = getStorageKey(field, this._variables);
|
|
188
|
+
var linkedID = RelayModernRecord.getLinkedRecordID(record, storageKey);
|
|
177
189
|
|
|
178
190
|
if (linkedID == null) {
|
|
179
191
|
return;
|
|
@@ -185,9 +197,8 @@ function () {
|
|
|
185
197
|
_proto._traversePluralLink = function _traversePluralLink(field, record) {
|
|
186
198
|
var _this2 = this;
|
|
187
199
|
|
|
188
|
-
var storageKey =
|
|
189
|
-
|
|
190
|
-
var linkedIDs = require("./RelayModernRecord").getLinkedRecordIDs(record, storageKey);
|
|
200
|
+
var storageKey = getStorageKey(field, this._variables);
|
|
201
|
+
var linkedIDs = RelayModernRecord.getLinkedRecordIDs(record, storageKey);
|
|
191
202
|
|
|
192
203
|
if (linkedIDs == null) {
|
|
193
204
|
return;
|