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
|
@@ -13,41 +13,22 @@
|
|
|
13
13
|
|
|
14
14
|
'use strict';
|
|
15
15
|
|
|
16
|
-
const RelayDefaultHandlerProvider = require('../handlers/RelayDefaultHandlerProvider');
|
|
17
|
-
const RelayFeatureFlags = require('../util/RelayFeatureFlags');
|
|
18
|
-
const RelayModernQueryExecutor = require('./RelayModernQueryExecutor');
|
|
19
|
-
const RelayObservable = require('../network/RelayObservable');
|
|
20
|
-
const RelayOperationTracker = require('../store/RelayOperationTracker');
|
|
21
|
-
const RelayPublishQueue = require('./RelayPublishQueue');
|
|
22
|
-
const RelayRecordSource = require('./RelayRecordSource');
|
|
23
|
-
|
|
24
|
-
const defaultGetDataID = require('./defaultGetDataID');
|
|
25
|
-
const defaultRequiredFieldLogger = require('./defaultRequiredFieldLogger');
|
|
26
|
-
const generateID = require('../util/generateID');
|
|
27
|
-
const invariant = require('invariant');
|
|
28
|
-
|
|
29
16
|
import type {HandlerProvider} from '../handlers/RelayDefaultHandlerProvider';
|
|
17
|
+
import type {ActorIdentifier} from '../multi-actor-environment/ActorIdentifier';
|
|
30
18
|
import type {
|
|
31
19
|
GraphQLResponse,
|
|
32
20
|
INetwork,
|
|
33
21
|
PayloadData,
|
|
34
|
-
UploadableMap,
|
|
35
22
|
} from '../network/RelayNetworkTypes';
|
|
36
|
-
import type {
|
|
37
|
-
import type {
|
|
38
|
-
CacheConfig,
|
|
39
|
-
Disposable,
|
|
40
|
-
RenderPolicy,
|
|
41
|
-
Variables,
|
|
42
|
-
} from '../util/RelayRuntimeTypes';
|
|
43
|
-
import type {ActiveState} from './RelayModernQueryExecutor';
|
|
44
|
-
import type {TaskScheduler} from './RelayModernQueryExecutor';
|
|
23
|
+
import type {Disposable, RenderPolicy} from '../util/RelayRuntimeTypes';
|
|
24
|
+
import type {ActiveState, TaskScheduler} from './OperationExecutor';
|
|
45
25
|
import type {GetDataID} from './RelayResponseNormalizer';
|
|
46
26
|
import type {
|
|
27
|
+
ExecuteMutationConfig,
|
|
47
28
|
IEnvironment,
|
|
48
29
|
LogFunction,
|
|
49
30
|
MissingFieldHandler,
|
|
50
|
-
|
|
31
|
+
MutationParameters,
|
|
51
32
|
OperationAvailability,
|
|
52
33
|
OperationDescriptor,
|
|
53
34
|
OperationLoader,
|
|
@@ -57,6 +38,7 @@ import type {
|
|
|
57
38
|
PublishQueue,
|
|
58
39
|
ReactFlightPayloadDeserializer,
|
|
59
40
|
ReactFlightServerErrorHandler,
|
|
41
|
+
RequiredFieldLogger,
|
|
60
42
|
SelectorStoreUpdater,
|
|
61
43
|
SingularReaderSelector,
|
|
62
44
|
Snapshot,
|
|
@@ -64,6 +46,23 @@ import type {
|
|
|
64
46
|
StoreUpdater,
|
|
65
47
|
} from './RelayStoreTypes';
|
|
66
48
|
|
|
49
|
+
const RelayDefaultHandlerProvider = require('../handlers/RelayDefaultHandlerProvider');
|
|
50
|
+
const {
|
|
51
|
+
INTERNAL_ACTOR_IDENTIFIER_DO_NOT_USE,
|
|
52
|
+
assertInternalActorIndentifier,
|
|
53
|
+
} = require('../multi-actor-environment/ActorIdentifier');
|
|
54
|
+
const RelayObservable = require('../network/RelayObservable');
|
|
55
|
+
const wrapNetworkWithLogObserver = require('../network/wrapNetworkWithLogObserver');
|
|
56
|
+
const RelayOperationTracker = require('../store/RelayOperationTracker');
|
|
57
|
+
const registerEnvironmentWithDevTools = require('../util/registerEnvironmentWithDevTools');
|
|
58
|
+
const RelayFeatureFlags = require('../util/RelayFeatureFlags');
|
|
59
|
+
const defaultGetDataID = require('./defaultGetDataID');
|
|
60
|
+
const defaultRequiredFieldLogger = require('./defaultRequiredFieldLogger');
|
|
61
|
+
const OperationExecutor = require('./OperationExecutor');
|
|
62
|
+
const RelayPublishQueue = require('./RelayPublishQueue');
|
|
63
|
+
const RelayRecordSource = require('./RelayRecordSource');
|
|
64
|
+
const invariant = require('invariant');
|
|
65
|
+
|
|
67
66
|
export type EnvironmentConfig = {|
|
|
68
67
|
+configName?: string,
|
|
69
68
|
+handlerProvider?: ?HandlerProvider,
|
|
@@ -108,9 +107,6 @@ class RelayModernEnvironment implements IEnvironment {
|
|
|
108
107
|
|
|
109
108
|
constructor(config: EnvironmentConfig) {
|
|
110
109
|
this.configName = config.configName;
|
|
111
|
-
const handlerProvider = config.handlerProvider
|
|
112
|
-
? config.handlerProvider
|
|
113
|
-
: RelayDefaultHandlerProvider;
|
|
114
110
|
this._treatMissingFieldsAsNull = config.treatMissingFieldsAsNull === true;
|
|
115
111
|
const operationLoader = config.operationLoader;
|
|
116
112
|
const reactFlightPayloadDeserializer =
|
|
@@ -146,11 +142,11 @@ class RelayModernEnvironment implements IEnvironment {
|
|
|
146
142
|
: 'full';
|
|
147
143
|
this._operationLoader = operationLoader;
|
|
148
144
|
this._operationExecutions = new Map();
|
|
149
|
-
this._network = this
|
|
145
|
+
this._network = wrapNetworkWithLogObserver(this, config.network);
|
|
150
146
|
this._getDataID = config.getDataID ?? defaultGetDataID;
|
|
151
147
|
this._publishQueue = new RelayPublishQueue(
|
|
152
148
|
config.store,
|
|
153
|
-
handlerProvider,
|
|
149
|
+
config.handlerProvider ?? RelayDefaultHandlerProvider,
|
|
154
150
|
this._getDataID,
|
|
155
151
|
);
|
|
156
152
|
this._scheduler = config.scheduler ?? null;
|
|
@@ -159,31 +155,23 @@ class RelayModernEnvironment implements IEnvironment {
|
|
|
159
155
|
this._isServer = config.isServer ?? false;
|
|
160
156
|
|
|
161
157
|
(this: any).__setNet = newNet =>
|
|
162
|
-
(this._network = this
|
|
158
|
+
(this._network = wrapNetworkWithLogObserver(this, newNet));
|
|
163
159
|
|
|
164
160
|
if (__DEV__) {
|
|
165
161
|
const {inspect} = require('./StoreInspector');
|
|
166
162
|
(this: any).DEBUG_inspect = (dataID: ?string) => inspect(this, dataID);
|
|
167
163
|
}
|
|
168
164
|
|
|
169
|
-
// Register this Relay Environment with Relay DevTools if it exists.
|
|
170
|
-
// Note: this must always be the last step in the constructor.
|
|
171
|
-
const _global =
|
|
172
|
-
typeof global !== 'undefined'
|
|
173
|
-
? global
|
|
174
|
-
: typeof window !== 'undefined'
|
|
175
|
-
? window
|
|
176
|
-
: undefined;
|
|
177
|
-
const devToolsHook = _global && _global.__RELAY_DEVTOOLS_HOOK__;
|
|
178
|
-
if (devToolsHook) {
|
|
179
|
-
devToolsHook.registerEnvironment(this);
|
|
180
|
-
}
|
|
181
165
|
this._missingFieldHandlers = config.missingFieldHandlers;
|
|
182
166
|
this._operationTracker =
|
|
183
167
|
config.operationTracker ?? new RelayOperationTracker();
|
|
184
168
|
this._reactFlightPayloadDeserializer = reactFlightPayloadDeserializer;
|
|
185
169
|
this._reactFlightServerErrorHandler = reactFlightServerErrorHandler;
|
|
186
170
|
this._shouldProcessClientComponents = config.shouldProcessClientComponents;
|
|
171
|
+
|
|
172
|
+
// Register this Relay Environment with Relay DevTools if it exists.
|
|
173
|
+
// Note: this must always be the last step in the constructor.
|
|
174
|
+
registerEnvironmentWithDevTools(this);
|
|
187
175
|
}
|
|
188
176
|
|
|
189
177
|
getStore(): Store {
|
|
@@ -239,28 +227,15 @@ class RelayModernEnvironment implements IEnvironment {
|
|
|
239
227
|
});
|
|
240
228
|
}
|
|
241
229
|
|
|
242
|
-
applyMutation
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
reactFlightPayloadDeserializer: this._reactFlightPayloadDeserializer,
|
|
252
|
-
reactFlightServerErrorHandler: this._reactFlightServerErrorHandler,
|
|
253
|
-
scheduler: this._scheduler,
|
|
254
|
-
sink,
|
|
255
|
-
source,
|
|
256
|
-
store: this._store,
|
|
257
|
-
updater: null,
|
|
258
|
-
operationTracker: this._operationTracker,
|
|
259
|
-
getDataID: this._getDataID,
|
|
260
|
-
treatMissingFieldsAsNull: this._treatMissingFieldsAsNull,
|
|
261
|
-
shouldProcessClientComponents: this._shouldProcessClientComponents,
|
|
262
|
-
});
|
|
263
|
-
return () => executor.cancel();
|
|
230
|
+
applyMutation<TMutation: MutationParameters>(
|
|
231
|
+
optimisticConfig: OptimisticResponseConfig<TMutation>,
|
|
232
|
+
): Disposable {
|
|
233
|
+
const subscription = this._execute({
|
|
234
|
+
createSource: () => RelayObservable.create(_sink => {}),
|
|
235
|
+
isClientPayload: false,
|
|
236
|
+
operation: optimisticConfig.operation,
|
|
237
|
+
optimisticConfig,
|
|
238
|
+
updater: null,
|
|
264
239
|
}).subscribe({});
|
|
265
240
|
return {
|
|
266
241
|
dispose: () => subscription.unsubscribe(),
|
|
@@ -281,29 +256,12 @@ class RelayModernEnvironment implements IEnvironment {
|
|
|
281
256
|
}
|
|
282
257
|
|
|
283
258
|
commitPayload(operation: OperationDescriptor, payload: PayloadData): void {
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
publishQueue: this._publishQueue,
|
|
291
|
-
reactFlightPayloadDeserializer: this._reactFlightPayloadDeserializer,
|
|
292
|
-
reactFlightServerErrorHandler: this._reactFlightServerErrorHandler,
|
|
293
|
-
scheduler: this._scheduler,
|
|
294
|
-
sink,
|
|
295
|
-
source: RelayObservable.from({
|
|
296
|
-
data: payload,
|
|
297
|
-
}),
|
|
298
|
-
store: this._store,
|
|
299
|
-
updater: null,
|
|
300
|
-
operationTracker: this._operationTracker,
|
|
301
|
-
getDataID: this._getDataID,
|
|
302
|
-
isClientPayload: true,
|
|
303
|
-
treatMissingFieldsAsNull: this._treatMissingFieldsAsNull,
|
|
304
|
-
shouldProcessClientComponents: this._shouldProcessClientComponents,
|
|
305
|
-
});
|
|
306
|
-
return () => executor.cancel();
|
|
259
|
+
this._execute({
|
|
260
|
+
createSource: () => RelayObservable.from({data: payload}),
|
|
261
|
+
isClientPayload: true,
|
|
262
|
+
operation: operation,
|
|
263
|
+
optimisticConfig: null,
|
|
264
|
+
updater: null,
|
|
307
265
|
}).subscribe({});
|
|
308
266
|
}
|
|
309
267
|
|
|
@@ -338,7 +296,19 @@ class RelayModernEnvironment implements IEnvironment {
|
|
|
338
296
|
handlers: $ReadOnlyArray<MissingFieldHandler>,
|
|
339
297
|
): OperationAvailability {
|
|
340
298
|
const target = RelayRecordSource.create();
|
|
341
|
-
const
|
|
299
|
+
const source = this._store.getSource();
|
|
300
|
+
const result = this._store.check(operation, {
|
|
301
|
+
handlers,
|
|
302
|
+
defaultActorIdentifier: INTERNAL_ACTOR_IDENTIFIER_DO_NOT_USE,
|
|
303
|
+
getSourceForActor(actorIdentifier: ActorIdentifier) {
|
|
304
|
+
assertInternalActorIndentifier(actorIdentifier);
|
|
305
|
+
return source;
|
|
306
|
+
},
|
|
307
|
+
getTargetForActor(actorIdentifier: ActorIdentifier) {
|
|
308
|
+
assertInternalActorIndentifier(actorIdentifier);
|
|
309
|
+
return target;
|
|
310
|
+
},
|
|
311
|
+
});
|
|
342
312
|
if (target.size() > 0) {
|
|
343
313
|
this._scheduleUpdates(() => {
|
|
344
314
|
this._publishQueue.commitSource(target);
|
|
@@ -359,7 +329,7 @@ class RelayModernEnvironment implements IEnvironment {
|
|
|
359
329
|
|
|
360
330
|
/**
|
|
361
331
|
* Returns an Observable of GraphQLResponse resulting from executing the
|
|
362
|
-
* provided Query
|
|
332
|
+
* provided Query operation, each result of which is then
|
|
363
333
|
* normalized and committed to the publish queue.
|
|
364
334
|
*
|
|
365
335
|
* Note: Observables are lazy, so calling this method will do nothing until
|
|
@@ -367,37 +337,51 @@ class RelayModernEnvironment implements IEnvironment {
|
|
|
367
337
|
*/
|
|
368
338
|
execute({
|
|
369
339
|
operation,
|
|
340
|
+
}: {|
|
|
341
|
+
operation: OperationDescriptor,
|
|
342
|
+
|}): RelayObservable<GraphQLResponse> {
|
|
343
|
+
return this._execute({
|
|
344
|
+
createSource: () =>
|
|
345
|
+
this._network.execute(
|
|
346
|
+
operation.request.node.params,
|
|
347
|
+
operation.request.variables,
|
|
348
|
+
operation.request.cacheConfig || {},
|
|
349
|
+
null,
|
|
350
|
+
),
|
|
351
|
+
isClientPayload: false,
|
|
352
|
+
operation,
|
|
353
|
+
optimisticConfig: null,
|
|
354
|
+
updater: null,
|
|
355
|
+
});
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/**
|
|
359
|
+
* Returns an Observable of GraphQLResponse resulting from executing the
|
|
360
|
+
* provided Subscription operation, each result of which is then
|
|
361
|
+
* normalized and committed to the publish queue.
|
|
362
|
+
*
|
|
363
|
+
* Note: Observables are lazy, so calling this method will do nothing until
|
|
364
|
+
* the result is subscribed to: environment.execute({...}).subscribe({...}).
|
|
365
|
+
*/
|
|
366
|
+
executeSubscription<TMutation: MutationParameters>({
|
|
367
|
+
operation,
|
|
370
368
|
updater,
|
|
371
369
|
}: {|
|
|
372
370
|
operation: OperationDescriptor,
|
|
373
|
-
updater?: ?SelectorStoreUpdater
|
|
371
|
+
updater?: ?SelectorStoreUpdater<TMutation['response']>,
|
|
374
372
|
|}): RelayObservable<GraphQLResponse> {
|
|
375
|
-
return
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
publishQueue: this._publishQueue,
|
|
388
|
-
reactFlightPayloadDeserializer: this._reactFlightPayloadDeserializer,
|
|
389
|
-
reactFlightServerErrorHandler: this._reactFlightServerErrorHandler,
|
|
390
|
-
scheduler: this._scheduler,
|
|
391
|
-
sink,
|
|
392
|
-
source,
|
|
393
|
-
store: this._store,
|
|
394
|
-
updater,
|
|
395
|
-
operationTracker: this._operationTracker,
|
|
396
|
-
getDataID: this._getDataID,
|
|
397
|
-
treatMissingFieldsAsNull: this._treatMissingFieldsAsNull,
|
|
398
|
-
shouldProcessClientComponents: this._shouldProcessClientComponents,
|
|
399
|
-
});
|
|
400
|
-
return () => executor.cancel();
|
|
373
|
+
return this._execute({
|
|
374
|
+
createSource: () =>
|
|
375
|
+
this._network.execute(
|
|
376
|
+
operation.request.node.params,
|
|
377
|
+
operation.request.variables,
|
|
378
|
+
operation.request.cacheConfig || {},
|
|
379
|
+
null,
|
|
380
|
+
),
|
|
381
|
+
isClientPayload: false,
|
|
382
|
+
operation,
|
|
383
|
+
optimisticConfig: null,
|
|
384
|
+
updater,
|
|
401
385
|
});
|
|
402
386
|
}
|
|
403
387
|
|
|
@@ -411,63 +395,43 @@ class RelayModernEnvironment implements IEnvironment {
|
|
|
411
395
|
* the result is subscribed to:
|
|
412
396
|
* environment.executeMutation({...}).subscribe({...}).
|
|
413
397
|
*/
|
|
414
|
-
executeMutation({
|
|
398
|
+
executeMutation<TMutation: MutationParameters>({
|
|
415
399
|
operation,
|
|
416
400
|
optimisticResponse,
|
|
417
401
|
optimisticUpdater,
|
|
418
402
|
updater,
|
|
419
403
|
uploadables,
|
|
420
|
-
}: {
|
|
421
|
-
|
|
422
|
-
optimisticUpdater
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
);
|
|
445
|
-
const executor = RelayModernQueryExecutor.execute({
|
|
446
|
-
operation,
|
|
447
|
-
operationExecutions: this._operationExecutions,
|
|
448
|
-
operationLoader: this._operationLoader,
|
|
449
|
-
optimisticConfig,
|
|
450
|
-
publishQueue: this._publishQueue,
|
|
451
|
-
reactFlightPayloadDeserializer: this._reactFlightPayloadDeserializer,
|
|
452
|
-
reactFlightServerErrorHandler: this._reactFlightServerErrorHandler,
|
|
453
|
-
scheduler: this._scheduler,
|
|
454
|
-
sink,
|
|
455
|
-
source,
|
|
456
|
-
store: this._store,
|
|
457
|
-
updater,
|
|
458
|
-
operationTracker: this._operationTracker,
|
|
459
|
-
getDataID: this._getDataID,
|
|
460
|
-
treatMissingFieldsAsNull: this._treatMissingFieldsAsNull,
|
|
461
|
-
shouldProcessClientComponents: this._shouldProcessClientComponents,
|
|
462
|
-
});
|
|
463
|
-
return () => executor.cancel();
|
|
404
|
+
}: ExecuteMutationConfig<TMutation>): RelayObservable<GraphQLResponse> {
|
|
405
|
+
let optimisticConfig;
|
|
406
|
+
if (optimisticResponse || optimisticUpdater) {
|
|
407
|
+
optimisticConfig = {
|
|
408
|
+
operation: operation,
|
|
409
|
+
response: optimisticResponse,
|
|
410
|
+
updater: optimisticUpdater,
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
return this._execute({
|
|
414
|
+
createSource: () =>
|
|
415
|
+
this._network.execute(
|
|
416
|
+
operation.request.node.params,
|
|
417
|
+
operation.request.variables,
|
|
418
|
+
{
|
|
419
|
+
...operation.request.cacheConfig,
|
|
420
|
+
force: true,
|
|
421
|
+
},
|
|
422
|
+
uploadables,
|
|
423
|
+
),
|
|
424
|
+
isClientPayload: false,
|
|
425
|
+
operation,
|
|
426
|
+
optimisticConfig,
|
|
427
|
+
updater,
|
|
464
428
|
});
|
|
465
429
|
}
|
|
466
430
|
|
|
467
431
|
/**
|
|
468
432
|
* Returns an Observable of GraphQLResponse resulting from executing the
|
|
469
433
|
* provided Query or Subscription operation responses, the result of which is
|
|
470
|
-
* then normalized and
|
|
434
|
+
* then normalized and committed to the publish queue.
|
|
471
435
|
*
|
|
472
436
|
* Note: Observables are lazy, so calling this method will do nothing until
|
|
473
437
|
* the result is subscribed to:
|
|
@@ -480,98 +444,67 @@ class RelayModernEnvironment implements IEnvironment {
|
|
|
480
444
|
operation: OperationDescriptor,
|
|
481
445
|
source: RelayObservable<GraphQLResponse>,
|
|
482
446
|
|}): RelayObservable<GraphQLResponse> {
|
|
447
|
+
return this._execute({
|
|
448
|
+
createSource: () => source,
|
|
449
|
+
isClientPayload: false,
|
|
450
|
+
operation,
|
|
451
|
+
optimisticConfig: null,
|
|
452
|
+
updater: null,
|
|
453
|
+
});
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
toJSON(): mixed {
|
|
457
|
+
return `RelayModernEnvironment(${this.configName ?? ''})`;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
_execute<TMutation: MutationParameters>({
|
|
461
|
+
createSource,
|
|
462
|
+
isClientPayload,
|
|
463
|
+
operation,
|
|
464
|
+
optimisticConfig,
|
|
465
|
+
updater,
|
|
466
|
+
}: {|
|
|
467
|
+
createSource: () => RelayObservable<GraphQLResponse>,
|
|
468
|
+
isClientPayload: boolean,
|
|
469
|
+
operation: OperationDescriptor,
|
|
470
|
+
optimisticConfig: ?OptimisticResponseConfig<TMutation>,
|
|
471
|
+
updater: ?SelectorStoreUpdater<TMutation['response']>,
|
|
472
|
+
|}): RelayObservable<GraphQLResponse> {
|
|
473
|
+
const publishQueue = this._publishQueue;
|
|
474
|
+
const store = this._store;
|
|
483
475
|
return RelayObservable.create(sink => {
|
|
484
|
-
const executor =
|
|
476
|
+
const executor = OperationExecutor.execute({
|
|
477
|
+
actorIdentifier: INTERNAL_ACTOR_IDENTIFIER_DO_NOT_USE,
|
|
478
|
+
getDataID: this._getDataID,
|
|
479
|
+
isClientPayload,
|
|
480
|
+
log: this.__log,
|
|
485
481
|
operation,
|
|
486
482
|
operationExecutions: this._operationExecutions,
|
|
487
483
|
operationLoader: this._operationLoader,
|
|
488
484
|
operationTracker: this._operationTracker,
|
|
489
|
-
optimisticConfig
|
|
490
|
-
|
|
485
|
+
optimisticConfig,
|
|
486
|
+
getPublishQueue(actorIdentifier: ActorIdentifier) {
|
|
487
|
+
assertInternalActorIndentifier(actorIdentifier);
|
|
488
|
+
return publishQueue;
|
|
489
|
+
},
|
|
491
490
|
reactFlightPayloadDeserializer: this._reactFlightPayloadDeserializer,
|
|
492
491
|
reactFlightServerErrorHandler: this._reactFlightServerErrorHandler,
|
|
493
492
|
scheduler: this._scheduler,
|
|
493
|
+
shouldProcessClientComponents: this._shouldProcessClientComponents,
|
|
494
494
|
sink,
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
495
|
+
// NOTE: Some product tests expect `Network.execute` to be called only
|
|
496
|
+
// when the Observable is executed.
|
|
497
|
+
source: createSource(),
|
|
498
|
+
getStore(actorIdentifier: ActorIdentifier) {
|
|
499
|
+
assertInternalActorIndentifier(actorIdentifier);
|
|
500
|
+
return store;
|
|
501
|
+
},
|
|
498
502
|
treatMissingFieldsAsNull: this._treatMissingFieldsAsNull,
|
|
499
|
-
|
|
503
|
+
updater,
|
|
500
504
|
});
|
|
501
505
|
return () => executor.cancel();
|
|
502
506
|
});
|
|
503
507
|
}
|
|
504
|
-
|
|
505
|
-
toJSON(): mixed {
|
|
506
|
-
return `RelayModernEnvironment(${this.configName ?? ''})`;
|
|
507
|
-
}
|
|
508
|
-
|
|
509
|
-
/**
|
|
510
|
-
* Wraps the network with logging to ensure that network requests are
|
|
511
|
-
* always logged. Relying on each network callsite to be wrapped is
|
|
512
|
-
* untenable and will eventually lead to holes in the logging.
|
|
513
|
-
*/
|
|
514
|
-
__wrapNetworkWithLogObserver(network: INetwork): INetwork {
|
|
515
|
-
const that = this;
|
|
516
|
-
return {
|
|
517
|
-
execute(
|
|
518
|
-
params: RequestParameters,
|
|
519
|
-
variables: Variables,
|
|
520
|
-
cacheConfig: CacheConfig,
|
|
521
|
-
uploadables?: ?UploadableMap,
|
|
522
|
-
): RelayObservable<GraphQLResponse> {
|
|
523
|
-
const transactionID = generateID();
|
|
524
|
-
const log = that.__log;
|
|
525
|
-
const logObserver = {
|
|
526
|
-
start: subscription => {
|
|
527
|
-
log({
|
|
528
|
-
name: 'network.start',
|
|
529
|
-
transactionID,
|
|
530
|
-
params,
|
|
531
|
-
variables,
|
|
532
|
-
cacheConfig,
|
|
533
|
-
});
|
|
534
|
-
},
|
|
535
|
-
next: response => {
|
|
536
|
-
log({
|
|
537
|
-
name: 'network.next',
|
|
538
|
-
transactionID,
|
|
539
|
-
response,
|
|
540
|
-
});
|
|
541
|
-
},
|
|
542
|
-
error: error => {
|
|
543
|
-
log({
|
|
544
|
-
name: 'network.error',
|
|
545
|
-
transactionID,
|
|
546
|
-
error,
|
|
547
|
-
});
|
|
548
|
-
},
|
|
549
|
-
complete: () => {
|
|
550
|
-
log({
|
|
551
|
-
name: 'network.complete',
|
|
552
|
-
transactionID,
|
|
553
|
-
});
|
|
554
|
-
},
|
|
555
|
-
unsubscribe: () => {
|
|
556
|
-
log({
|
|
557
|
-
name: 'network.unsubscribe',
|
|
558
|
-
transactionID,
|
|
559
|
-
});
|
|
560
|
-
},
|
|
561
|
-
};
|
|
562
|
-
const logRequestInfo = info => {
|
|
563
|
-
log({
|
|
564
|
-
name: 'network.info',
|
|
565
|
-
transactionID,
|
|
566
|
-
info,
|
|
567
|
-
});
|
|
568
|
-
};
|
|
569
|
-
return network
|
|
570
|
-
.execute(params, variables, cacheConfig, uploadables, logRequestInfo)
|
|
571
|
-
.do(logObserver);
|
|
572
|
-
},
|
|
573
|
-
};
|
|
574
|
-
}
|
|
575
508
|
}
|
|
576
509
|
|
|
577
510
|
// Add a sigil for detection by `isRelayModernEnvironment()` to avoid a
|