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
|
@@ -9,6 +9,42 @@
|
|
|
9
9
|
*/
|
|
10
10
|
'use strict';
|
|
11
11
|
|
|
12
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
13
|
+
|
|
14
|
+
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
15
|
+
|
|
16
|
+
var RelayModernRecord = require("./RelayModernRecord");
|
|
17
|
+
|
|
18
|
+
var RelayProfiler = require("./RelayProfiler");
|
|
19
|
+
|
|
20
|
+
var invariant = require("fbjs/lib/invariant");
|
|
21
|
+
|
|
22
|
+
var warning = require("fbjs/lib/warning");
|
|
23
|
+
|
|
24
|
+
var _require = require("./RelayConcreteNode"),
|
|
25
|
+
CONDITION = _require.CONDITION,
|
|
26
|
+
CLIENT_EXTENSION = _require.CLIENT_EXTENSION,
|
|
27
|
+
DEFER = _require.DEFER,
|
|
28
|
+
INLINE_FRAGMENT = _require.INLINE_FRAGMENT,
|
|
29
|
+
LINKED_FIELD = _require.LINKED_FIELD,
|
|
30
|
+
LINKED_HANDLE = _require.LINKED_HANDLE,
|
|
31
|
+
MODULE_IMPORT = _require.MODULE_IMPORT,
|
|
32
|
+
SCALAR_FIELD = _require.SCALAR_FIELD,
|
|
33
|
+
SCALAR_HANDLE = _require.SCALAR_HANDLE,
|
|
34
|
+
STREAM = _require.STREAM;
|
|
35
|
+
|
|
36
|
+
var _require2 = require("./ClientID"),
|
|
37
|
+
generateClientID = _require2.generateClientID,
|
|
38
|
+
isClientID = _require2.isClientID;
|
|
39
|
+
|
|
40
|
+
var _require3 = require("./RelayStoreUtils"),
|
|
41
|
+
getArgumentValues = _require3.getArgumentValues,
|
|
42
|
+
getHandleStorageKey = _require3.getHandleStorageKey,
|
|
43
|
+
getModuleComponentKey = _require3.getModuleComponentKey,
|
|
44
|
+
getModuleOperationKey = _require3.getModuleOperationKey,
|
|
45
|
+
getStorageKey = _require3.getStorageKey,
|
|
46
|
+
TYPENAME_KEY = _require3.TYPENAME_KEY;
|
|
47
|
+
|
|
12
48
|
/**
|
|
13
49
|
* Normalizes the results of a query and standard GraphQL response, writing the
|
|
14
50
|
* normalized records/fields into the given MutableRecordSource.
|
|
@@ -16,10 +52,7 @@
|
|
|
16
52
|
* If handleStrippedNulls is true, will replace fields on the Selector that
|
|
17
53
|
* are not present in the response with null. Otherwise will leave fields unset.
|
|
18
54
|
*/
|
|
19
|
-
function normalize(recordSource, selector, response) {
|
|
20
|
-
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
|
|
21
|
-
handleStrippedNulls: false
|
|
22
|
-
};
|
|
55
|
+
function normalize(recordSource, selector, response, options) {
|
|
23
56
|
var dataID = selector.dataID,
|
|
24
57
|
node = selector.node,
|
|
25
58
|
variables = selector.variables;
|
|
@@ -37,9 +70,12 @@ var RelayResponseNormalizer =
|
|
|
37
70
|
/*#__PURE__*/
|
|
38
71
|
function () {
|
|
39
72
|
function RelayResponseNormalizer(recordSource, variables, options) {
|
|
73
|
+
this._getDataId = options.getDataID;
|
|
40
74
|
this._handleFieldPayloads = [];
|
|
41
|
-
this._handleStrippedNulls = options.handleStrippedNulls;
|
|
42
|
-
this.
|
|
75
|
+
this._handleStrippedNulls = options.handleStrippedNulls === true;
|
|
76
|
+
this._incrementalPlaceholders = [];
|
|
77
|
+
this._moduleImportPayloads = [];
|
|
78
|
+
this._path = options.path ? (0, _toConsumableArray2["default"])(options.path) : [];
|
|
43
79
|
this._recordSource = recordSource;
|
|
44
80
|
this._variables = variables;
|
|
45
81
|
}
|
|
@@ -49,130 +85,176 @@ function () {
|
|
|
49
85
|
_proto.normalizeResponse = function normalizeResponse(node, dataID, data) {
|
|
50
86
|
var record = this._recordSource.get(dataID);
|
|
51
87
|
|
|
52
|
-
!record ? process.env.NODE_ENV !== "production" ?
|
|
88
|
+
!record ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayResponseNormalizer(): Expected root record `%s` to exist.', dataID) : invariant(false) : void 0;
|
|
53
89
|
|
|
54
90
|
this._traverseSelections(node, record, data);
|
|
55
91
|
|
|
56
92
|
return {
|
|
93
|
+
incrementalPlaceholders: this._incrementalPlaceholders,
|
|
57
94
|
fieldPayloads: this._handleFieldPayloads,
|
|
58
|
-
|
|
95
|
+
moduleImportPayloads: this._moduleImportPayloads
|
|
59
96
|
};
|
|
60
97
|
};
|
|
61
98
|
|
|
62
99
|
_proto._getVariableValue = function _getVariableValue(name) {
|
|
63
|
-
!this._variables.hasOwnProperty(name) ? process.env.NODE_ENV !== "production" ?
|
|
100
|
+
!this._variables.hasOwnProperty(name) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayResponseNormalizer(): Undefined variable `%s`.', name) : invariant(false) : void 0;
|
|
64
101
|
return this._variables[name];
|
|
65
102
|
};
|
|
66
103
|
|
|
67
104
|
_proto._getRecordType = function _getRecordType(data) {
|
|
68
|
-
var typeName = data[
|
|
69
|
-
|
|
70
|
-
!(typeName != null) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayResponseNormalizer(): Expected a typename for record `%s`.', JSON.stringify(data, null, 2)) : require("fbjs/lib/invariant")(false) : void 0;
|
|
105
|
+
var typeName = data[TYPENAME_KEY];
|
|
106
|
+
!(typeName != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayResponseNormalizer(): Expected a typename for record `%s`.', JSON.stringify(data, null, 2)) : invariant(false) : void 0;
|
|
71
107
|
return typeName;
|
|
72
108
|
};
|
|
73
109
|
|
|
74
110
|
_proto._traverseSelections = function _traverseSelections(node, record, data) {
|
|
75
|
-
var
|
|
111
|
+
for (var i = 0; i < node.selections.length; i++) {
|
|
112
|
+
var selection = node.selections[i];
|
|
76
113
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
var conditionValue = _this._getVariableValue(selection.condition);
|
|
82
|
-
|
|
83
|
-
if (conditionValue === selection.passingValue) {
|
|
84
|
-
_this._traverseSelections(selection, record, data);
|
|
85
|
-
}
|
|
86
|
-
} else if (selection.kind === require("./RelayConcreteNode").INLINE_FRAGMENT) {
|
|
87
|
-
var typeName = require("./RelayModernRecord").getType(record);
|
|
88
|
-
|
|
89
|
-
if (typeName === selection.type) {
|
|
90
|
-
_this._traverseSelections(selection, record, data);
|
|
91
|
-
}
|
|
92
|
-
} else if (selection.kind === require("./RelayConcreteNode").LINKED_HANDLE || selection.kind === require("./RelayConcreteNode").SCALAR_HANDLE) {
|
|
93
|
-
var args = selection.args ? require("./RelayStoreUtils").getArgumentValues(selection.args, _this._variables) : {};
|
|
94
|
-
|
|
95
|
-
var fieldKey = require("./RelayStoreUtils").getStorageKey(selection, _this._variables);
|
|
96
|
-
|
|
97
|
-
var handleKey = require("./RelayStoreUtils").getHandleStorageKey(selection, _this._variables);
|
|
98
|
-
|
|
99
|
-
_this._handleFieldPayloads.push({
|
|
100
|
-
args: args,
|
|
101
|
-
dataID: require("./RelayModernRecord").getDataID(record),
|
|
102
|
-
fieldKey: fieldKey,
|
|
103
|
-
handle: selection.handle,
|
|
104
|
-
handleKey: handleKey
|
|
105
|
-
});
|
|
106
|
-
} else if (selection.kind === require("./RelayConcreteNode").MATCH_FIELD) {
|
|
107
|
-
_this._normalizeMatchField(node, selection, record, data);
|
|
108
|
-
} else if (selection.kind === require("./RelayConcreteNode").FRAGMENT || selection.kind === require("./RelayConcreteNode").FRAGMENT_SPREAD) {
|
|
109
|
-
!false ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayResponseNormalizer(): Unexpected ast kind `%s`.', selection.kind) : require("fbjs/lib/invariant")(false) : void 0;
|
|
110
|
-
} else {
|
|
111
|
-
selection;
|
|
112
|
-
!false ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayResponseNormalizer(): Unexpected ast kind `%s`.', selection.kind) : require("fbjs/lib/invariant")(false) : void 0;
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
};
|
|
114
|
+
switch (selection.kind) {
|
|
115
|
+
case SCALAR_FIELD:
|
|
116
|
+
case LINKED_FIELD:
|
|
117
|
+
this._normalizeField(node, selection, record, data);
|
|
116
118
|
|
|
117
|
-
|
|
118
|
-
!(typeof data === 'object' && data) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'writeField(): Expected data for field `%s` to be an object.', field.name) : require("fbjs/lib/invariant")(false) : void 0;
|
|
119
|
-
var responseKey = field.alias || field.name;
|
|
119
|
+
break;
|
|
120
120
|
|
|
121
|
-
|
|
121
|
+
case CONDITION:
|
|
122
|
+
var conditionValue = this._getVariableValue(selection.condition);
|
|
122
123
|
|
|
123
|
-
|
|
124
|
+
if (conditionValue === selection.passingValue) {
|
|
125
|
+
this._traverseSelections(selection, record, data);
|
|
126
|
+
}
|
|
124
127
|
|
|
125
|
-
|
|
126
|
-
if (fieldValue === undefined && !this._handleStrippedNulls) {
|
|
127
|
-
// If we're not stripping nulls, undefined fields are unset
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
128
|
+
break;
|
|
130
129
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
130
|
+
case INLINE_FRAGMENT:
|
|
131
|
+
var _typeName = RelayModernRecord.getType(record);
|
|
134
132
|
|
|
135
|
-
|
|
133
|
+
if (_typeName === selection.type) {
|
|
134
|
+
this._traverseSelections(selection, record, data);
|
|
135
|
+
}
|
|
136
136
|
|
|
137
|
-
|
|
138
|
-
}
|
|
137
|
+
break;
|
|
139
138
|
|
|
140
|
-
|
|
139
|
+
case LINKED_HANDLE:
|
|
140
|
+
case SCALAR_HANDLE:
|
|
141
|
+
var args = selection.args ? getArgumentValues(selection.args, this._variables) : {};
|
|
142
|
+
var fieldKey = getStorageKey(selection, this._variables);
|
|
143
|
+
var handleKey = getHandleStorageKey(selection, this._variables);
|
|
141
144
|
|
|
142
|
-
|
|
145
|
+
this._handleFieldPayloads.push({
|
|
146
|
+
args: args,
|
|
147
|
+
dataID: RelayModernRecord.getDataID(record),
|
|
148
|
+
fieldKey: fieldKey,
|
|
149
|
+
handle: selection.handle,
|
|
150
|
+
handleKey: handleKey
|
|
151
|
+
});
|
|
143
152
|
|
|
144
|
-
|
|
153
|
+
break;
|
|
145
154
|
|
|
146
|
-
|
|
147
|
-
|
|
155
|
+
case MODULE_IMPORT:
|
|
156
|
+
this._normalizeModuleImport(node, selection, record, data);
|
|
148
157
|
|
|
149
|
-
|
|
158
|
+
break;
|
|
159
|
+
|
|
160
|
+
case DEFER:
|
|
161
|
+
this._normalizeDefer(selection, record, data);
|
|
162
|
+
|
|
163
|
+
break;
|
|
164
|
+
|
|
165
|
+
case STREAM:
|
|
166
|
+
this._normalizeStream(selection, record, data);
|
|
167
|
+
|
|
168
|
+
break;
|
|
169
|
+
|
|
170
|
+
case CLIENT_EXTENSION:
|
|
171
|
+
var handleStrippedNulls = this._handleStrippedNulls;
|
|
172
|
+
this._handleStrippedNulls = false;
|
|
173
|
+
|
|
174
|
+
this._traverseSelections(selection, record, data);
|
|
175
|
+
|
|
176
|
+
this._handleStrippedNulls = handleStrippedNulls;
|
|
177
|
+
break;
|
|
178
|
+
|
|
179
|
+
default:
|
|
180
|
+
selection;
|
|
181
|
+
!false ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayResponseNormalizer(): Unexpected ast kind `%s`.', selection.kind) : invariant(false) : void 0;
|
|
182
|
+
}
|
|
150
183
|
}
|
|
184
|
+
};
|
|
151
185
|
|
|
152
|
-
|
|
153
|
-
|
|
186
|
+
_proto._normalizeDefer = function _normalizeDefer(defer, record, data) {
|
|
187
|
+
var isDeferred = defer["if"] === null || this._getVariableValue(defer["if"]);
|
|
154
188
|
|
|
155
|
-
|
|
189
|
+
if (process.env.NODE_ENV !== "production") {
|
|
190
|
+
process.env.NODE_ENV !== "production" ? warning(typeof isDeferred === 'boolean', 'RelayResponseNormalizer: Expected value for @defer `if` argument to ' + 'be a boolean, got `%s`.', isDeferred) : void 0;
|
|
191
|
+
}
|
|
156
192
|
|
|
157
|
-
|
|
193
|
+
if (isDeferred === false) {
|
|
194
|
+
// If defer is disabled there will be no additional response chunk:
|
|
195
|
+
// normalize the data already present.
|
|
196
|
+
this._traverseSelections(defer, record, data);
|
|
197
|
+
} else {
|
|
198
|
+
// Otherwise data *for this selection* should not be present: enqueue
|
|
199
|
+
// metadata to process the subsequent response chunk.
|
|
200
|
+
this._incrementalPlaceholders.push({
|
|
201
|
+
kind: 'defer',
|
|
202
|
+
label: defer.label,
|
|
203
|
+
path: (0, _toConsumableArray2["default"])(this._path),
|
|
204
|
+
selector: {
|
|
205
|
+
dataID: RelayModernRecord.getDataID(record),
|
|
206
|
+
node: defer,
|
|
207
|
+
variables: this._variables
|
|
208
|
+
},
|
|
209
|
+
typeName: RelayModernRecord.getType(record)
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
};
|
|
158
213
|
|
|
159
|
-
|
|
214
|
+
_proto._normalizeStream = function _normalizeStream(stream, record, data) {
|
|
215
|
+
// Always normalize regardless of whether streaming is enabled or not,
|
|
216
|
+
// this populates the initial array value (including any items when
|
|
217
|
+
// initial_count > 0).
|
|
218
|
+
this._traverseSelections(stream, record, data);
|
|
160
219
|
|
|
161
|
-
if (
|
|
162
|
-
nextRecord = require("./RelayModernRecord").create(nextID, typeName);
|
|
220
|
+
var isStreamed = stream["if"] === null || this._getVariableValue(stream["if"]);
|
|
163
221
|
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
this._validateRecordType(nextRecord, field, fieldValue);
|
|
222
|
+
if (process.env.NODE_ENV !== "production") {
|
|
223
|
+
process.env.NODE_ENV !== "production" ? warning(typeof isStreamed === 'boolean', 'RelayResponseNormalizer: Expected value for @stream `if` argument ' + 'to be a boolean, got `%s`.', isStreamed) : void 0;
|
|
167
224
|
}
|
|
168
225
|
|
|
169
|
-
|
|
226
|
+
if (isStreamed === true) {
|
|
227
|
+
// If streaming is enabled, *also* emit metadata to process any
|
|
228
|
+
// response chunks that may be delivered.
|
|
229
|
+
this._incrementalPlaceholders.push({
|
|
230
|
+
kind: 'stream',
|
|
231
|
+
label: stream.label,
|
|
232
|
+
path: (0, _toConsumableArray2["default"])(this._path),
|
|
233
|
+
parentID: RelayModernRecord.getDataID(record),
|
|
234
|
+
node: stream,
|
|
235
|
+
variables: this._variables
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
_proto._normalizeModuleImport = function _normalizeModuleImport(parent, moduleImport, record, data) {
|
|
241
|
+
var _componentReference, _operationReference;
|
|
242
|
+
|
|
243
|
+
!(typeof data === 'object' && data) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayResponseNormalizer: Expected data for @module to be an object.') : invariant(false) : void 0;
|
|
244
|
+
var typeName = RelayModernRecord.getType(record);
|
|
245
|
+
var componentKey = getModuleComponentKey(moduleImport.documentName);
|
|
246
|
+
var componentReference = data[componentKey];
|
|
247
|
+
RelayModernRecord.setValue(record, componentKey, (_componentReference = componentReference) !== null && _componentReference !== void 0 ? _componentReference : null);
|
|
248
|
+
var operationKey = getModuleOperationKey(moduleImport.documentName);
|
|
249
|
+
var operationReference = data[operationKey];
|
|
250
|
+
RelayModernRecord.setValue(record, operationKey, (_operationReference = operationReference) !== null && _operationReference !== void 0 ? _operationReference : null);
|
|
170
251
|
|
|
171
252
|
if (operationReference != null) {
|
|
172
|
-
this.
|
|
253
|
+
this._moduleImportPayloads.push({
|
|
254
|
+
data: data,
|
|
255
|
+
dataID: RelayModernRecord.getDataID(record),
|
|
173
256
|
operationReference: operationReference,
|
|
174
|
-
|
|
175
|
-
data: fieldValue,
|
|
257
|
+
path: (0, _toConsumableArray2["default"])(this._path),
|
|
176
258
|
typeName: typeName,
|
|
177
259
|
variables: this._variables
|
|
178
260
|
});
|
|
@@ -180,11 +262,9 @@ function () {
|
|
|
180
262
|
};
|
|
181
263
|
|
|
182
264
|
_proto._normalizeField = function _normalizeField(parent, selection, record, data) {
|
|
183
|
-
!(typeof data === 'object' && data) ? process.env.NODE_ENV !== "production" ?
|
|
265
|
+
!(typeof data === 'object' && data) ? process.env.NODE_ENV !== "production" ? invariant(false, 'writeField(): Expected data for field `%s` to be an object.', selection.name) : invariant(false) : void 0;
|
|
184
266
|
var responseKey = selection.alias || selection.name;
|
|
185
|
-
|
|
186
|
-
var storageKey = require("./RelayStoreUtils").getStorageKey(selection, this._variables);
|
|
187
|
-
|
|
267
|
+
var storageKey = getStorageKey(selection, this._variables);
|
|
188
268
|
var fieldValue = data[responseKey];
|
|
189
269
|
|
|
190
270
|
if (fieldValue == null) {
|
|
@@ -194,110 +274,141 @@ function () {
|
|
|
194
274
|
}
|
|
195
275
|
|
|
196
276
|
if (process.env.NODE_ENV !== "production") {
|
|
197
|
-
process.env.NODE_ENV !== "production" ?
|
|
277
|
+
process.env.NODE_ENV !== "production" ? warning(parent.kind === LINKED_FIELD && parent.concreteType == null ? true : Object.prototype.hasOwnProperty.call(data, responseKey), 'RelayResponseNormalizer(): Payload did not contain a value ' + 'for field `%s: %s`. Check that you are parsing with the same ' + 'query that was used to fetch the payload.', responseKey, storageKey) : void 0;
|
|
198
278
|
}
|
|
199
279
|
|
|
200
|
-
|
|
201
|
-
|
|
280
|
+
RelayModernRecord.setValue(record, storageKey, null);
|
|
202
281
|
return;
|
|
203
282
|
}
|
|
204
283
|
|
|
205
|
-
if (selection.kind ===
|
|
206
|
-
|
|
207
|
-
} else if (selection.kind ===
|
|
284
|
+
if (selection.kind === SCALAR_FIELD) {
|
|
285
|
+
RelayModernRecord.setValue(record, storageKey, fieldValue);
|
|
286
|
+
} else if (selection.kind === LINKED_FIELD) {
|
|
287
|
+
this._path.push(responseKey);
|
|
288
|
+
|
|
208
289
|
if (selection.plural) {
|
|
209
290
|
this._normalizePluralLink(selection, record, storageKey, fieldValue);
|
|
210
291
|
} else {
|
|
211
292
|
this._normalizeLink(selection, record, storageKey, fieldValue);
|
|
212
293
|
}
|
|
213
|
-
|
|
214
|
-
|
|
294
|
+
|
|
295
|
+
this._path.pop();
|
|
215
296
|
} else {
|
|
216
297
|
selection;
|
|
217
|
-
!false ? process.env.NODE_ENV !== "production" ?
|
|
298
|
+
!false ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayResponseNormalizer(): Unexpected ast kind `%s` during normalization.', selection.kind) : invariant(false) : void 0;
|
|
218
299
|
}
|
|
219
300
|
};
|
|
220
301
|
|
|
221
302
|
_proto._normalizeLink = function _normalizeLink(field, record, storageKey, fieldValue) {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
303
|
+
var _field$concreteType;
|
|
304
|
+
|
|
305
|
+
!(typeof fieldValue === 'object' && fieldValue) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayResponseNormalizer: Expected data for field `%s` to be an object.', storageKey) : invariant(false) : void 0;
|
|
306
|
+
var nextID = this._getDataId(
|
|
307
|
+
/* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This comment
|
|
308
|
+
* suppresses an error found when Flow v0.98 was deployed. To see the
|
|
309
|
+
* error delete this comment and run Flow. */
|
|
310
|
+
fieldValue,
|
|
311
|
+
/* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This comment
|
|
312
|
+
* suppresses an error found when Flow v0.98 was deployed. To see the
|
|
313
|
+
* error delete this comment and run Flow. */
|
|
314
|
+
(_field$concreteType = field.concreteType) !== null && _field$concreteType !== void 0 ? _field$concreteType : this._getRecordType(fieldValue)) || // Reuse previously generated client IDs
|
|
315
|
+
RelayModernRecord.getLinkedRecordID(record, storageKey) || generateClientID(RelayModernRecord.getDataID(record), storageKey);
|
|
316
|
+
!(typeof nextID === 'string') ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayResponseNormalizer: Expected id on field `%s` to be a string.', storageKey) : invariant(false) : void 0;
|
|
317
|
+
RelayModernRecord.setLinkedRecordID(record, storageKey, nextID);
|
|
230
318
|
|
|
231
319
|
var nextRecord = this._recordSource.get(nextID);
|
|
232
320
|
|
|
233
321
|
if (!nextRecord) {
|
|
234
|
-
|
|
322
|
+
/* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This comment
|
|
323
|
+
* suppresses an error found when Flow v0.98 was deployed. To see the
|
|
324
|
+
* error delete this comment and run Flow. */
|
|
325
|
+
var _typeName2 = field.concreteType || this._getRecordType(fieldValue);
|
|
235
326
|
|
|
236
|
-
nextRecord =
|
|
327
|
+
nextRecord = RelayModernRecord.create(nextID, _typeName2);
|
|
237
328
|
|
|
238
329
|
this._recordSource.set(nextID, nextRecord);
|
|
239
330
|
} else if (process.env.NODE_ENV !== "production") {
|
|
240
331
|
this._validateRecordType(nextRecord, field, fieldValue);
|
|
241
332
|
}
|
|
333
|
+
/* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This comment
|
|
334
|
+
* suppresses an error found when Flow v0.98 was deployed. To see the error
|
|
335
|
+
* delete this comment and run Flow. */
|
|
336
|
+
|
|
242
337
|
|
|
243
338
|
this._traverseSelections(field, nextRecord, fieldValue);
|
|
244
339
|
};
|
|
245
340
|
|
|
246
341
|
_proto._normalizePluralLink = function _normalizePluralLink(field, record, storageKey, fieldValue) {
|
|
247
|
-
var
|
|
248
|
-
|
|
249
|
-
!Array.isArray(fieldValue) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayResponseNormalizer: Expected data for field `%s` to be an array ' + 'of objects.', storageKey) : require("fbjs/lib/invariant")(false) : void 0;
|
|
250
|
-
|
|
251
|
-
var prevIDs = require("./RelayModernRecord").getLinkedRecordIDs(record, storageKey);
|
|
342
|
+
var _this = this;
|
|
252
343
|
|
|
344
|
+
!Array.isArray(fieldValue) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayResponseNormalizer: Expected data for field `%s` to be an array ' + 'of objects.', storageKey) : invariant(false) : void 0;
|
|
345
|
+
var prevIDs = RelayModernRecord.getLinkedRecordIDs(record, storageKey);
|
|
253
346
|
var nextIDs = [];
|
|
254
347
|
fieldValue.forEach(function (item, nextIndex) {
|
|
348
|
+
var _field$concreteType2;
|
|
349
|
+
|
|
255
350
|
// validate response data
|
|
256
351
|
if (item == null) {
|
|
257
352
|
nextIDs.push(item);
|
|
258
353
|
return;
|
|
259
354
|
}
|
|
260
355
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
356
|
+
_this._path.push(String(nextIndex));
|
|
357
|
+
|
|
358
|
+
!(typeof item === 'object') ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayResponseNormalizer: Expected elements for field `%s` to be ' + 'objects.', storageKey) : invariant(false) : void 0;
|
|
359
|
+
var nextID = _this._getDataId(
|
|
360
|
+
/* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This comment
|
|
361
|
+
* suppresses an error found when Flow v0.98 was deployed. To see the
|
|
362
|
+
* error delete this comment and run Flow. */
|
|
363
|
+
item,
|
|
364
|
+
/* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This comment
|
|
365
|
+
* suppresses an error found when Flow v0.98 was deployed. To see the
|
|
366
|
+
* error delete this comment and run Flow. */
|
|
367
|
+
(_field$concreteType2 = field.concreteType) !== null && _field$concreteType2 !== void 0 ? _field$concreteType2 : _this._getRecordType(item)) || prevIDs && prevIDs[nextIndex] || // Reuse previously generated client IDs:
|
|
368
|
+
generateClientID(RelayModernRecord.getDataID(record), storageKey, nextIndex);
|
|
369
|
+
!(typeof nextID === 'string') ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayResponseNormalizer: Expected id of elements of field `%s` to ' + 'be strings.', storageKey) : invariant(false) : void 0;
|
|
267
370
|
nextIDs.push(nextID);
|
|
268
371
|
|
|
269
|
-
var nextRecord =
|
|
372
|
+
var nextRecord = _this._recordSource.get(nextID);
|
|
270
373
|
|
|
271
374
|
if (!nextRecord) {
|
|
272
|
-
|
|
375
|
+
/* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This comment
|
|
376
|
+
* suppresses an error found when Flow v0.98 was deployed. To see the
|
|
377
|
+
* error delete this comment and run Flow. */
|
|
378
|
+
var _typeName3 = field.concreteType || _this._getRecordType(item);
|
|
273
379
|
|
|
274
|
-
nextRecord =
|
|
380
|
+
nextRecord = RelayModernRecord.create(nextID, _typeName3);
|
|
275
381
|
|
|
276
|
-
|
|
382
|
+
_this._recordSource.set(nextID, nextRecord);
|
|
277
383
|
} else if (process.env.NODE_ENV !== "production") {
|
|
278
|
-
|
|
384
|
+
_this._validateRecordType(nextRecord, field, item);
|
|
279
385
|
}
|
|
386
|
+
/* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This comment
|
|
387
|
+
* suppresses an error found when Flow v0.98 was deployed. To see the
|
|
388
|
+
* error delete this comment and run Flow. */
|
|
280
389
|
|
|
281
|
-
_this2._traverseSelections(field, nextRecord, item);
|
|
282
|
-
});
|
|
283
390
|
|
|
284
|
-
|
|
285
|
-
|
|
391
|
+
_this._traverseSelections(field, nextRecord, item);
|
|
392
|
+
|
|
393
|
+
_this._path.pop();
|
|
394
|
+
});
|
|
395
|
+
RelayModernRecord.setLinkedRecordIDs(record, storageKey, nextIDs);
|
|
396
|
+
}
|
|
286
397
|
/**
|
|
287
398
|
* Warns if the type of the record does not match the type of the field/payload.
|
|
288
399
|
*/
|
|
289
|
-
|
|
400
|
+
;
|
|
290
401
|
|
|
291
402
|
_proto._validateRecordType = function _validateRecordType(record, field, payload) {
|
|
292
403
|
var typeName = field.kind === 'LinkedField' ? field.concreteType || this._getRecordType(payload) : this._getRecordType(payload);
|
|
293
|
-
process.env.NODE_ENV !== "production" ?
|
|
404
|
+
process.env.NODE_ENV !== "production" ? warning(isClientID(RelayModernRecord.getDataID(record)) || RelayModernRecord.getType(record) === typeName, 'RelayResponseNormalizer: Invalid record `%s`. Expected %s to be ' + 'be consistent, but the record was assigned conflicting types `%s` ' + 'and `%s`. The GraphQL server likely violated the globally unique ' + 'id requirement by returning the same id for different objects.', RelayModernRecord.getDataID(record), TYPENAME_KEY, RelayModernRecord.getType(record), typeName) : void 0;
|
|
294
405
|
};
|
|
295
406
|
|
|
296
407
|
return RelayResponseNormalizer;
|
|
297
408
|
}(); // eslint-disable-next-line no-func-assign
|
|
298
409
|
|
|
299
410
|
|
|
300
|
-
normalize =
|
|
411
|
+
normalize = RelayProfiler.instrument('RelayResponseNormalizer.normalize', normalize);
|
|
301
412
|
module.exports = {
|
|
302
413
|
normalize: normalize
|
|
303
414
|
};
|