relay-runtime 11.0.2 → 12.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.
Files changed (100) hide show
  1. package/index.js +1 -1
  2. package/index.js.flow +16 -1
  3. package/lib/index.js +15 -0
  4. package/lib/multi-actor-environment/ActorIdentifier.js +11 -1
  5. package/lib/multi-actor-environment/ActorSpecificEnvironment.js +59 -19
  6. package/lib/multi-actor-environment/ActorUtils.js +27 -0
  7. package/lib/multi-actor-environment/MultiActorEnvironment.js +305 -55
  8. package/lib/multi-actor-environment/index.js +5 -1
  9. package/lib/mutations/RelayRecordSourceSelectorProxy.js +6 -1
  10. package/lib/mutations/commitMutation.js +4 -1
  11. package/lib/mutations/validateMutation.js +6 -1
  12. package/lib/network/RelayObservable.js +3 -1
  13. package/lib/network/RelayQueryResponseCache.js +19 -3
  14. package/lib/network/wrapNetworkWithLogObserver.js +78 -0
  15. package/lib/store/DataChecker.js +110 -40
  16. package/lib/store/OperationExecutor.js +478 -204
  17. package/lib/store/RelayConcreteVariables.js +21 -0
  18. package/lib/store/RelayModernEnvironment.js +41 -85
  19. package/lib/store/RelayModernFragmentSpecResolver.js +48 -22
  20. package/lib/store/RelayModernRecord.js +35 -1
  21. package/lib/store/RelayModernStore.js +48 -14
  22. package/lib/store/RelayOperationTracker.js +33 -23
  23. package/lib/store/RelayPublishQueue.js +23 -5
  24. package/lib/store/RelayReader.js +138 -44
  25. package/lib/store/RelayRecordSource.js +87 -3
  26. package/lib/store/RelayReferenceMarker.js +28 -15
  27. package/lib/store/RelayResponseNormalizer.js +164 -91
  28. package/lib/store/RelayStoreReactFlightUtils.js +1 -7
  29. package/lib/store/RelayStoreSubscriptions.js +8 -5
  30. package/lib/store/RelayStoreUtils.js +7 -2
  31. package/lib/store/ResolverCache.js +213 -0
  32. package/lib/store/ResolverFragments.js +1 -1
  33. package/lib/store/createRelayContext.js +1 -1
  34. package/lib/subscription/requestSubscription.js +27 -29
  35. package/lib/util/RelayConcreteNode.js +1 -0
  36. package/lib/util/RelayFeatureFlags.js +3 -5
  37. package/lib/util/RelayReplaySubject.js +21 -6
  38. package/lib/util/getPaginationMetadata.js +41 -0
  39. package/lib/util/getPaginationVariables.js +67 -0
  40. package/lib/util/getPendingOperationsForFragment.js +55 -0
  41. package/lib/util/getRefetchMetadata.js +36 -0
  42. package/lib/util/getValueAtPath.js +51 -0
  43. package/lib/util/isEmptyObject.js +1 -1
  44. package/lib/util/registerEnvironmentWithDevTools.js +26 -0
  45. package/lib/util/withDuration.js +31 -0
  46. package/multi-actor-environment/ActorIdentifier.js.flow +17 -1
  47. package/multi-actor-environment/ActorSpecificEnvironment.js.flow +72 -44
  48. package/multi-actor-environment/ActorUtils.js.flow +33 -0
  49. package/multi-actor-environment/MultiActorEnvironment.js.flow +332 -80
  50. package/multi-actor-environment/MultiActorEnvironmentTypes.js.flow +61 -12
  51. package/multi-actor-environment/index.js.flow +3 -0
  52. package/mutations/RelayRecordSourceSelectorProxy.js.flow +7 -2
  53. package/mutations/commitMutation.js.flow +2 -0
  54. package/mutations/validateMutation.js.flow +8 -0
  55. package/network/RelayObservable.js.flow +2 -0
  56. package/network/RelayQueryResponseCache.js.flow +31 -18
  57. package/network/wrapNetworkWithLogObserver.js.flow +99 -0
  58. package/package.json +1 -1
  59. package/relay-runtime.js +2 -2
  60. package/relay-runtime.min.js +2 -2
  61. package/store/ClientID.js.flow +5 -1
  62. package/store/DataChecker.js.flow +126 -35
  63. package/store/OperationExecutor.js.flow +528 -265
  64. package/store/RelayConcreteVariables.js.flow +26 -1
  65. package/store/RelayModernEnvironment.js.flow +41 -94
  66. package/store/RelayModernFragmentSpecResolver.js.flow +40 -14
  67. package/store/RelayModernOperationDescriptor.js.flow +9 -3
  68. package/store/RelayModernRecord.js.flow +49 -0
  69. package/store/RelayModernStore.js.flow +50 -12
  70. package/store/RelayOperationTracker.js.flow +56 -34
  71. package/store/RelayPublishQueue.js.flow +31 -8
  72. package/store/RelayReader.js.flow +148 -42
  73. package/store/RelayRecordSource.js.flow +72 -6
  74. package/store/RelayReferenceMarker.js.flow +29 -12
  75. package/store/RelayResponseNormalizer.js.flow +164 -48
  76. package/store/RelayStoreReactFlightUtils.js.flow +1 -7
  77. package/store/RelayStoreSubscriptions.js.flow +10 -3
  78. package/store/RelayStoreTypes.js.flow +128 -12
  79. package/store/RelayStoreUtils.js.flow +17 -3
  80. package/store/ResolverCache.js.flow +247 -0
  81. package/store/ResolverFragments.js.flow +6 -3
  82. package/store/createRelayContext.js.flow +1 -1
  83. package/subscription/requestSubscription.js.flow +41 -29
  84. package/util/NormalizationNode.js.flow +10 -3
  85. package/util/ReaderNode.js.flow +15 -1
  86. package/util/RelayConcreteNode.js.flow +1 -0
  87. package/util/RelayFeatureFlags.js.flow +8 -10
  88. package/util/RelayReplaySubject.js.flow +7 -6
  89. package/util/getPaginationMetadata.js.flow +74 -0
  90. package/util/getPaginationVariables.js.flow +112 -0
  91. package/util/getPendingOperationsForFragment.js.flow +62 -0
  92. package/util/getRefetchMetadata.js.flow +80 -0
  93. package/util/getValueAtPath.js.flow +46 -0
  94. package/util/isEmptyObject.js.flow +1 -0
  95. package/util/registerEnvironmentWithDevTools.js.flow +33 -0
  96. package/util/withDuration.js.flow +32 -0
  97. package/lib/store/RelayRecordSourceMapImpl.js +0 -107
  98. package/lib/store/RelayStoreSubscriptionsUsingMapByID.js +0 -318
  99. package/store/RelayRecordSourceMapImpl.js.flow +0 -91
  100. package/store/RelayStoreSubscriptionsUsingMapByID.js.flow +0 -283
