relay-runtime 10.0.0 → 10.1.2
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 +121 -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 +147 -14
- package/lib/index.js +7 -0
- package/lib/mutations/RelayDeclarativeMutationConfig.js +5 -7
- package/lib/mutations/commitMutation.js +1 -4
- package/lib/mutations/validateMutation.js +28 -12
- package/lib/network/RelayQueryResponseCache.js +3 -7
- 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 +85 -10
- package/lib/store/RelayConcreteVariables.js +2 -6
- package/lib/store/RelayModernEnvironment.js +81 -72
- package/lib/store/RelayModernFragmentSpecResolver.js +14 -7
- package/lib/store/RelayModernOperationDescriptor.js +6 -5
- package/lib/store/RelayModernQueryExecutor.js +46 -33
- package/lib/store/RelayModernRecord.js +3 -7
- package/lib/store/RelayModernStore.js +45 -143
- package/lib/store/RelayOperationTracker.js +7 -9
- package/lib/store/RelayOptimisticRecordSource.js +2 -6
- package/lib/store/RelayPublishQueue.js +1 -1
- package/lib/store/RelayReader.js +200 -49
- package/lib/store/RelayRecordSourceMapImpl.js +3 -5
- package/lib/store/RelayReferenceMarker.js +87 -5
- package/lib/store/RelayResponseNormalizer.js +123 -54
- package/lib/store/RelayStoreReactFlightUtils.js +47 -0
- package/lib/store/RelayStoreSubscriptions.js +162 -0
- package/lib/store/RelayStoreSubscriptionsUsingMapByID.js +258 -0
- package/lib/store/StoreInspector.js +3 -9
- package/lib/store/createRelayContext.js +5 -0
- package/lib/store/defaultRequiredFieldLogger.js +18 -0
- package/lib/store/normalizeRelayPayload.js +2 -6
- 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 +6 -2
- package/lib/util/createPayloadFor3DField.js +2 -7
- 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 +6 -9
- 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 +107 -87
- 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 +40 -114
- package/store/RelayPublishQueue.js.flow +1 -1
- package/store/RelayReader.js.flow +184 -27
- package/store/RelayReferenceMarker.js.flow +72 -5
- package/store/RelayResponseNormalizer.js.flow +140 -50
- package/store/RelayStoreReactFlightUtils.js.flow +64 -0
- package/store/RelayStoreSubscriptions.js.flow +168 -0
- package/store/RelayStoreSubscriptionsUsingMapByID.js.flow +259 -0
- package/store/RelayStoreTypes.js.flow +130 -37
- package/store/StoreInspector.js.flow +1 -3
- package/store/createRelayContext.js.flow +3 -0
- 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 +10 -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 +13 -8
- package/util/reportMissingRequiredFields.js.flow +51 -0
|
@@ -0,0 +1,258 @@
|
|
|
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 RelayReader = require('./RelayReader');
|
|
14
|
+
|
|
15
|
+
var deepFreeze = require('../util/deepFreeze');
|
|
16
|
+
|
|
17
|
+
var recycleNodesInto = require('../util/recycleNodesInto');
|
|
18
|
+
|
|
19
|
+
var RelayStoreSubscriptionsUsingMapByID = /*#__PURE__*/function () {
|
|
20
|
+
function RelayStoreSubscriptionsUsingMapByID() {
|
|
21
|
+
this._notifiedRevision = 0;
|
|
22
|
+
this._snapshotRevision = 0;
|
|
23
|
+
this._subscriptionsByDataId = new Map();
|
|
24
|
+
this._staleSubscriptions = new Set();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
var _proto = RelayStoreSubscriptionsUsingMapByID.prototype;
|
|
28
|
+
|
|
29
|
+
_proto.subscribe = function subscribe(snapshot, callback) {
|
|
30
|
+
var _this = this;
|
|
31
|
+
|
|
32
|
+
var subscription = {
|
|
33
|
+
backup: null,
|
|
34
|
+
callback: callback,
|
|
35
|
+
notifiedRevision: this._notifiedRevision,
|
|
36
|
+
snapshotRevision: this._snapshotRevision,
|
|
37
|
+
snapshot: snapshot
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
var dispose = function dispose() {
|
|
41
|
+
for (var dataId in snapshot.seenRecords) {
|
|
42
|
+
var subscriptionsForDataId = _this._subscriptionsByDataId.get(dataId);
|
|
43
|
+
|
|
44
|
+
if (subscriptionsForDataId != null) {
|
|
45
|
+
subscriptionsForDataId["delete"](subscription);
|
|
46
|
+
|
|
47
|
+
if (subscriptionsForDataId.size === 0) {
|
|
48
|
+
_this._subscriptionsByDataId["delete"](dataId);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
for (var dataId in snapshot.seenRecords) {
|
|
55
|
+
var subscriptionsForDataId = this._subscriptionsByDataId.get(dataId);
|
|
56
|
+
|
|
57
|
+
if (subscriptionsForDataId != null) {
|
|
58
|
+
subscriptionsForDataId.add(subscription);
|
|
59
|
+
} else {
|
|
60
|
+
this._subscriptionsByDataId.set(dataId, new Set([subscription]));
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
dispose: dispose
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
_proto.snapshotSubscriptions = function snapshotSubscriptions(source) {
|
|
70
|
+
var _this2 = this;
|
|
71
|
+
|
|
72
|
+
this._snapshotRevision++;
|
|
73
|
+
|
|
74
|
+
this._subscriptionsByDataId.forEach(function (subscriptions) {
|
|
75
|
+
subscriptions.forEach(function (subscription) {
|
|
76
|
+
if (subscription.snapshotRevision === _this2._snapshotRevision) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
subscription.snapshotRevision = _this2._snapshotRevision; // Backup occurs after writing a new "final" payload(s) and before (re)applying
|
|
81
|
+
// optimistic changes. Each subscription's `snapshot` represents what was *last
|
|
82
|
+
// published to the subscriber*, which notably may include previous optimistic
|
|
83
|
+
// updates. Therefore a subscription can be in any of the following states:
|
|
84
|
+
// - stale=true: This subscription was restored to a different value than
|
|
85
|
+
// `snapshot`. That means this subscription has changes relative to its base,
|
|
86
|
+
// but its base has changed (we just applied a final payload): recompute
|
|
87
|
+
// a backup so that we can later restore to the state the subscription
|
|
88
|
+
// should be in.
|
|
89
|
+
// - stale=false: This subscription was restored to the same value than
|
|
90
|
+
// `snapshot`. That means this subscription does *not* have changes relative
|
|
91
|
+
// to its base, so the current `snapshot` is valid to use as a backup.
|
|
92
|
+
|
|
93
|
+
if (!_this2._staleSubscriptions.has(subscription)) {
|
|
94
|
+
subscription.backup = subscription.snapshot;
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
var snapshot = subscription.snapshot;
|
|
99
|
+
var backup = RelayReader.read(source, snapshot.selector);
|
|
100
|
+
var nextData = recycleNodesInto(snapshot.data, backup.data);
|
|
101
|
+
backup.data = nextData; // backup owns the snapshot and can safely mutate
|
|
102
|
+
|
|
103
|
+
subscription.backup = backup;
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
_proto.restoreSubscriptions = function restoreSubscriptions() {
|
|
109
|
+
var _this3 = this;
|
|
110
|
+
|
|
111
|
+
this._snapshotRevision++;
|
|
112
|
+
|
|
113
|
+
this._subscriptionsByDataId.forEach(function (subscriptions) {
|
|
114
|
+
subscriptions.forEach(function (subscription) {
|
|
115
|
+
if (subscription.snapshotRevision === _this3._snapshotRevision) {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
subscription.snapshotRevision = _this3._snapshotRevision;
|
|
120
|
+
var backup = subscription.backup;
|
|
121
|
+
subscription.backup = null;
|
|
122
|
+
|
|
123
|
+
if (backup) {
|
|
124
|
+
if (backup.data !== subscription.snapshot.data) {
|
|
125
|
+
_this3._staleSubscriptions.add(subscription);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
var prevSeenRecords = subscription.snapshot.seenRecords;
|
|
129
|
+
subscription.snapshot = {
|
|
130
|
+
data: subscription.snapshot.data,
|
|
131
|
+
isMissingData: backup.isMissingData,
|
|
132
|
+
seenRecords: backup.seenRecords,
|
|
133
|
+
selector: backup.selector,
|
|
134
|
+
missingRequiredFields: backup.missingRequiredFields
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
_this3._updateSubscriptionsMap(subscription, prevSeenRecords);
|
|
138
|
+
} else {
|
|
139
|
+
_this3._staleSubscriptions.add(subscription);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
_proto.updateSubscriptions = function updateSubscriptions(source, updatedRecordIDs, updatedOwners) {
|
|
146
|
+
var _this4 = this;
|
|
147
|
+
|
|
148
|
+
this._notifiedRevision++;
|
|
149
|
+
Object.keys(updatedRecordIDs).forEach(function (updatedRecordId) {
|
|
150
|
+
var subcriptionsForDataId = _this4._subscriptionsByDataId.get(updatedRecordId);
|
|
151
|
+
|
|
152
|
+
if (subcriptionsForDataId == null) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
subcriptionsForDataId.forEach(function (subscription) {
|
|
157
|
+
if (subscription.notifiedRevision === _this4._notifiedRevision) {
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
var owner = _this4._updateSubscription(source, subscription, false);
|
|
162
|
+
|
|
163
|
+
if (owner != null) {
|
|
164
|
+
updatedOwners.push(owner);
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
this._staleSubscriptions.forEach(function (subscription) {
|
|
170
|
+
if (subscription.notifiedRevision === _this4._notifiedRevision) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
var owner = _this4._updateSubscription(source, subscription, true);
|
|
175
|
+
|
|
176
|
+
if (owner != null) {
|
|
177
|
+
updatedOwners.push(owner);
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
this._staleSubscriptions.clear();
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Notifies the callback for the subscription if the data for the associated
|
|
185
|
+
* snapshot has changed.
|
|
186
|
+
* Additionally, updates the subscription snapshot with the latest snapshot,
|
|
187
|
+
* amarks it as not stale, and updates the subscription tracking for any
|
|
188
|
+
* any new ids observed in the latest data snapshot.
|
|
189
|
+
* Returns the owner (RequestDescriptor) if the subscription was affected by the
|
|
190
|
+
* latest update, or null if it was not affected.
|
|
191
|
+
*/
|
|
192
|
+
;
|
|
193
|
+
|
|
194
|
+
_proto._updateSubscription = function _updateSubscription(source, subscription, stale) {
|
|
195
|
+
var backup = subscription.backup,
|
|
196
|
+
callback = subscription.callback,
|
|
197
|
+
snapshot = subscription.snapshot;
|
|
198
|
+
var nextSnapshot = stale && backup != null ? backup : RelayReader.read(source, snapshot.selector);
|
|
199
|
+
var nextData = recycleNodesInto(snapshot.data, nextSnapshot.data);
|
|
200
|
+
nextSnapshot = {
|
|
201
|
+
data: nextData,
|
|
202
|
+
isMissingData: nextSnapshot.isMissingData,
|
|
203
|
+
seenRecords: nextSnapshot.seenRecords,
|
|
204
|
+
selector: nextSnapshot.selector,
|
|
205
|
+
missingRequiredFields: nextSnapshot.missingRequiredFields
|
|
206
|
+
};
|
|
207
|
+
|
|
208
|
+
if (process.env.NODE_ENV !== "production") {
|
|
209
|
+
deepFreeze(nextSnapshot);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
var prevSeenRecords = subscription.snapshot.seenRecords;
|
|
213
|
+
subscription.snapshot = nextSnapshot;
|
|
214
|
+
subscription.notifiedRevision = this._notifiedRevision;
|
|
215
|
+
|
|
216
|
+
this._updateSubscriptionsMap(subscription, prevSeenRecords);
|
|
217
|
+
|
|
218
|
+
if (nextSnapshot.data !== snapshot.data) {
|
|
219
|
+
callback(nextSnapshot);
|
|
220
|
+
return snapshot.selector.owner;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Updates the Map that tracks subscriptions by id.
|
|
225
|
+
* Given an updated subscription and the records that where seen
|
|
226
|
+
* on the previous subscription snapshot, updates our tracking
|
|
227
|
+
* to track the subscription for the newly and no longer seen ids.
|
|
228
|
+
*/
|
|
229
|
+
;
|
|
230
|
+
|
|
231
|
+
_proto._updateSubscriptionsMap = function _updateSubscriptionsMap(subscription, prevSeenRecords) {
|
|
232
|
+
for (var dataId in prevSeenRecords) {
|
|
233
|
+
var subscriptionsForDataId = this._subscriptionsByDataId.get(dataId);
|
|
234
|
+
|
|
235
|
+
if (subscriptionsForDataId != null) {
|
|
236
|
+
subscriptionsForDataId["delete"](subscription);
|
|
237
|
+
|
|
238
|
+
if (subscriptionsForDataId.size === 0) {
|
|
239
|
+
this._subscriptionsByDataId["delete"](dataId);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
for (var _dataId in subscription.snapshot.seenRecords) {
|
|
245
|
+
var _subscriptionsForDataId = this._subscriptionsByDataId.get(_dataId);
|
|
246
|
+
|
|
247
|
+
if (_subscriptionsForDataId != null) {
|
|
248
|
+
_subscriptionsForDataId.add(subscription);
|
|
249
|
+
} else {
|
|
250
|
+
this._subscriptionsByDataId.set(_dataId, new Set([subscription]));
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
return RelayStoreSubscriptionsUsingMapByID;
|
|
256
|
+
}();
|
|
257
|
+
|
|
258
|
+
module.exports = RelayStoreSubscriptionsUsingMapByID;
|
|
@@ -13,14 +13,10 @@
|
|
|
13
13
|
|
|
14
14
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
15
15
|
|
|
16
|
-
var
|
|
16
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
17
17
|
|
|
18
18
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
19
19
|
|
|
20
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
21
|
-
|
|
22
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
23
|
-
|
|
24
20
|
var inspect = function inspect() {};
|
|
25
21
|
|
|
26
22
|
if (process.env.NODE_ENV !== "production") {
|
|
@@ -138,7 +134,7 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
138
134
|
return record;
|
|
139
135
|
}
|
|
140
136
|
|
|
141
|
-
return new Proxy(
|
|
137
|
+
return new Proxy((0, _objectSpread2["default"])({}, record), {
|
|
142
138
|
get: function get(target, prop) {
|
|
143
139
|
var value = target[prop];
|
|
144
140
|
|
|
@@ -152,9 +148,7 @@ if (process.env.NODE_ENV !== "production") {
|
|
|
152
148
|
}
|
|
153
149
|
|
|
154
150
|
if (Array.isArray(value.__refs)) {
|
|
155
|
-
|
|
156
|
-
* suppresses an error found when Flow v0.111.0 was deployed. To
|
|
157
|
-
* see the error, delete this comment and run Flow. */
|
|
151
|
+
// $FlowFixMe[incompatible-call]
|
|
158
152
|
return value.__refs.map(function (ref) {
|
|
159
153
|
return getWrappedRecord(source, ref);
|
|
160
154
|
});
|
|
@@ -18,6 +18,11 @@ var firstReact;
|
|
|
18
18
|
function createRelayContext(react) {
|
|
19
19
|
if (!relayContext) {
|
|
20
20
|
relayContext = react.createContext(null);
|
|
21
|
+
|
|
22
|
+
if (process.env.NODE_ENV !== "production") {
|
|
23
|
+
relayContext.displayName = 'RelayContext';
|
|
24
|
+
}
|
|
25
|
+
|
|
21
26
|
firstReact = react;
|
|
22
27
|
}
|
|
23
28
|
|
|
@@ -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;
|
|
@@ -12,11 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
14
14
|
|
|
15
|
-
var
|
|
16
|
-
|
|
17
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
18
|
-
|
|
19
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
15
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
20
16
|
|
|
21
17
|
var RelayModernRecord = require('./RelayModernRecord');
|
|
22
18
|
|
|
@@ -31,7 +27,7 @@ function normalizeRelayPayload(selector, payload, errors, options) {
|
|
|
31
27
|
var source = RelayRecordSource.create();
|
|
32
28
|
source.set(selector.dataID, RelayModernRecord.create(selector.dataID, ROOT_TYPE));
|
|
33
29
|
var relayPayload = RelayResponseNormalizer.normalize(source, selector, payload, options);
|
|
34
|
-
return
|
|
30
|
+
return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, relayPayload), {}, {
|
|
35
31
|
errors: errors
|
|
36
32
|
});
|
|
37
33
|
}
|
|
@@ -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,14 @@
|
|
|
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,
|
|
22
|
+
ENABLE_STORE_SUBSCRIPTIONS_REFACTOR: false
|
|
19
23
|
};
|
|
20
24
|
module.exports = RelayFeatureFlags;
|
|
@@ -13,19 +13,14 @@
|
|
|
13
13
|
|
|
14
14
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
15
15
|
|
|
16
|
-
var
|
|
17
|
-
|
|
18
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
19
|
-
|
|
20
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
16
|
+
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
21
17
|
|
|
22
18
|
var _require = require('../store/RelayStoreUtils'),
|
|
23
19
|
getModuleComponentKey = _require.getModuleComponentKey,
|
|
24
20
|
getModuleOperationKey = _require.getModuleOperationKey;
|
|
25
21
|
|
|
26
22
|
function createPayloadFor3DField(name, operation, component, response) {
|
|
27
|
-
var data =
|
|
28
|
-
|
|
23
|
+
var data = (0, _objectSpread2["default"])({}, response);
|
|
29
24
|
data[getModuleComponentKey(name)] = component;
|
|
30
25
|
data[getModuleOperationKey(name)] = operation;
|
|
31
26
|
return data;
|
|
@@ -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
|
|
|
@@ -53,17 +56,11 @@ function recycleNodesInto(prevData, nextData) {
|
|
|
53
56
|
if (nextValue !== nextObject[key]) {
|
|
54
57
|
if (process.env.NODE_ENV !== "production") {
|
|
55
58
|
if (!Object.isFrozen(nextObject)) {
|
|
56
|
-
|
|
57
|
-
* native_fb,oss) This comment suppresses an error found when
|
|
58
|
-
* Flow v0.98 was deployed. To see the error delete this comment
|
|
59
|
-
* and run Flow. */
|
|
59
|
+
// $FlowFixMe[cannot-write]
|
|
60
60
|
nextObject[key] = nextValue;
|
|
61
61
|
}
|
|
62
62
|
} else {
|
|
63
|
-
|
|
64
|
-
* fb,oss) This comment suppresses an error found when Flow v0.98
|
|
65
|
-
* was deployed. To see the error delete this comment and run Flow.
|
|
66
|
-
*/
|
|
63
|
+
// $FlowFixMe[cannot-write]
|
|
67
64
|
nextObject[key] = nextValue;
|
|
68
65
|
}
|
|
69
66
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
* @emails oncall+relay
|
|
9
|
+
* @format
|
|
10
|
+
*/
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
function reportMissingRequiredFields(environment, missingRequiredFields) {
|
|
14
|
+
switch (missingRequiredFields.action) {
|
|
15
|
+
case 'THROW':
|
|
16
|
+
{
|
|
17
|
+
var _missingRequiredField = missingRequiredFields.field,
|
|
18
|
+
path = _missingRequiredField.path,
|
|
19
|
+
owner = _missingRequiredField.owner; // This gives the consumer the chance to throw their own error if they so wish.
|
|
20
|
+
|
|
21
|
+
environment.requiredFieldLogger({
|
|
22
|
+
kind: 'missing_field.throw',
|
|
23
|
+
owner: owner,
|
|
24
|
+
fieldPath: path
|
|
25
|
+
});
|
|
26
|
+
throw new Error("Relay: Missing @required value at path '".concat(path, "' in '").concat(owner, "'."));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
case 'LOG':
|
|
30
|
+
missingRequiredFields.fields.forEach(function (_ref) {
|
|
31
|
+
var path = _ref.path,
|
|
32
|
+
owner = _ref.owner;
|
|
33
|
+
environment.requiredFieldLogger({
|
|
34
|
+
kind: 'missing_field.log',
|
|
35
|
+
owner: owner,
|
|
36
|
+
fieldPath: path
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
break;
|
|
40
|
+
|
|
41
|
+
default:
|
|
42
|
+
{
|
|
43
|
+
missingRequiredFields.action;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
module.exports = reportMissingRequiredFields;
|
|
@@ -13,7 +13,6 @@
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
15
|
const RelayDeclarativeMutationConfig = require('./RelayDeclarativeMutationConfig');
|
|
16
|
-
const RelayFeatureFlags = require('../util/RelayFeatureFlags');
|
|
17
16
|
|
|
18
17
|
const invariant = require('invariant');
|
|
19
18
|
const isRelayModernEnvironment = require('../store/isRelayModernEnvironment');
|
|
@@ -115,6 +114,7 @@ function commitMutation<T: MutationParameters>(
|
|
|
115
114
|
const operation = createOperationDescriptor(
|
|
116
115
|
mutation,
|
|
117
116
|
variables,
|
|
117
|
+
cacheConfig,
|
|
118
118
|
generateUniqueClientID(),
|
|
119
119
|
);
|
|
120
120
|
// TODO: remove this check after we fix flow.
|
|
@@ -142,7 +142,6 @@ function commitMutation<T: MutationParameters>(
|
|
|
142
142
|
const errors = [];
|
|
143
143
|
const subscription = environment
|
|
144
144
|
.executeMutation({
|
|
145
|
-
cacheConfig,
|
|
146
145
|
operation,
|
|
147
146
|
optimisticResponse,
|
|
148
147
|
optimisticUpdater,
|