relay-runtime 11.0.0-rc.0 → 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 (128) hide show
  1. package/handlers/connection/ConnectionHandler.js.flow +7 -0
  2. package/handlers/connection/MutationHandlers.js.flow +28 -0
  3. package/index.js +1 -1
  4. package/index.js.flow +20 -3
  5. package/lib/handlers/RelayDefaultHandlerProvider.js +1 -1
  6. package/lib/handlers/connection/ConnectionHandler.js +12 -6
  7. package/lib/handlers/connection/MutationHandlers.js +67 -8
  8. package/lib/index.js +15 -0
  9. package/lib/multi-actor-environment/ActorIdentifier.js +33 -0
  10. package/lib/multi-actor-environment/ActorSpecificEnvironment.js +148 -0
  11. package/lib/multi-actor-environment/ActorUtils.js +27 -0
  12. package/lib/multi-actor-environment/MultiActorEnvironment.js +406 -0
  13. package/lib/multi-actor-environment/MultiActorEnvironmentTypes.js +11 -0
  14. package/lib/multi-actor-environment/index.js +21 -0
  15. package/lib/mutations/RelayRecordProxy.js +1 -1
  16. package/lib/mutations/RelayRecordSourceMutator.js +1 -1
  17. package/lib/mutations/RelayRecordSourceProxy.js +1 -1
  18. package/lib/mutations/RelayRecordSourceSelectorProxy.js +7 -2
  19. package/lib/mutations/applyOptimisticMutation.js +1 -1
  20. package/lib/mutations/commitMutation.js +5 -2
  21. package/lib/mutations/validateMutation.js +39 -17
  22. package/lib/network/RelayNetwork.js +1 -1
  23. package/lib/network/RelayObservable.js +3 -1
  24. package/lib/network/RelayQueryResponseCache.js +20 -3
  25. package/lib/network/wrapNetworkWithLogObserver.js +78 -0
  26. package/lib/query/GraphQLTag.js +1 -1
  27. package/lib/query/fetchQuery.js +1 -1
  28. package/lib/query/fetchQueryInternal.js +1 -1
  29. package/lib/store/DataChecker.js +132 -50
  30. package/lib/store/{RelayModernQueryExecutor.js → OperationExecutor.js} +524 -187
  31. package/lib/store/RelayConcreteVariables.js +29 -4
  32. package/lib/store/RelayModernEnvironment.js +137 -220
  33. package/lib/store/RelayModernFragmentSpecResolver.js +49 -23
  34. package/lib/store/RelayModernRecord.js +36 -2
  35. package/lib/store/RelayModernSelector.js +1 -1
  36. package/lib/store/RelayModernStore.js +53 -22
  37. package/lib/store/RelayOperationTracker.js +34 -24
  38. package/lib/store/RelayPublishQueue.js +30 -8
  39. package/lib/store/RelayReader.js +177 -29
  40. package/lib/store/RelayRecordSource.js +87 -3
  41. package/lib/store/RelayReferenceMarker.js +53 -28
  42. package/lib/store/RelayResponseNormalizer.js +247 -108
  43. package/lib/store/RelayStoreReactFlightUtils.js +7 -11
  44. package/lib/store/RelayStoreSubscriptions.js +8 -5
  45. package/lib/store/RelayStoreUtils.js +10 -4
  46. package/lib/store/ResolverCache.js +213 -0
  47. package/lib/store/ResolverFragments.js +57 -0
  48. package/lib/store/cloneRelayHandleSourceField.js +1 -1
  49. package/lib/store/cloneRelayScalarHandleSourceField.js +1 -1
  50. package/lib/store/createRelayContext.js +2 -2
  51. package/lib/store/defaultGetDataID.js +3 -1
  52. package/lib/store/readInlineData.js +1 -1
  53. package/lib/subscription/requestSubscription.js +32 -6
  54. package/lib/util/RelayConcreteNode.js +3 -0
  55. package/lib/util/RelayFeatureFlags.js +5 -4
  56. package/lib/util/RelayProfiler.js +17 -187
  57. package/lib/util/RelayReplaySubject.js +22 -7
  58. package/lib/util/deepFreeze.js +1 -0
  59. package/lib/util/getPaginationMetadata.js +41 -0
  60. package/lib/util/getPaginationVariables.js +67 -0
  61. package/lib/util/getPendingOperationsForFragment.js +55 -0
  62. package/lib/util/getRefetchMetadata.js +36 -0
  63. package/lib/util/getRelayHandleKey.js +1 -1
  64. package/lib/util/getRequestIdentifier.js +1 -1
  65. package/lib/util/getValueAtPath.js +51 -0
  66. package/lib/util/isEmptyObject.js +1 -1
  67. package/lib/util/registerEnvironmentWithDevTools.js +26 -0
  68. package/lib/util/withDuration.js +31 -0
  69. package/multi-actor-environment/ActorIdentifier.js.flow +43 -0
  70. package/multi-actor-environment/ActorSpecificEnvironment.js.flow +217 -0
  71. package/multi-actor-environment/ActorUtils.js.flow +33 -0
  72. package/multi-actor-environment/MultiActorEnvironment.js.flow +485 -0
  73. package/multi-actor-environment/MultiActorEnvironmentTypes.js.flow +245 -0
  74. package/multi-actor-environment/index.js.flow +27 -0
  75. package/mutations/RelayRecordSourceSelectorProxy.js.flow +7 -2
  76. package/mutations/commitMutation.js.flow +3 -1
  77. package/mutations/validateMutation.js.flow +42 -16
  78. package/network/RelayNetworkTypes.js.flow +17 -8
  79. package/network/RelayObservable.js.flow +2 -0
  80. package/network/RelayQueryResponseCache.js.flow +31 -17
  81. package/network/wrapNetworkWithLogObserver.js.flow +99 -0
  82. package/package.json +3 -2
  83. package/relay-runtime.js +2 -2
  84. package/relay-runtime.min.js +2 -2
  85. package/store/ClientID.js.flow +5 -1
  86. package/store/DataChecker.js.flow +148 -44
  87. package/store/{RelayModernQueryExecutor.js.flow → OperationExecutor.js.flow} +578 -237
  88. package/store/RelayConcreteVariables.js.flow +31 -1
  89. package/store/RelayModernEnvironment.js.flow +132 -220
  90. package/store/RelayModernFragmentSpecResolver.js.flow +40 -14
  91. package/store/RelayModernOperationDescriptor.js.flow +9 -3
  92. package/store/RelayModernRecord.js.flow +49 -0
  93. package/store/RelayModernStore.js.flow +57 -17
  94. package/store/RelayOperationTracker.js.flow +56 -34
  95. package/store/RelayPublishQueue.js.flow +37 -11
  96. package/store/RelayReader.js.flow +186 -27
  97. package/store/RelayRecordSource.js.flow +72 -6
  98. package/store/RelayReferenceMarker.js.flow +51 -21
  99. package/store/RelayResponseNormalizer.js.flow +251 -67
  100. package/store/RelayStoreReactFlightUtils.js.flow +6 -9
  101. package/store/RelayStoreSubscriptions.js.flow +10 -3
  102. package/store/RelayStoreTypes.js.flow +144 -21
  103. package/store/RelayStoreUtils.js.flow +19 -4
  104. package/store/ResolverCache.js.flow +247 -0
  105. package/store/ResolverFragments.js.flow +128 -0
  106. package/store/createRelayContext.js.flow +1 -1
  107. package/store/defaultGetDataID.js.flow +3 -1
  108. package/subscription/requestSubscription.js.flow +43 -8
  109. package/util/NormalizationNode.js.flow +16 -3
  110. package/util/ReaderNode.js.flow +29 -2
  111. package/util/RelayConcreteNode.js.flow +3 -0
  112. package/util/RelayFeatureFlags.js.flow +10 -6
  113. package/util/RelayProfiler.js.flow +22 -194
  114. package/util/RelayReplaySubject.js.flow +7 -6
  115. package/util/RelayRuntimeTypes.js.flow +4 -2
  116. package/util/deepFreeze.js.flow +2 -1
  117. package/util/getPaginationMetadata.js.flow +74 -0
  118. package/util/getPaginationVariables.js.flow +112 -0
  119. package/util/getPendingOperationsForFragment.js.flow +62 -0
  120. package/util/getRefetchMetadata.js.flow +80 -0
  121. package/util/getValueAtPath.js.flow +46 -0
  122. package/util/isEmptyObject.js.flow +2 -1
  123. package/util/registerEnvironmentWithDevTools.js.flow +33 -0
  124. package/util/withDuration.js.flow +32 -0
  125. package/lib/store/RelayRecordSourceMapImpl.js +0 -107
  126. package/lib/store/RelayStoreSubscriptionsUsingMapByID.js +0 -318
  127. package/store/RelayRecordSourceMapImpl.js.flow +0 -91
  128. package/store/RelayStoreSubscriptionsUsingMapByID.js.flow +0 -283
