relay-runtime 11.0.1 → 13.0.0-rc.1
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 +2 -2
- package/handlers/connection/ConnectionHandler.js.flow +8 -17
- package/handlers/connection/MutationHandlers.js.flow +7 -11
- package/index.js +1 -1
- package/index.js.flow +60 -36
- package/lib/handlers/RelayDefaultHandlerProvider.js +1 -1
- package/lib/handlers/connection/ConnectionHandler.js +13 -19
- package/lib/handlers/connection/MutationHandlers.js +4 -7
- package/lib/index.js +58 -43
- package/lib/multi-actor-environment/ActorIdentifier.js +33 -0
- package/lib/multi-actor-environment/ActorSpecificEnvironment.js +152 -0
- package/lib/multi-actor-environment/ActorUtils.js +27 -0
- package/lib/multi-actor-environment/MultiActorEnvironment.js +419 -0
- package/lib/multi-actor-environment/MultiActorEnvironmentTypes.js +11 -0
- package/lib/multi-actor-environment/index.js +21 -0
- package/lib/mutations/RelayDeclarativeMutationConfig.js +4 -1
- package/lib/mutations/RelayRecordProxy.js +3 -2
- package/lib/mutations/RelayRecordSourceMutator.js +3 -2
- package/lib/mutations/RelayRecordSourceProxy.js +12 -4
- package/lib/mutations/RelayRecordSourceSelectorProxy.js +18 -5
- package/lib/mutations/applyOptimisticMutation.js +6 -6
- package/lib/mutations/commitMutation.js +14 -10
- package/lib/mutations/readUpdatableQuery_EXPERIMENTAL.js +238 -0
- package/lib/mutations/validateMutation.js +10 -5
- package/lib/network/ConvertToExecuteFunction.js +2 -1
- package/lib/network/RelayNetwork.js +3 -2
- package/lib/network/RelayQueryResponseCache.js +21 -5
- package/lib/network/wrapNetworkWithLogObserver.js +79 -0
- package/lib/query/GraphQLTag.js +3 -2
- package/lib/query/fetchQuery.js +6 -5
- package/lib/query/fetchQueryInternal.js +1 -1
- package/lib/query/fetchQuery_DEPRECATED.js +2 -1
- package/lib/store/ClientID.js +7 -1
- package/lib/store/DataChecker.js +123 -54
- package/lib/store/{RelayModernQueryExecutor.js → OperationExecutor.js} +518 -200
- package/lib/store/RelayConcreteVariables.js +26 -8
- package/lib/store/RelayExperimentalGraphResponseHandler.js +153 -0
- package/lib/store/RelayExperimentalGraphResponseTransform.js +391 -0
- package/lib/store/RelayModernEnvironment.js +175 -240
- package/lib/store/RelayModernFragmentSpecResolver.js +52 -26
- package/lib/store/RelayModernOperationDescriptor.js +2 -1
- package/lib/store/RelayModernRecord.js +47 -12
- package/lib/store/RelayModernSelector.js +14 -8
- package/lib/store/RelayModernStore.js +56 -28
- package/lib/store/RelayOperationTracker.js +34 -24
- package/lib/store/RelayPublishQueue.js +41 -13
- package/lib/store/RelayReader.js +288 -48
- package/lib/store/RelayRecordSource.js +87 -3
- package/lib/store/RelayReferenceMarker.js +34 -22
- package/lib/store/RelayResponseNormalizer.js +211 -110
- package/lib/store/RelayStoreReactFlightUtils.js +4 -10
- package/lib/store/RelayStoreSubscriptions.js +14 -9
- package/lib/store/RelayStoreUtils.js +12 -7
- package/lib/store/ResolverCache.js +213 -0
- package/lib/store/ResolverFragments.js +61 -0
- package/lib/store/cloneRelayHandleSourceField.js +5 -4
- package/lib/store/cloneRelayScalarHandleSourceField.js +5 -4
- package/lib/store/createRelayContext.js +4 -2
- package/lib/store/readInlineData.js +6 -2
- package/lib/subscription/requestSubscription.js +34 -25
- package/lib/util/RelayConcreteNode.js +3 -0
- package/lib/util/RelayFeatureFlags.js +10 -4
- package/lib/util/RelayProfiler.js +17 -187
- package/lib/util/RelayReplaySubject.js +22 -7
- package/lib/util/RelayRuntimeTypes.js +0 -6
- package/lib/util/StringInterner.js +71 -0
- package/lib/util/getFragmentIdentifier.js +15 -7
- package/lib/util/getOperation.js +2 -1
- package/lib/util/getPaginationMetadata.js +41 -0
- package/lib/util/getPaginationVariables.js +66 -0
- package/lib/util/getPendingOperationsForFragment.js +55 -0
- package/lib/util/getRefetchMetadata.js +36 -0
- package/lib/util/getRelayHandleKey.js +2 -2
- package/lib/util/getRequestIdentifier.js +2 -2
- package/lib/util/getValueAtPath.js +51 -0
- package/lib/util/isEmptyObject.js +1 -1
- package/lib/util/registerEnvironmentWithDevTools.js +26 -0
- package/lib/util/withDuration.js +31 -0
- package/multi-actor-environment/ActorIdentifier.js.flow +43 -0
- package/multi-actor-environment/ActorSpecificEnvironment.js.flow +225 -0
- package/multi-actor-environment/ActorUtils.js.flow +33 -0
- package/multi-actor-environment/MultiActorEnvironment.js.flow +506 -0
- package/multi-actor-environment/MultiActorEnvironmentTypes.js.flow +261 -0
- package/multi-actor-environment/index.js.flow +26 -0
- package/mutations/RelayDeclarativeMutationConfig.js.flow +32 -26
- package/mutations/RelayRecordProxy.js.flow +4 -5
- package/mutations/RelayRecordSourceMutator.js.flow +4 -6
- package/mutations/RelayRecordSourceProxy.js.flow +19 -10
- package/mutations/RelayRecordSourceSelectorProxy.js.flow +22 -7
- package/mutations/applyOptimisticMutation.js.flow +13 -14
- package/mutations/commitLocalUpdate.js.flow +1 -1
- package/mutations/commitMutation.js.flow +35 -46
- package/mutations/readUpdatableQuery_EXPERIMENTAL.js.flow +309 -0
- package/mutations/validateMutation.js.flow +26 -16
- package/network/ConvertToExecuteFunction.js.flow +2 -2
- package/network/RelayNetwork.js.flow +4 -5
- package/network/RelayNetworkTypes.js.flow +5 -4
- package/network/RelayObservable.js.flow +1 -1
- package/network/RelayQueryResponseCache.js.flow +34 -21
- package/network/wrapNetworkWithLogObserver.js.flow +100 -0
- package/package.json +3 -2
- package/query/GraphQLTag.js.flow +9 -9
- package/query/PreloadableQueryRegistry.js.flow +2 -1
- package/query/fetchQuery.js.flow +11 -13
- package/query/fetchQueryInternal.js.flow +6 -9
- package/query/fetchQuery_DEPRECATED.js.flow +6 -6
- package/relay-runtime.js +2 -2
- package/relay-runtime.min.js +2 -2
- package/store/ClientID.js.flow +14 -3
- package/store/DataChecker.js.flow +141 -59
- package/store/{RelayModernQueryExecutor.js.flow → OperationExecutor.js.flow} +605 -303
- package/store/RelayConcreteVariables.js.flow +27 -8
- package/store/RelayExperimentalGraphResponseHandler.js.flow +124 -0
- package/store/RelayExperimentalGraphResponseTransform.js.flow +475 -0
- package/store/RelayModernEnvironment.js.flow +173 -240
- package/store/RelayModernFragmentSpecResolver.js.flow +55 -31
- package/store/RelayModernOperationDescriptor.js.flow +12 -7
- package/store/RelayModernRecord.js.flow +67 -11
- package/store/RelayModernSelector.js.flow +24 -14
- package/store/RelayModernStore.js.flow +66 -36
- package/store/RelayOperationTracker.js.flow +59 -43
- package/store/RelayOptimisticRecordSource.js.flow +2 -2
- package/store/RelayPublishQueue.js.flow +79 -34
- package/store/RelayReader.js.flow +351 -73
- package/store/RelayRecordSource.js.flow +72 -6
- package/store/RelayReferenceMarker.js.flow +40 -26
- package/store/RelayResponseNormalizer.js.flow +258 -99
- package/store/RelayStoreReactFlightUtils.js.flow +4 -11
- package/store/RelayStoreSubscriptions.js.flow +19 -11
- package/store/RelayStoreTypes.js.flow +209 -43
- package/store/RelayStoreUtils.js.flow +24 -11
- package/store/ResolverCache.js.flow +249 -0
- package/store/ResolverFragments.js.flow +121 -0
- package/store/StoreInspector.js.flow +2 -2
- package/store/TypeID.js.flow +1 -1
- package/store/ViewerPattern.js.flow +2 -2
- package/store/cloneRelayHandleSourceField.js.flow +5 -6
- package/store/cloneRelayScalarHandleSourceField.js.flow +5 -6
- package/store/createFragmentSpecResolver.js.flow +3 -4
- package/store/createRelayContext.js.flow +3 -3
- package/store/normalizeRelayPayload.js.flow +6 -7
- package/store/readInlineData.js.flow +7 -8
- package/subscription/requestSubscription.js.flow +53 -41
- package/util/NormalizationNode.js.flow +10 -3
- package/util/ReaderNode.js.flow +38 -2
- package/util/RelayConcreteNode.js.flow +5 -0
- package/util/RelayFeatureFlags.js.flow +24 -10
- package/util/RelayProfiler.js.flow +22 -194
- package/util/RelayReplaySubject.js.flow +9 -9
- package/util/RelayRuntimeTypes.js.flow +72 -3
- package/util/StringInterner.js.flow +69 -0
- package/util/createPayloadFor3DField.js.flow +3 -3
- package/util/getFragmentIdentifier.js.flow +27 -15
- package/util/getOperation.js.flow +2 -2
- package/util/getPaginationMetadata.js.flow +72 -0
- package/util/getPaginationVariables.js.flow +108 -0
- package/util/getPendingOperationsForFragment.js.flow +62 -0
- package/util/getRefetchMetadata.js.flow +79 -0
- package/util/getRelayHandleKey.js.flow +1 -2
- package/util/getRequestIdentifier.js.flow +3 -3
- package/util/getValueAtPath.js.flow +46 -0
- package/util/isEmptyObject.js.flow +1 -0
- package/util/registerEnvironmentWithDevTools.js.flow +33 -0
- package/util/resolveImmediate.js.flow +1 -1
- package/util/withDuration.js.flow +32 -0
- package/lib/store/RelayRecordSourceMapImpl.js +0 -107
- package/lib/store/RelayStoreSubscriptionsUsingMapByID.js +0 -318
- package/store/RelayRecordSourceMapImpl.js.flow +0 -91
- package/store/RelayStoreSubscriptionsUsingMapByID.js.flow +0 -283
|
@@ -0,0 +1,506 @@
|
|
|
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
|
+
import type {HandlerProvider} from '../handlers/RelayDefaultHandlerProvider';
|
|
15
|
+
import type {GraphQLResponse, PayloadData} from '../network/RelayNetworkTypes';
|
|
16
|
+
import type {INetwork} from '../network/RelayNetworkTypes';
|
|
17
|
+
import type {ActiveState, TaskScheduler} from '../store/OperationExecutor';
|
|
18
|
+
import type {GetDataID} from '../store/RelayResponseNormalizer';
|
|
19
|
+
import type {
|
|
20
|
+
ExecuteMutationConfig,
|
|
21
|
+
LogFunction,
|
|
22
|
+
MissingFieldHandler,
|
|
23
|
+
MutableRecordSource,
|
|
24
|
+
MutationParameters,
|
|
25
|
+
OperationAvailability,
|
|
26
|
+
OperationDescriptor,
|
|
27
|
+
OperationLoader,
|
|
28
|
+
OptimisticResponseConfig,
|
|
29
|
+
OptimisticUpdateFunction,
|
|
30
|
+
ReactFlightPayloadDeserializer,
|
|
31
|
+
ReactFlightServerErrorHandler,
|
|
32
|
+
RequiredFieldLogger,
|
|
33
|
+
SelectorStoreUpdater,
|
|
34
|
+
SingularReaderSelector,
|
|
35
|
+
Snapshot,
|
|
36
|
+
Store,
|
|
37
|
+
StoreUpdater,
|
|
38
|
+
} from '../store/RelayStoreTypes';
|
|
39
|
+
import type {Disposable} from '../util/RelayRuntimeTypes';
|
|
40
|
+
import type {RenderPolicy} from '../util/RelayRuntimeTypes';
|
|
41
|
+
import type {ActorIdentifier} from './ActorIdentifier';
|
|
42
|
+
import type {
|
|
43
|
+
IActorEnvironment,
|
|
44
|
+
IMultiActorEnvironment,
|
|
45
|
+
MultiActorStoreUpdater,
|
|
46
|
+
} from './MultiActorEnvironmentTypes';
|
|
47
|
+
|
|
48
|
+
const RelayDefaultHandlerProvider = require('../handlers/RelayDefaultHandlerProvider');
|
|
49
|
+
const RelayObservable = require('../network/RelayObservable');
|
|
50
|
+
const defaultGetDataID = require('../store/defaultGetDataID');
|
|
51
|
+
const defaultRequiredFieldLogger = require('../store/defaultRequiredFieldLogger');
|
|
52
|
+
const OperationExecutor = require('../store/OperationExecutor');
|
|
53
|
+
const RelayModernStore = require('../store/RelayModernStore');
|
|
54
|
+
const RelayRecordSource = require('../store/RelayRecordSource');
|
|
55
|
+
const ActorSpecificEnvironment = require('./ActorSpecificEnvironment');
|
|
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).getStore().getSource();
|
|
165
|
+
},
|
|
166
|
+
getTargetForActor: () => {
|
|
167
|
+
return RelayRecordSource.create();
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
return this._checkSelectorAndHandleMissingFields(
|
|
172
|
+
actorEnvironment,
|
|
173
|
+
operation,
|
|
174
|
+
this._missingFieldHandlers,
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
_checkSelectorAndHandleMissingFields(
|
|
179
|
+
actorEnvironment: IActorEnvironment,
|
|
180
|
+
operation: OperationDescriptor,
|
|
181
|
+
handlers: $ReadOnlyArray<MissingFieldHandler>,
|
|
182
|
+
): OperationAvailability {
|
|
183
|
+
const targets: Map<ActorIdentifier, MutableRecordSource> = new Map([
|
|
184
|
+
[actorEnvironment.actorIdentifier, RelayRecordSource.create()],
|
|
185
|
+
]);
|
|
186
|
+
const result = actorEnvironment.getStore().check(operation, {
|
|
187
|
+
handlers,
|
|
188
|
+
defaultActorIdentifier: actorEnvironment.actorIdentifier,
|
|
189
|
+
getSourceForActor: actorIdentifier => {
|
|
190
|
+
return this.forActor(actorIdentifier).getStore().getSource();
|
|
191
|
+
},
|
|
192
|
+
getTargetForActor: actorIdentifier => {
|
|
193
|
+
let target = targets.get(actorIdentifier);
|
|
194
|
+
if (target == null) {
|
|
195
|
+
target = RelayRecordSource.create();
|
|
196
|
+
targets.set(actorIdentifier, target);
|
|
197
|
+
}
|
|
198
|
+
return target;
|
|
199
|
+
},
|
|
200
|
+
});
|
|
201
|
+
for (const [actorIdentifier, target] of targets) {
|
|
202
|
+
if (target.size() > 0) {
|
|
203
|
+
this._scheduleUpdates(() => {
|
|
204
|
+
const publishQueue = this.forActor(actorIdentifier).getPublishQueue();
|
|
205
|
+
publishQueue.commitSource(target);
|
|
206
|
+
publishQueue.run();
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return result;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
subscribe(
|
|
215
|
+
actorEnvironment: IActorEnvironment,
|
|
216
|
+
snapshot: Snapshot,
|
|
217
|
+
callback: (snapshot: Snapshot) => void,
|
|
218
|
+
): Disposable {
|
|
219
|
+
// TODO: make actor aware
|
|
220
|
+
return actorEnvironment.getStore().subscribe(snapshot, callback);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
retain(
|
|
224
|
+
actorEnvironment: IActorEnvironment,
|
|
225
|
+
operation: OperationDescriptor,
|
|
226
|
+
): Disposable {
|
|
227
|
+
// TODO: make actor aware
|
|
228
|
+
return actorEnvironment.getStore().retain(operation);
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
applyUpdate(
|
|
232
|
+
actorEnvironment: IActorEnvironment,
|
|
233
|
+
optimisticUpdate: OptimisticUpdateFunction,
|
|
234
|
+
): Disposable {
|
|
235
|
+
const publishQueue = actorEnvironment.getPublishQueue();
|
|
236
|
+
const dispose = () => {
|
|
237
|
+
this._scheduleUpdates(() => {
|
|
238
|
+
publishQueue.revertUpdate(optimisticUpdate);
|
|
239
|
+
publishQueue.run();
|
|
240
|
+
});
|
|
241
|
+
};
|
|
242
|
+
this._scheduleUpdates(() => {
|
|
243
|
+
publishQueue.applyUpdate(optimisticUpdate);
|
|
244
|
+
publishQueue.run();
|
|
245
|
+
});
|
|
246
|
+
return {dispose};
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
revertUpdate(
|
|
250
|
+
actorEnvironment: IActorEnvironment,
|
|
251
|
+
update: OptimisticUpdateFunction,
|
|
252
|
+
): void {
|
|
253
|
+
const publishQueue = actorEnvironment.getPublishQueue();
|
|
254
|
+
this._scheduleUpdates(() => {
|
|
255
|
+
publishQueue.revertUpdate(update);
|
|
256
|
+
publishQueue.run();
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
replaceUpdate(
|
|
261
|
+
actorEnvironment: IActorEnvironment,
|
|
262
|
+
update: OptimisticUpdateFunction,
|
|
263
|
+
replacement: OptimisticUpdateFunction,
|
|
264
|
+
): void {
|
|
265
|
+
const publishQueue = actorEnvironment.getPublishQueue();
|
|
266
|
+
this._scheduleUpdates(() => {
|
|
267
|
+
publishQueue.revertUpdate(update);
|
|
268
|
+
publishQueue.applyUpdate(replacement);
|
|
269
|
+
publishQueue.run();
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
applyMutation<TMutation: MutationParameters>(
|
|
274
|
+
actorEnvironment: IActorEnvironment,
|
|
275
|
+
optimisticConfig: OptimisticResponseConfig<TMutation>,
|
|
276
|
+
): Disposable {
|
|
277
|
+
const subscription = this._execute(actorEnvironment, {
|
|
278
|
+
createSource: () => RelayObservable.create(_sink => {}),
|
|
279
|
+
isClientPayload: false,
|
|
280
|
+
operation: optimisticConfig.operation,
|
|
281
|
+
optimisticConfig,
|
|
282
|
+
updater: null,
|
|
283
|
+
}).subscribe({});
|
|
284
|
+
return {
|
|
285
|
+
dispose: () => subscription.unsubscribe(),
|
|
286
|
+
};
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
commitUpdate(
|
|
290
|
+
actorEnvironment: IActorEnvironment,
|
|
291
|
+
updater: StoreUpdater,
|
|
292
|
+
): void {
|
|
293
|
+
const publishQueue = actorEnvironment.getPublishQueue();
|
|
294
|
+
this._scheduleUpdates(() => {
|
|
295
|
+
publishQueue.commitUpdate(updater);
|
|
296
|
+
publishQueue.run();
|
|
297
|
+
});
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
commitPayload(
|
|
301
|
+
actorEnvironment: IActorEnvironment,
|
|
302
|
+
operationDescriptor: OperationDescriptor,
|
|
303
|
+
payload: PayloadData,
|
|
304
|
+
): void {
|
|
305
|
+
this._execute(actorEnvironment, {
|
|
306
|
+
createSource: () => RelayObservable.from({data: payload}),
|
|
307
|
+
isClientPayload: true,
|
|
308
|
+
operation: operationDescriptor,
|
|
309
|
+
optimisticConfig: null,
|
|
310
|
+
updater: null,
|
|
311
|
+
}).subscribe({});
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
lookup(
|
|
315
|
+
actorEnvironment: IActorEnvironment,
|
|
316
|
+
selector: SingularReaderSelector,
|
|
317
|
+
): Snapshot {
|
|
318
|
+
// TODO: make actor aware
|
|
319
|
+
return actorEnvironment.getStore().lookup(selector);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
execute(
|
|
323
|
+
actorEnvironment: IActorEnvironment,
|
|
324
|
+
{
|
|
325
|
+
operation,
|
|
326
|
+
}: {
|
|
327
|
+
operation: OperationDescriptor,
|
|
328
|
+
},
|
|
329
|
+
): RelayObservable<GraphQLResponse> {
|
|
330
|
+
return this._execute(actorEnvironment, {
|
|
331
|
+
createSource: () =>
|
|
332
|
+
actorEnvironment
|
|
333
|
+
.getNetwork()
|
|
334
|
+
.execute(
|
|
335
|
+
operation.request.node.params,
|
|
336
|
+
operation.request.variables,
|
|
337
|
+
operation.request.cacheConfig || {},
|
|
338
|
+
null,
|
|
339
|
+
),
|
|
340
|
+
isClientPayload: false,
|
|
341
|
+
operation,
|
|
342
|
+
optimisticConfig: null,
|
|
343
|
+
updater: null,
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
executeSubscription<TMutation: MutationParameters>(
|
|
348
|
+
actorEnvironment: IActorEnvironment,
|
|
349
|
+
{
|
|
350
|
+
operation,
|
|
351
|
+
updater,
|
|
352
|
+
}: {
|
|
353
|
+
operation: OperationDescriptor,
|
|
354
|
+
updater?: ?SelectorStoreUpdater<TMutation['response']>,
|
|
355
|
+
},
|
|
356
|
+
): RelayObservable<GraphQLResponse> {
|
|
357
|
+
return this._execute(actorEnvironment, {
|
|
358
|
+
createSource: () =>
|
|
359
|
+
actorEnvironment
|
|
360
|
+
.getNetwork()
|
|
361
|
+
.execute(
|
|
362
|
+
operation.request.node.params,
|
|
363
|
+
operation.request.variables,
|
|
364
|
+
operation.request.cacheConfig || {},
|
|
365
|
+
null,
|
|
366
|
+
),
|
|
367
|
+
isClientPayload: false,
|
|
368
|
+
operation,
|
|
369
|
+
optimisticConfig: null,
|
|
370
|
+
updater,
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
executeMutation<TMutation: MutationParameters>(
|
|
375
|
+
actorEnvironment: IActorEnvironment,
|
|
376
|
+
{
|
|
377
|
+
operation,
|
|
378
|
+
optimisticResponse,
|
|
379
|
+
optimisticUpdater,
|
|
380
|
+
updater,
|
|
381
|
+
uploadables,
|
|
382
|
+
}: ExecuteMutationConfig<TMutation>,
|
|
383
|
+
): RelayObservable<GraphQLResponse> {
|
|
384
|
+
let optimisticConfig;
|
|
385
|
+
if (optimisticResponse || optimisticUpdater) {
|
|
386
|
+
optimisticConfig = {
|
|
387
|
+
operation: operation,
|
|
388
|
+
response: optimisticResponse,
|
|
389
|
+
updater: optimisticUpdater,
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
return this._execute(actorEnvironment, {
|
|
393
|
+
createSource: () =>
|
|
394
|
+
actorEnvironment.getNetwork().execute(
|
|
395
|
+
operation.request.node.params,
|
|
396
|
+
operation.request.variables,
|
|
397
|
+
{
|
|
398
|
+
...operation.request.cacheConfig,
|
|
399
|
+
force: true,
|
|
400
|
+
},
|
|
401
|
+
uploadables,
|
|
402
|
+
),
|
|
403
|
+
isClientPayload: false,
|
|
404
|
+
operation,
|
|
405
|
+
optimisticConfig,
|
|
406
|
+
updater,
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
executeWithSource(
|
|
411
|
+
actorEnvironment: IActorEnvironment,
|
|
412
|
+
config: {
|
|
413
|
+
operation: OperationDescriptor,
|
|
414
|
+
source: RelayObservable<GraphQLResponse>,
|
|
415
|
+
},
|
|
416
|
+
): RelayObservable<GraphQLResponse> {
|
|
417
|
+
return this._execute(actorEnvironment, {
|
|
418
|
+
createSource: () => config.source,
|
|
419
|
+
isClientPayload: false,
|
|
420
|
+
operation: config.operation,
|
|
421
|
+
optimisticConfig: null,
|
|
422
|
+
updater: null,
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
isRequestActive(
|
|
427
|
+
_actorEnvironment: IActorEnvironment,
|
|
428
|
+
requestIdentifier: string,
|
|
429
|
+
): boolean {
|
|
430
|
+
const activeState = this._operationExecutions.get(requestIdentifier);
|
|
431
|
+
return activeState === 'active';
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
isServer(): boolean {
|
|
435
|
+
return this._isServer;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
_execute<TMutation: MutationParameters>(
|
|
439
|
+
actorEnvironment: IActorEnvironment,
|
|
440
|
+
{
|
|
441
|
+
createSource,
|
|
442
|
+
isClientPayload,
|
|
443
|
+
operation,
|
|
444
|
+
optimisticConfig,
|
|
445
|
+
updater,
|
|
446
|
+
}: {|
|
|
447
|
+
createSource: () => RelayObservable<GraphQLResponse>,
|
|
448
|
+
isClientPayload: boolean,
|
|
449
|
+
operation: OperationDescriptor,
|
|
450
|
+
optimisticConfig: ?OptimisticResponseConfig<TMutation>,
|
|
451
|
+
updater: ?SelectorStoreUpdater<TMutation['response']>,
|
|
452
|
+
|},
|
|
453
|
+
): RelayObservable<GraphQLResponse> {
|
|
454
|
+
return RelayObservable.create(sink => {
|
|
455
|
+
const executor = OperationExecutor.execute({
|
|
456
|
+
actorIdentifier: actorEnvironment.actorIdentifier,
|
|
457
|
+
getDataID: this._getDataID,
|
|
458
|
+
isClientPayload,
|
|
459
|
+
operation,
|
|
460
|
+
operationExecutions: this._operationExecutions,
|
|
461
|
+
operationLoader: this._operationLoader,
|
|
462
|
+
operationTracker: actorEnvironment.getOperationTracker(),
|
|
463
|
+
optimisticConfig,
|
|
464
|
+
getPublishQueue: (actorIdentifier: ActorIdentifier) => {
|
|
465
|
+
return this.forActor(actorIdentifier).getPublishQueue();
|
|
466
|
+
},
|
|
467
|
+
reactFlightPayloadDeserializer: this._reactFlightPayloadDeserializer,
|
|
468
|
+
reactFlightServerErrorHandler: this._reactFlightServerErrorHandler,
|
|
469
|
+
scheduler: this._scheduler,
|
|
470
|
+
shouldProcessClientComponents: this._shouldProcessClientComponents,
|
|
471
|
+
sink,
|
|
472
|
+
// NOTE: Some product tests expect `Network.execute` to be called only
|
|
473
|
+
// when the Observable is executed.
|
|
474
|
+
source: createSource(),
|
|
475
|
+
getStore: (actorIdentifier: ActorIdentifier) => {
|
|
476
|
+
return this.forActor(actorIdentifier).getStore();
|
|
477
|
+
},
|
|
478
|
+
treatMissingFieldsAsNull: this._treatMissingFieldsAsNull,
|
|
479
|
+
updater,
|
|
480
|
+
log: this._logFn,
|
|
481
|
+
});
|
|
482
|
+
return () => executor.cancel();
|
|
483
|
+
});
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
_scheduleUpdates(task: () => void) {
|
|
487
|
+
const scheduler = this._scheduler;
|
|
488
|
+
if (scheduler != null) {
|
|
489
|
+
scheduler.schedule(task);
|
|
490
|
+
} else {
|
|
491
|
+
task();
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
commitMultiActorUpdate(updater: MultiActorStoreUpdater): void {
|
|
496
|
+
for (const [actorIdentifier, environment] of this._actorEnvironments) {
|
|
497
|
+
environment.commitUpdate(storeProxy => {
|
|
498
|
+
updater(actorIdentifier, environment, storeProxy);
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
function emptyFunction() {}
|
|
505
|
+
|
|
506
|
+
module.exports = MultiActorEnvironment;
|