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
package/lib/RelayReader.js
CHANGED
|
@@ -4,11 +4,34 @@
|
|
|
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 RelayModernRecord = require("./RelayModernRecord");
|
|
13
|
+
|
|
14
|
+
var invariant = require("fbjs/lib/invariant");
|
|
15
|
+
|
|
16
|
+
var _require = require("./RelayConcreteNode"),
|
|
17
|
+
CONDITION = _require.CONDITION,
|
|
18
|
+
CLIENT_EXTENSION = _require.CLIENT_EXTENSION,
|
|
19
|
+
FRAGMENT_SPREAD = _require.FRAGMENT_SPREAD,
|
|
20
|
+
INLINE_FRAGMENT = _require.INLINE_FRAGMENT,
|
|
21
|
+
LINKED_FIELD = _require.LINKED_FIELD,
|
|
22
|
+
MODULE_IMPORT = _require.MODULE_IMPORT,
|
|
23
|
+
SCALAR_FIELD = _require.SCALAR_FIELD;
|
|
24
|
+
|
|
25
|
+
var _require2 = require("./RelayStoreUtils"),
|
|
26
|
+
FRAGMENTS_KEY = _require2.FRAGMENTS_KEY,
|
|
27
|
+
FRAGMENT_OWNER_KEY = _require2.FRAGMENT_OWNER_KEY,
|
|
28
|
+
FRAGMENT_PROP_NAME_KEY = _require2.FRAGMENT_PROP_NAME_KEY,
|
|
29
|
+
ID_KEY = _require2.ID_KEY,
|
|
30
|
+
MODULE_COMPONENT_KEY = _require2.MODULE_COMPONENT_KEY,
|
|
31
|
+
getArgumentValues = _require2.getArgumentValues,
|
|
32
|
+
getStorageKey = _require2.getStorageKey,
|
|
33
|
+
getModuleComponentKey = _require2.getModuleComponentKey;
|
|
34
|
+
|
|
12
35
|
function read(recordSource, selector, owner) {
|
|
13
36
|
var _owner;
|
|
14
37
|
|
|
@@ -45,7 +68,8 @@ function () {
|
|
|
45
68
|
node: node,
|
|
46
69
|
seenRecords: this._seenRecords,
|
|
47
70
|
variables: this._variables,
|
|
48
|
-
isMissingData: this._isMissingData
|
|
71
|
+
isMissingData: this._isMissingData,
|
|
72
|
+
owner: this._owner
|
|
49
73
|
};
|
|
50
74
|
};
|
|
51
75
|
|
|
@@ -70,52 +94,78 @@ function () {
|
|
|
70
94
|
};
|
|
71
95
|
|
|
72
96
|
_proto._getVariableValue = function _getVariableValue(name) {
|
|
73
|
-
!this._variables.hasOwnProperty(name) ? process.env.NODE_ENV !== "production" ?
|
|
97
|
+
!this._variables.hasOwnProperty(name) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReader(): Undefined variable `%s`.', name) : invariant(false) : void 0;
|
|
74
98
|
return this._variables[name];
|
|
75
99
|
};
|
|
76
100
|
|
|
77
101
|
_proto._traverseSelections = function _traverseSelections(selections, record, data) {
|
|
78
|
-
var
|
|
102
|
+
for (var i = 0; i < selections.length; i++) {
|
|
103
|
+
var selection = selections[i];
|
|
79
104
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
} else if (selection.kind === require("./RelayConcreteNode").LINKED_FIELD) {
|
|
84
|
-
if (selection.plural) {
|
|
85
|
-
_this._readPluralLink(selection, record, data);
|
|
86
|
-
} else {
|
|
87
|
-
_this._readLink(selection, record, data);
|
|
88
|
-
}
|
|
89
|
-
} else if (selection.kind === require("./RelayConcreteNode").CONDITION) {
|
|
90
|
-
var conditionValue = _this._getVariableValue(selection.condition);
|
|
105
|
+
switch (selection.kind) {
|
|
106
|
+
case SCALAR_FIELD:
|
|
107
|
+
this._readScalar(selection, record, data);
|
|
91
108
|
|
|
92
|
-
|
|
93
|
-
_this._traverseSelections(selection.selections, record, data);
|
|
94
|
-
}
|
|
95
|
-
} else if (selection.kind === require("./RelayConcreteNode").INLINE_FRAGMENT) {
|
|
96
|
-
var typeName = require("./RelayModernRecord").getType(record);
|
|
109
|
+
break;
|
|
97
110
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
111
|
+
case LINKED_FIELD:
|
|
112
|
+
if (selection.plural) {
|
|
113
|
+
this._readPluralLink(selection, record, data);
|
|
114
|
+
} else {
|
|
115
|
+
this._readLink(selection, record, data);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
break;
|
|
119
|
+
|
|
120
|
+
case CONDITION:
|
|
121
|
+
var conditionValue = this._getVariableValue(selection.condition);
|
|
122
|
+
|
|
123
|
+
if (conditionValue === selection.passingValue) {
|
|
124
|
+
this._traverseSelections(selection.selections, record, data);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
break;
|
|
128
|
+
|
|
129
|
+
case INLINE_FRAGMENT:
|
|
130
|
+
var typeName = RelayModernRecord.getType(record);
|
|
131
|
+
|
|
132
|
+
if (typeName != null && typeName === selection.type) {
|
|
133
|
+
this._traverseSelections(selection.selections, record, data);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
break;
|
|
137
|
+
|
|
138
|
+
case FRAGMENT_SPREAD:
|
|
139
|
+
this._createFragmentPointer(selection, record, data);
|
|
140
|
+
|
|
141
|
+
break;
|
|
142
|
+
|
|
143
|
+
case MODULE_IMPORT:
|
|
144
|
+
this._readModuleImport(selection, record, data);
|
|
145
|
+
|
|
146
|
+
break;
|
|
147
|
+
|
|
148
|
+
case CLIENT_EXTENSION:
|
|
149
|
+
var isMissingData = this._isMissingData;
|
|
150
|
+
|
|
151
|
+
this._traverseSelections(selection.selections, record, data);
|
|
152
|
+
|
|
153
|
+
this._isMissingData = isMissingData;
|
|
154
|
+
break;
|
|
155
|
+
|
|
156
|
+
default:
|
|
157
|
+
selection;
|
|
158
|
+
!false ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReader(): Unexpected ast kind `%s`.', selection.kind) : invariant(false) : void 0;
|
|
107
159
|
}
|
|
108
|
-
}
|
|
160
|
+
}
|
|
109
161
|
};
|
|
110
162
|
|
|
111
163
|
_proto._readScalar = function _readScalar(field, record, data) {
|
|
112
164
|
var _field$alias;
|
|
113
165
|
|
|
114
166
|
var applicationName = (_field$alias = field.alias) !== null && _field$alias !== void 0 ? _field$alias : field.name;
|
|
115
|
-
|
|
116
|
-
var
|
|
117
|
-
|
|
118
|
-
var value = require("./RelayModernRecord").getValue(record, storageKey);
|
|
167
|
+
var storageKey = getStorageKey(field, this._variables);
|
|
168
|
+
var value = RelayModernRecord.getValue(record, storageKey);
|
|
119
169
|
|
|
120
170
|
if (value === undefined) {
|
|
121
171
|
this._isMissingData = true;
|
|
@@ -128,10 +178,8 @@ function () {
|
|
|
128
178
|
var _field$alias2;
|
|
129
179
|
|
|
130
180
|
var applicationName = (_field$alias2 = field.alias) !== null && _field$alias2 !== void 0 ? _field$alias2 : field.name;
|
|
131
|
-
|
|
132
|
-
var
|
|
133
|
-
|
|
134
|
-
var linkedID = require("./RelayModernRecord").getLinkedRecordID(record, storageKey);
|
|
181
|
+
var storageKey = getStorageKey(field, this._variables);
|
|
182
|
+
var linkedID = RelayModernRecord.getLinkedRecordID(record, storageKey);
|
|
135
183
|
|
|
136
184
|
if (linkedID == null) {
|
|
137
185
|
data[applicationName] = linkedID;
|
|
@@ -144,20 +192,22 @@ function () {
|
|
|
144
192
|
}
|
|
145
193
|
|
|
146
194
|
var prevData = data[applicationName];
|
|
147
|
-
!(prevData == null || typeof prevData === 'object') ? process.env.NODE_ENV !== "production" ?
|
|
195
|
+
!(prevData == null || typeof prevData === 'object') ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReader(): Expected data for field `%s` on record `%s` ' + 'to be an object, got `%s`.', applicationName, RelayModernRecord.getDataID(record), prevData) : invariant(false) : void 0;
|
|
196
|
+
/* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This comment
|
|
197
|
+
* suppresses an error found when Flow v0.98 was deployed. To see the error
|
|
198
|
+
* delete this comment and run Flow. */
|
|
199
|
+
|
|
148
200
|
data[applicationName] = this._traverse(field, linkedID, prevData);
|
|
149
201
|
};
|
|
150
202
|
|
|
151
203
|
_proto._readPluralLink = function _readPluralLink(field, record, data) {
|
|
152
|
-
var
|
|
204
|
+
var _this = this;
|
|
153
205
|
|
|
154
206
|
var _field$alias3;
|
|
155
207
|
|
|
156
208
|
var applicationName = (_field$alias3 = field.alias) !== null && _field$alias3 !== void 0 ? _field$alias3 : field.name;
|
|
157
|
-
|
|
158
|
-
var
|
|
159
|
-
|
|
160
|
-
var linkedIDs = require("./RelayModernRecord").getLinkedRecordIDs(record, storageKey);
|
|
209
|
+
var storageKey = getStorageKey(field, this._variables);
|
|
210
|
+
var linkedIDs = RelayModernRecord.getLinkedRecordIDs(record, storageKey);
|
|
161
211
|
|
|
162
212
|
if (linkedIDs == null) {
|
|
163
213
|
data[applicationName] = linkedIDs;
|
|
@@ -170,92 +220,49 @@ function () {
|
|
|
170
220
|
}
|
|
171
221
|
|
|
172
222
|
var prevData = data[applicationName];
|
|
173
|
-
!(prevData == null || Array.isArray(prevData)) ? process.env.NODE_ENV !== "production" ?
|
|
223
|
+
!(prevData == null || Array.isArray(prevData)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReader(): Expected data for field `%s` on record `%s` ' + 'to be an array, got `%s`.', applicationName, RelayModernRecord.getDataID(record), prevData) : invariant(false) : void 0;
|
|
174
224
|
var linkedArray = prevData || [];
|
|
175
225
|
linkedIDs.forEach(function (linkedID, nextIndex) {
|
|
176
226
|
if (linkedID == null) {
|
|
177
227
|
if (linkedID === undefined) {
|
|
178
|
-
|
|
228
|
+
_this._isMissingData = true;
|
|
179
229
|
}
|
|
230
|
+
/* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This comment
|
|
231
|
+
* suppresses an error found when Flow v0.98 was deployed. To see the
|
|
232
|
+
* error delete this comment and run Flow. */
|
|
233
|
+
|
|
180
234
|
|
|
181
235
|
linkedArray[nextIndex] = linkedID;
|
|
182
236
|
return;
|
|
183
237
|
}
|
|
184
238
|
|
|
185
239
|
var prevItem = linkedArray[nextIndex];
|
|
186
|
-
!(prevItem == null || typeof prevItem === 'object') ? process.env.NODE_ENV !== "production" ?
|
|
187
|
-
|
|
240
|
+
!(prevItem == null || typeof prevItem === 'object') ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReader(): Expected data for field `%s` on record `%s` ' + 'to be an object, got `%s`.', applicationName, RelayModernRecord.getDataID(record), prevItem) : invariant(false) : void 0;
|
|
241
|
+
/* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This comment
|
|
242
|
+
* suppresses an error found when Flow v0.98 was deployed. To see the
|
|
243
|
+
* error delete this comment and run Flow. */
|
|
244
|
+
|
|
245
|
+
linkedArray[nextIndex] = _this._traverse(field, linkedID, prevItem);
|
|
188
246
|
});
|
|
189
247
|
data[applicationName] = linkedArray;
|
|
190
|
-
}
|
|
248
|
+
}
|
|
191
249
|
/**
|
|
192
|
-
* Reads a
|
|
193
|
-
* directive
|
|
250
|
+
* Reads a ReaderModuleImport, which was generated from using the @module
|
|
251
|
+
* directive.
|
|
194
252
|
*/
|
|
253
|
+
;
|
|
195
254
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
var _field$alias4;
|
|
199
|
-
|
|
200
|
-
var applicationName = (_field$alias4 = field.alias) !== null && _field$alias4 !== void 0 ? _field$alias4 : field.name;
|
|
201
|
-
|
|
202
|
-
var storageKey = require("./RelayStoreUtils").getStorageKey(field, this._variables);
|
|
203
|
-
|
|
204
|
-
var linkedID = require("./RelayModernRecord").getLinkedRecordID(record, storageKey);
|
|
205
|
-
|
|
206
|
-
if (linkedID == null) {
|
|
207
|
-
data[applicationName] = linkedID;
|
|
208
|
-
|
|
209
|
-
if (linkedID === undefined) {
|
|
210
|
-
this._isMissingData = true;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
var prevData = data[applicationName];
|
|
217
|
-
!(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
|
|
218
|
-
// one level to get the record associated with the match field
|
|
219
|
-
|
|
220
|
-
var linkedRecord = this._recordSource.get(linkedID);
|
|
221
|
-
|
|
222
|
-
this._seenRecords[linkedID] = linkedRecord;
|
|
223
|
-
|
|
224
|
-
if (linkedRecord == null) {
|
|
225
|
-
if (linkedRecord === undefined) {
|
|
226
|
-
this._isMissingData = true;
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
data[applicationName] = linkedRecord;
|
|
230
|
-
return;
|
|
231
|
-
} // Determine the concrete type for the match field record. The type of a
|
|
232
|
-
// match field must be a union type (i.e. abstract type), so here we
|
|
233
|
-
// read the concrete type on the record, which should be the type resolved
|
|
234
|
-
// by the server in the response.
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
var concreteType = require("./RelayModernRecord").getType(linkedRecord);
|
|
238
|
-
|
|
239
|
-
!(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
|
|
240
|
-
// type, return null as the result
|
|
241
|
-
|
|
242
|
-
var match = field.matchesByType[concreteType];
|
|
243
|
-
|
|
244
|
-
if (match == null) {
|
|
245
|
-
data[applicationName] = null;
|
|
246
|
-
return;
|
|
247
|
-
} // Determine the component module from the store: if the field is missing
|
|
255
|
+
_proto._readModuleImport = function _readModuleImport(moduleImport, record, data) {
|
|
256
|
+
// Determine the component module from the store: if the field is missing
|
|
248
257
|
// it means we don't know what component to render the match with.
|
|
258
|
+
var componentKey = getModuleComponentKey(moduleImport.documentName);
|
|
259
|
+
var component = RelayModernRecord.getValue(record, componentKey);
|
|
249
260
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
if (matchComponent == null) {
|
|
254
|
-
if (matchComponent === undefined) {
|
|
261
|
+
if (component == null) {
|
|
262
|
+
if (component === undefined) {
|
|
255
263
|
this._isMissingData = true;
|
|
256
264
|
}
|
|
257
265
|
|
|
258
|
-
data[applicationName] = null;
|
|
259
266
|
return;
|
|
260
267
|
} // Otherwise, read the fragment and module associated to the concrete
|
|
261
268
|
// type, and put that data with the result:
|
|
@@ -264,33 +271,35 @@ function () {
|
|
|
264
271
|
// - For the matched module, create a reference to the module
|
|
265
272
|
|
|
266
273
|
|
|
267
|
-
var matchResult = {};
|
|
268
|
-
|
|
269
274
|
this._createFragmentPointer({
|
|
270
275
|
kind: 'FragmentSpread',
|
|
271
|
-
name:
|
|
276
|
+
name: moduleImport.fragmentName,
|
|
272
277
|
args: null
|
|
273
|
-
},
|
|
278
|
+
}, record, data);
|
|
274
279
|
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
data[applicationName] = matchResult;
|
|
280
|
+
data[FRAGMENT_PROP_NAME_KEY] = moduleImport.fragmentPropName;
|
|
281
|
+
data[MODULE_COMPONENT_KEY] = component;
|
|
279
282
|
};
|
|
280
283
|
|
|
281
|
-
_proto._createFragmentPointer = function _createFragmentPointer(fragmentSpread, record, data
|
|
282
|
-
var
|
|
283
|
-
|
|
284
|
-
var fragmentPointers = data[require("./RelayStoreUtils").FRAGMENTS_KEY];
|
|
284
|
+
_proto._createFragmentPointer = function _createFragmentPointer(fragmentSpread, record, data) {
|
|
285
|
+
var fragmentPointers = data[FRAGMENTS_KEY];
|
|
285
286
|
|
|
286
287
|
if (fragmentPointers == null) {
|
|
287
|
-
fragmentPointers = data[
|
|
288
|
+
fragmentPointers = data[FRAGMENTS_KEY] = {};
|
|
288
289
|
}
|
|
289
290
|
|
|
290
|
-
!(typeof fragmentPointers === 'object' && fragmentPointers) ? process.env.NODE_ENV !== "production" ?
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
291
|
+
!(typeof fragmentPointers === 'object' && fragmentPointers) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReader: Expected fragment spread data to be an object, got `%s`.', fragmentPointers) : invariant(false) : void 0;
|
|
292
|
+
|
|
293
|
+
if (data[ID_KEY] == null) {
|
|
294
|
+
data[ID_KEY] = RelayModernRecord.getDataID(record);
|
|
295
|
+
}
|
|
296
|
+
/* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This comment
|
|
297
|
+
* suppresses an error found when Flow v0.98 was deployed. To see the error
|
|
298
|
+
* delete this comment and run Flow. */
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
fragmentPointers[fragmentSpread.name] = fragmentSpread.args ? getArgumentValues(fragmentSpread.args, this._variables) : {};
|
|
302
|
+
data[FRAGMENT_OWNER_KEY] = this._owner;
|
|
294
303
|
};
|
|
295
304
|
|
|
296
305
|
return RelayReader;
|
package/lib/RelayRecordProxy.js
CHANGED
|
@@ -4,11 +4,19 @@
|
|
|
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("./ClientID"),
|
|
15
|
+
generateClientID = _require.generateClientID;
|
|
16
|
+
|
|
17
|
+
var _require2 = require("./RelayStoreUtils"),
|
|
18
|
+
getStableStorageKey = _require2.getStableStorageKey;
|
|
19
|
+
|
|
12
20
|
/**
|
|
13
21
|
* @internal
|
|
14
22
|
*
|
|
@@ -37,20 +45,18 @@ function () {
|
|
|
37
45
|
_proto.getType = function getType() {
|
|
38
46
|
var type = this._mutator.getType(this._dataID);
|
|
39
47
|
|
|
40
|
-
!(type != null) ? process.env.NODE_ENV !== "production" ?
|
|
48
|
+
!(type != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayRecordProxy: Cannot get the type of deleted record `%s`.', this._dataID) : invariant(false) : void 0;
|
|
41
49
|
return type;
|
|
42
50
|
};
|
|
43
51
|
|
|
44
52
|
_proto.getValue = function getValue(name, args) {
|
|
45
|
-
var storageKey =
|
|
46
|
-
|
|
53
|
+
var storageKey = getStableStorageKey(name, args);
|
|
47
54
|
return this._mutator.getValue(this._dataID, storageKey);
|
|
48
55
|
};
|
|
49
56
|
|
|
50
57
|
_proto.setValue = function setValue(value, name, args) {
|
|
51
|
-
!isValidLeafValue(value) ? process.env.NODE_ENV !== "production" ?
|
|
52
|
-
|
|
53
|
-
var storageKey = require("./RelayStoreUtils").getStableStorageKey(name, args);
|
|
58
|
+
!isValidLeafValue(value) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayRecordProxy#setValue(): Expected a scalar or array of scalars, ' + 'got `%s`.', JSON.stringify(value)) : invariant(false) : void 0;
|
|
59
|
+
var storageKey = getStableStorageKey(name, args);
|
|
54
60
|
|
|
55
61
|
this._mutator.setValue(this._dataID, storageKey, value);
|
|
56
62
|
|
|
@@ -58,7 +64,7 @@ function () {
|
|
|
58
64
|
};
|
|
59
65
|
|
|
60
66
|
_proto.getLinkedRecord = function getLinkedRecord(name, args) {
|
|
61
|
-
var storageKey =
|
|
67
|
+
var storageKey = getStableStorageKey(name, args);
|
|
62
68
|
|
|
63
69
|
var linkedID = this._mutator.getLinkedRecordID(this._dataID, storageKey);
|
|
64
70
|
|
|
@@ -66,10 +72,8 @@ function () {
|
|
|
66
72
|
};
|
|
67
73
|
|
|
68
74
|
_proto.setLinkedRecord = function setLinkedRecord(record, name, args) {
|
|
69
|
-
!(record instanceof RelayRecordProxy) ? process.env.NODE_ENV !== "production" ?
|
|
70
|
-
|
|
71
|
-
var storageKey = require("./RelayStoreUtils").getStableStorageKey(name, args);
|
|
72
|
-
|
|
75
|
+
!(record instanceof RelayRecordProxy) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayRecordProxy#setLinkedRecord(): Expected a record, got `%s`.', record) : invariant(false) : void 0;
|
|
76
|
+
var storageKey = getStableStorageKey(name, args);
|
|
73
77
|
var linkedID = record.getDataID();
|
|
74
78
|
|
|
75
79
|
this._mutator.setLinkedRecordID(this._dataID, storageKey, linkedID);
|
|
@@ -81,11 +85,13 @@ function () {
|
|
|
81
85
|
var linkedRecord = this.getLinkedRecord(name, args);
|
|
82
86
|
|
|
83
87
|
if (!linkedRecord) {
|
|
84
|
-
var
|
|
88
|
+
var _this$_source$get;
|
|
85
89
|
|
|
86
|
-
var
|
|
90
|
+
var storageKey = getStableStorageKey(name, args);
|
|
91
|
+
var clientID = generateClientID(this.getDataID(), storageKey); // NOTE: it's possible that a client record for this field exists
|
|
92
|
+
// but the field itself was unset.
|
|
87
93
|
|
|
88
|
-
linkedRecord = this._source.create(clientID, typeName);
|
|
94
|
+
linkedRecord = (_this$_source$get = this._source.get(clientID)) !== null && _this$_source$get !== void 0 ? _this$_source$get : this._source.create(clientID, typeName);
|
|
89
95
|
this.setLinkedRecord(linkedRecord, name, args);
|
|
90
96
|
}
|
|
91
97
|
|
|
@@ -95,7 +101,7 @@ function () {
|
|
|
95
101
|
_proto.getLinkedRecords = function getLinkedRecords(name, args) {
|
|
96
102
|
var _this = this;
|
|
97
103
|
|
|
98
|
-
var storageKey =
|
|
104
|
+
var storageKey = getStableStorageKey(name, args);
|
|
99
105
|
|
|
100
106
|
var linkedIDs = this._mutator.getLinkedRecordIDs(this._dataID, storageKey);
|
|
101
107
|
|
|
@@ -109,10 +115,8 @@ function () {
|
|
|
109
115
|
};
|
|
110
116
|
|
|
111
117
|
_proto.setLinkedRecords = function setLinkedRecords(records, name, args) {
|
|
112
|
-
!Array.isArray(records) ? process.env.NODE_ENV !== "production" ?
|
|
113
|
-
|
|
114
|
-
var storageKey = require("./RelayStoreUtils").getStableStorageKey(name, args);
|
|
115
|
-
|
|
118
|
+
!Array.isArray(records) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayRecordProxy#setLinkedRecords(): Expected records to be an array, got `%s`.', records) : invariant(false) : void 0;
|
|
119
|
+
var storageKey = getStableStorageKey(name, args);
|
|
116
120
|
var linkedIDs = records.map(function (record) {
|
|
117
121
|
return record && record.getDataID();
|
|
118
122
|
});
|