@@ -10,6 +10,12 @@
10
10
  */
11
11
  'use strict';
12
12
 
13
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
14
+
15
+ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
16
+
17
+ var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
18
+
13
19
  var ActorSpecificEnvironment = require('./ActorSpecificEnvironment');
14
20
 
15
21
  var OperationExecutor = require('../store/OperationExecutor');
@@ -20,32 +26,38 @@ var RelayModernStore = require('../store/RelayModernStore');
20
26
 
21
27
  var RelayObservable = require('../network/RelayObservable');
22
28
 
23
- var RelayPublishQueue = require('../store/RelayPublishQueue');
24
-
25
29
  var RelayRecordSource = require('../store/RelayRecordSource');
26
30
 
27
31
  var defaultGetDataID = require('../store/defaultGetDataID');
28
32
 
29
- function todo(what) {
30
- throw new Error("Not implementd: ".concat(what));
31
- }
33
+ var defaultRequiredFieldLogger = require('../store/defaultRequiredFieldLogger');
32
34
 
33
35
  var MultiActorEnvironment = /*#__PURE__*/function () {
34
36
  function MultiActorEnvironment(config) {
35
- var _config$getDataID, _config$treatMissingF;
37
+ var _config$getDataID, _config$logFn, _config$requiredField, _config$treatMissingF, _config$isServer, _config$defaultRender;
36
38
 
37
39
  this._actorEnvironments = new Map();
40
+ this._operationLoader = config.operationLoader;
38
41
  this._createNetworkForActor = config.createNetworkForActor;
42
+ this._scheduler = config.scheduler;
39
43
  this._getDataID = (_config$getDataID = config.getDataID) !== null && _config$getDataID !== void 0 ? _config$getDataID : defaultGetDataID;
40
44
  this._handlerProvider = config.handlerProvider ? config.handlerProvider : RelayDefaultHandlerProvider;
41
- this._logFn = config.logFn;
45
+ this._logFn = (_config$logFn = config.logFn) !== null && _config$logFn !== void 0 ? _config$logFn : emptyFunction;
42
46
  this._operationExecutions = new Map();
43
- this._requiredFieldLogger = config.requiredFieldLogger;
47
+ this._requiredFieldLogger = (_config$requiredField = config.requiredFieldLogger) !== null && _config$requiredField !== void 0 ? _config$requiredField : defaultRequiredFieldLogger;
48
+ this._shouldProcessClientComponents = config.shouldProcessClientComponents;
44
49
  this._treatMissingFieldsAsNull = (_config$treatMissingF = config.treatMissingFieldsAsNull) !== null && _config$treatMissingF !== void 0 ? _config$treatMissingF : false;
50
+ this._isServer = (_config$isServer = config.isServer) !== null && _config$isServer !== void 0 ? _config$isServer : false;
51
+ this._missingFieldHandlers = config.missingFieldHandlers;
52
+ this._createStoreForActor = config.createStoreForActor;
53
+ this._reactFlightPayloadDeserializer = config.reactFlightPayloadDeserializer;
54
+ this._reactFlightServerErrorHandler = config.reactFlightServerErrorHandler;
55
+ this._createConfigNameForActor = config.createConfigNameForActor;
56
+ this._defaultRenderPolicy = (_config$defaultRender = config.defaultRenderPolicy) !== null && _config$defaultRender !== void 0 ? _config$defaultRender : 'partial';
45
57
  }
46
58
  /**
47
- * This method will create an actor specfic environment. It will create a new instance
48
- * and store it in the internal maps. If will return a memozied version
59
+ * This method will create an actor specific environment. It will create a new instance
60
+ * and store it in the internal maps. If will return a memoized version
49
61
  * of the environment if we already created one for actor.
50
62
  */
51
63
 
@@ -57,12 +69,15 @@ var MultiActorEnvironment = /*#__PURE__*/function () {
57
69
 
58
70
  if (environment == null) {
59
71
  var newEnvironment = new ActorSpecificEnvironment({
72
+ configName: this._createConfigNameForActor ? this._createConfigNameForActor(actorIdentifier) : null,
60
73
  actorIdentifier: actorIdentifier,
61
74
  multiActorEnvironment: this,
62
75
  logFn: this._logFn,
63
76
  requiredFieldLogger: this._requiredFieldLogger,
64
- store: new RelayModernStore(RelayRecordSource.create()),
65
- network: this._createNetworkForActor(actorIdentifier)
77
+ store: this._createStoreForActor != null ? this._createStoreForActor(actorIdentifier) : new RelayModernStore(RelayRecordSource.create()),
78
+ network: this._createNetworkForActor(actorIdentifier),
79
+ handlerProvider: this._handlerProvider,
80
+ defaultRenderPolicy: this._defaultRenderPolicy
66
81
  });
67
82
 
68
83
  this._actorEnvironments.set(actorIdentifier, newEnvironment);
@@ -73,64 +88,275 @@ var MultiActorEnvironment = /*#__PURE__*/function () {
73
88
  }
74
89
  };
75
90
 
76
- _proto.check = function check(actorIdentifier, operation) {
77
- return todo('check');
91
+ _proto.check = function check(actorEnvironment, operation) {
92
+ var _this = this;
93
+
94
+ if (this._missingFieldHandlers == null || this._missingFieldHandlers.length === 0) {
95
+ return actorEnvironment.getStore().check(operation, {
96
+ handlers: [],
97
+ defaultActorIdentifier: actorEnvironment.actorIdentifier,
98
+ getSourceForActor: function getSourceForActor(actorIdentifier) {
99
+ return _this.forActor(actorIdentifier).getStore().getSource();
100
+ },
101
+ getTargetForActor: function getTargetForActor() {
102
+ return RelayRecordSource.create();
103
+ }
104
+ });
105
+ }
106
+
107
+ return this._checkSelectorAndHandleMissingFields(actorEnvironment, operation, this._missingFieldHandlers);
78
108
  };
79
109
 
80
- _proto.subscribe = function subscribe(actorIdentifier, snapshot, callback) {
81
- return todo('subscribe');
110
+ _proto._checkSelectorAndHandleMissingFields = function _checkSelectorAndHandleMissingFields(actorEnvironment, operation, handlers) {
111
+ var _this2 = this;
112
+
113
+ var targets = new Map([[actorEnvironment.actorIdentifier, RelayRecordSource.create()]]);
114
+ var result = actorEnvironment.getStore().check(operation, {
115
+ handlers: handlers,
116
+ defaultActorIdentifier: actorEnvironment.actorIdentifier,
117
+ getSourceForActor: function getSourceForActor(actorIdentifier) {
118
+ return _this2.forActor(actorIdentifier).getStore().getSource();
119
+ },
120
+ getTargetForActor: function getTargetForActor(actorIdentifier) {
121
+ var target = targets.get(actorIdentifier);
122
+
123
+ if (target == null) {
124
+ target = RelayRecordSource.create();
125
+ targets.set(actorIdentifier, target);
126
+ }
127
+
128
+ return target;
129
+ }
130
+ });
131
+
132
+ var _iterator = (0, _createForOfIteratorHelper2["default"])(targets),
133
+ _step;
134
+
135
+ try {
136
+ var _loop = function _loop() {
137
+ var _step$value = _step.value,
138
+ actorIdentifier = _step$value[0],
139
+ target = _step$value[1];
140
+
141
+ if (target.size() > 0) {
142
+ _this2._scheduleUpdates(function () {
143
+ var publishQueue = _this2.forActor(actorIdentifier).getPublishQueue();
144
+
145
+ publishQueue.commitSource(target);
146
+ publishQueue.run();
147
+ });
148
+ }
149
+ };
150
+
151
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
152
+ _loop();
153
+ }
154
+ } catch (err) {
155
+ _iterator.e(err);
156
+ } finally {
157
+ _iterator.f();
158
+ }
159
+
160
+ return result;
82
161
  };
83
162
 
84
- _proto.retain = function retain(actorIdentifier, operation) {
85
- return todo('retain');
163
+ _proto.subscribe = function subscribe(actorEnvironment, snapshot, callback) {
164
+ // TODO: make actor aware
165
+ return actorEnvironment.getStore().subscribe(snapshot, callback);
86
166
  };
87
167
 
88
- _proto.applyUpdate = function applyUpdate(actorIdentifier, optimisticUpdate) {
89
- return todo('applyUpdate');
168
+ _proto.retain = function retain(actorEnvironment, operation) {
169
+ // TODO: make actor aware
170
+ return actorEnvironment.getStore().retain(operation);
90
171
  };
91
172
 
92
- _proto.applyMutation = function applyMutation(actorIdentifier, optimisticConfig) {
93
- return todo('applyMutation');
173
+ _proto.applyUpdate = function applyUpdate(actorEnvironment, optimisticUpdate) {
174
+ var _this3 = this;
175
+
176
+ var publishQueue = actorEnvironment.getPublishQueue();
177
+
178
+ var dispose = function dispose() {
179
+ _this3._scheduleUpdates(function () {
180
+ publishQueue.revertUpdate(optimisticUpdate);
181
+ publishQueue.run();
182
+ });
183
+ };
184
+
185
+ this._scheduleUpdates(function () {
186
+ publishQueue.applyUpdate(optimisticUpdate);
187
+ publishQueue.run();
188
+ });
189
+
190
+ return {
191
+ dispose: dispose
192
+ };
94
193
  };
95
194
 
96
- _proto.commitUpdate = function commitUpdate(actorIdentifier, updater) {
97
- return todo('commitUpdate');
195
+ _proto.revertUpdate = function revertUpdate(actorEnvironment, update) {
196
+ var publishQueue = actorEnvironment.getPublishQueue();
197
+
198
+ this._scheduleUpdates(function () {
199
+ publishQueue.revertUpdate(update);
200
+ publishQueue.run();
201
+ });
98
202
  };
99
203
 
100
- _proto.commitPayload = function commitPayload(actorIdentifier, operationDescriptor, payload) {
101
- return todo('commitPayload');
204
+ _proto.replaceUpdate = function replaceUpdate(actorEnvironment, update, replacement) {
205
+ var publishQueue = actorEnvironment.getPublishQueue();
206
+
207
+ this._scheduleUpdates(function () {
208
+ publishQueue.revertUpdate(update);
209
+ publishQueue.applyUpdate(replacement);
210
+ publishQueue.run();
211
+ });
102
212
  };
103
213
 
104
- _proto.lookup = function lookup(actorIdentifier, selector) {
105
- return todo('lookup');
214
+ _proto.applyMutation = function applyMutation(actorEnvironment, optimisticConfig) {
215
+ var subscription = this._execute(actorEnvironment, {
216
+ createSource: function createSource() {
217
+ return RelayObservable.create(function (_sink) {});
218
+ },
219
+ isClientPayload: false,
220
+ operation: optimisticConfig.operation,
221
+ optimisticConfig: optimisticConfig,
222
+ updater: null
223
+ }).subscribe({});
224
+
225
+ return {
226
+ dispose: function dispose() {
227
+ return subscription.unsubscribe();
228
+ }
229
+ };
106
230
  };
107
231
 
108
- _proto.execute = function execute(actorIdentifier, config) {
109
- var _this = this;
232
+ _proto.commitUpdate = function commitUpdate(actorEnvironment, updater) {
233
+ var publishQueue = actorEnvironment.getPublishQueue();
110
234
 
111
- var operation = config.operation,
112
- updater = config.updater;
113
- return RelayObservable.create(function (sink) {
114
- var actorEnvironemnt = _this.forActor(actorIdentifier);
235
+ this._scheduleUpdates(function () {
236
+ publishQueue.commitUpdate(updater);
237
+ publishQueue.run();
238
+ });
239
+ };
115
240
 
116
- var source = actorEnvironemnt.getNetwork().execute(operation.request.node.params, operation.request.variables, operation.request.cacheConfig || {}, null);
241
+ _proto.commitPayload = function commitPayload(actorEnvironment, operationDescriptor, payload) {
242
+ this._execute(actorEnvironment, {
243
+ createSource: function createSource() {
244
+ return RelayObservable.from({
245
+ data: payload
246
+ });
247
+ },
248
+ isClientPayload: true,
249
+ operation: operationDescriptor,
250
+ optimisticConfig: null,
251
+ updater: null
252
+ }).subscribe({});
253
+ };
254
+
255
+ _proto.lookup = function lookup(actorEnvironment, selector) {
256
+ // TODO: make actor aware
257
+ return actorEnvironment.getStore().lookup(selector);
258
+ };
259
+
260
+ _proto.execute = function execute(actorEnvironment, _ref) {
261
+ var operation = _ref.operation,
262
+ updater = _ref.updater;
263
+ return this._execute(actorEnvironment, {
264
+ createSource: function createSource() {
265
+ return actorEnvironment.getNetwork().execute(operation.request.node.params, operation.request.variables, operation.request.cacheConfig || {}, null);
266
+ },
267
+ isClientPayload: false,
268
+ operation: operation,
269
+ optimisticConfig: null,
270
+ updater: updater
271
+ });
272
+ };
273
+
274
+ _proto.executeMutation = function executeMutation(actorEnvironment, _ref2) {
275
+ var operation = _ref2.operation,
276
+ optimisticResponse = _ref2.optimisticResponse,
277
+ optimisticUpdater = _ref2.optimisticUpdater,
278
+ updater = _ref2.updater,
279
+ uploadables = _ref2.uploadables;
280
+ var optimisticConfig;
281
+
282
+ if (optimisticResponse || optimisticUpdater) {
283
+ optimisticConfig = {
284
+ operation: operation,
285
+ response: optimisticResponse,
286
+ updater: optimisticUpdater
287
+ };
288
+ }
289
+
290
+ return this._execute(actorEnvironment, {
291
+ createSource: function createSource() {
292
+ return actorEnvironment.getNetwork().execute(operation.request.node.params, operation.request.variables, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, operation.request.cacheConfig), {}, {
293
+ force: true
294
+ }), uploadables);
295
+ },
296
+ isClientPayload: false,
297
+ operation: operation,
298
+ optimisticConfig: optimisticConfig,
299
+ updater: updater
300
+ });
301
+ };
302
+
303
+ _proto.executeWithSource = function executeWithSource(actorEnvironment, config) {
304
+ return this._execute(actorEnvironment, {
305
+ createSource: function createSource() {
306
+ return config.source;
307
+ },
308
+ isClientPayload: false,
309
+ operation: config.operation,
310
+ optimisticConfig: null,
311
+ updater: null
312
+ });
313
+ };
314
+
315
+ _proto.isRequestActive = function isRequestActive(_actorEnvironment, requestIdentifier) {
316
+ var activeState = this._operationExecutions.get(requestIdentifier);
317
+
318
+ return activeState === 'active';
319
+ };
320
+
321
+ _proto.isServer = function isServer() {
322
+ return this._isServer;
323
+ };
324
+
325
+ _proto._execute = function _execute(actorEnvironment, _ref3) {
326
+ var _this4 = this;
327
+
328
+ var createSource = _ref3.createSource,
329
+ isClientPayload = _ref3.isClientPayload,
330
+ operation = _ref3.operation,
331
+ optimisticConfig = _ref3.optimisticConfig,
332
+ updater = _ref3.updater;
333
+ return RelayObservable.create(function (sink) {
117
334
  var executor = OperationExecutor.execute({
335
+ actorIdentifier: actorEnvironment.actorIdentifier,
336
+ getDataID: _this4._getDataID,
337
+ isClientPayload: isClientPayload,
118
338
  operation: operation,
119
- operationExecutions: _this._operationExecutions,
120
- operationLoader: null,
121
- optimisticConfig: null,
122
- publishQueue: new RelayPublishQueue(actorEnvironemnt.getStore(), _this._handlerProvider, _this._getDataID),
123
- reactFlightPayloadDeserializer: null,
124
- reactFlightServerErrorHandler: null,
125
- scheduler: null,
339
+ operationExecutions: _this4._operationExecutions,
340
+ operationLoader: _this4._operationLoader,
341
+ operationTracker: actorEnvironment.getOperationTracker(),
342
+ optimisticConfig: optimisticConfig,
343
+ getPublishQueue: function getPublishQueue(actorIdentifier) {
344
+ return _this4.forActor(actorIdentifier).getPublishQueue();
345
+ },
346
+ reactFlightPayloadDeserializer: _this4._reactFlightPayloadDeserializer,
347
+ reactFlightServerErrorHandler: _this4._reactFlightServerErrorHandler,
348
+ scheduler: _this4._scheduler,
349
+ shouldProcessClientComponents: _this4._shouldProcessClientComponents,
126
350
  sink: sink,
127
- source: source,
128
- store: actorEnvironemnt.getStore(),
351
+ // NOTE: Some product tests expect `Network.execute` to be called only
352
+ // when the Observable is executed.
353
+ source: createSource(),
354
+ getStore: function getStore(actorIdentifier) {
355
+ return _this4.forActor(actorIdentifier).getStore();
356
+ },
357
+ treatMissingFieldsAsNull: _this4._treatMissingFieldsAsNull,
129
358
  updater: updater,
130
- operationTracker: actorEnvironemnt.getOperationTracker(),
131
- getDataID: _this._getDataID,
132
- treatMissingFieldsAsNull: _this._treatMissingFieldsAsNull,
133
- shouldProcessClientComponents: false
359
+ log: _this4._logFn
134
360
  });
135
361
  return function () {
136
362
  return executor.cancel();
@@ -138,19 +364,43 @@ var MultiActorEnvironment = /*#__PURE__*/function () {
138
364
  });
139
365
  };
140
366
 
141
- _proto.executeMutation = function executeMutation(actorIdentifier, config) {
142
- return todo('executeMutation');
143
- };
367
+ _proto._scheduleUpdates = function _scheduleUpdates(task) {
368
+ var scheduler = this._scheduler;
144
369
 
145
- _proto.executeWithSource = function executeWithSource(actorIdentifier, config) {
146
- return todo('executeWithSource');
370
+ if (scheduler != null) {
371
+ scheduler.schedule(task);
372
+ } else {
373
+ task();
374
+ }
147
375
  };
148
376
 
149
- _proto.isRequestActive = function isRequestActive(actorIdentifier, requestIdentifier) {
150
- return todo('isRequestActive');
377
+ _proto.commitMultiActorUpdate = function commitMultiActorUpdate(updater) {
378
+ var _iterator2 = (0, _createForOfIteratorHelper2["default"])(this._actorEnvironments),
379
+ _step2;
380
+
381
+ try {
382
+ var _loop2 = function _loop2() {
383
+ var _step2$value = _step2.value,
384
+ actorIdentifier = _step2$value[0],
385
+ environment = _step2$value[1];
386
+ environment.commitUpdate(function (storeProxy) {
387
+ updater(actorIdentifier, environment, storeProxy);
388
+ });
389
+ };
390
+
391
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
392
+ _loop2();
393
+ }
394
+ } catch (err) {
395
+ _iterator2.e(err);
396
+ } finally {
397
+ _iterator2.f();
398
+ }
151
399
  };
152
400
 
153
401
  return MultiActorEnvironment;
154
402
  }();
155
403
 
404
+ function emptyFunction() {}
405
+
156
406
  module.exports = MultiActorEnvironment;
@@ -12,6 +12,10 @@
12
12
 
13
13
  var MultiActorEnvironment = require('./MultiActorEnvironment');
14
14
 
15
+ var _require = require('./ActorIdentifier'),
16
+ getActorIdentifier = _require.getActorIdentifier;
17
+
15
18
  module.exports = {
16
- MultiActorEnvironment: MultiActorEnvironment
19
+ MultiActorEnvironment: MultiActorEnvironment,
20
+ getActorIdentifier: getActorIdentifier
17
21
  };
@@ -61,8 +61,13 @@ var RelayRecordSourceSelectorProxy = /*#__PURE__*/function () {
61
61
 
62
62
  _proto._getRootField = function _getRootField(selector, fieldName, plural) {
63
63
  var field = selector.node.selections.find(function (selection) {
64
- return selection.kind === 'LinkedField' && selection.name === fieldName;
64
+ return selection.kind === 'LinkedField' && selection.name === fieldName || selection.kind === 'RequiredField' && selection.field.name === fieldName;
65
65
  });
66
+
67
+ if (field && field.kind === 'RequiredField') {
68
+ field = field.field;
69
+ }
70
+
66
71
  !(field && field.kind === 'LinkedField') ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayRecordSourceSelectorProxy#getRootField(): Cannot find root ' + 'field `%s`, no such field is defined on GraphQL document `%s`.', fieldName, selector.node.name) : invariant(false) : void 0;
67
72
  !(field.plural === plural) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayRecordSourceSelectorProxy#getRootField(): Expected root field ' + '`%s` to be %s.', fieldName, plural ? 'plural' : 'singular') : invariant(false) : void 0;
68
73
  return field;
@@ -58,7 +58,10 @@ function commitMutation(environment, config) {
58
58
  onUnsubscribe = config.onUnsubscribe,
59
59
  variables = config.variables,
60
60
  uploadables = config.uploadables;
61
- var operation = createOperationDescriptor(mutation, variables, cacheConfig, generateUniqueClientID()); // TODO: remove this check after we fix flow.
61
+ var operation = createOperationDescriptor(mutation,
62
+ /* $FlowFixMe[class-object-subtyping] added when improving typing for this
63
+ * parameters */
64
+ variables, cacheConfig, generateUniqueClientID()); // TODO: remove this check after we fix flow.
62
65
 
63
66
  if (typeof optimisticResponse === 'function') {
64
67
  optimisticResponse = optimisticResponse();
@@ -14,11 +14,13 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
14
14
 
15
15
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
16
16
 
17
- var warning = require("fbjs/lib/warning");
17
+ var warning = require("fbjs/lib/warning"); // $FlowFixMe[method-unbinding] added when improving typing for this parameters
18
+
18
19
 
19
20
  var hasOwnProperty = Object.prototype.hasOwnProperty;
20
21
 
21
22
  var _require = require('../util/RelayConcreteNode'),
23
+ ACTOR_CHANGE = _require.ACTOR_CHANGE,
22
24
  CONDITION = _require.CONDITION,
23
25
  CLIENT_COMPONENT = _require.CLIENT_COMPONENT,
24
26
  CLIENT_EXTENSION = _require.CLIENT_EXTENSION,
@@ -90,6 +92,9 @@ if (process.env.NODE_ENV !== "production") {
90
92
  case FLIGHT_FIELD:
91
93
  return validateField(optimisticResponse, selection, context);
92
94
 
95
+ case ACTOR_CHANGE:
96
+ return validateField(optimisticResponse, selection.linkedField, context);
97
+
93
98
  case INLINE_FRAGMENT:
94
99
  var type = selection.type;
95
100
  var isConcreteType = selection.abstractKey == null;
@@ -332,13 +332,15 @@ var RelayObservable = /*#__PURE__*/function () {
332
332
  if (subscriptions.length === 0) {
333
333
  sink.complete();
334
334
  }
335
- }
335
+ } // $FlowFixMe[incompatible-call]
336
+
336
337
 
337
338
  _this7.subscribe({
338
339
  start: start,
339
340
  next: function next(value) {
340
341
  try {
341
342
  if (!sink.closed) {
343
+ // $FlowFixMe[incompatible-call]
342
344
  RelayObservable.from(fn(value)).subscribe({
343
345
  start: start,
344
346
  next: sink.next,
@@ -53,12 +53,28 @@ var RelayQueryResponseCache = /*#__PURE__*/function () {
53
53
 
54
54
  var response = this._responses.get(cacheKey);
55
55
 
56
- return response != null ? // $FlowFixMe[speculation-ambiguous]
57
- (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, response.payload), {}, {
56
+ if (response == null) {
57
+ return null;
58
+ }
59
+
60
+ if (Array.isArray(response.payload)) {
61
+ return response.payload.map(function (payload) {
62
+ return (// $FlowFixMe[incompatible-cast]
63
+ (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, payload), {}, {
64
+ extensions: (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, payload.extensions), {}, {
65
+ cacheTimestamp: response.fetchTime
66
+ })
67
+ })
68
+ );
69
+ });
70
+ } // $FlowFixMe[incompatible-cast]
71
+
72
+
73
+ return (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, response.payload), {}, {
58
74
  extensions: (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, response.payload.extensions), {}, {
59
75
  cacheTimestamp: response.fetchTime
60
76
  })
61
- }) : null;
77
+ });
62
78
  };
63
79
 
64
80
  _proto.set = function set(queryID, variables, payload) {
@@ -0,0 +1,78 @@
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 generateID = require('../util/generateID');
14
+
15
+ /**
16
+ * Wraps the network with logging to ensure that network requests are
17
+ * always logged. Relying on each network callsite to be wrapped is
18
+ * untenable and will eventually lead to holes in the logging.
19
+ * NOTE: This function takes an environment instance, because Relay
20
+ * devtools will mutate the `env.__log` method, and the devtools rely
21
+ * on it to receive network events.
22
+ */
23
+ function wrapNetworkWithLogObserver(env, network) {
24
+ return {
25
+ execute: function execute(params, variables, cacheConfig, uploadables) {
26
+ var networkRequestId = generateID();
27
+ var logObserver = {
28
+ start: function start(subscription) {
29
+ env.__log({
30
+ name: 'network.start',
31
+ networkRequestId: networkRequestId,
32
+ params: params,
33
+ variables: variables,
34
+ cacheConfig: cacheConfig
35
+ });
36
+ },
37
+ next: function next(response) {
38
+ env.__log({
39
+ name: 'network.next',
40
+ networkRequestId: networkRequestId,
41
+ response: response
42
+ });
43
+ },
44
+ error: function error(_error) {
45
+ env.__log({
46
+ name: 'network.error',
47
+ networkRequestId: networkRequestId,
48
+ error: _error
49
+ });
50
+ },
51
+ complete: function complete() {
52
+ env.__log({
53
+ name: 'network.complete',
54
+ networkRequestId: networkRequestId
55
+ });
56
+ },
57
+ unsubscribe: function unsubscribe() {
58
+ env.__log({
59
+ name: 'network.unsubscribe',
60
+ networkRequestId: networkRequestId
61
+ });
62
+ }
63
+ };
64
+
65
+ var logRequestInfo = function logRequestInfo(info) {
66
+ env.__log({
67
+ name: 'network.info',
68
+ networkRequestId: networkRequestId,
69
+ info: info
70
+ });
71
+ };
72
+
73
+ return network.execute(params, variables, cacheConfig, uploadables, logRequestInfo)["do"](logObserver);
74
+ }
75
+ };
76
+ }
77
+
78
+ module.exports = wrapNetworkWithLogObserver;