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,14 +7,9 @@
|
|
|
7
7
|
* strict-local
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
10
|
'use strict';
|
|
12
11
|
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
var _classCallCheck3 = _interopRequireDefault(require('babel-runtime/helpers/classCallCheck'));
|
|
16
|
-
|
|
17
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
12
|
+
var _objectSpread2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/objectSpread"));
|
|
18
13
|
|
|
19
14
|
/**
|
|
20
15
|
* @internal
|
|
@@ -36,126 +31,159 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'd
|
|
|
36
31
|
* so that the new record can be removed from the store by publishing the
|
|
37
32
|
* backup.
|
|
38
33
|
*/
|
|
39
|
-
var RelayRecordSourceMutator =
|
|
34
|
+
var RelayRecordSourceMutator =
|
|
35
|
+
/*#__PURE__*/
|
|
36
|
+
function () {
|
|
40
37
|
function RelayRecordSourceMutator(base, sink, backup) {
|
|
41
|
-
(0, _classCallCheck3['default'])(this, RelayRecordSourceMutator);
|
|
42
|
-
|
|
43
38
|
this._backup = backup;
|
|
44
39
|
this._base = base;
|
|
45
40
|
this._sink = sink;
|
|
46
41
|
this.__sources = [sink, base];
|
|
47
42
|
}
|
|
48
43
|
|
|
49
|
-
RelayRecordSourceMutator.prototype
|
|
44
|
+
var _proto = RelayRecordSourceMutator.prototype;
|
|
45
|
+
|
|
46
|
+
_proto._createBackupRecord = function _createBackupRecord(dataID) {
|
|
50
47
|
var backup = this._backup;
|
|
48
|
+
|
|
51
49
|
if (backup && !backup.has(dataID)) {
|
|
52
50
|
var baseRecord = this._base.get(dataID);
|
|
51
|
+
|
|
53
52
|
if (baseRecord != null) {
|
|
54
53
|
backup.set(dataID, baseRecord);
|
|
55
54
|
} else if (baseRecord === null) {
|
|
56
|
-
backup[
|
|
55
|
+
backup["delete"](dataID);
|
|
57
56
|
}
|
|
58
57
|
}
|
|
59
58
|
};
|
|
60
59
|
|
|
61
|
-
|
|
60
|
+
_proto._setSentinelFieldsInBackupRecord = function _setSentinelFieldsInBackupRecord(dataID, record) {
|
|
62
61
|
var backup = this._backup;
|
|
62
|
+
|
|
63
63
|
if (backup) {
|
|
64
64
|
var backupRecord = backup.get(dataID);
|
|
65
|
-
|
|
65
|
+
|
|
66
|
+
if (backupRecord && backupRecord !== require("./RelayStoreUtils").UNPUBLISH_RECORD_SENTINEL) {
|
|
66
67
|
var copy = null;
|
|
68
|
+
|
|
67
69
|
for (var key in record) {
|
|
68
70
|
if (record.hasOwnProperty(key)) {
|
|
69
71
|
if (!(key in backupRecord)) {
|
|
70
|
-
copy = copy || (0,
|
|
71
|
-
copy[key] = require(
|
|
72
|
+
copy = copy || (0, _objectSpread2["default"])({}, backupRecord);
|
|
73
|
+
copy[key] = require("./RelayStoreUtils").UNPUBLISH_FIELD_SENTINEL;
|
|
72
74
|
}
|
|
73
75
|
}
|
|
74
76
|
}
|
|
77
|
+
|
|
75
78
|
backup.set(dataID, copy || backupRecord);
|
|
76
79
|
}
|
|
77
80
|
}
|
|
78
81
|
};
|
|
79
82
|
|
|
80
|
-
|
|
83
|
+
_proto._setSentinelFieldInBackupRecord = function _setSentinelFieldInBackupRecord(dataID, storageKey) {
|
|
81
84
|
var backup = this._backup;
|
|
85
|
+
|
|
82
86
|
if (backup) {
|
|
83
87
|
var backupRecord = backup.get(dataID);
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
88
|
+
|
|
89
|
+
if (backupRecord && backupRecord !== require("./RelayStoreUtils").UNPUBLISH_RECORD_SENTINEL && !(storageKey in backupRecord)) {
|
|
90
|
+
var copy = (0, _objectSpread2["default"])({}, backupRecord);
|
|
91
|
+
|
|
92
|
+
require("./RelayModernRecord").setValue(copy, storageKey, require("./RelayStoreUtils").UNPUBLISH_FIELD_SENTINEL);
|
|
93
|
+
|
|
87
94
|
backup.set(dataID, copy);
|
|
88
95
|
}
|
|
89
96
|
}
|
|
90
97
|
};
|
|
91
98
|
|
|
92
|
-
|
|
99
|
+
_proto._getSinkRecord = function _getSinkRecord(dataID) {
|
|
93
100
|
var sinkRecord = this._sink.get(dataID);
|
|
101
|
+
|
|
94
102
|
if (!sinkRecord) {
|
|
95
103
|
var baseRecord = this._base.get(dataID);
|
|
96
|
-
|
|
97
|
-
|
|
104
|
+
|
|
105
|
+
!baseRecord ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayRecordSourceMutator: Cannot modify non-existent record `%s`.', dataID) : require("fbjs/lib/invariant")(false) : void 0;
|
|
106
|
+
sinkRecord = require("./RelayModernRecord").create(dataID, require("./RelayModernRecord").getType(baseRecord));
|
|
107
|
+
|
|
98
108
|
this._sink.set(dataID, sinkRecord);
|
|
99
109
|
}
|
|
110
|
+
|
|
100
111
|
return sinkRecord;
|
|
101
112
|
};
|
|
102
113
|
|
|
103
|
-
|
|
114
|
+
_proto.copyFields = function copyFields(sourceID, sinkID) {
|
|
104
115
|
var sinkSource = this._sink.get(sourceID);
|
|
116
|
+
|
|
105
117
|
var baseSource = this._base.get(sourceID);
|
|
106
|
-
|
|
118
|
+
|
|
119
|
+
!(sinkSource || baseSource) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayRecordSourceMutator#copyFields(): Cannot copy fields from ' + 'non-existent record `%s`.', sourceID) : require("fbjs/lib/invariant")(false) : void 0;
|
|
120
|
+
|
|
107
121
|
this._createBackupRecord(sinkID);
|
|
122
|
+
|
|
108
123
|
var sink = this._getSinkRecord(sinkID);
|
|
124
|
+
|
|
109
125
|
if (baseSource) {
|
|
110
|
-
require(
|
|
126
|
+
require("./RelayModernRecord").copyFields(baseSource, sink);
|
|
111
127
|
}
|
|
128
|
+
|
|
112
129
|
if (sinkSource) {
|
|
113
|
-
require(
|
|
130
|
+
require("./RelayModernRecord").copyFields(sinkSource, sink);
|
|
114
131
|
}
|
|
132
|
+
|
|
115
133
|
this._setSentinelFieldsInBackupRecord(sinkID, sink);
|
|
116
134
|
};
|
|
117
135
|
|
|
118
|
-
|
|
119
|
-
this.copyFields(require(
|
|
136
|
+
_proto.copyFieldsFromRecord = function copyFieldsFromRecord(record, sinkID) {
|
|
137
|
+
this.copyFields(require("./RelayModernRecord").getDataID(record), sinkID);
|
|
138
|
+
|
|
120
139
|
var sink = this._getSinkRecord(sinkID);
|
|
121
|
-
|
|
140
|
+
|
|
141
|
+
require("./RelayModernRecord").copyFields(record, sink);
|
|
142
|
+
|
|
122
143
|
this._setSentinelFieldsInBackupRecord(sinkID, sink);
|
|
123
144
|
};
|
|
124
145
|
|
|
125
|
-
|
|
126
|
-
!(this._base.getStatus(dataID) !== require(
|
|
146
|
+
_proto.create = function create(dataID, typeName) {
|
|
147
|
+
!(this._base.getStatus(dataID) !== require("./RelayRecordState").EXISTENT && this._sink.getStatus(dataID) !== require("./RelayRecordState").EXISTENT) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayRecordSourceMutator#create(): Cannot create a record with id ' + '`%s`, this record already exists.', dataID) : require("fbjs/lib/invariant")(false) : void 0;
|
|
148
|
+
|
|
127
149
|
if (this._backup) {
|
|
128
|
-
this._backup.set(dataID, require(
|
|
150
|
+
this._backup.set(dataID, require("./RelayStoreUtils").UNPUBLISH_RECORD_SENTINEL);
|
|
129
151
|
}
|
|
130
|
-
|
|
152
|
+
|
|
153
|
+
var record = require("./RelayModernRecord").create(dataID, typeName);
|
|
154
|
+
|
|
131
155
|
this._sink.set(dataID, record);
|
|
132
156
|
};
|
|
133
157
|
|
|
134
|
-
|
|
158
|
+
_proto["delete"] = function _delete(dataID) {
|
|
135
159
|
this._createBackupRecord(dataID);
|
|
136
|
-
|
|
160
|
+
|
|
161
|
+
this._sink["delete"](dataID);
|
|
137
162
|
};
|
|
138
163
|
|
|
139
|
-
|
|
164
|
+
_proto.getStatus = function getStatus(dataID) {
|
|
140
165
|
return this._sink.has(dataID) ? this._sink.getStatus(dataID) : this._base.getStatus(dataID);
|
|
141
166
|
};
|
|
142
167
|
|
|
143
|
-
|
|
168
|
+
_proto.getType = function getType(dataID) {
|
|
144
169
|
for (var ii = 0; ii < this.__sources.length; ii++) {
|
|
145
170
|
var record = this.__sources[ii].get(dataID);
|
|
171
|
+
|
|
146
172
|
if (record) {
|
|
147
|
-
return require(
|
|
173
|
+
return require("./RelayModernRecord").getType(record);
|
|
148
174
|
} else if (record === null) {
|
|
149
175
|
return null;
|
|
150
176
|
}
|
|
151
177
|
}
|
|
152
178
|
};
|
|
153
179
|
|
|
154
|
-
|
|
180
|
+
_proto.getValue = function getValue(dataID, storageKey) {
|
|
155
181
|
for (var ii = 0; ii < this.__sources.length; ii++) {
|
|
156
182
|
var record = this.__sources[ii].get(dataID);
|
|
183
|
+
|
|
157
184
|
if (record) {
|
|
158
|
-
var value = require(
|
|
185
|
+
var value = require("./RelayModernRecord").getValue(record, storageKey);
|
|
186
|
+
|
|
159
187
|
if (value !== undefined) {
|
|
160
188
|
return value;
|
|
161
189
|
}
|
|
@@ -165,18 +193,23 @@ var RelayRecordSourceMutator = function () {
|
|
|
165
193
|
}
|
|
166
194
|
};
|
|
167
195
|
|
|
168
|
-
|
|
196
|
+
_proto.setValue = function setValue(dataID, storageKey, value) {
|
|
169
197
|
this._createBackupRecord(dataID);
|
|
198
|
+
|
|
170
199
|
var sinkRecord = this._getSinkRecord(dataID);
|
|
171
|
-
|
|
200
|
+
|
|
201
|
+
require("./RelayModernRecord").setValue(sinkRecord, storageKey, value);
|
|
202
|
+
|
|
172
203
|
this._setSentinelFieldInBackupRecord(dataID, storageKey);
|
|
173
204
|
};
|
|
174
205
|
|
|
175
|
-
|
|
206
|
+
_proto.getLinkedRecordID = function getLinkedRecordID(dataID, storageKey) {
|
|
176
207
|
for (var ii = 0; ii < this.__sources.length; ii++) {
|
|
177
208
|
var record = this.__sources[ii].get(dataID);
|
|
209
|
+
|
|
178
210
|
if (record) {
|
|
179
|
-
var linkedID = require(
|
|
211
|
+
var linkedID = require("./RelayModernRecord").getLinkedRecordID(record, storageKey);
|
|
212
|
+
|
|
180
213
|
if (linkedID !== undefined) {
|
|
181
214
|
return linkedID;
|
|
182
215
|
}
|
|
@@ -186,18 +219,23 @@ var RelayRecordSourceMutator = function () {
|
|
|
186
219
|
}
|
|
187
220
|
};
|
|
188
221
|
|
|
189
|
-
|
|
222
|
+
_proto.setLinkedRecordID = function setLinkedRecordID(dataID, storageKey, linkedID) {
|
|
190
223
|
this._createBackupRecord(dataID);
|
|
224
|
+
|
|
191
225
|
var sinkRecord = this._getSinkRecord(dataID);
|
|
192
|
-
|
|
226
|
+
|
|
227
|
+
require("./RelayModernRecord").setLinkedRecordID(sinkRecord, storageKey, linkedID);
|
|
228
|
+
|
|
193
229
|
this._setSentinelFieldInBackupRecord(dataID, storageKey);
|
|
194
230
|
};
|
|
195
231
|
|
|
196
|
-
|
|
232
|
+
_proto.getLinkedRecordIDs = function getLinkedRecordIDs(dataID, storageKey) {
|
|
197
233
|
for (var ii = 0; ii < this.__sources.length; ii++) {
|
|
198
234
|
var record = this.__sources[ii].get(dataID);
|
|
235
|
+
|
|
199
236
|
if (record) {
|
|
200
|
-
var linkedIDs = require(
|
|
237
|
+
var linkedIDs = require("./RelayModernRecord").getLinkedRecordIDs(record, storageKey);
|
|
238
|
+
|
|
201
239
|
if (linkedIDs !== undefined) {
|
|
202
240
|
return linkedIDs;
|
|
203
241
|
}
|
|
@@ -207,10 +245,13 @@ var RelayRecordSourceMutator = function () {
|
|
|
207
245
|
}
|
|
208
246
|
};
|
|
209
247
|
|
|
210
|
-
|
|
248
|
+
_proto.setLinkedRecordIDs = function setLinkedRecordIDs(dataID, storageKey, linkedIDs) {
|
|
211
249
|
this._createBackupRecord(dataID);
|
|
250
|
+
|
|
212
251
|
var sinkRecord = this._getSinkRecord(dataID);
|
|
213
|
-
|
|
252
|
+
|
|
253
|
+
require("./RelayModernRecord").setLinkedRecordIDs(sinkRecord, storageKey, linkedIDs);
|
|
254
|
+
|
|
214
255
|
this._setSentinelFieldInBackupRecord(dataID, storageKey);
|
|
215
256
|
};
|
|
216
257
|
|
|
@@ -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,102 +7,110 @@
|
|
|
7
7
|
*
|
|
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 for manipulating a `RecordSource` via an imperative/OO-style API.
|
|
21
16
|
*/
|
|
22
|
-
var RelayRecordSourceProxy =
|
|
17
|
+
var RelayRecordSourceProxy =
|
|
18
|
+
/*#__PURE__*/
|
|
19
|
+
function () {
|
|
23
20
|
function RelayRecordSourceProxy(mutator, handlerProvider) {
|
|
24
|
-
(0, _classCallCheck3['default'])(this, RelayRecordSourceProxy);
|
|
25
|
-
|
|
26
21
|
this.__mutator = mutator;
|
|
27
22
|
this._handlerProvider = handlerProvider || null;
|
|
28
23
|
this._proxies = {};
|
|
29
24
|
}
|
|
30
25
|
|
|
31
|
-
RelayRecordSourceProxy.prototype
|
|
26
|
+
var _proto = RelayRecordSourceProxy.prototype;
|
|
27
|
+
|
|
28
|
+
_proto.publishSource = function publishSource(source, fieldPayloads) {
|
|
32
29
|
var _this = this;
|
|
33
30
|
|
|
34
31
|
var dataIDs = source.getRecordIDs();
|
|
35
32
|
dataIDs.forEach(function (dataID) {
|
|
36
33
|
var status = source.getStatus(dataID);
|
|
37
|
-
|
|
34
|
+
|
|
35
|
+
if (status === require("./RelayRecordState").EXISTENT) {
|
|
38
36
|
var sourceRecord = source.get(dataID);
|
|
37
|
+
|
|
39
38
|
if (sourceRecord) {
|
|
40
|
-
if (_this.__mutator.getStatus(dataID) !== require(
|
|
41
|
-
_this.create(dataID, require(
|
|
39
|
+
if (_this.__mutator.getStatus(dataID) !== require("./RelayRecordState").EXISTENT) {
|
|
40
|
+
_this.create(dataID, require("./RelayModernRecord").getType(sourceRecord));
|
|
42
41
|
}
|
|
42
|
+
|
|
43
43
|
_this.__mutator.copyFieldsFromRecord(sourceRecord, dataID);
|
|
44
|
+
|
|
44
45
|
delete _this._proxies[dataID];
|
|
45
46
|
}
|
|
46
|
-
} else if (status === require(
|
|
47
|
-
_this[
|
|
47
|
+
} else if (status === require("./RelayRecordState").NONEXISTENT) {
|
|
48
|
+
_this["delete"](dataID);
|
|
48
49
|
}
|
|
49
50
|
});
|
|
50
51
|
|
|
51
52
|
if (fieldPayloads && fieldPayloads.length) {
|
|
52
53
|
fieldPayloads.forEach(function (fieldPayload) {
|
|
53
54
|
var handler = _this._handlerProvider && _this._handlerProvider(fieldPayload.handle);
|
|
54
|
-
|
|
55
|
+
|
|
56
|
+
!handler ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayModernEnvironment: Expected a handler to be provided for handle `%s`.', fieldPayload.handle) : require("fbjs/lib/invariant")(false) : void 0;
|
|
55
57
|
handler.update(_this, fieldPayload);
|
|
56
58
|
});
|
|
57
59
|
}
|
|
58
60
|
};
|
|
59
61
|
|
|
60
|
-
|
|
62
|
+
_proto.commitPayload = function commitPayload(operation, response) {
|
|
61
63
|
if (!response) {
|
|
62
|
-
return new (require(
|
|
64
|
+
return new (require("./RelayRecordSourceSelectorProxy"))(this, operation.fragment);
|
|
63
65
|
}
|
|
64
66
|
|
|
65
|
-
var _normalizeRelayPayloa = require(
|
|
67
|
+
var _normalizeRelayPayloa = require("./normalizeRelayPayload")(operation.root, response),
|
|
66
68
|
source = _normalizeRelayPayloa.source,
|
|
67
69
|
fieldPayloads = _normalizeRelayPayloa.fieldPayloads;
|
|
68
70
|
|
|
69
71
|
this.publishSource(source, fieldPayloads);
|
|
70
|
-
return new (require(
|
|
72
|
+
return new (require("./RelayRecordSourceSelectorProxy"))(this, operation.fragment);
|
|
71
73
|
};
|
|
72
74
|
|
|
73
|
-
|
|
75
|
+
_proto.create = function create(dataID, typeName) {
|
|
74
76
|
this.__mutator.create(dataID, typeName);
|
|
77
|
+
|
|
75
78
|
delete this._proxies[dataID];
|
|
76
|
-
var record = this.get(dataID);
|
|
77
|
-
|
|
78
|
-
!record ? process.env.NODE_ENV !==
|
|
79
|
+
var record = this.get(dataID); // For flow
|
|
80
|
+
|
|
81
|
+
!record ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayRecordSourceProxy#create(): Expected the created record to exist.') : require("fbjs/lib/invariant")(false) : void 0;
|
|
79
82
|
return record;
|
|
80
83
|
};
|
|
81
84
|
|
|
82
|
-
|
|
83
|
-
!(dataID !== require(
|
|
85
|
+
_proto["delete"] = function _delete(dataID) {
|
|
86
|
+
!(dataID !== require("./RelayStoreUtils").ROOT_ID) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayRecordSourceProxy#delete(): Cannot delete the root record.') : require("fbjs/lib/invariant")(false) : void 0;
|
|
84
87
|
delete this._proxies[dataID];
|
|
85
|
-
|
|
88
|
+
|
|
89
|
+
this.__mutator["delete"](dataID);
|
|
86
90
|
};
|
|
87
91
|
|
|
88
|
-
|
|
92
|
+
_proto.get = function get(dataID) {
|
|
89
93
|
if (!this._proxies.hasOwnProperty(dataID)) {
|
|
90
94
|
var status = this.__mutator.getStatus(dataID);
|
|
91
|
-
|
|
92
|
-
|
|
95
|
+
|
|
96
|
+
if (status === require("./RelayRecordState").EXISTENT) {
|
|
97
|
+
this._proxies[dataID] = new (require("./RelayRecordProxy"))(this, this.__mutator, dataID);
|
|
93
98
|
} else {
|
|
94
|
-
this._proxies[dataID] = status === require(
|
|
99
|
+
this._proxies[dataID] = status === require("./RelayRecordState").NONEXISTENT ? null : undefined;
|
|
95
100
|
}
|
|
96
101
|
}
|
|
102
|
+
|
|
97
103
|
return this._proxies[dataID];
|
|
98
104
|
};
|
|
99
105
|
|
|
100
|
-
|
|
101
|
-
var root = this.get(require(
|
|
106
|
+
_proto.getRoot = function getRoot() {
|
|
107
|
+
var root = this.get(require("./RelayStoreUtils").ROOT_ID);
|
|
108
|
+
|
|
102
109
|
if (!root) {
|
|
103
|
-
root = this.create(require(
|
|
110
|
+
root = this.create(require("./RelayStoreUtils").ROOT_ID, require("./RelayStoreUtils").ROOT_TYPE);
|
|
104
111
|
}
|
|
105
|
-
|
|
112
|
+
|
|
113
|
+
!(root && root.getType() === require("./RelayStoreUtils").ROOT_TYPE) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayRecordSourceProxy#getRoot(): Expected the source to contain a ' + 'root record.') : require("fbjs/lib/invariant")(false) : void 0;
|
|
106
114
|
return root;
|
|
107
115
|
};
|
|
108
116
|
|
|
@@ -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,13 +7,8 @@
|
|
|
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
|
*
|
|
@@ -22,48 +17,54 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'd
|
|
|
22
17
|
* complex arguments and it can be tedious to re-construct the correct sets of
|
|
23
18
|
* arguments to pass to e.g. `getRoot().getLinkedRecord()`.
|
|
24
19
|
*/
|
|
25
|
-
var RelayRecordSourceSelectorProxy =
|
|
20
|
+
var RelayRecordSourceSelectorProxy =
|
|
21
|
+
/*#__PURE__*/
|
|
22
|
+
function () {
|
|
26
23
|
function RelayRecordSourceSelectorProxy(recordSource, readSelector) {
|
|
27
|
-
(0, _classCallCheck3['default'])(this, RelayRecordSourceSelectorProxy);
|
|
28
|
-
|
|
29
24
|
this.__recordSource = recordSource;
|
|
30
25
|
this._readSelector = readSelector;
|
|
31
26
|
}
|
|
32
27
|
|
|
33
|
-
RelayRecordSourceSelectorProxy.prototype
|
|
28
|
+
var _proto = RelayRecordSourceSelectorProxy.prototype;
|
|
29
|
+
|
|
30
|
+
_proto.create = function create(dataID, typeName) {
|
|
34
31
|
return this.__recordSource.create(dataID, typeName);
|
|
35
32
|
};
|
|
36
33
|
|
|
37
|
-
|
|
38
|
-
this.__recordSource[
|
|
34
|
+
_proto["delete"] = function _delete(dataID) {
|
|
35
|
+
this.__recordSource["delete"](dataID);
|
|
39
36
|
};
|
|
40
37
|
|
|
41
|
-
|
|
38
|
+
_proto.get = function get(dataID) {
|
|
42
39
|
return this.__recordSource.get(dataID);
|
|
43
40
|
};
|
|
44
41
|
|
|
45
|
-
|
|
42
|
+
_proto.getRoot = function getRoot() {
|
|
46
43
|
return this.__recordSource.getRoot();
|
|
47
44
|
};
|
|
48
45
|
|
|
49
|
-
|
|
46
|
+
_proto._getRootField = function _getRootField(selector, fieldName, plural) {
|
|
50
47
|
var field = selector.node.selections.find(function (selection) {
|
|
51
48
|
return selection.kind === 'LinkedField' && selection.name === fieldName;
|
|
52
49
|
});
|
|
53
|
-
!(field && field.kind === 'LinkedField') ? process.env.NODE_ENV !==
|
|
54
|
-
!(field.plural === plural) ? process.env.NODE_ENV !==
|
|
50
|
+
!(field && field.kind === 'LinkedField') ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayRecordSourceSelectorProxy#getRootField(): Cannot find root ' + 'field `%s`, no such field is defined on GraphQL document `%s`.', fieldName, selector.node.name) : require("fbjs/lib/invariant")(false) : void 0;
|
|
51
|
+
!(field.plural === plural) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayRecordSourceSelectorProxy#getRootField(): Expected root field ' + '`%s` to be %s.', fieldName, plural ? 'plural' : 'singular') : require("fbjs/lib/invariant")(false) : void 0;
|
|
55
52
|
return field;
|
|
56
53
|
};
|
|
57
54
|
|
|
58
|
-
|
|
55
|
+
_proto.getRootField = function getRootField(fieldName) {
|
|
59
56
|
var field = this._getRootField(this._readSelector, fieldName, false);
|
|
60
|
-
|
|
57
|
+
|
|
58
|
+
var storageKey = require("./RelayStoreUtils").getStorageKey(field, this._readSelector.variables);
|
|
59
|
+
|
|
61
60
|
return this.getRoot().getLinkedRecord(storageKey);
|
|
62
61
|
};
|
|
63
62
|
|
|
64
|
-
|
|
63
|
+
_proto.getPluralRootField = function getPluralRootField(fieldName) {
|
|
65
64
|
var field = this._getRootField(this._readSelector, fieldName, true);
|
|
66
|
-
|
|
65
|
+
|
|
66
|
+
var storageKey = require("./RelayStoreUtils").getStorageKey(field, this._readSelector.variables);
|
|
67
|
+
|
|
67
68
|
return this.getRoot().getLinkedRecords(storageKey);
|
|
68
69
|
};
|
|
69
70
|
|
package/lib/RelayRecordState.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,7 +7,6 @@
|
|
|
7
7
|
* strict
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
10
|
'use strict';
|
|
12
11
|
|
|
13
12
|
var RelayRecordState = {
|
|
@@ -29,5 +28,4 @@ var RelayRecordState = {
|
|
|
29
28
|
*/
|
|
30
29
|
UNKNOWN: 'UNKNOWN'
|
|
31
30
|
};
|
|
32
|
-
|
|
33
31
|
module.exports = RelayRecordState;
|