relay-runtime 10.0.1 → 10.1.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/handlers/RelayDefaultHandlerProvider.js.flow +6 -0
- package/handlers/connection/MutationHandlers.js.flow +114 -3
- package/index.js +1 -1
- package/index.js.flow +16 -1
- package/lib/handlers/RelayDefaultHandlerProvider.js +9 -0
- package/lib/handlers/connection/MutationHandlers.js +138 -12
- package/lib/index.js +7 -0
- package/lib/mutations/RelayDeclarativeMutationConfig.js +2 -2
- package/lib/mutations/commitMutation.js +1 -4
- package/lib/mutations/validateMutation.js +27 -7
- package/lib/network/RelayQueryResponseCache.js +2 -2
- package/lib/query/GraphQLTag.js +2 -1
- package/lib/query/fetchQuery.js +2 -3
- package/lib/query/fetchQueryInternal.js +2 -3
- package/lib/store/DataChecker.js +82 -5
- package/lib/store/RelayModernEnvironment.js +18 -6
- package/lib/store/RelayModernFragmentSpecResolver.js +10 -1
- package/lib/store/RelayModernOperationDescriptor.js +6 -5
- package/lib/store/RelayModernQueryExecutor.js +44 -23
- package/lib/store/RelayModernStore.js +25 -14
- package/lib/store/RelayOperationTracker.js +2 -2
- package/lib/store/RelayPublishQueue.js +1 -1
- package/lib/store/RelayReader.js +196 -33
- package/lib/store/RelayRecordSourceMapImpl.js +2 -2
- package/lib/store/RelayReferenceMarker.js +89 -5
- package/lib/store/RelayResponseNormalizer.js +119 -19
- package/lib/store/RelayStoreReactFlightUtils.js +47 -0
- package/lib/store/defaultRequiredFieldLogger.js +18 -0
- package/lib/store/normalizeRelayPayload.js +1 -1
- package/lib/subscription/requestSubscription.js +2 -3
- package/lib/util/NormalizationNode.js +1 -5
- package/lib/util/RelayConcreteNode.js +2 -0
- package/lib/util/RelayFeatureFlags.js +5 -2
- package/lib/util/getFragmentIdentifier.js +12 -3
- package/lib/util/getOperation.js +33 -0
- package/lib/util/isEmptyObject.js +25 -0
- package/lib/util/recycleNodesInto.js +4 -1
- package/lib/util/reportMissingRequiredFields.js +48 -0
- package/mutations/commitMutation.js.flow +1 -2
- package/mutations/validateMutation.js.flow +34 -5
- package/network/RelayNetworkTypes.js.flow +22 -0
- package/package.json +2 -2
- package/query/GraphQLTag.js.flow +3 -1
- package/query/fetchQuery.js.flow +2 -2
- package/query/fetchQueryInternal.js.flow +0 -5
- package/relay-runtime.js +2 -2
- package/relay-runtime.min.js +2 -2
- package/store/DataChecker.js.flow +68 -2
- package/store/RelayModernEnvironment.js.flow +29 -9
- package/store/RelayModernFragmentSpecResolver.js.flow +13 -1
- package/store/RelayModernOperationDescriptor.js.flow +5 -1
- package/store/RelayModernQueryExecutor.js.flow +47 -23
- package/store/RelayModernStore.js.flow +31 -15
- package/store/RelayPublishQueue.js.flow +1 -1
- package/store/RelayReader.js.flow +180 -15
- package/store/RelayReferenceMarker.js.flow +72 -5
- package/store/RelayResponseNormalizer.js.flow +130 -19
- package/store/RelayStoreReactFlightUtils.js.flow +64 -0
- package/store/RelayStoreTypes.js.flow +90 -31
- package/store/defaultRequiredFieldLogger.js.flow +23 -0
- package/subscription/requestSubscription.js.flow +5 -2
- package/util/NormalizationNode.js.flow +17 -2
- package/util/ReaderNode.js.flow +20 -1
- package/util/RelayConcreteNode.js.flow +6 -0
- package/util/RelayFeatureFlags.js.flow +8 -1
- package/util/getFragmentIdentifier.js.flow +33 -9
- package/util/getOperation.js.flow +40 -0
- package/util/isEmptyObject.js.flow +25 -0
- package/util/recycleNodesInto.js.flow +11 -0
- package/util/reportMissingRequiredFields.js.flow +51 -0
|
@@ -10,16 +10,26 @@
|
|
|
10
10
|
// flowlint ambiguous-object-type:error
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
14
|
+
|
|
15
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
16
|
+
|
|
17
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
18
|
+
|
|
13
19
|
var RelayConcreteNode = require('../util/RelayConcreteNode');
|
|
14
20
|
|
|
15
21
|
var RelayFeatureFlags = require('../util/RelayFeatureFlags');
|
|
16
22
|
|
|
17
23
|
var RelayModernRecord = require('./RelayModernRecord');
|
|
18
24
|
|
|
25
|
+
var RelayStoreReactFlightUtils = require('./RelayStoreReactFlightUtils');
|
|
26
|
+
|
|
19
27
|
var RelayStoreUtils = require('./RelayStoreUtils');
|
|
20
28
|
|
|
21
29
|
var cloneRelayHandleSourceField = require('./cloneRelayHandleSourceField');
|
|
22
30
|
|
|
31
|
+
var getOperation = require('../util/getOperation');
|
|
32
|
+
|
|
23
33
|
var invariant = require("fbjs/lib/invariant");
|
|
24
34
|
|
|
25
35
|
var _require = require('./TypeID'),
|
|
@@ -28,6 +38,7 @@ var _require = require('./TypeID'),
|
|
|
28
38
|
var CONDITION = RelayConcreteNode.CONDITION,
|
|
29
39
|
CLIENT_EXTENSION = RelayConcreteNode.CLIENT_EXTENSION,
|
|
30
40
|
DEFER = RelayConcreteNode.DEFER,
|
|
41
|
+
FLIGHT_FIELD = RelayConcreteNode.FLIGHT_FIELD,
|
|
31
42
|
FRAGMENT_SPREAD = RelayConcreteNode.FRAGMENT_SPREAD,
|
|
32
43
|
INLINE_FRAGMENT = RelayConcreteNode.INLINE_FRAGMENT,
|
|
33
44
|
LINKED_FIELD = RelayConcreteNode.LINKED_FIELD,
|
|
@@ -37,7 +48,8 @@ var CONDITION = RelayConcreteNode.CONDITION,
|
|
|
37
48
|
SCALAR_HANDLE = RelayConcreteNode.SCALAR_HANDLE,
|
|
38
49
|
STREAM = RelayConcreteNode.STREAM,
|
|
39
50
|
TYPE_DISCRIMINATOR = RelayConcreteNode.TYPE_DISCRIMINATOR;
|
|
40
|
-
var
|
|
51
|
+
var ROOT_ID = RelayStoreUtils.ROOT_ID,
|
|
52
|
+
getStorageKey = RelayStoreUtils.getStorageKey,
|
|
41
53
|
getModuleOperationKey = RelayStoreUtils.getModuleOperationKey;
|
|
42
54
|
|
|
43
55
|
function mark(recordSource, selector, references, operationLoader) {
|
|
@@ -55,6 +67,7 @@ function mark(recordSource, selector, references, operationLoader) {
|
|
|
55
67
|
var RelayReferenceMarker = /*#__PURE__*/function () {
|
|
56
68
|
function RelayReferenceMarker(recordSource, variables, references, operationLoader) {
|
|
57
69
|
this._operationLoader = operationLoader !== null && operationLoader !== void 0 ? operationLoader : null;
|
|
70
|
+
this._operationName = null;
|
|
58
71
|
this._recordSource = recordSource;
|
|
59
72
|
this._references = references;
|
|
60
73
|
this._variables = variables;
|
|
@@ -63,6 +76,10 @@ var RelayReferenceMarker = /*#__PURE__*/function () {
|
|
|
63
76
|
var _proto = RelayReferenceMarker.prototype;
|
|
64
77
|
|
|
65
78
|
_proto.mark = function mark(node, dataID) {
|
|
79
|
+
if (node.kind === 'Operation' || node.kind === 'SplitOperation') {
|
|
80
|
+
this._operationName = node.name;
|
|
81
|
+
}
|
|
82
|
+
|
|
66
83
|
this._traverse(node, dataID);
|
|
67
84
|
};
|
|
68
85
|
|
|
@@ -127,6 +144,7 @@ var RelayReferenceMarker = /*#__PURE__*/function () {
|
|
|
127
144
|
}
|
|
128
145
|
|
|
129
146
|
break;
|
|
147
|
+
// $FlowFixMe[incompatible-type]
|
|
130
148
|
|
|
131
149
|
case FRAGMENT_SPREAD:
|
|
132
150
|
!false ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReferenceMarker(): Unexpected fragment spread `...%s`, ' + 'expected all fragments to be inlined.', selection.name) : invariant(false) : void 0;
|
|
@@ -184,6 +202,15 @@ var RelayReferenceMarker = /*#__PURE__*/function () {
|
|
|
184
202
|
|
|
185
203
|
break;
|
|
186
204
|
|
|
205
|
+
case FLIGHT_FIELD:
|
|
206
|
+
if (RelayFeatureFlags.ENABLE_REACT_FLIGHT_COMPONENT_FIELD) {
|
|
207
|
+
_this._traverseFlightField(selection, record);
|
|
208
|
+
} else {
|
|
209
|
+
throw new Error('Flight fields are not yet supported.');
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
break;
|
|
213
|
+
|
|
187
214
|
default:
|
|
188
215
|
selection;
|
|
189
216
|
!false ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReferenceMarker: Unknown AST node `%s`.', selection) : invariant(false) : void 0;
|
|
@@ -192,8 +219,10 @@ var RelayReferenceMarker = /*#__PURE__*/function () {
|
|
|
192
219
|
};
|
|
193
220
|
|
|
194
221
|
_proto._traverseModuleImport = function _traverseModuleImport(moduleImport, record) {
|
|
222
|
+
var _this$_operationName;
|
|
223
|
+
|
|
195
224
|
var operationLoader = this._operationLoader;
|
|
196
|
-
!(operationLoader !== null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReferenceMarker: Expected an operationLoader to be configured when using `@module`.') : invariant(false) : void 0;
|
|
225
|
+
!(operationLoader !== null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayReferenceMarker: Expected an operationLoader to be configured when using `@module`. ' + 'Could not load fragment `%s` in operation `%s`.', moduleImport.fragmentName, (_this$_operationName = this._operationName) !== null && _this$_operationName !== void 0 ? _this$_operationName : '(unknown)') : invariant(false) : void 0;
|
|
197
226
|
var operationKey = getModuleOperationKey(moduleImport.documentName);
|
|
198
227
|
var operationReference = RelayModernRecord.getValue(record, operationKey);
|
|
199
228
|
|
|
@@ -201,10 +230,12 @@ var RelayReferenceMarker = /*#__PURE__*/function () {
|
|
|
201
230
|
return;
|
|
202
231
|
}
|
|
203
232
|
|
|
204
|
-
var
|
|
233
|
+
var normalizationRootNode = operationLoader.get(operationReference);
|
|
234
|
+
|
|
235
|
+
if (normalizationRootNode != null) {
|
|
236
|
+
var selections = getOperation(normalizationRootNode).selections;
|
|
205
237
|
|
|
206
|
-
|
|
207
|
-
this._traverseSelections(operation.selections, record);
|
|
238
|
+
this._traverseSelections(selections, record);
|
|
208
239
|
} // Otherwise, if the operation is not available, we assume that the data
|
|
209
240
|
// cannot have been processed yet and therefore isn't in the store to
|
|
210
241
|
// begin with.
|
|
@@ -239,6 +270,59 @@ var RelayReferenceMarker = /*#__PURE__*/function () {
|
|
|
239
270
|
});
|
|
240
271
|
};
|
|
241
272
|
|
|
273
|
+
_proto._traverseFlightField = function _traverseFlightField(field, record) {
|
|
274
|
+
var storageKey = getStorageKey(field, this._variables);
|
|
275
|
+
var linkedID = RelayModernRecord.getLinkedRecordID(record, storageKey);
|
|
276
|
+
|
|
277
|
+
if (linkedID == null) {
|
|
278
|
+
return;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
this._references.add(linkedID);
|
|
282
|
+
|
|
283
|
+
var reactFlightClientResponseRecord = this._recordSource.get(linkedID);
|
|
284
|
+
|
|
285
|
+
if (reactFlightClientResponseRecord == null) {
|
|
286
|
+
return;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
var reachableQueries = RelayModernRecord.getValue(reactFlightClientResponseRecord, RelayStoreReactFlightUtils.REACT_FLIGHT_QUERIES_STORAGE_KEY);
|
|
290
|
+
|
|
291
|
+
if (!Array.isArray(reachableQueries)) {
|
|
292
|
+
return;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
var operationLoader = this._operationLoader;
|
|
296
|
+
!(operationLoader !== null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'DataChecker: Expected an operationLoader to be configured when using ' + 'React Flight') : invariant(false) : void 0; // In Flight, the variables that are in scope for reachable queries aren't
|
|
297
|
+
// the same as what's in scope for the outer query.
|
|
298
|
+
|
|
299
|
+
var prevVariables = this._variables; // $FlowFixMe[incompatible-cast]
|
|
300
|
+
|
|
301
|
+
var _iterator = _createForOfIteratorHelper(reachableQueries),
|
|
302
|
+
_step;
|
|
303
|
+
|
|
304
|
+
try {
|
|
305
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
306
|
+
var query = _step.value;
|
|
307
|
+
this._variables = query.variables;
|
|
308
|
+
var operationReference = query.module;
|
|
309
|
+
var normalizationRootNode = operationLoader.get(operationReference);
|
|
310
|
+
|
|
311
|
+
if (normalizationRootNode != null) {
|
|
312
|
+
var operation = getOperation(normalizationRootNode);
|
|
313
|
+
|
|
314
|
+
this._traverse(operation, ROOT_ID);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
} catch (err) {
|
|
318
|
+
_iterator.e(err);
|
|
319
|
+
} finally {
|
|
320
|
+
_iterator.f();
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
this._variables = prevVariables;
|
|
324
|
+
};
|
|
325
|
+
|
|
242
326
|
return RelayReferenceMarker;
|
|
243
327
|
}();
|
|
244
328
|
|
|
@@ -14,12 +14,20 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
14
14
|
|
|
15
15
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
16
16
|
|
|
17
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it; if (typeof Symbol === "undefined" || o[Symbol.iterator] == null) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = o[Symbol.iterator](); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
18
|
+
|
|
19
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
20
|
+
|
|
21
|
+
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
|
22
|
+
|
|
17
23
|
var RelayFeatureFlags = require('../util/RelayFeatureFlags');
|
|
18
24
|
|
|
19
25
|
var RelayModernRecord = require('./RelayModernRecord');
|
|
20
26
|
|
|
21
27
|
var RelayProfiler = require('../util/RelayProfiler');
|
|
22
28
|
|
|
29
|
+
var areEqual = require("fbjs/lib/areEqual");
|
|
30
|
+
|
|
23
31
|
var invariant = require("fbjs/lib/invariant");
|
|
24
32
|
|
|
25
33
|
var warning = require("fbjs/lib/warning");
|
|
@@ -28,6 +36,7 @@ var _require = require('../util/RelayConcreteNode'),
|
|
|
28
36
|
CONDITION = _require.CONDITION,
|
|
29
37
|
CLIENT_EXTENSION = _require.CLIENT_EXTENSION,
|
|
30
38
|
DEFER = _require.DEFER,
|
|
39
|
+
FLIGHT_FIELD = _require.FLIGHT_FIELD,
|
|
31
40
|
INLINE_FRAGMENT = _require.INLINE_FRAGMENT,
|
|
32
41
|
LINKED_FIELD = _require.LINKED_FIELD,
|
|
33
42
|
LINKED_HANDLE = _require.LINKED_HANDLE,
|
|
@@ -44,18 +53,25 @@ var _require2 = require('./ClientID'),
|
|
|
44
53
|
var _require3 = require('./RelayModernSelector'),
|
|
45
54
|
createNormalizationSelector = _require3.createNormalizationSelector;
|
|
46
55
|
|
|
47
|
-
var _require4 = require('./
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
var _require4 = require('./RelayStoreReactFlightUtils'),
|
|
57
|
+
refineToReactFlightPayloadData = _require4.refineToReactFlightPayloadData,
|
|
58
|
+
REACT_FLIGHT_QUERIES_STORAGE_KEY = _require4.REACT_FLIGHT_QUERIES_STORAGE_KEY,
|
|
59
|
+
REACT_FLIGHT_TREE_STORAGE_KEY = _require4.REACT_FLIGHT_TREE_STORAGE_KEY,
|
|
60
|
+
REACT_FLIGHT_TYPE_NAME = _require4.REACT_FLIGHT_TYPE_NAME;
|
|
61
|
+
|
|
62
|
+
var _require5 = require('./RelayStoreUtils'),
|
|
63
|
+
getArgumentValues = _require5.getArgumentValues,
|
|
64
|
+
getHandleStorageKey = _require5.getHandleStorageKey,
|
|
65
|
+
getModuleComponentKey = _require5.getModuleComponentKey,
|
|
66
|
+
getModuleOperationKey = _require5.getModuleOperationKey,
|
|
67
|
+
getStorageKey = _require5.getStorageKey,
|
|
68
|
+
TYPENAME_KEY = _require5.TYPENAME_KEY,
|
|
69
|
+
ROOT_ID = _require5.ROOT_ID,
|
|
70
|
+
ROOT_TYPE = _require5.ROOT_TYPE;
|
|
71
|
+
|
|
72
|
+
var _require6 = require('./TypeID'),
|
|
73
|
+
generateTypeID = _require6.generateTypeID,
|
|
74
|
+
TYPE_SCHEMA_TYPE = _require6.TYPE_SCHEMA_TYPE;
|
|
59
75
|
|
|
60
76
|
/**
|
|
61
77
|
* Normalizes the results of a query and standard GraphQL response, writing the
|
|
@@ -87,6 +103,7 @@ var RelayResponseNormalizer = /*#__PURE__*/function () {
|
|
|
87
103
|
this._path = options.path ? (0, _toConsumableArray2["default"])(options.path) : [];
|
|
88
104
|
this._recordSource = recordSource;
|
|
89
105
|
this._variables = variables;
|
|
106
|
+
this._reactFlightPayloadDeserializer = options.reactFlightPayloadDeserializer;
|
|
90
107
|
}
|
|
91
108
|
|
|
92
109
|
var _proto = RelayResponseNormalizer.prototype;
|
|
@@ -252,6 +269,15 @@ var RelayResponseNormalizer = /*#__PURE__*/function () {
|
|
|
252
269
|
this._isClientExtension = isClientExtension;
|
|
253
270
|
break;
|
|
254
271
|
|
|
272
|
+
case FLIGHT_FIELD:
|
|
273
|
+
if (RelayFeatureFlags.ENABLE_REACT_FLIGHT_COMPONENT_FIELD) {
|
|
274
|
+
this._normalizeFlightField(node, selection, record, data);
|
|
275
|
+
} else {
|
|
276
|
+
throw new Error('Flight fields are not yet supported.');
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
break;
|
|
280
|
+
|
|
255
281
|
default:
|
|
256
282
|
selection;
|
|
257
283
|
!false ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayResponseNormalizer(): Unexpected ast kind `%s`.', selection.kind) : invariant(false) : void 0;
|
|
@@ -366,8 +392,10 @@ var RelayResponseNormalizer = /*#__PURE__*/function () {
|
|
|
366
392
|
}
|
|
367
393
|
}
|
|
368
394
|
|
|
369
|
-
if (
|
|
370
|
-
|
|
395
|
+
if (process.env.NODE_ENV !== "production") {
|
|
396
|
+
if (selection.kind === SCALAR_FIELD) {
|
|
397
|
+
this._validateConflictingFieldsWithIdenticalId(record, storageKey, fieldValue);
|
|
398
|
+
}
|
|
371
399
|
}
|
|
372
400
|
|
|
373
401
|
RelayModernRecord.setValue(record, storageKey, null);
|
|
@@ -375,7 +403,9 @@ var RelayResponseNormalizer = /*#__PURE__*/function () {
|
|
|
375
403
|
}
|
|
376
404
|
|
|
377
405
|
if (selection.kind === SCALAR_FIELD) {
|
|
378
|
-
|
|
406
|
+
if (process.env.NODE_ENV !== "production") {
|
|
407
|
+
this._validateConflictingFieldsWithIdenticalId(record, storageKey, fieldValue);
|
|
408
|
+
}
|
|
379
409
|
|
|
380
410
|
RelayModernRecord.setValue(record, storageKey, fieldValue);
|
|
381
411
|
} else if (selection.kind === LINKED_FIELD) {
|
|
@@ -394,6 +424,70 @@ var RelayResponseNormalizer = /*#__PURE__*/function () {
|
|
|
394
424
|
}
|
|
395
425
|
};
|
|
396
426
|
|
|
427
|
+
_proto._normalizeFlightField = function _normalizeFlightField(parent, selection, record, data) {
|
|
428
|
+
var responseKey = selection.alias || selection.name;
|
|
429
|
+
var storageKey = getStorageKey(selection, this._variables);
|
|
430
|
+
var fieldValue = data[responseKey];
|
|
431
|
+
|
|
432
|
+
if (fieldValue == null) {
|
|
433
|
+
RelayModernRecord.setValue(record, storageKey, null);
|
|
434
|
+
return;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
var reactFlightPayload = refineToReactFlightPayloadData(fieldValue);
|
|
438
|
+
!(reactFlightPayload != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayResponseNormalizer(): Expected React Flight payload data ' + 'to be an object with `tree` and `queries` properties, got `%s`.', fieldValue) : invariant(false) : void 0;
|
|
439
|
+
!(typeof this._reactFlightPayloadDeserializer === 'function') ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayResponseNormalizer: Expected reactFlightPayloadDeserializer to ' + 'be a function, got `%s`.', this._reactFlightPayloadDeserializer) : invariant(false) : void 0; // We store the deserialized reactFlightClientResponse in a separate
|
|
440
|
+
// record and link it to the parent record. This is so we can GC the Flight
|
|
441
|
+
// tree later even if the parent record is still reachable.
|
|
442
|
+
|
|
443
|
+
var reactFlightClientResponse = this._reactFlightPayloadDeserializer(reactFlightPayload.tree);
|
|
444
|
+
|
|
445
|
+
var reactFlightID = generateClientID(RelayModernRecord.getDataID(record), getStorageKey(selection, this._variables));
|
|
446
|
+
|
|
447
|
+
var reactFlightClientResponseRecord = this._recordSource.get(reactFlightID);
|
|
448
|
+
|
|
449
|
+
if (reactFlightClientResponseRecord == null) {
|
|
450
|
+
reactFlightClientResponseRecord = RelayModernRecord.create(reactFlightID, REACT_FLIGHT_TYPE_NAME);
|
|
451
|
+
|
|
452
|
+
this._recordSource.set(reactFlightID, reactFlightClientResponseRecord);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
RelayModernRecord.setValue(reactFlightClientResponseRecord, REACT_FLIGHT_TREE_STORAGE_KEY, reactFlightClientResponse);
|
|
456
|
+
var reachableQueries = [];
|
|
457
|
+
|
|
458
|
+
var _iterator = _createForOfIteratorHelper(reactFlightPayload.queries),
|
|
459
|
+
_step;
|
|
460
|
+
|
|
461
|
+
try {
|
|
462
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
463
|
+
var query = _step.value;
|
|
464
|
+
|
|
465
|
+
if (query.response.data != null) {
|
|
466
|
+
this._moduleImportPayloads.push({
|
|
467
|
+
data: query.response.data,
|
|
468
|
+
dataID: ROOT_ID,
|
|
469
|
+
operationReference: query.module,
|
|
470
|
+
path: [],
|
|
471
|
+
typeName: ROOT_TYPE,
|
|
472
|
+
variables: query.variables
|
|
473
|
+
});
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
reachableQueries.push({
|
|
477
|
+
module: query.module,
|
|
478
|
+
variables: query.variables
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
} catch (err) {
|
|
482
|
+
_iterator.e(err);
|
|
483
|
+
} finally {
|
|
484
|
+
_iterator.f();
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
RelayModernRecord.setValue(reactFlightClientResponseRecord, REACT_FLIGHT_QUERIES_STORAGE_KEY, reachableQueries);
|
|
488
|
+
RelayModernRecord.setLinkedRecordID(record, storageKey, reactFlightID);
|
|
489
|
+
};
|
|
490
|
+
|
|
397
491
|
_proto._normalizeLink = function _normalizeLink(field, record, storageKey, fieldValue) {
|
|
398
492
|
var _field$concreteType;
|
|
399
493
|
|
|
@@ -463,10 +557,14 @@ var RelayResponseNormalizer = /*#__PURE__*/function () {
|
|
|
463
557
|
_this._recordSource.set(nextID, nextRecord);
|
|
464
558
|
} else if (process.env.NODE_ENV !== "production") {
|
|
465
559
|
_this._validateRecordType(nextRecord, field, item);
|
|
466
|
-
}
|
|
560
|
+
} // NOTE: the check to strip __DEV__ code only works for simple
|
|
561
|
+
// `if (__DEV__)`
|
|
467
562
|
|
|
468
|
-
|
|
469
|
-
|
|
563
|
+
|
|
564
|
+
if (process.env.NODE_ENV !== "production") {
|
|
565
|
+
if (prevIDs) {
|
|
566
|
+
_this._validateConflictingLinkedFieldsWithIdenticalId(record, prevIDs[nextIndex], nextID, storageKey);
|
|
567
|
+
}
|
|
470
568
|
} // $FlowFixMe[incompatible-variance]
|
|
471
569
|
|
|
472
570
|
|
|
@@ -494,10 +592,11 @@ var RelayResponseNormalizer = /*#__PURE__*/function () {
|
|
|
494
592
|
;
|
|
495
593
|
|
|
496
594
|
_proto._validateConflictingFieldsWithIdenticalId = function _validateConflictingFieldsWithIdenticalId(record, storageKey, fieldValue) {
|
|
595
|
+
// NOTE: Only call this function in DEV
|
|
497
596
|
if (process.env.NODE_ENV !== "production") {
|
|
498
597
|
var dataID = RelayModernRecord.getDataID(record);
|
|
499
598
|
var previousValue = RelayModernRecord.getValue(record, storageKey);
|
|
500
|
-
process.env.NODE_ENV !== "production" ? warning(storageKey === TYPENAME_KEY || previousValue === undefined || previousValue
|
|
599
|
+
process.env.NODE_ENV !== "production" ? warning(storageKey === TYPENAME_KEY || previousValue === undefined || areEqual(previousValue, fieldValue), 'RelayResponseNormalizer: Invalid record. The record contains two ' + 'instances of the same id: `%s` with conflicting field, %s and its values: %s and %s. ' + 'If two fields are different but share ' + 'the same id, one field will overwrite the other.', dataID, storageKey, previousValue, fieldValue) : void 0;
|
|
501
600
|
}
|
|
502
601
|
}
|
|
503
602
|
/**
|
|
@@ -506,6 +605,7 @@ var RelayResponseNormalizer = /*#__PURE__*/function () {
|
|
|
506
605
|
;
|
|
507
606
|
|
|
508
607
|
_proto._validateConflictingLinkedFieldsWithIdenticalId = function _validateConflictingLinkedFieldsWithIdenticalId(record, prevID, nextID, storageKey) {
|
|
608
|
+
// NOTE: Only call this function in DEV
|
|
509
609
|
if (process.env.NODE_ENV !== "production") {
|
|
510
610
|
process.env.NODE_ENV !== "production" ? warning(prevID === undefined || prevID === nextID, 'RelayResponseNormalizer: Invalid record. The record contains ' + 'references to the conflicting field, %s and its id values: %s and %s. ' + 'We need to make sure that the record the field points ' + 'to remains consistent or one field will overwrite the other.', storageKey, prevID, nextID) : void 0;
|
|
511
611
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
// flowlint ambiguous-object-type:error
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
var invariant = require("fbjs/lib/invariant");
|
|
14
|
+
|
|
15
|
+
var _require = require('./RelayModernRecord'),
|
|
16
|
+
getType = _require.getType;
|
|
17
|
+
|
|
18
|
+
var REACT_FLIGHT_QUERIES_STORAGE_KEY = 'queries';
|
|
19
|
+
var REACT_FLIGHT_TREE_STORAGE_KEY = 'tree';
|
|
20
|
+
var REACT_FLIGHT_TYPE_NAME = 'ReactFlightComponent';
|
|
21
|
+
|
|
22
|
+
function refineToReactFlightPayloadData(payload) {
|
|
23
|
+
if (payload == null || typeof payload !== 'object' || !Array.isArray(payload.tree) || !Array.isArray(payload.queries)) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
return payload;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function getReactFlightClientResponse(record) {
|
|
31
|
+
!(getType(record) === REACT_FLIGHT_TYPE_NAME) ? process.env.NODE_ENV !== "production" ? invariant(false, 'getReactFlightClientResponse(): Expected a ReactFlightComponentRecord, ' + 'got %s.', record) : invariant(false) : void 0;
|
|
32
|
+
var response = record[REACT_FLIGHT_TREE_STORAGE_KEY];
|
|
33
|
+
|
|
34
|
+
if (response != null) {
|
|
35
|
+
return response;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
module.exports = {
|
|
42
|
+
REACT_FLIGHT_QUERIES_STORAGE_KEY: REACT_FLIGHT_QUERIES_STORAGE_KEY,
|
|
43
|
+
REACT_FLIGHT_TREE_STORAGE_KEY: REACT_FLIGHT_TREE_STORAGE_KEY,
|
|
44
|
+
REACT_FLIGHT_TYPE_NAME: REACT_FLIGHT_TYPE_NAME,
|
|
45
|
+
getReactFlightClientResponse: getReactFlightClientResponse,
|
|
46
|
+
refineToReactFlightPayloadData: refineToReactFlightPayloadData
|
|
47
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
'use strict';
|
|
11
|
+
|
|
12
|
+
var defaultRequiredFieldLogger = function defaultRequiredFieldLogger(event) {
|
|
13
|
+
if (process.env.NODE_ENV !== "production" && event.kind === 'missing_field.log') {
|
|
14
|
+
throw new Error('Relay Environment Configuration Error (dev only): `@required(action: LOG)` requires that the Relay Environment be configured with a `requiredFieldLogger`.');
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
module.exports = defaultRequiredFieldLogger;
|
|
@@ -31,7 +31,7 @@ function normalizeRelayPayload(selector, payload, errors, options) {
|
|
|
31
31
|
var source = RelayRecordSource.create();
|
|
32
32
|
source.set(selector.dataID, RelayModernRecord.create(selector.dataID, ROOT_TYPE));
|
|
33
33
|
var relayPayload = RelayResponseNormalizer.normalize(source, selector, payload, options);
|
|
34
|
-
return _objectSpread({}, relayPayload, {
|
|
34
|
+
return _objectSpread(_objectSpread({}, relayPayload), {}, {
|
|
35
35
|
errors: errors
|
|
36
36
|
});
|
|
37
37
|
}
|
|
@@ -33,7 +33,7 @@ function requestSubscription(environment, config) {
|
|
|
33
33
|
onNext = config.onNext,
|
|
34
34
|
variables = config.variables,
|
|
35
35
|
cacheConfig = config.cacheConfig;
|
|
36
|
-
var operation = createOperationDescriptor(subscription, variables);
|
|
36
|
+
var operation = createOperationDescriptor(subscription, variables, cacheConfig);
|
|
37
37
|
process.env.NODE_ENV !== "production" ? warning(!(config.updater && configs), 'requestSubscription: Expected only one of `updater` and `configs` to be provided') : void 0;
|
|
38
38
|
|
|
39
39
|
var _ref = configs ? RelayDeclarativeMutationConfig.convert(configs, subscription, null
|
|
@@ -43,8 +43,7 @@ function requestSubscription(environment, config) {
|
|
|
43
43
|
|
|
44
44
|
var sub = environment.execute({
|
|
45
45
|
operation: operation,
|
|
46
|
-
updater: updater
|
|
47
|
-
cacheConfig: cacheConfig
|
|
46
|
+
updater: updater
|
|
48
47
|
}).map(function () {
|
|
49
48
|
var data = environment.lookup(operation.fragment).data; // $FlowFixMe[incompatible-cast]
|
|
50
49
|
|
|
@@ -28,6 +28,7 @@ var RelayConcreteNode = {
|
|
|
28
28
|
CLIENT_EXTENSION: 'ClientExtension',
|
|
29
29
|
DEFER: 'Defer',
|
|
30
30
|
CONNECTION: 'Connection',
|
|
31
|
+
FLIGHT_FIELD: 'FlightField',
|
|
31
32
|
FRAGMENT: 'Fragment',
|
|
32
33
|
FRAGMENT_SPREAD: 'FragmentSpread',
|
|
33
34
|
INLINE_DATA_FRAGMENT_SPREAD: 'InlineDataFragmentSpread',
|
|
@@ -39,6 +40,7 @@ var RelayConcreteNode = {
|
|
|
39
40
|
LIST_VALUE: 'ListValue',
|
|
40
41
|
LOCAL_ARGUMENT: 'LocalArgument',
|
|
41
42
|
MODULE_IMPORT: 'ModuleImport',
|
|
43
|
+
REQUIRED_FIELD: 'RequiredField',
|
|
42
44
|
OBJECT_VALUE: 'ObjectValue',
|
|
43
45
|
OPERATION: 'Operation',
|
|
44
46
|
REQUEST: 'Request',
|
|
@@ -11,10 +11,13 @@
|
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
13
|
var RelayFeatureFlags = {
|
|
14
|
-
// T45504512: new connection model
|
|
15
14
|
ENABLE_VARIABLE_CONNECTION_KEY: false,
|
|
16
15
|
ENABLE_PARTIAL_RENDERING_DEFAULT: false,
|
|
17
16
|
ENABLE_RELAY_CONTAINERS_SUSPENSE: false,
|
|
18
|
-
ENABLE_PRECISE_TYPE_REFINEMENT: false
|
|
17
|
+
ENABLE_PRECISE_TYPE_REFINEMENT: false,
|
|
18
|
+
ENABLE_REACT_FLIGHT_COMPONENT_FIELD: false,
|
|
19
|
+
ENABLE_REQUIRED_DIRECTIVES: false,
|
|
20
|
+
ENABLE_GETFRAGMENTIDENTIFIER_OPTIMIZATION: false,
|
|
21
|
+
ENABLE_FRIENDLY_QUERY_NAME_GQL_URL: false
|
|
19
22
|
};
|
|
20
23
|
module.exports = RelayFeatureFlags;
|
|
@@ -11,6 +11,10 @@
|
|
|
11
11
|
// flowlint ambiguous-object-type:error
|
|
12
12
|
'use strict';
|
|
13
13
|
|
|
14
|
+
var RelayFeatureFlags = require('./RelayFeatureFlags');
|
|
15
|
+
|
|
16
|
+
var isEmptyObject = require('./isEmptyObject');
|
|
17
|
+
|
|
14
18
|
var stableCopy = require('./stableCopy');
|
|
15
19
|
|
|
16
20
|
var _require = require('../store/RelayModernSelector'),
|
|
@@ -19,15 +23,20 @@ var _require = require('../store/RelayModernSelector'),
|
|
|
19
23
|
getSelector = _require.getSelector;
|
|
20
24
|
|
|
21
25
|
function getFragmentIdentifier(fragmentNode, fragmentRef) {
|
|
22
|
-
var _JSON$stringify;
|
|
23
|
-
|
|
24
26
|
var selector = getSelector(fragmentNode, fragmentRef);
|
|
25
27
|
var fragmentOwnerIdentifier = selector == null ? 'null' : selector.kind === 'SingularReaderSelector' ? selector.owner.identifier : '[' + selector.selectors.map(function (sel) {
|
|
26
28
|
return sel.owner.identifier;
|
|
27
29
|
}).join(',') + ']';
|
|
28
30
|
var fragmentVariables = getVariablesFromFragment(fragmentNode, fragmentRef);
|
|
29
31
|
var dataIDs = getDataIDsFromFragment(fragmentNode, fragmentRef);
|
|
30
|
-
|
|
32
|
+
|
|
33
|
+
if (RelayFeatureFlags.ENABLE_GETFRAGMENTIDENTIFIER_OPTIMIZATION) {
|
|
34
|
+
return fragmentOwnerIdentifier + '/' + fragmentNode.name + '/' + (fragmentVariables == null || isEmptyObject(fragmentVariables) ? '{}' : JSON.stringify(stableCopy(fragmentVariables))) + '/' + (typeof dataIDs === 'undefined' ? 'missing' : dataIDs == null ? 'null' : Array.isArray(dataIDs) ? '[' + dataIDs.join(',') + ']' : dataIDs);
|
|
35
|
+
} else {
|
|
36
|
+
var _JSON$stringify;
|
|
37
|
+
|
|
38
|
+
return fragmentOwnerIdentifier + '/' + fragmentNode.name + '/' + JSON.stringify(stableCopy(fragmentVariables)) + '/' + ((_JSON$stringify = JSON.stringify(dataIDs)) !== null && _JSON$stringify !== void 0 ? _JSON$stringify : 'missing');
|
|
39
|
+
}
|
|
31
40
|
}
|
|
32
41
|
|
|
33
42
|
module.exports = getFragmentIdentifier;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @format
|
|
9
|
+
* @emails oncall+relay
|
|
10
|
+
*/
|
|
11
|
+
// flowlint ambiguous-object-type:error
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
var _require = require('./RelayConcreteNode'),
|
|
15
|
+
REQUEST = _require.REQUEST,
|
|
16
|
+
SPLIT_OPERATION = _require.SPLIT_OPERATION;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* OperationLoaders can return either a NormalizationSplitOperation or
|
|
20
|
+
* ConcreteRequest.
|
|
21
|
+
*/
|
|
22
|
+
function getOperation(node) {
|
|
23
|
+
switch (node.kind) {
|
|
24
|
+
case REQUEST:
|
|
25
|
+
return node.operation;
|
|
26
|
+
|
|
27
|
+
case SPLIT_OPERATION:
|
|
28
|
+
default:
|
|
29
|
+
return node;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
module.exports = getOperation;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @format
|
|
9
|
+
* @emails oncall+relay
|
|
10
|
+
*/
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
14
|
+
|
|
15
|
+
function isEmptyObject(obj) {
|
|
16
|
+
for (var _key in obj) {
|
|
17
|
+
if (hasOwnProperty.call(obj, _key)) {
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
module.exports = isEmptyObject;
|
|
@@ -9,12 +9,15 @@
|
|
|
9
9
|
*/
|
|
10
10
|
// flowlint ambiguous-object-type:error
|
|
11
11
|
'use strict';
|
|
12
|
+
|
|
13
|
+
var hasWeakSetDefined = typeof WeakSet !== 'undefined';
|
|
14
|
+
var hasWeakMapDefined = typeof WeakMap !== 'undefined';
|
|
12
15
|
/**
|
|
13
16
|
* Recycles subtrees from `prevData` by replacing equal subtrees in `nextData`.
|
|
14
17
|
*/
|
|
15
18
|
|
|
16
19
|
function recycleNodesInto(prevData, nextData) {
|
|
17
|
-
if (prevData === nextData || typeof prevData !== 'object' || !prevData || typeof nextData !== 'object' || !nextData) {
|
|
20
|
+
if (prevData === nextData || typeof prevData !== 'object' || prevData instanceof Set || prevData instanceof Map || hasWeakSetDefined && prevData instanceof WeakSet || hasWeakMapDefined && prevData instanceof WeakMap || !prevData || typeof nextData !== 'object' || nextData instanceof Set || nextData instanceof Map || hasWeakSetDefined && nextData instanceof WeakSet || hasWeakMapDefined && nextData instanceof WeakMap || !nextData) {
|
|
18
21
|
return nextData;
|
|
19
22
|
}
|
|
20
23
|
|