relay-runtime 11.0.0 → 13.0.0-rc.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/RelayDefaultHandlerProvider.js.flow +2 -2
- package/handlers/connection/ConnectionHandler.js.flow +8 -10
- package/handlers/connection/MutationHandlers.js.flow +31 -7
- package/index.js +1 -1
- package/index.js.flow +60 -36
- package/lib/handlers/RelayDefaultHandlerProvider.js +1 -1
- package/lib/handlers/connection/ConnectionHandler.js +8 -8
- package/lib/handlers/connection/MutationHandlers.js +61 -5
- 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 +12 -5
- package/lib/network/ConvertToExecuteFunction.js +2 -1
- package/lib/network/RelayNetwork.js +3 -2
- package/lib/network/RelayQueryResponseCache.js +21 -4
- 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 +141 -60
- package/lib/store/{RelayModernQueryExecutor.js → OperationExecutor.js} +532 -195
- package/lib/store/RelayConcreteVariables.js +24 -4
- package/lib/store/RelayModernEnvironment.js +175 -234
- 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 +58 -29
- package/lib/store/RelayOperationTracker.js +34 -24
- package/lib/store/RelayPublishQueue.js +41 -13
- package/lib/store/RelayReader.js +287 -46
- package/lib/store/RelayRecordSource.js +87 -3
- package/lib/store/RelayReferenceMarker.js +55 -31
- package/lib/store/RelayResponseNormalizer.js +250 -108
- package/lib/store/RelayStoreReactFlightUtils.js +8 -12
- package/lib/store/RelayStoreSubscriptions.js +14 -9
- package/lib/store/RelayStoreUtils.js +11 -5
- 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/defaultGetDataID.js +3 -1
- package/lib/store/readInlineData.js +6 -2
- package/lib/subscription/requestSubscription.js +35 -9
- package/lib/util/RelayConcreteNode.js +4 -0
- package/lib/util/RelayFeatureFlags.js +11 -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/deepFreeze.js +1 -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 +28 -16
- package/network/ConvertToExecuteFunction.js.flow +2 -2
- package/network/RelayNetwork.js.flow +4 -5
- package/network/RelayNetworkTypes.js.flow +17 -8
- package/network/RelayObservable.js.flow +1 -1
- package/network/RelayQueryResponseCache.js.flow +34 -20
- 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 +162 -67
- package/store/{RelayModernQueryExecutor.js.flow → OperationExecutor.js.flow} +616 -283
- package/store/RelayConcreteVariables.js.flow +27 -5
- package/store/RelayModernEnvironment.js.flow +176 -235
- 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 +72 -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 -72
- package/store/RelayRecordSource.js.flow +72 -6
- package/store/RelayReferenceMarker.js.flow +60 -33
- package/store/RelayResponseNormalizer.js.flow +288 -102
- package/store/RelayStoreReactFlightUtils.js.flow +9 -13
- package/store/RelayStoreSubscriptions.js.flow +19 -11
- package/store/RelayStoreTypes.js.flow +210 -44
- package/store/RelayStoreUtils.js.flow +25 -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/defaultGetDataID.js.flow +3 -1
- package/store/normalizeRelayPayload.js.flow +6 -7
- package/store/readInlineData.js.flow +7 -8
- package/subscription/requestSubscription.js.flow +54 -27
- package/util/NormalizationNode.js.flow +16 -3
- package/util/ReaderNode.js.flow +38 -2
- package/util/RelayConcreteNode.js.flow +4 -0
- package/util/RelayFeatureFlags.js.flow +24 -8
- package/util/RelayProfiler.js.flow +22 -194
- package/util/RelayReplaySubject.js.flow +9 -9
- package/util/RelayRuntimeTypes.js.flow +73 -4
- package/util/StringInterner.js.flow +69 -0
- package/util/createPayloadFor3DField.js.flow +3 -3
- package/util/deepFreeze.js.flow +2 -1
- 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 +2 -1
- 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
|
@@ -12,12 +12,17 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
import type {
|
|
16
|
+
NormalizationArgument,
|
|
17
|
+
NormalizationLocalArgumentDefinition,
|
|
18
|
+
NormalizationOperation,
|
|
19
|
+
} from '../util/NormalizationNode';
|
|
18
20
|
import type {ReaderFragment} from '../util/ReaderNode';
|
|
19
21
|
import type {Variables} from '../util/RelayRuntimeTypes';
|
|
20
22
|
|
|
23
|
+
const {getArgumentValues} = require('./RelayStoreUtils');
|
|
24
|
+
const invariant = require('invariant');
|
|
25
|
+
|
|
21
26
|
/**
|
|
22
27
|
* Determines the variables that are in scope for a fragment given the variables
|
|
23
28
|
* in scope at the root query as well as any arguments applied at the fragment
|
|
@@ -51,11 +56,9 @@ function getFragmentVariables(
|
|
|
51
56
|
* RelayStoreUtils.getStableVariableValue() that variable keys are all
|
|
52
57
|
* present.
|
|
53
58
|
*/
|
|
54
|
-
// $FlowFixMe[incompatible-use]
|
|
55
59
|
variables[definition.name] = undefined;
|
|
56
60
|
break;
|
|
57
61
|
}
|
|
58
|
-
// $FlowFixMe[incompatible-use]
|
|
59
62
|
variables[definition.name] = rootVariables[definition.name];
|
|
60
63
|
break;
|
|
61
64
|
default:
|
|
@@ -92,7 +95,26 @@ function getOperationVariables(
|
|
|
92
95
|
return operationVariables;
|
|
93
96
|
}
|
|
94
97
|
|
|
98
|
+
function getLocalVariables(
|
|
99
|
+
currentVariables: Variables,
|
|
100
|
+
argumentDefinitions: ?$ReadOnlyArray<NormalizationLocalArgumentDefinition>,
|
|
101
|
+
args: ?$ReadOnlyArray<NormalizationArgument>,
|
|
102
|
+
): Variables {
|
|
103
|
+
if (argumentDefinitions == null) {
|
|
104
|
+
return currentVariables;
|
|
105
|
+
}
|
|
106
|
+
const nextVariables = {...currentVariables};
|
|
107
|
+
const nextArgs = args ? getArgumentValues(args, currentVariables) : {};
|
|
108
|
+
argumentDefinitions.forEach(def => {
|
|
109
|
+
// $FlowFixMe[cannot-write]
|
|
110
|
+
const value = nextArgs[def.name] ?? def.defaultValue;
|
|
111
|
+
nextVariables[def.name] = value;
|
|
112
|
+
});
|
|
113
|
+
return nextVariables;
|
|
114
|
+
}
|
|
115
|
+
|
|
95
116
|
module.exports = {
|
|
117
|
+
getLocalVariables,
|
|
96
118
|
getFragmentVariables,
|
|
97
119
|
getOperationVariables,
|
|
98
120
|
};
|
|
@@ -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,
|
|
@@ -82,6 +81,7 @@ export type EnvironmentConfig = {|
|
|
|
82
81
|
+options?: mixed,
|
|
83
82
|
+isServer?: boolean,
|
|
84
83
|
+requiredFieldLogger?: ?RequiredFieldLogger,
|
|
84
|
+
+shouldProcessClientComponents?: ?boolean,
|
|
85
85
|
|};
|
|
86
86
|
|
|
87
87
|
class RelayModernEnvironment implements IEnvironment {
|
|
@@ -90,6 +90,7 @@ class RelayModernEnvironment implements IEnvironment {
|
|
|
90
90
|
_operationLoader: ?OperationLoader;
|
|
91
91
|
_reactFlightPayloadDeserializer: ?ReactFlightPayloadDeserializer;
|
|
92
92
|
_reactFlightServerErrorHandler: ?ReactFlightServerErrorHandler;
|
|
93
|
+
_shouldProcessClientComponents: ?boolean;
|
|
93
94
|
_network: INetwork;
|
|
94
95
|
_publishQueue: PublishQueue;
|
|
95
96
|
_scheduler: ?TaskScheduler;
|
|
@@ -106,9 +107,6 @@ class RelayModernEnvironment implements IEnvironment {
|
|
|
106
107
|
|
|
107
108
|
constructor(config: EnvironmentConfig) {
|
|
108
109
|
this.configName = config.configName;
|
|
109
|
-
const handlerProvider = config.handlerProvider
|
|
110
|
-
? config.handlerProvider
|
|
111
|
-
: RelayDefaultHandlerProvider;
|
|
112
110
|
this._treatMissingFieldsAsNull = config.treatMissingFieldsAsNull === true;
|
|
113
111
|
const operationLoader = config.operationLoader;
|
|
114
112
|
const reactFlightPayloadDeserializer =
|
|
@@ -144,11 +142,11 @@ class RelayModernEnvironment implements IEnvironment {
|
|
|
144
142
|
: 'full';
|
|
145
143
|
this._operationLoader = operationLoader;
|
|
146
144
|
this._operationExecutions = new Map();
|
|
147
|
-
this._network = this
|
|
145
|
+
this._network = wrapNetworkWithLogObserver(this, config.network);
|
|
148
146
|
this._getDataID = config.getDataID ?? defaultGetDataID;
|
|
149
147
|
this._publishQueue = new RelayPublishQueue(
|
|
150
148
|
config.store,
|
|
151
|
-
handlerProvider,
|
|
149
|
+
config.handlerProvider ?? RelayDefaultHandlerProvider,
|
|
152
150
|
this._getDataID,
|
|
153
151
|
);
|
|
154
152
|
this._scheduler = config.scheduler ?? null;
|
|
@@ -157,30 +155,23 @@ class RelayModernEnvironment implements IEnvironment {
|
|
|
157
155
|
this._isServer = config.isServer ?? false;
|
|
158
156
|
|
|
159
157
|
(this: any).__setNet = newNet =>
|
|
160
|
-
(this._network = this
|
|
158
|
+
(this._network = wrapNetworkWithLogObserver(this, newNet));
|
|
161
159
|
|
|
162
160
|
if (__DEV__) {
|
|
163
161
|
const {inspect} = require('./StoreInspector');
|
|
164
162
|
(this: any).DEBUG_inspect = (dataID: ?string) => inspect(this, dataID);
|
|
165
163
|
}
|
|
166
164
|
|
|
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
165
|
this._missingFieldHandlers = config.missingFieldHandlers;
|
|
180
166
|
this._operationTracker =
|
|
181
167
|
config.operationTracker ?? new RelayOperationTracker();
|
|
182
168
|
this._reactFlightPayloadDeserializer = reactFlightPayloadDeserializer;
|
|
183
169
|
this._reactFlightServerErrorHandler = reactFlightServerErrorHandler;
|
|
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);
|
|
184
175
|
}
|
|
185
176
|
|
|
186
177
|
getStore(): Store {
|
|
@@ -236,27 +227,15 @@ class RelayModernEnvironment implements IEnvironment {
|
|
|
236
227
|
});
|
|
237
228
|
}
|
|
238
229
|
|
|
239
|
-
applyMutation
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
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();
|
|
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,
|
|
260
239
|
}).subscribe({});
|
|
261
240
|
return {
|
|
262
241
|
dispose: () => subscription.unsubscribe(),
|
|
@@ -277,28 +256,12 @@ class RelayModernEnvironment implements IEnvironment {
|
|
|
277
256
|
}
|
|
278
257
|
|
|
279
258
|
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();
|
|
259
|
+
this._execute({
|
|
260
|
+
createSource: () => RelayObservable.from({data: payload}),
|
|
261
|
+
isClientPayload: true,
|
|
262
|
+
operation: operation,
|
|
263
|
+
optimisticConfig: null,
|
|
264
|
+
updater: null,
|
|
302
265
|
}).subscribe({});
|
|
303
266
|
}
|
|
304
267
|
|
|
@@ -333,7 +296,19 @@ class RelayModernEnvironment implements IEnvironment {
|
|
|
333
296
|
handlers: $ReadOnlyArray<MissingFieldHandler>,
|
|
334
297
|
): OperationAvailability {
|
|
335
298
|
const target = RelayRecordSource.create();
|
|
336
|
-
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
|
+
});
|
|
337
312
|
if (target.size() > 0) {
|
|
338
313
|
this._scheduleUpdates(() => {
|
|
339
314
|
this._publishQueue.commitSource(target);
|
|
@@ -354,7 +329,7 @@ class RelayModernEnvironment implements IEnvironment {
|
|
|
354
329
|
|
|
355
330
|
/**
|
|
356
331
|
* Returns an Observable of GraphQLResponse resulting from executing the
|
|
357
|
-
* provided Query
|
|
332
|
+
* provided Query operation, each result of which is then
|
|
358
333
|
* normalized and committed to the publish queue.
|
|
359
334
|
*
|
|
360
335
|
* Note: Observables are lazy, so calling this method will do nothing until
|
|
@@ -362,36 +337,51 @@ class RelayModernEnvironment implements IEnvironment {
|
|
|
362
337
|
*/
|
|
363
338
|
execute({
|
|
364
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,
|
|
365
368
|
updater,
|
|
366
369
|
}: {|
|
|
367
370
|
operation: OperationDescriptor,
|
|
368
|
-
updater?: ?SelectorStoreUpdater
|
|
371
|
+
updater?: ?SelectorStoreUpdater<TMutation['response']>,
|
|
369
372
|
|}): 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();
|
|
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,
|
|
395
385
|
});
|
|
396
386
|
}
|
|
397
387
|
|
|
@@ -405,62 +395,43 @@ class RelayModernEnvironment implements IEnvironment {
|
|
|
405
395
|
* the result is subscribed to:
|
|
406
396
|
* environment.executeMutation({...}).subscribe({...}).
|
|
407
397
|
*/
|
|
408
|
-
executeMutation({
|
|
398
|
+
executeMutation<TMutation: MutationParameters>({
|
|
409
399
|
operation,
|
|
410
400
|
optimisticResponse,
|
|
411
401
|
optimisticUpdater,
|
|
412
402
|
updater,
|
|
413
403
|
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();
|
|
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,
|
|
457
428
|
});
|
|
458
429
|
}
|
|
459
430
|
|
|
460
431
|
/**
|
|
461
432
|
* Returns an Observable of GraphQLResponse resulting from executing the
|
|
462
433
|
* provided Query or Subscription operation responses, the result of which is
|
|
463
|
-
* then normalized and
|
|
434
|
+
* then normalized and committed to the publish queue.
|
|
464
435
|
*
|
|
465
436
|
* Note: Observables are lazy, so calling this method will do nothing until
|
|
466
437
|
* the result is subscribed to:
|
|
@@ -473,97 +444,67 @@ class RelayModernEnvironment implements IEnvironment {
|
|
|
473
444
|
operation: OperationDescriptor,
|
|
474
445
|
source: RelayObservable<GraphQLResponse>,
|
|
475
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;
|
|
476
475
|
return RelayObservable.create(sink => {
|
|
477
|
-
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,
|
|
478
481
|
operation,
|
|
479
482
|
operationExecutions: this._operationExecutions,
|
|
480
483
|
operationLoader: this._operationLoader,
|
|
481
484
|
operationTracker: this._operationTracker,
|
|
482
|
-
optimisticConfig
|
|
483
|
-
|
|
485
|
+
optimisticConfig,
|
|
486
|
+
getPublishQueue(actorIdentifier: ActorIdentifier) {
|
|
487
|
+
assertInternalActorIndentifier(actorIdentifier);
|
|
488
|
+
return publishQueue;
|
|
489
|
+
},
|
|
484
490
|
reactFlightPayloadDeserializer: this._reactFlightPayloadDeserializer,
|
|
485
491
|
reactFlightServerErrorHandler: this._reactFlightServerErrorHandler,
|
|
486
492
|
scheduler: this._scheduler,
|
|
493
|
+
shouldProcessClientComponents: this._shouldProcessClientComponents,
|
|
487
494
|
sink,
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
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
|
+
},
|
|
491
502
|
treatMissingFieldsAsNull: this._treatMissingFieldsAsNull,
|
|
503
|
+
updater,
|
|
492
504
|
});
|
|
493
505
|
return () => executor.cancel();
|
|
494
506
|
});
|
|
495
507
|
}
|
|
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
508
|
}
|
|
568
509
|
|
|
569
510
|
// Add a sigil for detection by `isRelayModernEnvironment()` to avoid a
|