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,16 +7,9 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
10
|
'use strict';
|
|
12
11
|
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
var _extends4 = _interopRequireDefault(require('babel-runtime/helpers/extends'));
|
|
16
|
-
|
|
17
|
-
var _classCallCheck3 = _interopRequireDefault(require('babel-runtime/helpers/classCallCheck'));
|
|
18
|
-
|
|
19
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
|
12
|
+
var _toConsumableArray2 = require("@babel/runtime/helpers/interopRequireDefault")(require("@babel/runtime/helpers/toConsumableArray"));
|
|
20
13
|
|
|
21
14
|
/**
|
|
22
15
|
* Normalizes the results of a query and standard GraphQL response, writing the
|
|
@@ -26,142 +19,306 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'd
|
|
|
26
19
|
* are not present in the response with null. Otherwise will leave fields unset.
|
|
27
20
|
*/
|
|
28
21
|
function normalize(recordSource, selector, response) {
|
|
29
|
-
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
|
|
22
|
+
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {
|
|
23
|
+
handleStrippedNulls: false
|
|
24
|
+
};
|
|
30
25
|
var dataID = selector.dataID,
|
|
31
26
|
node = selector.node,
|
|
32
27
|
variables = selector.variables;
|
|
33
|
-
|
|
34
28
|
var normalizer = new RelayResponseNormalizer(recordSource, variables, options);
|
|
35
29
|
return normalizer.normalizeResponse(node, dataID, response);
|
|
36
30
|
}
|
|
37
|
-
|
|
38
31
|
/**
|
|
39
32
|
* @private
|
|
40
33
|
*
|
|
41
34
|
* Helper for handling payloads.
|
|
42
35
|
*/
|
|
43
36
|
|
|
44
|
-
|
|
37
|
+
|
|
38
|
+
var RelayResponseNormalizer =
|
|
39
|
+
/*#__PURE__*/
|
|
40
|
+
function () {
|
|
45
41
|
function RelayResponseNormalizer(recordSource, variables, options) {
|
|
46
|
-
(0, _classCallCheck3['default'])(this, RelayResponseNormalizer);
|
|
47
42
|
this._handleFieldPayloads = [];
|
|
48
|
-
this.
|
|
49
|
-
|
|
43
|
+
this._handleStrippedNulls = options.handleStrippedNulls;
|
|
44
|
+
this._incrementalPayloads = [];
|
|
45
|
+
this._matchFieldPayloads = [];
|
|
46
|
+
this._path = options.path ? (0, _toConsumableArray2["default"])(options.path) : [];
|
|
50
47
|
this._recordSource = recordSource;
|
|
51
48
|
this._variables = variables;
|
|
52
|
-
this._handleStrippedNulls = options.handleStrippedNulls;
|
|
53
49
|
}
|
|
54
50
|
|
|
55
|
-
RelayResponseNormalizer.prototype
|
|
51
|
+
var _proto = RelayResponseNormalizer.prototype;
|
|
52
|
+
|
|
53
|
+
_proto.normalizeResponse = function normalizeResponse(node, dataID, data) {
|
|
56
54
|
var record = this._recordSource.get(dataID);
|
|
57
|
-
|
|
55
|
+
|
|
56
|
+
!record ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayResponseNormalizer(): Expected root record `%s` to exist.', dataID) : require("fbjs/lib/invariant")(false) : void 0;
|
|
57
|
+
|
|
58
58
|
this._traverseSelections(node, record, data);
|
|
59
|
+
|
|
59
60
|
return {
|
|
61
|
+
incrementalPayloads: this._incrementalPayloads,
|
|
60
62
|
fieldPayloads: this._handleFieldPayloads,
|
|
61
|
-
|
|
63
|
+
matchPayloads: this._matchFieldPayloads
|
|
62
64
|
};
|
|
63
65
|
};
|
|
64
66
|
|
|
65
|
-
|
|
66
|
-
!this._variables.hasOwnProperty(name) ? process.env.NODE_ENV !==
|
|
67
|
+
_proto._getVariableValue = function _getVariableValue(name) {
|
|
68
|
+
!this._variables.hasOwnProperty(name) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayResponseNormalizer(): Undefined variable `%s`.', name) : require("fbjs/lib/invariant")(false) : void 0;
|
|
67
69
|
return this._variables[name];
|
|
68
70
|
};
|
|
69
71
|
|
|
70
|
-
|
|
71
|
-
var typeName = data[require(
|
|
72
|
-
|
|
72
|
+
_proto._getRecordType = function _getRecordType(data) {
|
|
73
|
+
var typeName = data[require("./RelayStoreUtils").TYPENAME_KEY];
|
|
74
|
+
|
|
75
|
+
!(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;
|
|
73
76
|
return typeName;
|
|
74
77
|
};
|
|
75
78
|
|
|
76
|
-
|
|
79
|
+
_proto._traverseSelections = function _traverseSelections(node, record, data) {
|
|
77
80
|
var _this = this;
|
|
78
81
|
|
|
79
82
|
node.selections.forEach(function (selection) {
|
|
80
|
-
if (selection.kind === require(
|
|
83
|
+
if (selection.kind === require("./RelayConcreteNode").SCALAR_FIELD || selection.kind === require("./RelayConcreteNode").LINKED_FIELD) {
|
|
81
84
|
_this._normalizeField(node, selection, record, data);
|
|
82
|
-
} else if (selection.kind === require(
|
|
85
|
+
} else if (selection.kind === require("./RelayConcreteNode").CONDITION) {
|
|
83
86
|
var conditionValue = _this._getVariableValue(selection.condition);
|
|
87
|
+
|
|
84
88
|
if (conditionValue === selection.passingValue) {
|
|
85
89
|
_this._traverseSelections(selection, record, data);
|
|
86
90
|
}
|
|
87
|
-
} else if (selection.kind === require(
|
|
88
|
-
var typeName = require(
|
|
91
|
+
} else if (selection.kind === require("./RelayConcreteNode").INLINE_FRAGMENT) {
|
|
92
|
+
var typeName = require("./RelayModernRecord").getType(record);
|
|
93
|
+
|
|
89
94
|
if (typeName === selection.type) {
|
|
90
95
|
_this._traverseSelections(selection, record, data);
|
|
91
96
|
}
|
|
92
|
-
} else if (selection.kind === require(
|
|
93
|
-
var args = selection.args ? require(
|
|
94
|
-
|
|
95
|
-
var
|
|
97
|
+
} else if (selection.kind === require("./RelayConcreteNode").LINKED_HANDLE || selection.kind === require("./RelayConcreteNode").SCALAR_HANDLE) {
|
|
98
|
+
var args = selection.args ? require("./RelayStoreUtils").getArgumentValues(selection.args, _this._variables) : {};
|
|
99
|
+
|
|
100
|
+
var fieldKey = require("./RelayStoreUtils").getStorageKey(selection, _this._variables);
|
|
101
|
+
|
|
102
|
+
var handleKey = require("./RelayStoreUtils").getHandleStorageKey(selection, _this._variables);
|
|
103
|
+
|
|
96
104
|
_this._handleFieldPayloads.push({
|
|
97
105
|
args: args,
|
|
98
|
-
dataID: require(
|
|
106
|
+
dataID: require("./RelayModernRecord").getDataID(record),
|
|
99
107
|
fieldKey: fieldKey,
|
|
100
108
|
handle: selection.handle,
|
|
101
109
|
handleKey: handleKey
|
|
102
110
|
});
|
|
103
|
-
} else if (selection.kind === require(
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
111
|
+
} else if (selection.kind === require("./RelayConcreteNode").MATCH_FIELD) {
|
|
112
|
+
_this._normalizeMatchField(node, selection, record, data);
|
|
113
|
+
} else if (selection.kind === require("./RelayConcreteNode").DEFER) {
|
|
114
|
+
_this._normalizeDefer(selection, record, data);
|
|
115
|
+
} else if (selection.kind === require("./RelayConcreteNode").STREAM) {
|
|
116
|
+
_this._normalizeStream(selection, record, data);
|
|
117
|
+
} else if (selection.kind === require("./RelayConcreteNode").FRAGMENT || selection.kind === require("./RelayConcreteNode").FRAGMENT_SPREAD) {
|
|
118
|
+
!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
119
|
} else {
|
|
111
|
-
|
|
120
|
+
selection;
|
|
121
|
+
!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;
|
|
112
122
|
}
|
|
113
123
|
});
|
|
114
124
|
};
|
|
115
125
|
|
|
116
|
-
|
|
117
|
-
|
|
126
|
+
_proto._normalizeDefer = function _normalizeDefer(defer, record, data) {
|
|
127
|
+
var isDeferred = defer["if"] === null || this._getVariableValue(defer["if"]);
|
|
128
|
+
|
|
129
|
+
if (process.env.NODE_ENV !== "production") {
|
|
130
|
+
process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(typeof isDeferred === 'boolean', 'RelayResponseNormalizer: Expected value for @defer `if` argument to ' + 'be a boolean, got `%s`.', isDeferred) : void 0;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (isDeferred === false) {
|
|
134
|
+
// If defer is disabled there will be no additional response chunk:
|
|
135
|
+
// normalize the data already present.
|
|
136
|
+
this._traverseSelections(defer, record, data);
|
|
137
|
+
} else {
|
|
138
|
+
// Otherwise data *for this selection* should not be present: enqueue
|
|
139
|
+
// metadata to process the subsequent response chunk.
|
|
140
|
+
this._incrementalPayloads.push({
|
|
141
|
+
kind: 'defer',
|
|
142
|
+
label: defer.label,
|
|
143
|
+
path: (0, _toConsumableArray2["default"])(this._path),
|
|
144
|
+
selector: {
|
|
145
|
+
dataID: require("./RelayModernRecord").getDataID(record),
|
|
146
|
+
node: defer,
|
|
147
|
+
variables: this._variables
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
_proto._normalizeStream = function _normalizeStream(stream, record, data) {
|
|
154
|
+
// Always normalize regardless of whether streaming is enabled or not,
|
|
155
|
+
// this populates the initial array value (including any items when
|
|
156
|
+
// initial_count > 0).
|
|
157
|
+
this._traverseSelections(stream, record, data);
|
|
158
|
+
|
|
159
|
+
var isStreamed = stream["if"] === null || this._getVariableValue(stream["if"]);
|
|
160
|
+
|
|
161
|
+
if (process.env.NODE_ENV !== "production") {
|
|
162
|
+
process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(typeof isStreamed === 'boolean', 'RelayResponseNormalizer: Expected value for @stream `if` argument ' + 'to be a boolean, got `%s`.', isStreamed) : void 0;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (isStreamed === true) {
|
|
166
|
+
// If streaming is enabled, *also* emit metadata to process any
|
|
167
|
+
// response chunks that may be delivered.
|
|
168
|
+
this._incrementalPayloads.push({
|
|
169
|
+
kind: 'stream',
|
|
170
|
+
label: stream.label,
|
|
171
|
+
path: (0, _toConsumableArray2["default"])(this._path),
|
|
172
|
+
selector: {
|
|
173
|
+
dataID: require("./RelayModernRecord").getDataID(record),
|
|
174
|
+
node: stream,
|
|
175
|
+
variables: this._variables
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
_proto._normalizeMatchField = function _normalizeMatchField(parent, field, record, data) {
|
|
182
|
+
!(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;
|
|
183
|
+
var responseKey = field.alias || field.name;
|
|
184
|
+
|
|
185
|
+
var storageKey = require("./RelayStoreUtils").getStorageKey(field, this._variables);
|
|
186
|
+
|
|
187
|
+
var fieldValue = data[responseKey];
|
|
188
|
+
|
|
189
|
+
if (fieldValue == null) {
|
|
190
|
+
if (fieldValue === undefined && !this._handleStrippedNulls) {
|
|
191
|
+
// If we're not stripping nulls, undefined fields are unset
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
if (process.env.NODE_ENV !== "production") {
|
|
196
|
+
process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(parent.kind === require("./RelayConcreteNode").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;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
require("./RelayModernRecord").setValue(record, storageKey, null);
|
|
200
|
+
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
!(typeof fieldValue === 'object' && fieldValue) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayResponseNormalizer: Expected data for field `%s` to be an object.', storageKey) : require("fbjs/lib/invariant")(false) : void 0;
|
|
205
|
+
|
|
206
|
+
var typeName = this._getRecordType(fieldValue);
|
|
207
|
+
|
|
208
|
+
var match = field.matchesByType[typeName];
|
|
209
|
+
|
|
210
|
+
if (match == null) {
|
|
211
|
+
require("./RelayModernRecord").setValue(record, storageKey, null);
|
|
212
|
+
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
var nextID = fieldValue.id || // Reuse previously generated client IDs
|
|
217
|
+
require("./RelayModernRecord").getLinkedRecordID(record, storageKey) || require("./generateRelayClientID")(require("./RelayModernRecord").getDataID(record), storageKey);
|
|
218
|
+
|
|
219
|
+
!(typeof nextID === 'string') ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayResponseNormalizer: Expected id on field `%s` to be a string.', storageKey) : require("fbjs/lib/invariant")(false) : void 0;
|
|
220
|
+
|
|
221
|
+
require("./RelayModernRecord").setLinkedRecordID(record, storageKey, nextID);
|
|
222
|
+
|
|
223
|
+
var nextRecord = this._recordSource.get(nextID);
|
|
224
|
+
|
|
225
|
+
if (!nextRecord) {
|
|
226
|
+
nextRecord = require("./RelayModernRecord").create(nextID, typeName);
|
|
227
|
+
|
|
228
|
+
this._recordSource.set(nextID, nextRecord);
|
|
229
|
+
} else if (process.env.NODE_ENV !== "production") {
|
|
230
|
+
this._validateRecordType(nextRecord, field, fieldValue);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
var operationReference = fieldValue[require("./RelayStoreUtils").MATCH_FRAGMENT_KEY];
|
|
234
|
+
|
|
235
|
+
if (operationReference != null) {
|
|
236
|
+
this._matchFieldPayloads.push({
|
|
237
|
+
data: fieldValue,
|
|
238
|
+
dataID: nextID,
|
|
239
|
+
operationReference: operationReference,
|
|
240
|
+
path: (0, _toConsumableArray2["default"])(this._path).concat([responseKey]),
|
|
241
|
+
typeName: typeName,
|
|
242
|
+
variables: this._variables
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
_proto._normalizeField = function _normalizeField(parent, selection, record, data) {
|
|
248
|
+
!(typeof data === 'object' && data) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'writeField(): Expected data for field `%s` to be an object.', selection.name) : require("fbjs/lib/invariant")(false) : void 0;
|
|
118
249
|
var responseKey = selection.alias || selection.name;
|
|
119
|
-
|
|
250
|
+
|
|
251
|
+
var storageKey = require("./RelayStoreUtils").getStorageKey(selection, this._variables);
|
|
252
|
+
|
|
120
253
|
var fieldValue = data[responseKey];
|
|
254
|
+
|
|
121
255
|
if (fieldValue == null) {
|
|
122
256
|
if (fieldValue === undefined && !this._handleStrippedNulls) {
|
|
123
257
|
// If we're not stripping nulls, undefined fields are unset
|
|
124
258
|
return;
|
|
125
259
|
}
|
|
126
|
-
|
|
127
|
-
|
|
260
|
+
|
|
261
|
+
if (process.env.NODE_ENV !== "production") {
|
|
262
|
+
process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(parent.kind === require("./RelayConcreteNode").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;
|
|
128
263
|
}
|
|
129
|
-
|
|
264
|
+
|
|
265
|
+
require("./RelayModernRecord").setValue(record, storageKey, null);
|
|
266
|
+
|
|
130
267
|
return;
|
|
131
268
|
}
|
|
132
269
|
|
|
133
|
-
if (selection.kind === require(
|
|
134
|
-
require(
|
|
135
|
-
} else if (selection.
|
|
136
|
-
this.
|
|
270
|
+
if (selection.kind === require("./RelayConcreteNode").SCALAR_FIELD) {
|
|
271
|
+
require("./RelayModernRecord").setValue(record, storageKey, fieldValue);
|
|
272
|
+
} else if (selection.kind === require("./RelayConcreteNode").LINKED_FIELD) {
|
|
273
|
+
this._path.push(responseKey);
|
|
274
|
+
|
|
275
|
+
if (selection.plural) {
|
|
276
|
+
this._normalizePluralLink(selection, record, storageKey, fieldValue);
|
|
277
|
+
} else {
|
|
278
|
+
this._normalizeLink(selection, record, storageKey, fieldValue);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
this._path.pop();
|
|
282
|
+
} else if (selection.kind === require("./RelayConcreteNode").MATCH_FIELD) {
|
|
283
|
+
!false ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayResponseNormalizer(): Unexpected ast kind `%s` during normalization.', selection.kind) : require("fbjs/lib/invariant")(false) : void 0;
|
|
137
284
|
} else {
|
|
138
|
-
|
|
285
|
+
selection;
|
|
286
|
+
!false ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayResponseNormalizer(): Unexpected ast kind `%s` during normalization.', selection.kind) : require("fbjs/lib/invariant")(false) : void 0;
|
|
139
287
|
}
|
|
140
288
|
};
|
|
141
289
|
|
|
142
|
-
|
|
143
|
-
!(typeof fieldValue === 'object' && fieldValue) ? process.env.NODE_ENV !==
|
|
144
|
-
|
|
145
|
-
// Reuse previously generated client IDs
|
|
146
|
-
require(
|
|
147
|
-
|
|
148
|
-
|
|
290
|
+
_proto._normalizeLink = function _normalizeLink(field, record, storageKey, fieldValue) {
|
|
291
|
+
!(typeof fieldValue === 'object' && fieldValue) ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayResponseNormalizer: Expected data for field `%s` to be an object.', storageKey) : require("fbjs/lib/invariant")(false) : void 0;
|
|
292
|
+
|
|
293
|
+
var nextID = fieldValue.id || // Reuse previously generated client IDs
|
|
294
|
+
require("./RelayModernRecord").getLinkedRecordID(record, storageKey) || require("./generateRelayClientID")(require("./RelayModernRecord").getDataID(record), storageKey);
|
|
295
|
+
|
|
296
|
+
!(typeof nextID === 'string') ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayResponseNormalizer: Expected id on field `%s` to be a string.', storageKey) : require("fbjs/lib/invariant")(false) : void 0;
|
|
297
|
+
|
|
298
|
+
require("./RelayModernRecord").setLinkedRecordID(record, storageKey, nextID);
|
|
299
|
+
|
|
149
300
|
var nextRecord = this._recordSource.get(nextID);
|
|
301
|
+
|
|
150
302
|
if (!nextRecord) {
|
|
151
303
|
var typeName = field.concreteType || this._getRecordType(fieldValue);
|
|
152
|
-
|
|
304
|
+
|
|
305
|
+
nextRecord = require("./RelayModernRecord").create(nextID, typeName);
|
|
306
|
+
|
|
153
307
|
this._recordSource.set(nextID, nextRecord);
|
|
154
|
-
} else if (process.env.NODE_ENV !==
|
|
308
|
+
} else if (process.env.NODE_ENV !== "production") {
|
|
155
309
|
this._validateRecordType(nextRecord, field, fieldValue);
|
|
156
310
|
}
|
|
311
|
+
|
|
157
312
|
this._traverseSelections(field, nextRecord, fieldValue);
|
|
158
313
|
};
|
|
159
314
|
|
|
160
|
-
|
|
315
|
+
_proto._normalizePluralLink = function _normalizePluralLink(field, record, storageKey, fieldValue) {
|
|
161
316
|
var _this2 = this;
|
|
162
317
|
|
|
163
|
-
!Array.isArray(fieldValue) ? process.env.NODE_ENV !==
|
|
164
|
-
|
|
318
|
+
!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;
|
|
319
|
+
|
|
320
|
+
var prevIDs = require("./RelayModernRecord").getLinkedRecordIDs(record, storageKey);
|
|
321
|
+
|
|
165
322
|
var nextIDs = [];
|
|
166
323
|
fieldValue.forEach(function (item, nextIndex) {
|
|
167
324
|
// validate response data
|
|
@@ -169,42 +326,51 @@ var RelayResponseNormalizer = function () {
|
|
|
169
326
|
nextIDs.push(item);
|
|
170
327
|
return;
|
|
171
328
|
}
|
|
172
|
-
|
|
329
|
+
|
|
330
|
+
_this2._path.push(String(nextIndex));
|
|
331
|
+
|
|
332
|
+
!(typeof item === 'object') ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayResponseNormalizer: Expected elements for field `%s` to be ' + 'objects.', storageKey) : require("fbjs/lib/invariant")(false) : void 0;
|
|
173
333
|
|
|
174
334
|
var nextID = item.id || prevIDs && prevIDs[nextIndex] || // Reuse previously generated client IDs
|
|
175
|
-
require(
|
|
176
|
-
!(typeof nextID === 'string') ? process.env.NODE_ENV !== 'production' ? require('fbjs/lib/invariant')(false, 'RelayResponseNormalizer: Expected id of elements of field `%s` to ' + 'be strings.', storageKey) : require('fbjs/lib/invariant')(false) : void 0;
|
|
335
|
+
require("./generateRelayClientID")(require("./RelayModernRecord").getDataID(record), storageKey, nextIndex);
|
|
177
336
|
|
|
337
|
+
!(typeof nextID === 'string') ? process.env.NODE_ENV !== "production" ? require("fbjs/lib/invariant")(false, 'RelayResponseNormalizer: Expected id of elements of field `%s` to ' + 'be strings.', storageKey) : require("fbjs/lib/invariant")(false) : void 0;
|
|
178
338
|
nextIDs.push(nextID);
|
|
339
|
+
|
|
179
340
|
var nextRecord = _this2._recordSource.get(nextID);
|
|
341
|
+
|
|
180
342
|
if (!nextRecord) {
|
|
181
343
|
var typeName = field.concreteType || _this2._getRecordType(item);
|
|
182
|
-
|
|
344
|
+
|
|
345
|
+
nextRecord = require("./RelayModernRecord").create(nextID, typeName);
|
|
346
|
+
|
|
183
347
|
_this2._recordSource.set(nextID, nextRecord);
|
|
184
|
-
} else if (process.env.NODE_ENV !==
|
|
348
|
+
} else if (process.env.NODE_ENV !== "production") {
|
|
185
349
|
_this2._validateRecordType(nextRecord, field, item);
|
|
186
350
|
}
|
|
351
|
+
|
|
187
352
|
_this2._traverseSelections(field, nextRecord, item);
|
|
353
|
+
|
|
354
|
+
_this2._path.pop();
|
|
188
355
|
});
|
|
189
|
-
require('./RelayModernRecord').setLinkedRecordIDs(record, storageKey, nextIDs);
|
|
190
|
-
};
|
|
191
356
|
|
|
357
|
+
require("./RelayModernRecord").setLinkedRecordIDs(record, storageKey, nextIDs);
|
|
358
|
+
};
|
|
192
359
|
/**
|
|
193
360
|
* Warns if the type of the record does not match the type of the field/payload.
|
|
194
361
|
*/
|
|
195
362
|
|
|
196
363
|
|
|
197
|
-
|
|
198
|
-
var typeName = field.concreteType || this._getRecordType(payload);
|
|
199
|
-
process.env.NODE_ENV !==
|
|
364
|
+
_proto._validateRecordType = function _validateRecordType(record, field, payload) {
|
|
365
|
+
var typeName = field.kind === 'LinkedField' ? field.concreteType || this._getRecordType(payload) : this._getRecordType(payload);
|
|
366
|
+
process.env.NODE_ENV !== "production" ? require("fbjs/lib/warning")(require("./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.', require("./RelayModernRecord").getDataID(record), require("./RelayStoreUtils").TYPENAME_KEY, require("./RelayModernRecord").getType(record), typeName) : void 0;
|
|
200
367
|
};
|
|
201
368
|
|
|
202
369
|
return RelayResponseNormalizer;
|
|
203
|
-
}();
|
|
204
|
-
|
|
205
|
-
// eslint-disable-next-line no-func-assign
|
|
206
|
-
|
|
370
|
+
}(); // eslint-disable-next-line no-func-assign
|
|
207
371
|
|
|
208
|
-
normalize = require('./RelayProfiler').instrument('RelayResponseNormalizer.normalize', normalize);
|
|
209
372
|
|
|
210
|
-
|
|
373
|
+
normalize = require("./RelayProfiler").instrument('RelayResponseNormalizer.normalize', normalize);
|
|
374
|
+
module.exports = {
|
|
375
|
+
normalize: normalize
|
|
376
|
+
};
|
package/lib/RelayRuntimeTypes.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,9 +7,7 @@
|
|
|
7
7
|
* strict
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
10
|
'use strict';
|
|
12
|
-
|
|
13
11
|
/**
|
|
14
12
|
* Basic types used throughout Relay.
|
|
15
13
|
*/
|
package/lib/RelayStoreTypes.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,5 +7,4 @@
|
|
|
7
7
|
*
|
|
8
8
|
* @format
|
|
9
9
|
*/
|
|
10
|
-
|
|
11
10
|
'use strict';
|