relay-runtime 11.0.0-rc.0 → 12.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/handlers/connection/ConnectionHandler.js.flow +7 -0
- package/handlers/connection/MutationHandlers.js.flow +28 -0
- package/index.js +1 -1
- package/index.js.flow +20 -3
- package/lib/handlers/RelayDefaultHandlerProvider.js +1 -1
- package/lib/handlers/connection/ConnectionHandler.js +12 -6
- package/lib/handlers/connection/MutationHandlers.js +67 -8
- package/lib/index.js +15 -0
- package/lib/multi-actor-environment/ActorIdentifier.js +33 -0
- package/lib/multi-actor-environment/ActorSpecificEnvironment.js +148 -0
- package/lib/multi-actor-environment/ActorUtils.js +27 -0
- package/lib/multi-actor-environment/MultiActorEnvironment.js +406 -0
- package/lib/multi-actor-environment/MultiActorEnvironmentTypes.js +11 -0
- package/lib/multi-actor-environment/index.js +21 -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 +7 -2
- package/lib/mutations/applyOptimisticMutation.js +1 -1
- package/lib/mutations/commitMutation.js +5 -2
- package/lib/mutations/validateMutation.js +39 -17
- package/lib/network/RelayNetwork.js +1 -1
- package/lib/network/RelayObservable.js +3 -1
- package/lib/network/RelayQueryResponseCache.js +20 -3
- package/lib/network/wrapNetworkWithLogObserver.js +78 -0
- package/lib/query/GraphQLTag.js +1 -1
- package/lib/query/fetchQuery.js +1 -1
- package/lib/query/fetchQueryInternal.js +1 -1
- package/lib/store/DataChecker.js +132 -50
- package/lib/store/{RelayModernQueryExecutor.js → OperationExecutor.js} +524 -187
- package/lib/store/RelayConcreteVariables.js +29 -4
- package/lib/store/RelayModernEnvironment.js +137 -220
- package/lib/store/RelayModernFragmentSpecResolver.js +49 -23
- package/lib/store/RelayModernRecord.js +36 -2
- package/lib/store/RelayModernSelector.js +1 -1
- package/lib/store/RelayModernStore.js +53 -22
- package/lib/store/RelayOperationTracker.js +34 -24
- package/lib/store/RelayPublishQueue.js +30 -8
- package/lib/store/RelayReader.js +177 -29
- package/lib/store/RelayRecordSource.js +87 -3
- package/lib/store/RelayReferenceMarker.js +53 -28
- package/lib/store/RelayResponseNormalizer.js +247 -108
- package/lib/store/RelayStoreReactFlightUtils.js +7 -11
- package/lib/store/RelayStoreSubscriptions.js +8 -5
- package/lib/store/RelayStoreUtils.js +10 -4
- package/lib/store/ResolverCache.js +213 -0
- package/lib/store/ResolverFragments.js +57 -0
- package/lib/store/cloneRelayHandleSourceField.js +1 -1
- package/lib/store/cloneRelayScalarHandleSourceField.js +1 -1
- package/lib/store/createRelayContext.js +2 -2
- package/lib/store/defaultGetDataID.js +3 -1
- package/lib/store/readInlineData.js +1 -1
- package/lib/subscription/requestSubscription.js +32 -6
- package/lib/util/RelayConcreteNode.js +3 -0
- package/lib/util/RelayFeatureFlags.js +5 -4
- package/lib/util/RelayProfiler.js +17 -187
- package/lib/util/RelayReplaySubject.js +22 -7
- package/lib/util/deepFreeze.js +1 -0
- package/lib/util/getPaginationMetadata.js +41 -0
- package/lib/util/getPaginationVariables.js +67 -0
- package/lib/util/getPendingOperationsForFragment.js +55 -0
- package/lib/util/getRefetchMetadata.js +36 -0
- package/lib/util/getRelayHandleKey.js +1 -1
- package/lib/util/getRequestIdentifier.js +1 -1
- 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 +217 -0
- package/multi-actor-environment/ActorUtils.js.flow +33 -0
- package/multi-actor-environment/MultiActorEnvironment.js.flow +485 -0
- package/multi-actor-environment/MultiActorEnvironmentTypes.js.flow +245 -0
- package/multi-actor-environment/index.js.flow +27 -0
- package/mutations/RelayRecordSourceSelectorProxy.js.flow +7 -2
- package/mutations/commitMutation.js.flow +3 -1
- package/mutations/validateMutation.js.flow +42 -16
- package/network/RelayNetworkTypes.js.flow +17 -8
- package/network/RelayObservable.js.flow +2 -0
- package/network/RelayQueryResponseCache.js.flow +31 -17
- package/network/wrapNetworkWithLogObserver.js.flow +99 -0
- package/package.json +3 -2
- package/relay-runtime.js +2 -2
- package/relay-runtime.min.js +2 -2
- package/store/ClientID.js.flow +5 -1
- package/store/DataChecker.js.flow +148 -44
- package/store/{RelayModernQueryExecutor.js.flow → OperationExecutor.js.flow} +578 -237
- package/store/RelayConcreteVariables.js.flow +31 -1
- package/store/RelayModernEnvironment.js.flow +132 -220
- package/store/RelayModernFragmentSpecResolver.js.flow +40 -14
- package/store/RelayModernOperationDescriptor.js.flow +9 -3
- package/store/RelayModernRecord.js.flow +49 -0
- package/store/RelayModernStore.js.flow +57 -17
- package/store/RelayOperationTracker.js.flow +56 -34
- package/store/RelayPublishQueue.js.flow +37 -11
- package/store/RelayReader.js.flow +186 -27
- package/store/RelayRecordSource.js.flow +72 -6
- package/store/RelayReferenceMarker.js.flow +51 -21
- package/store/RelayResponseNormalizer.js.flow +251 -67
- package/store/RelayStoreReactFlightUtils.js.flow +6 -9
- package/store/RelayStoreSubscriptions.js.flow +10 -3
- package/store/RelayStoreTypes.js.flow +144 -21
- package/store/RelayStoreUtils.js.flow +19 -4
- package/store/ResolverCache.js.flow +247 -0
- package/store/ResolverFragments.js.flow +128 -0
- package/store/createRelayContext.js.flow +1 -1
- package/store/defaultGetDataID.js.flow +3 -1
- package/subscription/requestSubscription.js.flow +43 -8
- package/util/NormalizationNode.js.flow +16 -3
- package/util/ReaderNode.js.flow +29 -2
- package/util/RelayConcreteNode.js.flow +3 -0
- package/util/RelayFeatureFlags.js.flow +10 -6
- package/util/RelayProfiler.js.flow +22 -194
- package/util/RelayReplaySubject.js.flow +7 -6
- package/util/RelayRuntimeTypes.js.flow +4 -2
- package/util/deepFreeze.js.flow +2 -1
- package/util/getPaginationMetadata.js.flow +74 -0
- package/util/getPaginationVariables.js.flow +112 -0
- package/util/getPendingOperationsForFragment.js.flow +62 -0
- package/util/getRefetchMetadata.js.flow +80 -0
- package/util/getValueAtPath.js.flow +46 -0
- package/util/isEmptyObject.js.flow +2 -1
- package/util/registerEnvironmentWithDevTools.js.flow +33 -0
- 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
|
@@ -14,7 +14,13 @@
|
|
|
14
14
|
|
|
15
15
|
const invariant = require('invariant');
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
const {getArgumentValues} = require('./RelayStoreUtils');
|
|
18
|
+
|
|
19
|
+
import type {
|
|
20
|
+
NormalizationLocalArgumentDefinition,
|
|
21
|
+
NormalizationArgument,
|
|
22
|
+
NormalizationOperation,
|
|
23
|
+
} from '../util/NormalizationNode';
|
|
18
24
|
import type {ReaderFragment} from '../util/ReaderNode';
|
|
19
25
|
import type {Variables} from '../util/RelayRuntimeTypes';
|
|
20
26
|
|
|
@@ -35,6 +41,7 @@ function getFragmentVariables(
|
|
|
35
41
|
if (argumentVariables.hasOwnProperty(definition.name)) {
|
|
36
42
|
return;
|
|
37
43
|
}
|
|
44
|
+
// $FlowFixMe[cannot-spread-interface]
|
|
38
45
|
variables = variables || {...argumentVariables};
|
|
39
46
|
switch (definition.kind) {
|
|
40
47
|
case 'LocalArgument':
|
|
@@ -51,9 +58,12 @@ function getFragmentVariables(
|
|
|
51
58
|
* RelayStoreUtils.getStableVariableValue() that variable keys are all
|
|
52
59
|
* present.
|
|
53
60
|
*/
|
|
61
|
+
// $FlowFixMe[incompatible-use]
|
|
54
62
|
variables[definition.name] = undefined;
|
|
55
63
|
break;
|
|
56
64
|
}
|
|
65
|
+
// $FlowFixMe[incompatible-use]
|
|
66
|
+
// $FlowFixMe[cannot-write]
|
|
57
67
|
variables[definition.name] = rootVariables[definition.name];
|
|
58
68
|
break;
|
|
59
69
|
default:
|
|
@@ -82,6 +92,7 @@ function getOperationVariables(
|
|
|
82
92
|
const operationVariables = {};
|
|
83
93
|
operation.argumentDefinitions.forEach(def => {
|
|
84
94
|
let value = def.defaultValue;
|
|
95
|
+
// $FlowFixMe[cannot-write]
|
|
85
96
|
if (variables[def.name] != null) {
|
|
86
97
|
value = variables[def.name];
|
|
87
98
|
}
|
|
@@ -90,7 +101,26 @@ function getOperationVariables(
|
|
|
90
101
|
return operationVariables;
|
|
91
102
|
}
|
|
92
103
|
|
|
104
|
+
function getLocalVariables(
|
|
105
|
+
currentVariables: Variables,
|
|
106
|
+
argumentDefinitions: ?$ReadOnlyArray<NormalizationLocalArgumentDefinition>,
|
|
107
|
+
args: ?$ReadOnlyArray<NormalizationArgument>,
|
|
108
|
+
): Variables {
|
|
109
|
+
if (argumentDefinitions == null) {
|
|
110
|
+
return currentVariables;
|
|
111
|
+
}
|
|
112
|
+
const nextVariables = {...currentVariables};
|
|
113
|
+
const nextArgs = args ? getArgumentValues(args, currentVariables) : {};
|
|
114
|
+
argumentDefinitions.forEach(def => {
|
|
115
|
+
// $FlowFixMe[cannot-write]
|
|
116
|
+
const value = nextArgs[def.name] ?? def.defaultValue;
|
|
117
|
+
nextVariables[def.name] = value;
|
|
118
|
+
});
|
|
119
|
+
return nextVariables;
|
|
120
|
+
}
|
|
121
|
+
|
|
93
122
|
module.exports = {
|
|
123
|
+
getLocalVariables,
|
|
94
124
|
getFragmentVariables,
|
|
95
125
|
getOperationVariables,
|
|
96
126
|
};
|
|
@@ -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');
|
|
@@ -23,31 +23,30 @@ const RelayRecordSource = require('./RelayRecordSource');
|
|
|
23
23
|
|
|
24
24
|
const defaultGetDataID = require('./defaultGetDataID');
|
|
25
25
|
const defaultRequiredFieldLogger = require('./defaultRequiredFieldLogger');
|
|
26
|
-
const generateID = require('../util/generateID');
|
|
27
26
|
const invariant = require('invariant');
|
|
27
|
+
const registerEnvironmentWithDevTools = require('../util/registerEnvironmentWithDevTools');
|
|
28
|
+
const wrapNetworkWithLogObserver = require('../network/wrapNetworkWithLogObserver');
|
|
29
|
+
|
|
30
|
+
const {
|
|
31
|
+
INTERNAL_ACTOR_IDENTIFIER_DO_NOT_USE,
|
|
32
|
+
assertInternalActorIndentifier,
|
|
33
|
+
} = require('../multi-actor-environment/ActorIdentifier');
|
|
28
34
|
|
|
29
35
|
import type {HandlerProvider} from '../handlers/RelayDefaultHandlerProvider';
|
|
36
|
+
import type {ActorIdentifier} from '../multi-actor-environment/ActorIdentifier';
|
|
30
37
|
import type {
|
|
31
38
|
GraphQLResponse,
|
|
32
39
|
INetwork,
|
|
33
40
|
PayloadData,
|
|
34
|
-
UploadableMap,
|
|
35
41
|
} 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';
|
|
42
|
+
import type {Disposable, RenderPolicy} from '../util/RelayRuntimeTypes';
|
|
43
|
+
import type {ActiveState, TaskScheduler} from './OperationExecutor';
|
|
45
44
|
import type {GetDataID} from './RelayResponseNormalizer';
|
|
46
45
|
import type {
|
|
46
|
+
ExecuteMutationConfig,
|
|
47
47
|
IEnvironment,
|
|
48
48
|
LogFunction,
|
|
49
49
|
MissingFieldHandler,
|
|
50
|
-
RequiredFieldLogger,
|
|
51
50
|
OperationAvailability,
|
|
52
51
|
OperationDescriptor,
|
|
53
52
|
OperationLoader,
|
|
@@ -57,6 +56,7 @@ import type {
|
|
|
57
56
|
PublishQueue,
|
|
58
57
|
ReactFlightPayloadDeserializer,
|
|
59
58
|
ReactFlightServerErrorHandler,
|
|
59
|
+
RequiredFieldLogger,
|
|
60
60
|
SelectorStoreUpdater,
|
|
61
61
|
SingularReaderSelector,
|
|
62
62
|
Snapshot,
|
|
@@ -82,6 +82,7 @@ export type EnvironmentConfig = {|
|
|
|
82
82
|
+options?: mixed,
|
|
83
83
|
+isServer?: boolean,
|
|
84
84
|
+requiredFieldLogger?: ?RequiredFieldLogger,
|
|
85
|
+
+shouldProcessClientComponents?: ?boolean,
|
|
85
86
|
|};
|
|
86
87
|
|
|
87
88
|
class RelayModernEnvironment implements IEnvironment {
|
|
@@ -90,6 +91,7 @@ class RelayModernEnvironment implements IEnvironment {
|
|
|
90
91
|
_operationLoader: ?OperationLoader;
|
|
91
92
|
_reactFlightPayloadDeserializer: ?ReactFlightPayloadDeserializer;
|
|
92
93
|
_reactFlightServerErrorHandler: ?ReactFlightServerErrorHandler;
|
|
94
|
+
_shouldProcessClientComponents: ?boolean;
|
|
93
95
|
_network: INetwork;
|
|
94
96
|
_publishQueue: PublishQueue;
|
|
95
97
|
_scheduler: ?TaskScheduler;
|
|
@@ -106,9 +108,6 @@ class RelayModernEnvironment implements IEnvironment {
|
|
|
106
108
|
|
|
107
109
|
constructor(config: EnvironmentConfig) {
|
|
108
110
|
this.configName = config.configName;
|
|
109
|
-
const handlerProvider = config.handlerProvider
|
|
110
|
-
? config.handlerProvider
|
|
111
|
-
: RelayDefaultHandlerProvider;
|
|
112
111
|
this._treatMissingFieldsAsNull = config.treatMissingFieldsAsNull === true;
|
|
113
112
|
const operationLoader = config.operationLoader;
|
|
114
113
|
const reactFlightPayloadDeserializer =
|
|
@@ -144,11 +143,11 @@ class RelayModernEnvironment implements IEnvironment {
|
|
|
144
143
|
: 'full';
|
|
145
144
|
this._operationLoader = operationLoader;
|
|
146
145
|
this._operationExecutions = new Map();
|
|
147
|
-
this._network = this
|
|
146
|
+
this._network = wrapNetworkWithLogObserver(this, config.network);
|
|
148
147
|
this._getDataID = config.getDataID ?? defaultGetDataID;
|
|
149
148
|
this._publishQueue = new RelayPublishQueue(
|
|
150
149
|
config.store,
|
|
151
|
-
handlerProvider,
|
|
150
|
+
config.handlerProvider ?? RelayDefaultHandlerProvider,
|
|
152
151
|
this._getDataID,
|
|
153
152
|
);
|
|
154
153
|
this._scheduler = config.scheduler ?? null;
|
|
@@ -157,30 +156,23 @@ class RelayModernEnvironment implements IEnvironment {
|
|
|
157
156
|
this._isServer = config.isServer ?? false;
|
|
158
157
|
|
|
159
158
|
(this: any).__setNet = newNet =>
|
|
160
|
-
(this._network = this
|
|
159
|
+
(this._network = wrapNetworkWithLogObserver(this, newNet));
|
|
161
160
|
|
|
162
161
|
if (__DEV__) {
|
|
163
162
|
const {inspect} = require('./StoreInspector');
|
|
164
163
|
(this: any).DEBUG_inspect = (dataID: ?string) => inspect(this, dataID);
|
|
165
164
|
}
|
|
166
165
|
|
|
167
|
-
// Register this Relay Environment with Relay DevTools if it exists.
|
|
168
|
-
// Note: this must always be the last step in the constructor.
|
|
169
|
-
const _global =
|
|
170
|
-
typeof global !== 'undefined'
|
|
171
|
-
? global
|
|
172
|
-
: typeof window !== 'undefined'
|
|
173
|
-
? window
|
|
174
|
-
: undefined;
|
|
175
|
-
const devToolsHook = _global && _global.__RELAY_DEVTOOLS_HOOK__;
|
|
176
|
-
if (devToolsHook) {
|
|
177
|
-
devToolsHook.registerEnvironment(this);
|
|
178
|
-
}
|
|
179
166
|
this._missingFieldHandlers = config.missingFieldHandlers;
|
|
180
167
|
this._operationTracker =
|
|
181
168
|
config.operationTracker ?? new RelayOperationTracker();
|
|
182
169
|
this._reactFlightPayloadDeserializer = reactFlightPayloadDeserializer;
|
|
183
170
|
this._reactFlightServerErrorHandler = reactFlightServerErrorHandler;
|
|
171
|
+
this._shouldProcessClientComponents = config.shouldProcessClientComponents;
|
|
172
|
+
|
|
173
|
+
// Register this Relay Environment with Relay DevTools if it exists.
|
|
174
|
+
// Note: this must always be the last step in the constructor.
|
|
175
|
+
registerEnvironmentWithDevTools(this);
|
|
184
176
|
}
|
|
185
177
|
|
|
186
178
|
getStore(): Store {
|
|
@@ -237,26 +229,12 @@ class RelayModernEnvironment implements IEnvironment {
|
|
|
237
229
|
}
|
|
238
230
|
|
|
239
231
|
applyMutation(optimisticConfig: OptimisticResponseConfig): Disposable {
|
|
240
|
-
const subscription =
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
optimisticConfig,
|
|
247
|
-
publishQueue: this._publishQueue,
|
|
248
|
-
reactFlightPayloadDeserializer: this._reactFlightPayloadDeserializer,
|
|
249
|
-
reactFlightServerErrorHandler: this._reactFlightServerErrorHandler,
|
|
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();
|
|
232
|
+
const subscription = this._execute({
|
|
233
|
+
createSource: () => RelayObservable.create(_sink => {}),
|
|
234
|
+
isClientPayload: false,
|
|
235
|
+
operation: optimisticConfig.operation,
|
|
236
|
+
optimisticConfig,
|
|
237
|
+
updater: null,
|
|
260
238
|
}).subscribe({});
|
|
261
239
|
return {
|
|
262
240
|
dispose: () => subscription.unsubscribe(),
|
|
@@ -277,28 +255,12 @@ class RelayModernEnvironment implements IEnvironment {
|
|
|
277
255
|
}
|
|
278
256
|
|
|
279
257
|
commitPayload(operation: OperationDescriptor, payload: PayloadData): void {
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
publishQueue: this._publishQueue,
|
|
287
|
-
reactFlightPayloadDeserializer: this._reactFlightPayloadDeserializer,
|
|
288
|
-
reactFlightServerErrorHandler: this._reactFlightServerErrorHandler,
|
|
289
|
-
scheduler: this._scheduler,
|
|
290
|
-
sink,
|
|
291
|
-
source: RelayObservable.from({
|
|
292
|
-
data: payload,
|
|
293
|
-
}),
|
|
294
|
-
store: this._store,
|
|
295
|
-
updater: null,
|
|
296
|
-
operationTracker: this._operationTracker,
|
|
297
|
-
getDataID: this._getDataID,
|
|
298
|
-
isClientPayload: true,
|
|
299
|
-
treatMissingFieldsAsNull: this._treatMissingFieldsAsNull,
|
|
300
|
-
});
|
|
301
|
-
return () => executor.cancel();
|
|
258
|
+
this._execute({
|
|
259
|
+
createSource: () => RelayObservable.from({data: payload}),
|
|
260
|
+
isClientPayload: true,
|
|
261
|
+
operation: operation,
|
|
262
|
+
optimisticConfig: null,
|
|
263
|
+
updater: null,
|
|
302
264
|
}).subscribe({});
|
|
303
265
|
}
|
|
304
266
|
|
|
@@ -333,7 +295,19 @@ class RelayModernEnvironment implements IEnvironment {
|
|
|
333
295
|
handlers: $ReadOnlyArray<MissingFieldHandler>,
|
|
334
296
|
): OperationAvailability {
|
|
335
297
|
const target = RelayRecordSource.create();
|
|
336
|
-
const
|
|
298
|
+
const source = this._store.getSource();
|
|
299
|
+
const result = this._store.check(operation, {
|
|
300
|
+
handlers,
|
|
301
|
+
defaultActorIdentifier: INTERNAL_ACTOR_IDENTIFIER_DO_NOT_USE,
|
|
302
|
+
getSourceForActor(actorIdentifier: ActorIdentifier) {
|
|
303
|
+
assertInternalActorIndentifier(actorIdentifier);
|
|
304
|
+
return source;
|
|
305
|
+
},
|
|
306
|
+
getTargetForActor(actorIdentifier: ActorIdentifier) {
|
|
307
|
+
assertInternalActorIndentifier(actorIdentifier);
|
|
308
|
+
return target;
|
|
309
|
+
},
|
|
310
|
+
});
|
|
337
311
|
if (target.size() > 0) {
|
|
338
312
|
this._scheduleUpdates(() => {
|
|
339
313
|
this._publishQueue.commitSource(target);
|
|
@@ -367,31 +341,18 @@ class RelayModernEnvironment implements IEnvironment {
|
|
|
367
341
|
operation: OperationDescriptor,
|
|
368
342
|
updater?: ?SelectorStoreUpdater,
|
|
369
343
|
|}): RelayObservable<GraphQLResponse> {
|
|
370
|
-
return
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
publishQueue: this._publishQueue,
|
|
383
|
-
reactFlightPayloadDeserializer: this._reactFlightPayloadDeserializer,
|
|
384
|
-
reactFlightServerErrorHandler: this._reactFlightServerErrorHandler,
|
|
385
|
-
scheduler: this._scheduler,
|
|
386
|
-
sink,
|
|
387
|
-
source,
|
|
388
|
-
store: this._store,
|
|
389
|
-
updater,
|
|
390
|
-
operationTracker: this._operationTracker,
|
|
391
|
-
getDataID: this._getDataID,
|
|
392
|
-
treatMissingFieldsAsNull: this._treatMissingFieldsAsNull,
|
|
393
|
-
});
|
|
394
|
-
return () => executor.cancel();
|
|
344
|
+
return this._execute({
|
|
345
|
+
createSource: () =>
|
|
346
|
+
this._network.execute(
|
|
347
|
+
operation.request.node.params,
|
|
348
|
+
operation.request.variables,
|
|
349
|
+
operation.request.cacheConfig || {},
|
|
350
|
+
null,
|
|
351
|
+
),
|
|
352
|
+
isClientPayload: false,
|
|
353
|
+
operation,
|
|
354
|
+
optimisticConfig: null,
|
|
355
|
+
updater,
|
|
395
356
|
});
|
|
396
357
|
}
|
|
397
358
|
|
|
@@ -411,56 +372,37 @@ class RelayModernEnvironment implements IEnvironment {
|
|
|
411
372
|
optimisticUpdater,
|
|
412
373
|
updater,
|
|
413
374
|
uploadables,
|
|
414
|
-
}: {
|
|
415
|
-
|
|
416
|
-
optimisticUpdater
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
);
|
|
439
|
-
const executor = RelayModernQueryExecutor.execute({
|
|
440
|
-
operation,
|
|
441
|
-
operationExecutions: this._operationExecutions,
|
|
442
|
-
operationLoader: this._operationLoader,
|
|
443
|
-
optimisticConfig,
|
|
444
|
-
publishQueue: this._publishQueue,
|
|
445
|
-
reactFlightPayloadDeserializer: this._reactFlightPayloadDeserializer,
|
|
446
|
-
reactFlightServerErrorHandler: this._reactFlightServerErrorHandler,
|
|
447
|
-
scheduler: this._scheduler,
|
|
448
|
-
sink,
|
|
449
|
-
source,
|
|
450
|
-
store: this._store,
|
|
451
|
-
updater,
|
|
452
|
-
operationTracker: this._operationTracker,
|
|
453
|
-
getDataID: this._getDataID,
|
|
454
|
-
treatMissingFieldsAsNull: this._treatMissingFieldsAsNull,
|
|
455
|
-
});
|
|
456
|
-
return () => executor.cancel();
|
|
375
|
+
}: ExecuteMutationConfig): RelayObservable<GraphQLResponse> {
|
|
376
|
+
let optimisticConfig;
|
|
377
|
+
if (optimisticResponse || optimisticUpdater) {
|
|
378
|
+
optimisticConfig = {
|
|
379
|
+
operation: operation,
|
|
380
|
+
response: optimisticResponse,
|
|
381
|
+
updater: optimisticUpdater,
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
return this._execute({
|
|
385
|
+
createSource: () =>
|
|
386
|
+
this._network.execute(
|
|
387
|
+
operation.request.node.params,
|
|
388
|
+
operation.request.variables,
|
|
389
|
+
{
|
|
390
|
+
...operation.request.cacheConfig,
|
|
391
|
+
force: true,
|
|
392
|
+
},
|
|
393
|
+
uploadables,
|
|
394
|
+
),
|
|
395
|
+
isClientPayload: false,
|
|
396
|
+
operation,
|
|
397
|
+
optimisticConfig,
|
|
398
|
+
updater,
|
|
457
399
|
});
|
|
458
400
|
}
|
|
459
401
|
|
|
460
402
|
/**
|
|
461
403
|
* Returns an Observable of GraphQLResponse resulting from executing the
|
|
462
404
|
* provided Query or Subscription operation responses, the result of which is
|
|
463
|
-
* then normalized and
|
|
405
|
+
* then normalized and committed to the publish queue.
|
|
464
406
|
*
|
|
465
407
|
* Note: Observables are lazy, so calling this method will do nothing until
|
|
466
408
|
* the result is subscribed to:
|
|
@@ -473,97 +415,67 @@ class RelayModernEnvironment implements IEnvironment {
|
|
|
473
415
|
operation: OperationDescriptor,
|
|
474
416
|
source: RelayObservable<GraphQLResponse>,
|
|
475
417
|
|}): RelayObservable<GraphQLResponse> {
|
|
418
|
+
return this._execute({
|
|
419
|
+
createSource: () => source,
|
|
420
|
+
isClientPayload: false,
|
|
421
|
+
operation,
|
|
422
|
+
optimisticConfig: null,
|
|
423
|
+
updater: null,
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
toJSON(): mixed {
|
|
428
|
+
return `RelayModernEnvironment(${this.configName ?? ''})`;
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
_execute({
|
|
432
|
+
createSource,
|
|
433
|
+
isClientPayload,
|
|
434
|
+
operation,
|
|
435
|
+
optimisticConfig,
|
|
436
|
+
updater,
|
|
437
|
+
}: {|
|
|
438
|
+
createSource: () => RelayObservable<GraphQLResponse>,
|
|
439
|
+
isClientPayload: boolean,
|
|
440
|
+
operation: OperationDescriptor,
|
|
441
|
+
optimisticConfig: ?OptimisticResponseConfig,
|
|
442
|
+
updater: ?SelectorStoreUpdater,
|
|
443
|
+
|}): RelayObservable<GraphQLResponse> {
|
|
444
|
+
const publishQueue = this._publishQueue;
|
|
445
|
+
const store = this._store;
|
|
476
446
|
return RelayObservable.create(sink => {
|
|
477
|
-
const executor =
|
|
447
|
+
const executor = OperationExecutor.execute({
|
|
448
|
+
actorIdentifier: INTERNAL_ACTOR_IDENTIFIER_DO_NOT_USE,
|
|
449
|
+
getDataID: this._getDataID,
|
|
450
|
+
isClientPayload,
|
|
451
|
+
log: this.__log,
|
|
478
452
|
operation,
|
|
479
453
|
operationExecutions: this._operationExecutions,
|
|
480
454
|
operationLoader: this._operationLoader,
|
|
481
455
|
operationTracker: this._operationTracker,
|
|
482
|
-
optimisticConfig
|
|
483
|
-
|
|
456
|
+
optimisticConfig,
|
|
457
|
+
getPublishQueue(actorIdentifier: ActorIdentifier) {
|
|
458
|
+
assertInternalActorIndentifier(actorIdentifier);
|
|
459
|
+
return publishQueue;
|
|
460
|
+
},
|
|
484
461
|
reactFlightPayloadDeserializer: this._reactFlightPayloadDeserializer,
|
|
485
462
|
reactFlightServerErrorHandler: this._reactFlightServerErrorHandler,
|
|
486
463
|
scheduler: this._scheduler,
|
|
464
|
+
shouldProcessClientComponents: this._shouldProcessClientComponents,
|
|
487
465
|
sink,
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
466
|
+
// NOTE: Some product tests expect `Network.execute` to be called only
|
|
467
|
+
// when the Observable is executed.
|
|
468
|
+
source: createSource(),
|
|
469
|
+
getStore(actorIdentifier: ActorIdentifier) {
|
|
470
|
+
assertInternalActorIndentifier(actorIdentifier);
|
|
471
|
+
return store;
|
|
472
|
+
},
|
|
491
473
|
treatMissingFieldsAsNull: this._treatMissingFieldsAsNull,
|
|
474
|
+
updater,
|
|
492
475
|
});
|
|
493
476
|
return () => executor.cancel();
|
|
494
477
|
});
|
|
495
478
|
}
|
|
496
|
-
|
|
497
|
-
toJSON(): mixed {
|
|
498
|
-
return `RelayModernEnvironment(${this.configName ?? ''})`;
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
/**
|
|
502
|
-
* Wraps the network with logging to ensure that network requests are
|
|
503
|
-
* always logged. Relying on each network callsite to be wrapped is
|
|
504
|
-
* untenable and will eventually lead to holes in the logging.
|
|
505
|
-
*/
|
|
506
|
-
__wrapNetworkWithLogObserver(network: INetwork): INetwork {
|
|
507
|
-
const that = this;
|
|
508
|
-
return {
|
|
509
|
-
execute(
|
|
510
|
-
params: RequestParameters,
|
|
511
|
-
variables: Variables,
|
|
512
|
-
cacheConfig: CacheConfig,
|
|
513
|
-
uploadables?: ?UploadableMap,
|
|
514
|
-
): RelayObservable<GraphQLResponse> {
|
|
515
|
-
const transactionID = generateID();
|
|
516
|
-
const log = that.__log;
|
|
517
|
-
const logObserver = {
|
|
518
|
-
start: subscription => {
|
|
519
|
-
log({
|
|
520
|
-
name: 'network.start',
|
|
521
|
-
transactionID,
|
|
522
|
-
params,
|
|
523
|
-
variables,
|
|
524
|
-
cacheConfig,
|
|
525
|
-
});
|
|
526
|
-
},
|
|
527
|
-
next: response => {
|
|
528
|
-
log({
|
|
529
|
-
name: 'network.next',
|
|
530
|
-
transactionID,
|
|
531
|
-
response,
|
|
532
|
-
});
|
|
533
|
-
},
|
|
534
|
-
error: error => {
|
|
535
|
-
log({
|
|
536
|
-
name: 'network.error',
|
|
537
|
-
transactionID,
|
|
538
|
-
error,
|
|
539
|
-
});
|
|
540
|
-
},
|
|
541
|
-
complete: () => {
|
|
542
|
-
log({
|
|
543
|
-
name: 'network.complete',
|
|
544
|
-
transactionID,
|
|
545
|
-
});
|
|
546
|
-
},
|
|
547
|
-
unsubscribe: () => {
|
|
548
|
-
log({
|
|
549
|
-
name: 'network.unsubscribe',
|
|
550
|
-
transactionID,
|
|
551
|
-
});
|
|
552
|
-
},
|
|
553
|
-
};
|
|
554
|
-
const logRequestInfo = info => {
|
|
555
|
-
log({
|
|
556
|
-
name: 'network.info',
|
|
557
|
-
transactionID,
|
|
558
|
-
info,
|
|
559
|
-
});
|
|
560
|
-
};
|
|
561
|
-
return network
|
|
562
|
-
.execute(params, variables, cacheConfig, uploadables, logRequestInfo)
|
|
563
|
-
.do(logObserver);
|
|
564
|
-
},
|
|
565
|
-
};
|
|
566
|
-
}
|
|
567
479
|
}
|
|
568
480
|
|
|
569
481
|
// Add a sigil for detection by `isRelayModernEnvironment()` to avoid a
|