relay-runtime 10.1.3 → 11.0.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/connection/ConnectionHandler.js.flow +60 -0
- package/handlers/connection/MutationHandlers.js.flow +28 -0
- package/index.js +1 -1
- package/index.js.flow +9 -3
- package/lib/handlers/RelayDefaultHandlerProvider.js +1 -1
- package/lib/handlers/connection/ConnectionHandler.js +68 -6
- package/lib/handlers/connection/MutationHandlers.js +67 -8
- package/lib/index.js +3 -0
- package/lib/multi-actor-environment/ActorIdentifier.js +23 -0
- package/lib/multi-actor-environment/ActorSpecificEnvironment.js +108 -0
- package/lib/multi-actor-environment/MultiActorEnvironment.js +156 -0
- package/lib/multi-actor-environment/MultiActorEnvironmentTypes.js +11 -0
- package/lib/multi-actor-environment/index.js +17 -0
- package/lib/mutations/RelayRecordProxy.js +1 -1
- package/lib/mutations/RelayRecordSourceMutator.js +1 -1
- package/lib/mutations/RelayRecordSourceProxy.js +1 -1
- package/lib/mutations/RelayRecordSourceSelectorProxy.js +1 -1
- package/lib/mutations/applyOptimisticMutation.js +1 -1
- package/lib/mutations/commitMutation.js +1 -1
- package/lib/mutations/validateMutation.js +36 -15
- package/lib/network/RelayNetwork.js +1 -1
- package/lib/network/RelayQueryResponseCache.js +3 -2
- package/lib/query/GraphQLTag.js +1 -1
- package/lib/query/fetchQuery.js +129 -13
- package/lib/query/fetchQueryInternal.js +3 -4
- package/lib/query/fetchQuery_DEPRECATED.js +39 -0
- package/lib/store/DataChecker.js +26 -14
- package/lib/store/{RelayModernQueryExecutor.js → OperationExecutor.js} +117 -47
- package/lib/store/RelayConcreteVariables.js +8 -4
- package/lib/store/RelayModernEnvironment.js +105 -136
- package/lib/store/RelayModernFragmentSpecResolver.js +16 -9
- package/lib/store/RelayModernRecord.js +1 -1
- package/lib/store/RelayModernSelector.js +1 -1
- package/lib/store/RelayModernStore.js +19 -20
- package/lib/store/RelayOperationTracker.js +55 -49
- package/lib/store/RelayPublishQueue.js +9 -5
- package/lib/store/RelayReader.js +68 -14
- package/lib/store/RelayReferenceMarker.js +28 -14
- package/lib/store/RelayResponseNormalizer.js +109 -15
- package/lib/store/RelayStoreReactFlightUtils.js +6 -4
- package/lib/store/RelayStoreSubscriptions.js +18 -8
- package/lib/store/RelayStoreSubscriptionsUsingMapByID.js +90 -30
- package/lib/store/RelayStoreUtils.js +3 -2
- package/lib/store/ResolverFragments.js +57 -0
- package/lib/store/cloneRelayHandleSourceField.js +1 -1
- package/lib/store/cloneRelayScalarHandleSourceField.js +1 -1
- package/lib/store/createFragmentSpecResolver.js +2 -2
- package/lib/store/createRelayContext.js +1 -1
- package/lib/store/defaultGetDataID.js +3 -1
- package/lib/store/hasOverlappingIDs.js +11 -3
- package/lib/store/readInlineData.js +1 -1
- package/lib/subscription/requestSubscription.js +33 -5
- package/lib/util/RelayConcreteNode.js +2 -0
- package/lib/util/RelayFeatureFlags.js +8 -3
- package/lib/util/RelayProfiler.js +17 -187
- package/lib/util/RelayReplaySubject.js +1 -1
- package/lib/util/deepFreeze.js +1 -0
- package/lib/util/getRelayHandleKey.js +1 -1
- package/lib/util/getRequestIdentifier.js +1 -1
- package/multi-actor-environment/ActorIdentifier.js.flow +27 -0
- package/multi-actor-environment/ActorSpecificEnvironment.js.flow +189 -0
- package/multi-actor-environment/MultiActorEnvironment.js.flow +233 -0
- package/multi-actor-environment/MultiActorEnvironmentTypes.js.flow +196 -0
- package/multi-actor-environment/index.js.flow +24 -0
- package/mutations/RelayRecordSourceProxy.js.flow +3 -2
- package/mutations/commitMutation.js.flow +1 -1
- package/mutations/validateMutation.js.flow +40 -15
- package/network/RelayNetworkTypes.js.flow +31 -11
- package/network/RelayQueryResponseCache.js.flow +2 -1
- package/package.json +3 -2
- package/query/fetchQuery.js.flow +147 -20
- package/query/fetchQueryInternal.js.flow +2 -3
- package/query/fetchQuery_DEPRECATED.js.flow +47 -0
- package/relay-runtime.js +2 -2
- package/relay-runtime.min.js +2 -2
- package/store/DataChecker.js.flow +23 -15
- package/store/{RelayModernQueryExecutor.js.flow → OperationExecutor.js.flow} +128 -40
- package/store/RelayConcreteVariables.js.flow +5 -0
- package/store/RelayModernEnvironment.js.flow +100 -130
- package/store/RelayModernFragmentSpecResolver.js.flow +30 -8
- package/store/RelayModernStore.js.flow +28 -24
- package/store/RelayOperationTracker.js.flow +69 -56
- package/store/RelayPublishQueue.js.flow +7 -4
- package/store/RelayReader.js.flow +63 -11
- package/store/RelayRecordSource.js.flow +3 -3
- package/store/RelayRecordSourceMapImpl.js.flow +6 -2
- package/store/RelayReferenceMarker.js.flow +28 -18
- package/store/RelayResponseNormalizer.js.flow +134 -23
- package/store/RelayStoreReactFlightUtils.js.flow +9 -4
- package/store/RelayStoreSubscriptions.js.flow +22 -7
- package/store/RelayStoreSubscriptionsUsingMapByID.js.flow +36 -12
- package/store/RelayStoreTypes.js.flow +51 -22
- package/store/RelayStoreUtils.js.flow +2 -1
- package/store/ResolverFragments.js.flow +125 -0
- package/store/createFragmentSpecResolver.js.flow +2 -0
- package/store/defaultGetDataID.js.flow +3 -1
- package/store/hasOverlappingIDs.js.flow +11 -9
- package/subscription/requestSubscription.js.flow +25 -2
- package/util/NormalizationNode.js.flow +13 -0
- package/util/ReaderNode.js.flow +14 -1
- package/util/RelayConcreteNode.js.flow +2 -0
- package/util/RelayFeatureFlags.js.flow +12 -2
- package/util/RelayProfiler.js.flow +22 -194
- package/util/RelayRuntimeTypes.js.flow +4 -5
- package/util/deepFreeze.js.flow +2 -1
- package/util/isEmptyObject.js.flow +1 -1
|
@@ -13,9 +13,9 @@
|
|
|
13
13
|
|
|
14
14
|
'use strict';
|
|
15
15
|
|
|
16
|
+
const OperationExecutor = require('./OperationExecutor');
|
|
16
17
|
const RelayDefaultHandlerProvider = require('../handlers/RelayDefaultHandlerProvider');
|
|
17
18
|
const RelayFeatureFlags = require('../util/RelayFeatureFlags');
|
|
18
|
-
const RelayModernQueryExecutor = require('./RelayModernQueryExecutor');
|
|
19
19
|
const RelayObservable = require('../network/RelayObservable');
|
|
20
20
|
const RelayOperationTracker = require('../store/RelayOperationTracker');
|
|
21
21
|
const RelayPublishQueue = require('./RelayPublishQueue');
|
|
@@ -33,7 +33,6 @@ import type {
|
|
|
33
33
|
PayloadData,
|
|
34
34
|
UploadableMap,
|
|
35
35
|
} from '../network/RelayNetworkTypes';
|
|
36
|
-
import type {Observer} from '../network/RelayObservable';
|
|
37
36
|
import type {RequestParameters} from '../util/RelayConcreteNode';
|
|
38
37
|
import type {
|
|
39
38
|
CacheConfig,
|
|
@@ -41,14 +40,13 @@ import type {
|
|
|
41
40
|
RenderPolicy,
|
|
42
41
|
Variables,
|
|
43
42
|
} from '../util/RelayRuntimeTypes';
|
|
44
|
-
import type {ActiveState} from './
|
|
45
|
-
import type {TaskScheduler} from './RelayModernQueryExecutor';
|
|
43
|
+
import type {ActiveState, TaskScheduler} from './OperationExecutor';
|
|
46
44
|
import type {GetDataID} from './RelayResponseNormalizer';
|
|
47
45
|
import type {
|
|
46
|
+
ExecuteMutationConfig,
|
|
48
47
|
IEnvironment,
|
|
49
48
|
LogFunction,
|
|
50
49
|
MissingFieldHandler,
|
|
51
|
-
RequiredFieldLogger,
|
|
52
50
|
OperationAvailability,
|
|
53
51
|
OperationDescriptor,
|
|
54
52
|
OperationLoader,
|
|
@@ -57,6 +55,8 @@ import type {
|
|
|
57
55
|
OptimisticUpdateFunction,
|
|
58
56
|
PublishQueue,
|
|
59
57
|
ReactFlightPayloadDeserializer,
|
|
58
|
+
ReactFlightServerErrorHandler,
|
|
59
|
+
RequiredFieldLogger,
|
|
60
60
|
SelectorStoreUpdater,
|
|
61
61
|
SingularReaderSelector,
|
|
62
62
|
Snapshot,
|
|
@@ -71,21 +71,18 @@ export type EnvironmentConfig = {|
|
|
|
71
71
|
+log?: ?LogFunction,
|
|
72
72
|
+operationLoader?: ?OperationLoader,
|
|
73
73
|
+reactFlightPayloadDeserializer?: ?ReactFlightPayloadDeserializer,
|
|
74
|
+
+reactFlightServerErrorHandler?: ?ReactFlightServerErrorHandler,
|
|
74
75
|
+network: INetwork,
|
|
75
76
|
+scheduler?: ?TaskScheduler,
|
|
76
77
|
+store: Store,
|
|
77
78
|
+missingFieldHandlers?: ?$ReadOnlyArray<MissingFieldHandler>,
|
|
78
79
|
+operationTracker?: ?OperationTracker,
|
|
79
|
-
|
|
80
|
-
* This method is likely to change in future versions, use at your own risk.
|
|
81
|
-
* It can potentially break existing calls like store.get(<id>),
|
|
82
|
-
* because the internal ID might not be the `id` field on the node anymore
|
|
83
|
-
*/
|
|
84
|
-
+UNSTABLE_DO_NOT_USE_getDataID?: ?GetDataID,
|
|
80
|
+
+getDataID?: ?GetDataID,
|
|
85
81
|
+UNSTABLE_defaultRenderPolicy?: ?RenderPolicy,
|
|
86
82
|
+options?: mixed,
|
|
87
83
|
+isServer?: boolean,
|
|
88
84
|
+requiredFieldLogger?: ?RequiredFieldLogger,
|
|
85
|
+
+shouldProcessClientComponents?: ?boolean,
|
|
89
86
|
|};
|
|
90
87
|
|
|
91
88
|
class RelayModernEnvironment implements IEnvironment {
|
|
@@ -93,6 +90,8 @@ class RelayModernEnvironment implements IEnvironment {
|
|
|
93
90
|
+_defaultRenderPolicy: RenderPolicy;
|
|
94
91
|
_operationLoader: ?OperationLoader;
|
|
95
92
|
_reactFlightPayloadDeserializer: ?ReactFlightPayloadDeserializer;
|
|
93
|
+
_reactFlightServerErrorHandler: ?ReactFlightServerErrorHandler;
|
|
94
|
+
_shouldProcessClientComponents: ?boolean;
|
|
96
95
|
_network: INetwork;
|
|
97
96
|
_publishQueue: PublishQueue;
|
|
98
97
|
_scheduler: ?TaskScheduler;
|
|
@@ -109,13 +108,11 @@ class RelayModernEnvironment implements IEnvironment {
|
|
|
109
108
|
|
|
110
109
|
constructor(config: EnvironmentConfig) {
|
|
111
110
|
this.configName = config.configName;
|
|
112
|
-
const handlerProvider = config.handlerProvider
|
|
113
|
-
? config.handlerProvider
|
|
114
|
-
: RelayDefaultHandlerProvider;
|
|
115
111
|
this._treatMissingFieldsAsNull = config.treatMissingFieldsAsNull === true;
|
|
116
112
|
const operationLoader = config.operationLoader;
|
|
117
113
|
const reactFlightPayloadDeserializer =
|
|
118
114
|
config.reactFlightPayloadDeserializer;
|
|
115
|
+
const reactFlightServerErrorHandler = config.reactFlightServerErrorHandler;
|
|
119
116
|
if (__DEV__) {
|
|
120
117
|
if (operationLoader != null) {
|
|
121
118
|
invariant(
|
|
@@ -147,10 +144,10 @@ class RelayModernEnvironment implements IEnvironment {
|
|
|
147
144
|
this._operationLoader = operationLoader;
|
|
148
145
|
this._operationExecutions = new Map();
|
|
149
146
|
this._network = this.__wrapNetworkWithLogObserver(config.network);
|
|
150
|
-
this._getDataID = config.
|
|
147
|
+
this._getDataID = config.getDataID ?? defaultGetDataID;
|
|
151
148
|
this._publishQueue = new RelayPublishQueue(
|
|
152
149
|
config.store,
|
|
153
|
-
handlerProvider,
|
|
150
|
+
config.handlerProvider ?? RelayDefaultHandlerProvider,
|
|
154
151
|
this._getDataID,
|
|
155
152
|
);
|
|
156
153
|
this._scheduler = config.scheduler ?? null;
|
|
@@ -182,6 +179,8 @@ class RelayModernEnvironment implements IEnvironment {
|
|
|
182
179
|
this._operationTracker =
|
|
183
180
|
config.operationTracker ?? new RelayOperationTracker();
|
|
184
181
|
this._reactFlightPayloadDeserializer = reactFlightPayloadDeserializer;
|
|
182
|
+
this._reactFlightServerErrorHandler = reactFlightServerErrorHandler;
|
|
183
|
+
this._shouldProcessClientComponents = config.shouldProcessClientComponents;
|
|
185
184
|
}
|
|
186
185
|
|
|
187
186
|
getStore(): Store {
|
|
@@ -238,25 +237,12 @@ class RelayModernEnvironment implements IEnvironment {
|
|
|
238
237
|
}
|
|
239
238
|
|
|
240
239
|
applyMutation(optimisticConfig: OptimisticResponseConfig): Disposable {
|
|
241
|
-
const subscription =
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
optimisticConfig,
|
|
248
|
-
publishQueue: this._publishQueue,
|
|
249
|
-
reactFlightPayloadDeserializer: this._reactFlightPayloadDeserializer,
|
|
250
|
-
scheduler: this._scheduler,
|
|
251
|
-
sink,
|
|
252
|
-
source,
|
|
253
|
-
store: this._store,
|
|
254
|
-
updater: null,
|
|
255
|
-
operationTracker: this._operationTracker,
|
|
256
|
-
getDataID: this._getDataID,
|
|
257
|
-
treatMissingFieldsAsNull: this._treatMissingFieldsAsNull,
|
|
258
|
-
});
|
|
259
|
-
return () => executor.cancel();
|
|
240
|
+
const subscription = this._execute({
|
|
241
|
+
createSource: () => RelayObservable.create(_sink => {}),
|
|
242
|
+
isClientPayload: false,
|
|
243
|
+
operation: optimisticConfig.operation,
|
|
244
|
+
optimisticConfig,
|
|
245
|
+
updater: null,
|
|
260
246
|
}).subscribe({});
|
|
261
247
|
return {
|
|
262
248
|
dispose: () => subscription.unsubscribe(),
|
|
@@ -277,27 +263,12 @@ class RelayModernEnvironment implements IEnvironment {
|
|
|
277
263
|
}
|
|
278
264
|
|
|
279
265
|
commitPayload(operation: OperationDescriptor, payload: PayloadData): void {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
publishQueue: this._publishQueue,
|
|
287
|
-
reactFlightPayloadDeserializer: this._reactFlightPayloadDeserializer,
|
|
288
|
-
scheduler: this._scheduler,
|
|
289
|
-
sink,
|
|
290
|
-
source: RelayObservable.from({
|
|
291
|
-
data: payload,
|
|
292
|
-
}),
|
|
293
|
-
store: this._store,
|
|
294
|
-
updater: null,
|
|
295
|
-
operationTracker: this._operationTracker,
|
|
296
|
-
getDataID: this._getDataID,
|
|
297
|
-
isClientPayload: true,
|
|
298
|
-
treatMissingFieldsAsNull: this._treatMissingFieldsAsNull,
|
|
299
|
-
});
|
|
300
|
-
return () => executor.cancel();
|
|
266
|
+
this._execute({
|
|
267
|
+
createSource: () => RelayObservable.from({data: payload}),
|
|
268
|
+
isClientPayload: true,
|
|
269
|
+
operation: operation,
|
|
270
|
+
optimisticConfig: null,
|
|
271
|
+
updater: null,
|
|
301
272
|
}).subscribe({});
|
|
302
273
|
}
|
|
303
274
|
|
|
@@ -366,30 +337,18 @@ class RelayModernEnvironment implements IEnvironment {
|
|
|
366
337
|
operation: OperationDescriptor,
|
|
367
338
|
updater?: ?SelectorStoreUpdater,
|
|
368
339
|
|}): RelayObservable<GraphQLResponse> {
|
|
369
|
-
return
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
publishQueue: this._publishQueue,
|
|
382
|
-
reactFlightPayloadDeserializer: this._reactFlightPayloadDeserializer,
|
|
383
|
-
scheduler: this._scheduler,
|
|
384
|
-
sink,
|
|
385
|
-
source,
|
|
386
|
-
store: this._store,
|
|
387
|
-
updater,
|
|
388
|
-
operationTracker: this._operationTracker,
|
|
389
|
-
getDataID: this._getDataID,
|
|
390
|
-
treatMissingFieldsAsNull: this._treatMissingFieldsAsNull,
|
|
391
|
-
});
|
|
392
|
-
return () => executor.cancel();
|
|
340
|
+
return this._execute({
|
|
341
|
+
createSource: () =>
|
|
342
|
+
this._network.execute(
|
|
343
|
+
operation.request.node.params,
|
|
344
|
+
operation.request.variables,
|
|
345
|
+
operation.request.cacheConfig || {},
|
|
346
|
+
null,
|
|
347
|
+
),
|
|
348
|
+
isClientPayload: false,
|
|
349
|
+
operation,
|
|
350
|
+
optimisticConfig: null,
|
|
351
|
+
updater,
|
|
393
352
|
});
|
|
394
353
|
}
|
|
395
354
|
|
|
@@ -409,48 +368,30 @@ class RelayModernEnvironment implements IEnvironment {
|
|
|
409
368
|
optimisticUpdater,
|
|
410
369
|
updater,
|
|
411
370
|
uploadables,
|
|
412
|
-
}: {
|
|
413
|
-
|
|
414
|
-
optimisticUpdater
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
);
|
|
437
|
-
const executor = RelayModernQueryExecutor.execute({
|
|
438
|
-
operation,
|
|
439
|
-
operationExecutions: this._operationExecutions,
|
|
440
|
-
operationLoader: this._operationLoader,
|
|
441
|
-
optimisticConfig,
|
|
442
|
-
publishQueue: this._publishQueue,
|
|
443
|
-
reactFlightPayloadDeserializer: this._reactFlightPayloadDeserializer,
|
|
444
|
-
scheduler: this._scheduler,
|
|
445
|
-
sink,
|
|
446
|
-
source,
|
|
447
|
-
store: this._store,
|
|
448
|
-
updater,
|
|
449
|
-
operationTracker: this._operationTracker,
|
|
450
|
-
getDataID: this._getDataID,
|
|
451
|
-
treatMissingFieldsAsNull: this._treatMissingFieldsAsNull,
|
|
452
|
-
});
|
|
453
|
-
return () => executor.cancel();
|
|
371
|
+
}: ExecuteMutationConfig): RelayObservable<GraphQLResponse> {
|
|
372
|
+
let optimisticConfig;
|
|
373
|
+
if (optimisticResponse || optimisticUpdater) {
|
|
374
|
+
optimisticConfig = {
|
|
375
|
+
operation: operation,
|
|
376
|
+
response: optimisticResponse,
|
|
377
|
+
updater: optimisticUpdater,
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
return this._execute({
|
|
381
|
+
createSource: () =>
|
|
382
|
+
this._network.execute(
|
|
383
|
+
operation.request.node.params,
|
|
384
|
+
operation.request.variables,
|
|
385
|
+
{
|
|
386
|
+
...operation.request.cacheConfig,
|
|
387
|
+
force: true,
|
|
388
|
+
},
|
|
389
|
+
uploadables,
|
|
390
|
+
),
|
|
391
|
+
isClientPayload: false,
|
|
392
|
+
operation,
|
|
393
|
+
optimisticConfig,
|
|
394
|
+
updater,
|
|
454
395
|
});
|
|
455
396
|
}
|
|
456
397
|
|
|
@@ -469,31 +410,59 @@ class RelayModernEnvironment implements IEnvironment {
|
|
|
469
410
|
}: {|
|
|
470
411
|
operation: OperationDescriptor,
|
|
471
412
|
source: RelayObservable<GraphQLResponse>,
|
|
413
|
+
|}): RelayObservable<GraphQLResponse> {
|
|
414
|
+
return this._execute({
|
|
415
|
+
createSource: () => source,
|
|
416
|
+
isClientPayload: false,
|
|
417
|
+
operation,
|
|
418
|
+
optimisticConfig: null,
|
|
419
|
+
updater: null,
|
|
420
|
+
});
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
toJSON(): mixed {
|
|
424
|
+
return `RelayModernEnvironment(${this.configName ?? ''})`;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
_execute({
|
|
428
|
+
createSource,
|
|
429
|
+
isClientPayload,
|
|
430
|
+
operation,
|
|
431
|
+
optimisticConfig,
|
|
432
|
+
updater,
|
|
433
|
+
}: {|
|
|
434
|
+
createSource: () => RelayObservable<GraphQLResponse>,
|
|
435
|
+
isClientPayload: boolean,
|
|
436
|
+
operation: OperationDescriptor,
|
|
437
|
+
optimisticConfig: ?OptimisticResponseConfig,
|
|
438
|
+
updater: ?SelectorStoreUpdater,
|
|
472
439
|
|}): RelayObservable<GraphQLResponse> {
|
|
473
440
|
return RelayObservable.create(sink => {
|
|
474
|
-
const executor =
|
|
441
|
+
const executor = OperationExecutor.execute({
|
|
442
|
+
getDataID: this._getDataID,
|
|
443
|
+
isClientPayload,
|
|
475
444
|
operation,
|
|
476
445
|
operationExecutions: this._operationExecutions,
|
|
477
446
|
operationLoader: this._operationLoader,
|
|
478
447
|
operationTracker: this._operationTracker,
|
|
479
|
-
optimisticConfig
|
|
448
|
+
optimisticConfig,
|
|
480
449
|
publishQueue: this._publishQueue,
|
|
481
450
|
reactFlightPayloadDeserializer: this._reactFlightPayloadDeserializer,
|
|
451
|
+
reactFlightServerErrorHandler: this._reactFlightServerErrorHandler,
|
|
482
452
|
scheduler: this._scheduler,
|
|
453
|
+
shouldProcessClientComponents: this._shouldProcessClientComponents,
|
|
483
454
|
sink,
|
|
484
|
-
|
|
455
|
+
// NOTE: Some product tests expect `Network.execute` to be called only
|
|
456
|
+
// when the Observable is executed.
|
|
457
|
+
source: createSource(),
|
|
485
458
|
store: this._store,
|
|
486
|
-
getDataID: this._getDataID,
|
|
487
459
|
treatMissingFieldsAsNull: this._treatMissingFieldsAsNull,
|
|
460
|
+
updater,
|
|
488
461
|
});
|
|
489
462
|
return () => executor.cancel();
|
|
490
463
|
});
|
|
491
464
|
}
|
|
492
465
|
|
|
493
|
-
toJSON(): mixed {
|
|
494
|
-
return `RelayModernEnvironment(${this.configName ?? ''})`;
|
|
495
|
-
}
|
|
496
|
-
|
|
497
466
|
/**
|
|
498
467
|
* Wraps the network with logging to ensure that network requests are
|
|
499
468
|
* always logged. Relying on each network callsite to be wrapped is
|
|
@@ -517,6 +486,7 @@ class RelayModernEnvironment implements IEnvironment {
|
|
|
517
486
|
transactionID,
|
|
518
487
|
params,
|
|
519
488
|
variables,
|
|
489
|
+
cacheConfig,
|
|
520
490
|
});
|
|
521
491
|
},
|
|
522
492
|
next: response => {
|
|
@@ -71,6 +71,7 @@ type Resolvers = {
|
|
|
71
71
|
class RelayModernFragmentSpecResolver implements FragmentSpecResolver {
|
|
72
72
|
_callback: ?() => void;
|
|
73
73
|
_context: RelayContext;
|
|
74
|
+
_rootIsQueryRenderer: boolean;
|
|
74
75
|
_data: Object;
|
|
75
76
|
_fragments: FragmentMap;
|
|
76
77
|
_props: Props;
|
|
@@ -82,6 +83,7 @@ class RelayModernFragmentSpecResolver implements FragmentSpecResolver {
|
|
|
82
83
|
fragments: FragmentMap,
|
|
83
84
|
props: Props,
|
|
84
85
|
callback?: () => void,
|
|
86
|
+
rootIsQueryRenderer: boolean,
|
|
85
87
|
) {
|
|
86
88
|
this._callback = callback;
|
|
87
89
|
this._context = context;
|
|
@@ -90,6 +92,7 @@ class RelayModernFragmentSpecResolver implements FragmentSpecResolver {
|
|
|
90
92
|
this._props = {};
|
|
91
93
|
this._resolvers = {};
|
|
92
94
|
this._stale = false;
|
|
95
|
+
this._rootIsQueryRenderer = rootIsQueryRenderer;
|
|
93
96
|
|
|
94
97
|
this.setProps(props);
|
|
95
98
|
}
|
|
@@ -155,6 +158,7 @@ class RelayModernFragmentSpecResolver implements FragmentSpecResolver {
|
|
|
155
158
|
if (resolver == null) {
|
|
156
159
|
resolver = new SelectorListResolver(
|
|
157
160
|
this._context.environment,
|
|
161
|
+
this._rootIsQueryRenderer,
|
|
158
162
|
ownedSelector,
|
|
159
163
|
this._onChange,
|
|
160
164
|
);
|
|
@@ -170,6 +174,7 @@ class RelayModernFragmentSpecResolver implements FragmentSpecResolver {
|
|
|
170
174
|
if (resolver == null) {
|
|
171
175
|
resolver = new SelectorResolver(
|
|
172
176
|
this._context.environment,
|
|
177
|
+
this._rootIsQueryRenderer,
|
|
173
178
|
ownedSelector,
|
|
174
179
|
this._onChange,
|
|
175
180
|
);
|
|
@@ -219,11 +224,13 @@ class SelectorResolver {
|
|
|
219
224
|
_environment: IEnvironment;
|
|
220
225
|
_isMissingData: boolean;
|
|
221
226
|
_missingRequiredFields: ?MissingRequiredFields;
|
|
227
|
+
_rootIsQueryRenderer: boolean;
|
|
222
228
|
_selector: SingularReaderSelector;
|
|
223
229
|
_subscription: ?Disposable;
|
|
224
230
|
|
|
225
231
|
constructor(
|
|
226
232
|
environment: IEnvironment,
|
|
233
|
+
rootIsQueryRenderer: boolean,
|
|
227
234
|
selector: SingularReaderSelector,
|
|
228
235
|
callback: () => void,
|
|
229
236
|
) {
|
|
@@ -233,6 +240,7 @@ class SelectorResolver {
|
|
|
233
240
|
this._isMissingData = snapshot.isMissingData;
|
|
234
241
|
this._missingRequiredFields = snapshot.missingRequiredFields;
|
|
235
242
|
this._environment = environment;
|
|
243
|
+
this._rootIsQueryRenderer = rootIsQueryRenderer;
|
|
236
244
|
this._selector = selector;
|
|
237
245
|
this._subscription = environment.subscribe(snapshot, this._onChange);
|
|
238
246
|
}
|
|
@@ -276,14 +284,24 @@ class SelectorResolver {
|
|
|
276
284
|
.getOperationTracker()
|
|
277
285
|
.getPromiseForPendingOperationsAffectingOwner(this._selector.owner);
|
|
278
286
|
if (promise != null) {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
'
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
+
if (this._rootIsQueryRenderer) {
|
|
288
|
+
warning(
|
|
289
|
+
false,
|
|
290
|
+
'Relay: Relay Container for fragment `%s` has missing data and ' +
|
|
291
|
+
'would suspend. When using features such as @defer or @module, ' +
|
|
292
|
+
'use `useFragment` instead of a Relay Container.',
|
|
293
|
+
this._selector.node.name,
|
|
294
|
+
);
|
|
295
|
+
} else {
|
|
296
|
+
warning(
|
|
297
|
+
false,
|
|
298
|
+
'Relay: Relay Container for fragment `%s` suspended. When using ' +
|
|
299
|
+
'features such as @defer or @module, use `useFragment` instead ' +
|
|
300
|
+
'of a Relay Container.',
|
|
301
|
+
this._selector.node.name,
|
|
302
|
+
);
|
|
303
|
+
throw promise;
|
|
304
|
+
}
|
|
287
305
|
}
|
|
288
306
|
}
|
|
289
307
|
if (this._missingRequiredFields != null) {
|
|
@@ -355,10 +373,12 @@ class SelectorListResolver {
|
|
|
355
373
|
_data: Array<?SelectorData>;
|
|
356
374
|
_environment: IEnvironment;
|
|
357
375
|
_resolvers: Array<SelectorResolver>;
|
|
376
|
+
_rootIsQueryRenderer: boolean;
|
|
358
377
|
_stale: boolean;
|
|
359
378
|
|
|
360
379
|
constructor(
|
|
361
380
|
environment: IEnvironment,
|
|
381
|
+
rootIsQueryRenderer: boolean,
|
|
362
382
|
selector: PluralReaderSelector,
|
|
363
383
|
callback: () => void,
|
|
364
384
|
) {
|
|
@@ -367,6 +387,7 @@ class SelectorListResolver {
|
|
|
367
387
|
this._environment = environment;
|
|
368
388
|
this._resolvers = [];
|
|
369
389
|
this._stale = true;
|
|
390
|
+
this._rootIsQueryRenderer = rootIsQueryRenderer;
|
|
370
391
|
|
|
371
392
|
this.setSelector(selector);
|
|
372
393
|
}
|
|
@@ -410,6 +431,7 @@ class SelectorListResolver {
|
|
|
410
431
|
} else {
|
|
411
432
|
this._resolvers[ii] = new SelectorResolver(
|
|
412
433
|
this._environment,
|
|
434
|
+
this._rootIsQueryRenderer,
|
|
413
435
|
selectors[ii],
|
|
414
436
|
this._onChange,
|
|
415
437
|
);
|
|
@@ -16,7 +16,6 @@ const DataChecker = require('./DataChecker');
|
|
|
16
16
|
const RelayFeatureFlags = require('../util/RelayFeatureFlags');
|
|
17
17
|
const RelayModernRecord = require('./RelayModernRecord');
|
|
18
18
|
const RelayOptimisticRecordSource = require('./RelayOptimisticRecordSource');
|
|
19
|
-
const RelayProfiler = require('../util/RelayProfiler');
|
|
20
19
|
const RelayReader = require('./RelayReader');
|
|
21
20
|
const RelayReferenceMarker = require('./RelayReferenceMarker');
|
|
22
21
|
const RelayStoreReactFlightUtils = require('./RelayStoreReactFlightUtils');
|
|
@@ -48,7 +47,7 @@ import type {
|
|
|
48
47
|
Snapshot,
|
|
49
48
|
Store,
|
|
50
49
|
StoreSubscriptions,
|
|
51
|
-
|
|
50
|
+
DataIDSet,
|
|
52
51
|
} from './RelayStoreTypes';
|
|
53
52
|
|
|
54
53
|
export opaque type InvalidationState = {|
|
|
@@ -61,7 +60,7 @@ type InvalidationSubscription = {|
|
|
|
61
60
|
invalidationState: InvalidationState,
|
|
62
61
|
|};
|
|
63
62
|
|
|
64
|
-
const DEFAULT_RELEASE_BUFFER_SIZE =
|
|
63
|
+
const DEFAULT_RELEASE_BUFFER_SIZE = 10;
|
|
65
64
|
|
|
66
65
|
/**
|
|
67
66
|
* @public
|
|
@@ -84,7 +83,7 @@ class RelayModernStore implements Store {
|
|
|
84
83
|
_getDataID: GetDataID;
|
|
85
84
|
_globalInvalidationEpoch: ?number;
|
|
86
85
|
_invalidationSubscriptions: Set<InvalidationSubscription>;
|
|
87
|
-
_invalidatedRecordIDs:
|
|
86
|
+
_invalidatedRecordIDs: DataIDSet;
|
|
88
87
|
__log: ?LogFunction;
|
|
89
88
|
_queryCacheExpirationTime: ?number;
|
|
90
89
|
_operationLoader: ?OperationLoader;
|
|
@@ -102,7 +101,8 @@ class RelayModernStore implements Store {
|
|
|
102
101
|
>;
|
|
103
102
|
_shouldScheduleGC: boolean;
|
|
104
103
|
_storeSubscriptions: StoreSubscriptions;
|
|
105
|
-
_updatedRecordIDs:
|
|
104
|
+
_updatedRecordIDs: DataIDSet;
|
|
105
|
+
_shouldProcessClientComponents: ?boolean;
|
|
106
106
|
|
|
107
107
|
constructor(
|
|
108
108
|
source: MutableRecordSource,
|
|
@@ -110,9 +110,10 @@ class RelayModernStore implements Store {
|
|
|
110
110
|
gcScheduler?: ?Scheduler,
|
|
111
111
|
log?: ?LogFunction,
|
|
112
112
|
operationLoader?: ?OperationLoader,
|
|
113
|
-
|
|
113
|
+
getDataID?: ?GetDataID,
|
|
114
114
|
gcReleaseBufferSize?: ?number,
|
|
115
115
|
queryCacheExpirationTime?: ?number,
|
|
116
|
+
shouldProcessClientComponents?: ?boolean,
|
|
116
117
|
|},
|
|
117
118
|
) {
|
|
118
119
|
// Prevent mutation of a record from outside the store.
|
|
@@ -131,8 +132,7 @@ class RelayModernStore implements Store {
|
|
|
131
132
|
options?.gcReleaseBufferSize ?? DEFAULT_RELEASE_BUFFER_SIZE;
|
|
132
133
|
this._gcRun = null;
|
|
133
134
|
this._gcScheduler = options?.gcScheduler ?? resolveImmediate;
|
|
134
|
-
this._getDataID =
|
|
135
|
-
options?.UNSTABLE_DO_NOT_USE_getDataID ?? defaultGetDataID;
|
|
135
|
+
this._getDataID = options?.getDataID ?? defaultGetDataID;
|
|
136
136
|
this._globalInvalidationEpoch = null;
|
|
137
137
|
this._invalidationSubscriptions = new Set();
|
|
138
138
|
this._invalidatedRecordIDs = new Set();
|
|
@@ -146,9 +146,11 @@ class RelayModernStore implements Store {
|
|
|
146
146
|
this._shouldScheduleGC = false;
|
|
147
147
|
this._storeSubscriptions =
|
|
148
148
|
RelayFeatureFlags.ENABLE_STORE_SUBSCRIPTIONS_REFACTOR === true
|
|
149
|
-
? new RelayStoreSubscriptionsUsingMapByID()
|
|
150
|
-
: new RelayStoreSubscriptions();
|
|
151
|
-
this._updatedRecordIDs =
|
|
149
|
+
? new RelayStoreSubscriptionsUsingMapByID(options?.log)
|
|
150
|
+
: new RelayStoreSubscriptions(options?.log);
|
|
151
|
+
this._updatedRecordIDs = new Set();
|
|
152
|
+
this._shouldProcessClientComponents =
|
|
153
|
+
options?.shouldProcessClientComponents;
|
|
152
154
|
|
|
153
155
|
initializeRecordSource(this._recordSource);
|
|
154
156
|
}
|
|
@@ -193,6 +195,7 @@ class RelayModernStore implements Store {
|
|
|
193
195
|
handlers,
|
|
194
196
|
this._operationLoader,
|
|
195
197
|
this._getDataID,
|
|
198
|
+
this._shouldProcessClientComponents,
|
|
196
199
|
);
|
|
197
200
|
|
|
198
201
|
return getAvailabilityStatus(
|
|
@@ -287,6 +290,7 @@ class RelayModernStore implements Store {
|
|
|
287
290
|
if (log != null) {
|
|
288
291
|
log({
|
|
289
292
|
name: 'store.notify.start',
|
|
293
|
+
sourceOperation,
|
|
290
294
|
});
|
|
291
295
|
}
|
|
292
296
|
|
|
@@ -304,6 +308,7 @@ class RelayModernStore implements Store {
|
|
|
304
308
|
source,
|
|
305
309
|
this._updatedRecordIDs,
|
|
306
310
|
updatedOwners,
|
|
311
|
+
sourceOperation,
|
|
307
312
|
);
|
|
308
313
|
this._invalidationSubscriptions.forEach(subscription => {
|
|
309
314
|
this._updateInvalidationSubscription(
|
|
@@ -314,12 +319,13 @@ class RelayModernStore implements Store {
|
|
|
314
319
|
if (log != null) {
|
|
315
320
|
log({
|
|
316
321
|
name: 'store.notify.complete',
|
|
322
|
+
sourceOperation,
|
|
317
323
|
updatedRecordIDs: this._updatedRecordIDs,
|
|
318
324
|
invalidatedRecordIDs: this._invalidatedRecordIDs,
|
|
319
325
|
});
|
|
320
326
|
}
|
|
321
327
|
|
|
322
|
-
this._updatedRecordIDs
|
|
328
|
+
this._updatedRecordIDs.clear();
|
|
323
329
|
this._invalidatedRecordIDs.clear();
|
|
324
330
|
|
|
325
331
|
// If a source operation was provided (indicating the operation
|
|
@@ -357,7 +363,7 @@ class RelayModernStore implements Store {
|
|
|
357
363
|
return updatedOwners;
|
|
358
364
|
}
|
|
359
365
|
|
|
360
|
-
publish(source: RecordSource, idsMarkedForInvalidation?:
|
|
366
|
+
publish(source: RecordSource, idsMarkedForInvalidation?: DataIDSet): void {
|
|
361
367
|
const target = this._optimisticSource ?? this._recordSource;
|
|
362
368
|
updateTargetFromSource(
|
|
363
369
|
target,
|
|
@@ -412,7 +418,7 @@ class RelayModernStore implements Store {
|
|
|
412
418
|
}
|
|
413
419
|
|
|
414
420
|
// Internal API
|
|
415
|
-
__getUpdatedRecordIDs():
|
|
421
|
+
__getUpdatedRecordIDs(): DataIDSet {
|
|
416
422
|
return this._updatedRecordIDs;
|
|
417
423
|
}
|
|
418
424
|
|
|
@@ -572,6 +578,7 @@ class RelayModernStore implements Store {
|
|
|
572
578
|
selector,
|
|
573
579
|
references,
|
|
574
580
|
this._operationLoader,
|
|
581
|
+
this._shouldProcessClientComponents,
|
|
575
582
|
);
|
|
576
583
|
// Yield for other work after each operation
|
|
577
584
|
yield;
|
|
@@ -626,9 +633,9 @@ function updateTargetFromSource(
|
|
|
626
633
|
target: MutableRecordSource,
|
|
627
634
|
source: RecordSource,
|
|
628
635
|
currentWriteEpoch: number,
|
|
629
|
-
idsMarkedForInvalidation: ?
|
|
630
|
-
updatedRecordIDs:
|
|
631
|
-
invalidatedRecordIDs:
|
|
636
|
+
idsMarkedForInvalidation: ?DataIDSet,
|
|
637
|
+
updatedRecordIDs: DataIDSet,
|
|
638
|
+
invalidatedRecordIDs: DataIDSet,
|
|
632
639
|
): void {
|
|
633
640
|
// First, update any records that were marked for invalidation.
|
|
634
641
|
// For each provided dataID that was invalidated, we write the
|
|
@@ -670,6 +677,7 @@ function updateTargetFromSource(
|
|
|
670
677
|
currentWriteEpoch,
|
|
671
678
|
);
|
|
672
679
|
invalidatedRecordIDs.add(dataID);
|
|
680
|
+
// $FlowFixMe[incompatible-call]
|
|
673
681
|
target.set(dataID, nextRecord);
|
|
674
682
|
});
|
|
675
683
|
}
|
|
@@ -702,17 +710,17 @@ function updateTargetFromSource(
|
|
|
702
710
|
if (__DEV__) {
|
|
703
711
|
RelayModernRecord.freeze(nextRecord);
|
|
704
712
|
}
|
|
705
|
-
updatedRecordIDs
|
|
713
|
+
updatedRecordIDs.add(dataID);
|
|
706
714
|
target.set(dataID, nextRecord);
|
|
707
715
|
}
|
|
708
716
|
} else if (sourceRecord === null) {
|
|
709
717
|
target.delete(dataID);
|
|
710
718
|
if (targetRecord !== null) {
|
|
711
|
-
updatedRecordIDs
|
|
719
|
+
updatedRecordIDs.add(dataID);
|
|
712
720
|
}
|
|
713
721
|
} else if (sourceRecord) {
|
|
714
722
|
target.set(dataID, sourceRecord);
|
|
715
|
-
updatedRecordIDs
|
|
723
|
+
updatedRecordIDs.add(dataID);
|
|
716
724
|
} // don't add explicit undefined
|
|
717
725
|
}
|
|
718
726
|
}
|
|
@@ -761,8 +769,4 @@ function getAvailabilityStatus(
|
|
|
761
769
|
return {status: 'available', fetchTime: operationFetchTime ?? null};
|
|
762
770
|
}
|
|
763
771
|
|
|
764
|
-
RelayProfiler.instrumentMethods(RelayModernStore.prototype, {
|
|
765
|
-
lookup: 'RelayModernStore.prototype.lookup',
|
|
766
|
-
});
|
|
767
|
-
|
|
768
772
|
module.exports = RelayModernStore;
|