@@ -0,0 +1,485 @@
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
+ * @emails oncall+relay
8
+ * @flow strict-local
9
+ * @format
10
+ */
11
+
12
+ 'use strict';
13
+
14
+ const ActorSpecificEnvironment = require('./ActorSpecificEnvironment');
15
+ const OperationExecutor = require('../store/OperationExecutor');
16
+ const RelayDefaultHandlerProvider = require('../handlers/RelayDefaultHandlerProvider');
17
+ const RelayModernStore = require('../store/RelayModernStore');
18
+ const RelayObservable = require('../network/RelayObservable');
19
+ const RelayRecordSource = require('../store/RelayRecordSource');
20
+
21
+ const defaultGetDataID = require('../store/defaultGetDataID');
22
+ const defaultRequiredFieldLogger = require('../store/defaultRequiredFieldLogger');
23
+
24
+ import type {HandlerProvider} from '../handlers/RelayDefaultHandlerProvider';
25
+ import type {GraphQLResponse, PayloadData} from '../network/RelayNetworkTypes';
26
+ import type {INetwork} from '../network/RelayNetworkTypes';
27
+ import type {ActiveState, TaskScheduler} from '../store/OperationExecutor';
28
+ import type {GetDataID} from '../store/RelayResponseNormalizer';
29
+ import type {
30
+ ExecuteMutationConfig,
31
+ LogFunction,
32
+ MissingFieldHandler,
33
+ MutableRecordSource,
34
+ OperationAvailability,
35
+ OperationDescriptor,
36
+ OperationLoader,
37
+ OptimisticResponseConfig,
38
+ OptimisticUpdateFunction,
39
+ ReactFlightPayloadDeserializer,
40
+ ReactFlightServerErrorHandler,
41
+ RequiredFieldLogger,
42
+ SelectorStoreUpdater,
43
+ SingularReaderSelector,
44
+ Snapshot,
45
+ Store,
46
+ StoreUpdater,
47
+ } from '../store/RelayStoreTypes';
48
+ import type {Disposable} from '../util/RelayRuntimeTypes';
49
+ import type {RenderPolicy} from '../util/RelayRuntimeTypes';
50
+ import type {ActorIdentifier} from './ActorIdentifier';
51
+ import type {
52
+ IActorEnvironment,
53
+ IMultiActorEnvironment,
54
+ MultiActorStoreUpdater,
55
+ } from './MultiActorEnvironmentTypes';
56
+
57
+ export type MultiActorEnvironmentConfig = $ReadOnly<{
58
+ createConfigNameForActor?: ?(actorIdentifier: ActorIdentifier) => string,
59
+ createNetworkForActor: (actorIdentifier: ActorIdentifier) => INetwork,
60
+ createStoreForActor?: ?(actorIdentifier: ActorIdentifier) => Store,
61
+ defaultRenderPolicy?: ?RenderPolicy,
62
+ getDataID?: GetDataID,
63
+ handlerProvider?: HandlerProvider,
64
+ isServer?: ?boolean,
65
+ logFn?: ?LogFunction,
66
+ missingFieldHandlers?: ?$ReadOnlyArray<MissingFieldHandler>,
67
+ operationLoader?: ?OperationLoader,
68
+ reactFlightPayloadDeserializer?: ?ReactFlightPayloadDeserializer,
69
+ reactFlightServerErrorHandler?: ?ReactFlightServerErrorHandler,
70
+ requiredFieldLogger?: ?RequiredFieldLogger,
71
+ scheduler?: ?TaskScheduler,
72
+ shouldProcessClientComponents?: ?boolean,
73
+ treatMissingFieldsAsNull?: boolean,
74
+ }>;
75
+
76
+ class MultiActorEnvironment implements IMultiActorEnvironment {
77
+ +_actorEnvironments: Map<ActorIdentifier, IActorEnvironment>;
78
+ +_createConfigNameForActor: ?(actorIdentifier: ActorIdentifier) => string;
79
+ +_createNetworkForActor: (actorIdentifier: ActorIdentifier) => INetwork;
80
+ +_createStoreForActor: ?(actorIdentifier: ActorIdentifier) => Store;
81
+ +_defaultRenderPolicy: RenderPolicy;
82
+ +_getDataID: GetDataID;
83
+ +_handlerProvider: HandlerProvider;
84
+ +_isServer: boolean;
85
+ +_logFn: LogFunction;
86
+ +_missingFieldHandlers: ?$ReadOnlyArray<MissingFieldHandler>;
87
+ +_operationExecutions: Map<string, ActiveState>;
88
+ +_operationLoader: ?OperationLoader;
89
+ +_reactFlightPayloadDeserializer: ?ReactFlightPayloadDeserializer;
90
+ +_reactFlightServerErrorHandler: ?ReactFlightServerErrorHandler;
91
+ +_requiredFieldLogger: RequiredFieldLogger;
92
+ +_scheduler: ?TaskScheduler;
93
+ +_shouldProcessClientComponents: ?boolean;
94
+ +_treatMissingFieldsAsNull: boolean;
95
+
96
+ constructor(config: MultiActorEnvironmentConfig) {
97
+ this._actorEnvironments = new Map();
98
+ this._operationLoader = config.operationLoader;
99
+ this._createNetworkForActor = config.createNetworkForActor;
100
+ this._scheduler = config.scheduler;
101
+ this._getDataID = config.getDataID ?? defaultGetDataID;
102
+ this._handlerProvider = config.handlerProvider
103
+ ? config.handlerProvider
104
+ : RelayDefaultHandlerProvider;
105
+ this._logFn = config.logFn ?? emptyFunction;
106
+ this._operationExecutions = new Map();
107
+ this._requiredFieldLogger =
108
+ config.requiredFieldLogger ?? defaultRequiredFieldLogger;
109
+ this._shouldProcessClientComponents = config.shouldProcessClientComponents;
110
+ this._treatMissingFieldsAsNull = config.treatMissingFieldsAsNull ?? false;
111
+ this._isServer = config.isServer ?? false;
112
+ this._missingFieldHandlers = config.missingFieldHandlers;
113
+ this._createStoreForActor = config.createStoreForActor;
114
+ this._reactFlightPayloadDeserializer =
115
+ config.reactFlightPayloadDeserializer;
116
+ this._reactFlightServerErrorHandler = config.reactFlightServerErrorHandler;
117
+ this._createConfigNameForActor = config.createConfigNameForActor;
118
+ this._defaultRenderPolicy = config.defaultRenderPolicy ?? 'partial';
119
+ }
120
+
121
+ /**
122
+ * This method will create an actor specific environment. It will create a new instance
123
+ * and store it in the internal maps. If will return a memoized version
124
+ * of the environment if we already created one for actor.
125
+ */
126
+ forActor(actorIdentifier: ActorIdentifier): IActorEnvironment {
127
+ const environment = this._actorEnvironments.get(actorIdentifier);
128
+ if (environment == null) {
129
+ const newEnvironment = new ActorSpecificEnvironment({
130
+ configName: this._createConfigNameForActor
131
+ ? this._createConfigNameForActor(actorIdentifier)
132
+ : null,
133
+ actorIdentifier,
134
+ multiActorEnvironment: this,
135
+ logFn: this._logFn,
136
+ requiredFieldLogger: this._requiredFieldLogger,
137
+ store:
138
+ this._createStoreForActor != null
139
+ ? this._createStoreForActor(actorIdentifier)
140
+ : new RelayModernStore(RelayRecordSource.create()),
141
+ network: this._createNetworkForActor(actorIdentifier),
142
+ handlerProvider: this._handlerProvider,
143
+ defaultRenderPolicy: this._defaultRenderPolicy,
144
+ });
145
+ this._actorEnvironments.set(actorIdentifier, newEnvironment);
146
+ return newEnvironment;
147
+ } else {
148
+ return environment;
149
+ }
150
+ }
151
+
152
+ check(
153
+ actorEnvironment: IActorEnvironment,
154
+ operation: OperationDescriptor,
155
+ ): OperationAvailability {
156
+ if (
157
+ this._missingFieldHandlers == null ||
158
+ this._missingFieldHandlers.length === 0
159
+ ) {
160
+ return actorEnvironment.getStore().check(operation, {
161
+ handlers: [],
162
+ defaultActorIdentifier: actorEnvironment.actorIdentifier,
163
+ getSourceForActor: actorIdentifier => {
164
+ return this.forActor(actorIdentifier)
165
+ .getStore()
166
+ .getSource();
167
+ },
168
+ getTargetForActor: () => {
169
+ return RelayRecordSource.create();
170
+ },
171
+ });
172
+ }
173
+ return this._checkSelectorAndHandleMissingFields(
174
+ actorEnvironment,
175
+ operation,
176
+ this._missingFieldHandlers,
177
+ );
178
+ }
179
+
180
+ _checkSelectorAndHandleMissingFields(
181
+ actorEnvironment: IActorEnvironment,
182
+ operation: OperationDescriptor,
183
+ handlers: $ReadOnlyArray<MissingFieldHandler>,
184
+ ): OperationAvailability {
185
+ const targets: Map<ActorIdentifier, MutableRecordSource> = new Map([
186
+ [actorEnvironment.actorIdentifier, RelayRecordSource.create()],
187
+ ]);
188
+ const result = actorEnvironment.getStore().check(operation, {
189
+ handlers,
190
+ defaultActorIdentifier: actorEnvironment.actorIdentifier,
191
+ getSourceForActor: actorIdentifier => {
192
+ return this.forActor(actorIdentifier)
193
+ .getStore()
194
+ .getSource();
195
+ },
196
+ getTargetForActor: actorIdentifier => {
197
+ let target = targets.get(actorIdentifier);
198
+ if (target == null) {
199
+ target = RelayRecordSource.create();
200
+ targets.set(actorIdentifier, target);
201
+ }
202
+ return target;
203
+ },
204
+ });
205
+ for (const [actorIdentifier, target] of targets) {
206
+ if (target.size() > 0) {
207
+ this._scheduleUpdates(() => {
208
+ const publishQueue = this.forActor(actorIdentifier).getPublishQueue();
209
+ publishQueue.commitSource(target);
210
+ publishQueue.run();
211
+ });
212
+ }
213
+ }
214
+
215
+ return result;
216
+ }
217
+
218
+ subscribe(
219
+ actorEnvironment: IActorEnvironment,
220
+ snapshot: Snapshot,
221
+ callback: (snapshot: Snapshot) => void,
222
+ ): Disposable {
223
+ // TODO: make actor aware
224
+ return actorEnvironment.getStore().subscribe(snapshot, callback);
225
+ }
226
+
227
+ retain(
228
+ actorEnvironment: IActorEnvironment,
229
+ operation: OperationDescriptor,
230
+ ): Disposable {
231
+ // TODO: make actor aware
232
+ return actorEnvironment.getStore().retain(operation);
233
+ }
234
+
235
+ applyUpdate(
236
+ actorEnvironment: IActorEnvironment,
237
+ optimisticUpdate: OptimisticUpdateFunction,
238
+ ): Disposable {
239
+ const publishQueue = actorEnvironment.getPublishQueue();
240
+ const dispose = () => {
241
+ this._scheduleUpdates(() => {
242
+ publishQueue.revertUpdate(optimisticUpdate);
243
+ publishQueue.run();
244
+ });
245
+ };
246
+ this._scheduleUpdates(() => {
247
+ publishQueue.applyUpdate(optimisticUpdate);
248
+ publishQueue.run();
249
+ });
250
+ return {dispose};
251
+ }
252
+
253
+ revertUpdate(
254
+ actorEnvironment: IActorEnvironment,
255
+ update: OptimisticUpdateFunction,
256
+ ): void {
257
+ const publishQueue = actorEnvironment.getPublishQueue();
258
+ this._scheduleUpdates(() => {
259
+ publishQueue.revertUpdate(update);
260
+ publishQueue.run();
261
+ });
262
+ }
263
+
264
+ replaceUpdate(
265
+ actorEnvironment: IActorEnvironment,
266
+ update: OptimisticUpdateFunction,
267
+ replacement: OptimisticUpdateFunction,
268
+ ): void {
269
+ const publishQueue = actorEnvironment.getPublishQueue();
270
+ this._scheduleUpdates(() => {
271
+ publishQueue.revertUpdate(update);
272
+ publishQueue.applyUpdate(replacement);
273
+ publishQueue.run();
274
+ });
275
+ }
276
+
277
+ applyMutation(
278
+ actorEnvironment: IActorEnvironment,
279
+ optimisticConfig: OptimisticResponseConfig,
280
+ ): Disposable {
281
+ const subscription = this._execute(actorEnvironment, {
282
+ createSource: () => RelayObservable.create(_sink => {}),
283
+ isClientPayload: false,
284
+ operation: optimisticConfig.operation,
285
+ optimisticConfig,
286
+ updater: null,
287
+ }).subscribe({});
288
+ return {
289
+ dispose: () => subscription.unsubscribe(),
290
+ };
291
+ }
292
+
293
+ commitUpdate(
294
+ actorEnvironment: IActorEnvironment,
295
+ updater: StoreUpdater,
296
+ ): void {
297
+ const publishQueue = actorEnvironment.getPublishQueue();
298
+ this._scheduleUpdates(() => {
299
+ publishQueue.commitUpdate(updater);
300
+ publishQueue.run();
301
+ });
302
+ }
303
+
304
+ commitPayload(
305
+ actorEnvironment: IActorEnvironment,
306
+ operationDescriptor: OperationDescriptor,
307
+ payload: PayloadData,
308
+ ): void {
309
+ this._execute(actorEnvironment, {
310
+ createSource: () => RelayObservable.from({data: payload}),
311
+ isClientPayload: true,
312
+ operation: operationDescriptor,
313
+ optimisticConfig: null,
314
+ updater: null,
315
+ }).subscribe({});
316
+ }
317
+
318
+ lookup(
319
+ actorEnvironment: IActorEnvironment,
320
+ selector: SingularReaderSelector,
321
+ ): Snapshot {
322
+ // TODO: make actor aware
323
+ return actorEnvironment.getStore().lookup(selector);
324
+ }
325
+
326
+ execute(
327
+ actorEnvironment: IActorEnvironment,
328
+ {
329
+ operation,
330
+ updater,
331
+ }: {
332
+ operation: OperationDescriptor,
333
+ updater?: ?SelectorStoreUpdater,
334
+ },
335
+ ): RelayObservable<GraphQLResponse> {
336
+ return this._execute(actorEnvironment, {
337
+ createSource: () =>
338
+ actorEnvironment
339
+ .getNetwork()
340
+ .execute(
341
+ operation.request.node.params,
342
+ operation.request.variables,
343
+ operation.request.cacheConfig || {},
344
+ null,
345
+ ),
346
+ isClientPayload: false,
347
+ operation,
348
+ optimisticConfig: null,
349
+ updater,
350
+ });
351
+ }
352
+
353
+ executeMutation(
354
+ actorEnvironment: IActorEnvironment,
355
+ {
356
+ operation,
357
+ optimisticResponse,
358
+ optimisticUpdater,
359
+ updater,
360
+ uploadables,
361
+ }: ExecuteMutationConfig,
362
+ ): RelayObservable<GraphQLResponse> {
363
+ let optimisticConfig;
364
+ if (optimisticResponse || optimisticUpdater) {
365
+ optimisticConfig = {
366
+ operation: operation,
367
+ response: optimisticResponse,
368
+ updater: optimisticUpdater,
369
+ };
370
+ }
371
+ return this._execute(actorEnvironment, {
372
+ createSource: () =>
373
+ actorEnvironment.getNetwork().execute(
374
+ operation.request.node.params,
375
+ operation.request.variables,
376
+ {
377
+ ...operation.request.cacheConfig,
378
+ force: true,
379
+ },
380
+ uploadables,
381
+ ),
382
+ isClientPayload: false,
383
+ operation,
384
+ optimisticConfig,
385
+ updater,
386
+ });
387
+ }
388
+
389
+ executeWithSource(
390
+ actorEnvironment: IActorEnvironment,
391
+ config: {
392
+ operation: OperationDescriptor,
393
+ source: RelayObservable<GraphQLResponse>,
394
+ },
395
+ ): RelayObservable<GraphQLResponse> {
396
+ return this._execute(actorEnvironment, {
397
+ createSource: () => config.source,
398
+ isClientPayload: false,
399
+ operation: config.operation,
400
+ optimisticConfig: null,
401
+ updater: null,
402
+ });
403
+ }
404
+
405
+ isRequestActive(
406
+ _actorEnvironment: IActorEnvironment,
407
+ requestIdentifier: string,
408
+ ): boolean {
409
+ const activeState = this._operationExecutions.get(requestIdentifier);
410
+ return activeState === 'active';
411
+ }
412
+
413
+ isServer(): boolean {
414
+ return this._isServer;
415
+ }
416
+
417
+ _execute(
418
+ actorEnvironment: IActorEnvironment,
419
+ {
420
+ createSource,
421
+ isClientPayload,
422
+ operation,
423
+ optimisticConfig,
424
+ updater,
425
+ }: {|
426
+ createSource: () => RelayObservable<GraphQLResponse>,
427
+ isClientPayload: boolean,
428
+ operation: OperationDescriptor,
429
+ optimisticConfig: ?OptimisticResponseConfig,
430
+ updater: ?SelectorStoreUpdater,
431
+ |},
432
+ ): RelayObservable<GraphQLResponse> {
433
+ return RelayObservable.create(sink => {
434
+ const executor = OperationExecutor.execute({
435
+ actorIdentifier: actorEnvironment.actorIdentifier,
436
+ getDataID: this._getDataID,
437
+ isClientPayload,
438
+ operation,
439
+ operationExecutions: this._operationExecutions,
440
+ operationLoader: this._operationLoader,
441
+ operationTracker: actorEnvironment.getOperationTracker(),
442
+ optimisticConfig,
443
+ getPublishQueue: (actorIdentifier: ActorIdentifier) => {
444
+ return this.forActor(actorIdentifier).getPublishQueue();
445
+ },
446
+ reactFlightPayloadDeserializer: this._reactFlightPayloadDeserializer,
447
+ reactFlightServerErrorHandler: this._reactFlightServerErrorHandler,
448
+ scheduler: this._scheduler,
449
+ shouldProcessClientComponents: this._shouldProcessClientComponents,
450
+ sink,
451
+ // NOTE: Some product tests expect `Network.execute` to be called only
452
+ // when the Observable is executed.
453
+ source: createSource(),
454
+ getStore: (actorIdentifier: ActorIdentifier) => {
455
+ return this.forActor(actorIdentifier).getStore();
456
+ },
457
+ treatMissingFieldsAsNull: this._treatMissingFieldsAsNull,
458
+ updater,
459
+ log: this._logFn,
460
+ });
461
+ return () => executor.cancel();
462
+ });
463
+ }
464
+
465
+ _scheduleUpdates(task: () => void) {
466
+ const scheduler = this._scheduler;
467
+ if (scheduler != null) {
468
+ scheduler.schedule(task);
469
+ } else {
470
+ task();
471
+ }
472
+ }
473
+
474
+ commitMultiActorUpdate(updater: MultiActorStoreUpdater): void {
475
+ for (const [actorIdentifier, environment] of this._actorEnvironments) {
476
+ environment.commitUpdate(storeProxy => {
477
+ updater(actorIdentifier, environment, storeProxy);
478
+ });
479
+ }
480
+ }
481
+ }
482
+
483
+ function emptyFunction() {}
484
+
485
+ module.exports = MultiActorEnvironment;