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
|
@@ -10,10 +10,10 @@
|
|
|
10
10
|
// flowlint ambiguous-object-type:error
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
var invariant = require("fbjs/lib/invariant");
|
|
14
|
-
|
|
15
13
|
var stableCopy = require('./stableCopy');
|
|
16
14
|
|
|
15
|
+
var invariant = require('invariant');
|
|
16
|
+
|
|
17
17
|
/**
|
|
18
18
|
* Returns a stable identifier for the given pair of `RequestParameters` +
|
|
19
19
|
* variables.
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @emails oncall+relay
|
|
8
|
+
*
|
|
9
|
+
* @format
|
|
10
|
+
*/
|
|
11
|
+
// flowlint ambiguous-object-type:error
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
15
|
+
|
|
16
|
+
var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
|
|
17
|
+
|
|
18
|
+
var invariant = require('invariant');
|
|
19
|
+
|
|
20
|
+
function getValueAtPath(data, path) {
|
|
21
|
+
var result = data;
|
|
22
|
+
|
|
23
|
+
var _iterator = (0, _createForOfIteratorHelper2["default"])(path),
|
|
24
|
+
_step;
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
28
|
+
var key = _step.value;
|
|
29
|
+
|
|
30
|
+
if (result == null) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (typeof key === 'number') {
|
|
35
|
+
!Array.isArray(result) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected an array when extracting value at path. ' + "If you're seeing this, this is likely a bug in Relay.") : invariant(false) : void 0;
|
|
36
|
+
result = result[key];
|
|
37
|
+
} else {
|
|
38
|
+
!(typeof result === 'object' && !Array.isArray(result)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected an object when extracting value at path. ' + "If you're seeing this, this is likely a bug in Relay.") : invariant(false) : void 0;
|
|
39
|
+
result = result[key];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
} catch (err) {
|
|
43
|
+
_iterator.e(err);
|
|
44
|
+
} finally {
|
|
45
|
+
_iterator.f();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return result;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
module.exports = getValueAtPath;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @format
|
|
9
|
+
* @emails oncall+relay
|
|
10
|
+
*/
|
|
11
|
+
// flowlint ambiguous-object-type:error
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
function registerEnvironmentWithDevTools(environment) {
|
|
15
|
+
// Register this Relay Environment with Relay DevTools if it exists.
|
|
16
|
+
// Note: this must always be the last step in the constructor.
|
|
17
|
+
var _global = typeof global !== 'undefined' ? global : typeof window !== 'undefined' ? window : undefined;
|
|
18
|
+
|
|
19
|
+
var devToolsHook = _global && _global.__RELAY_DEVTOOLS_HOOK__;
|
|
20
|
+
|
|
21
|
+
if (devToolsHook) {
|
|
22
|
+
devToolsHook.registerEnvironment(environment);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
module.exports = registerEnvironmentWithDevTools;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
// flowlint ambiguous-object-type:error
|
|
11
|
+
'use strict';
|
|
12
|
+
|
|
13
|
+
var _window, _window$performance;
|
|
14
|
+
|
|
15
|
+
var isPerformanceNowAvailable = typeof window !== 'undefined' && typeof ((_window = window) === null || _window === void 0 ? void 0 : (_window$performance = _window.performance) === null || _window$performance === void 0 ? void 0 : _window$performance.now) === 'function';
|
|
16
|
+
|
|
17
|
+
function currentTimestamp() {
|
|
18
|
+
if (isPerformanceNowAvailable) {
|
|
19
|
+
return window.performance.now();
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return Date.now();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function withDuration(cb) {
|
|
26
|
+
var startTime = currentTimestamp();
|
|
27
|
+
var result = cb();
|
|
28
|
+
return [currentTimestamp() - startTime, result];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
module.exports = withDuration;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @emails oncall+relay
|
|
8
|
+
* @flow strict
|
|
9
|
+
* @format
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A unique identifier of the current actor.
|
|
16
|
+
*/
|
|
17
|
+
export opaque type ActorIdentifier = string;
|
|
18
|
+
|
|
19
|
+
const invariant = require('invariant');
|
|
20
|
+
|
|
21
|
+
const INTERNAL_ACTOR_IDENTIFIER_DO_NOT_USE: ActorIdentifier =
|
|
22
|
+
'INTERNAL_ACTOR_IDENTIFIER_DO_NOT_USE';
|
|
23
|
+
|
|
24
|
+
function assertInternalActorIndentifier(
|
|
25
|
+
actorIdentifier: ActorIdentifier,
|
|
26
|
+
): void {
|
|
27
|
+
invariant(
|
|
28
|
+
actorIdentifier === INTERNAL_ACTOR_IDENTIFIER_DO_NOT_USE,
|
|
29
|
+
'Expected to use only internal version of the `actorIdentifier`. "%s" was provided.',
|
|
30
|
+
actorIdentifier,
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
module.exports = {
|
|
35
|
+
assertInternalActorIndentifier,
|
|
36
|
+
getActorIdentifier(actorID: string): ActorIdentifier {
|
|
37
|
+
return (actorID: ActorIdentifier);
|
|
38
|
+
},
|
|
39
|
+
getDefaultActorIdentifier(): ActorIdentifier {
|
|
40
|
+
throw new Error('Not Implemented');
|
|
41
|
+
},
|
|
42
|
+
INTERNAL_ACTOR_IDENTIFIER_DO_NOT_USE,
|
|
43
|
+
};
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @emails oncall+relay
|
|
8
|
+
* @flow strict-local
|
|
9
|
+
* @format
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
import type {HandlerProvider} from '../handlers/RelayDefaultHandlerProvider';
|
|
15
|
+
import type {GraphQLResponse, PayloadData} from '../network/RelayNetworkTypes';
|
|
16
|
+
import type {INetwork} from '../network/RelayNetworkTypes';
|
|
17
|
+
import type RelayObservable from '../network/RelayObservable';
|
|
18
|
+
import type {
|
|
19
|
+
ExecuteMutationConfig,
|
|
20
|
+
LogFunction,
|
|
21
|
+
MutationParameters,
|
|
22
|
+
OperationAvailability,
|
|
23
|
+
OperationDescriptor,
|
|
24
|
+
OperationTracker,
|
|
25
|
+
OptimisticResponseConfig,
|
|
26
|
+
OptimisticUpdateFunction,
|
|
27
|
+
RequiredFieldLogger,
|
|
28
|
+
SelectorStoreUpdater,
|
|
29
|
+
SingularReaderSelector,
|
|
30
|
+
Snapshot,
|
|
31
|
+
Store,
|
|
32
|
+
StoreUpdater,
|
|
33
|
+
} from '../store/RelayStoreTypes';
|
|
34
|
+
import type {Disposable, RenderPolicy} from '../util/RelayRuntimeTypes';
|
|
35
|
+
import type {ActorIdentifier} from './ActorIdentifier';
|
|
36
|
+
import type {
|
|
37
|
+
IActorEnvironment,
|
|
38
|
+
IMultiActorEnvironment,
|
|
39
|
+
} from './MultiActorEnvironmentTypes';
|
|
40
|
+
|
|
41
|
+
const wrapNetworkWithLogObserver = require('../network/wrapNetworkWithLogObserver');
|
|
42
|
+
const defaultGetDataID = require('../store/defaultGetDataID');
|
|
43
|
+
const RelayOperationTracker = require('../store/RelayOperationTracker');
|
|
44
|
+
const RelayPublishQueue = require('../store/RelayPublishQueue');
|
|
45
|
+
const registerEnvironmentWithDevTools = require('../util/registerEnvironmentWithDevTools');
|
|
46
|
+
|
|
47
|
+
export type ActorSpecificEnvironmentConfig = $ReadOnly<{
|
|
48
|
+
actorIdentifier: ActorIdentifier,
|
|
49
|
+
configName: ?string,
|
|
50
|
+
defaultRenderPolicy: RenderPolicy,
|
|
51
|
+
handlerProvider: HandlerProvider,
|
|
52
|
+
logFn: LogFunction,
|
|
53
|
+
multiActorEnvironment: IMultiActorEnvironment,
|
|
54
|
+
network: INetwork,
|
|
55
|
+
requiredFieldLogger: RequiredFieldLogger,
|
|
56
|
+
store: Store,
|
|
57
|
+
}>;
|
|
58
|
+
|
|
59
|
+
class ActorSpecificEnvironment implements IActorEnvironment {
|
|
60
|
+
__log: LogFunction;
|
|
61
|
+
+_defaultRenderPolicy: RenderPolicy;
|
|
62
|
+
+_network: INetwork;
|
|
63
|
+
+_operationTracker: OperationTracker;
|
|
64
|
+
+_publishQueue: RelayPublishQueue;
|
|
65
|
+
+_store: Store;
|
|
66
|
+
+actorIdentifier: ActorIdentifier;
|
|
67
|
+
+configName: ?string;
|
|
68
|
+
+multiActorEnvironment: IMultiActorEnvironment;
|
|
69
|
+
+options: mixed;
|
|
70
|
+
requiredFieldLogger: RequiredFieldLogger;
|
|
71
|
+
|
|
72
|
+
constructor(config: ActorSpecificEnvironmentConfig) {
|
|
73
|
+
this.configName = config.configName;
|
|
74
|
+
this.actorIdentifier = config.actorIdentifier;
|
|
75
|
+
this.multiActorEnvironment = config.multiActorEnvironment;
|
|
76
|
+
|
|
77
|
+
this.__log = config.logFn;
|
|
78
|
+
this.requiredFieldLogger = config.requiredFieldLogger;
|
|
79
|
+
this._operationTracker = new RelayOperationTracker();
|
|
80
|
+
this._store = config.store;
|
|
81
|
+
this._network = wrapNetworkWithLogObserver(this, config.network);
|
|
82
|
+
this._publishQueue = new RelayPublishQueue(
|
|
83
|
+
config.store,
|
|
84
|
+
config.handlerProvider,
|
|
85
|
+
defaultGetDataID,
|
|
86
|
+
);
|
|
87
|
+
this._defaultRenderPolicy = config.defaultRenderPolicy;
|
|
88
|
+
// TODO:T92305692 Remove `options` in favor of directly using `actorIdentifier` on the environment
|
|
89
|
+
this.options = {
|
|
90
|
+
actorID: this.actorIdentifier,
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
// We need to add this here to pass `isRelayModernEnvironment` check
|
|
94
|
+
// $FlowFixMe[prop-missing]
|
|
95
|
+
this['@@RelayModernEnvironment'] = true;
|
|
96
|
+
|
|
97
|
+
if (__DEV__) {
|
|
98
|
+
const {inspect} = require('../store/StoreInspector');
|
|
99
|
+
(this: $FlowFixMe).DEBUG_inspect = (dataID: ?string) =>
|
|
100
|
+
inspect(this, dataID);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Register this Relay Environment with Relay DevTools if it exists.
|
|
104
|
+
// Note: this must always be the last step in the constructor.
|
|
105
|
+
registerEnvironmentWithDevTools(this);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
getPublishQueue(): RelayPublishQueue {
|
|
109
|
+
return this._publishQueue;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
UNSTABLE_getDefaultRenderPolicy(): RenderPolicy {
|
|
113
|
+
return this._defaultRenderPolicy;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
applyMutation<TMutation: MutationParameters>(
|
|
117
|
+
optimisticConfig: OptimisticResponseConfig<TMutation>,
|
|
118
|
+
): Disposable {
|
|
119
|
+
return this.multiActorEnvironment.applyMutation(this, optimisticConfig);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
applyUpdate(optimisticUpdate: OptimisticUpdateFunction): Disposable {
|
|
123
|
+
return this.multiActorEnvironment.applyUpdate(this, optimisticUpdate);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
revertUpdate(optimisticUpdate: OptimisticUpdateFunction): void {
|
|
127
|
+
return this.multiActorEnvironment.revertUpdate(this, optimisticUpdate);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
replaceUpdate(
|
|
131
|
+
optimisticUpdate: OptimisticUpdateFunction,
|
|
132
|
+
replacementUpdate: OptimisticUpdateFunction,
|
|
133
|
+
): void {
|
|
134
|
+
return this.multiActorEnvironment.replaceUpdate(
|
|
135
|
+
this,
|
|
136
|
+
optimisticUpdate,
|
|
137
|
+
replacementUpdate,
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
check(operation: OperationDescriptor): OperationAvailability {
|
|
142
|
+
return this.multiActorEnvironment.check(this, operation);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
subscribe(
|
|
146
|
+
snapshot: Snapshot,
|
|
147
|
+
callback: (snapshot: Snapshot) => void,
|
|
148
|
+
): Disposable {
|
|
149
|
+
return this.multiActorEnvironment.subscribe(this, snapshot, callback);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
retain(operation: OperationDescriptor): Disposable {
|
|
153
|
+
return this.multiActorEnvironment.retain(this, operation);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
commitUpdate(updater: StoreUpdater): void {
|
|
157
|
+
return this.multiActorEnvironment.commitUpdate(this, updater);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Commit a payload to the environment using the given operation selector.
|
|
162
|
+
*/
|
|
163
|
+
commitPayload(
|
|
164
|
+
operationDescriptor: OperationDescriptor,
|
|
165
|
+
payload: PayloadData,
|
|
166
|
+
): void {
|
|
167
|
+
return this.multiActorEnvironment.commitPayload(
|
|
168
|
+
this,
|
|
169
|
+
operationDescriptor,
|
|
170
|
+
payload,
|
|
171
|
+
);
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
getNetwork(): INetwork {
|
|
175
|
+
return this._network;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
getStore(): Store {
|
|
179
|
+
return this._store;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
getOperationTracker(): OperationTracker {
|
|
183
|
+
return this._operationTracker;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
lookup(selector: SingularReaderSelector): Snapshot {
|
|
187
|
+
return this.multiActorEnvironment.lookup(this, selector);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
execute(config: {
|
|
191
|
+
operation: OperationDescriptor,
|
|
192
|
+
}): RelayObservable<GraphQLResponse> {
|
|
193
|
+
return this.multiActorEnvironment.execute(this, config);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
executeSubscription<TMutation: MutationParameters>(config: {
|
|
197
|
+
operation: OperationDescriptor,
|
|
198
|
+
updater?: ?SelectorStoreUpdater<TMutation['response']>,
|
|
199
|
+
}): RelayObservable<GraphQLResponse> {
|
|
200
|
+
return this.multiActorEnvironment.executeSubscription(this, config);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
executeMutation<TMutation: MutationParameters>(
|
|
204
|
+
options: ExecuteMutationConfig<TMutation>,
|
|
205
|
+
): RelayObservable<GraphQLResponse> {
|
|
206
|
+
return this.multiActorEnvironment.executeMutation(this, options);
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
executeWithSource(options: {
|
|
210
|
+
operation: OperationDescriptor,
|
|
211
|
+
source: RelayObservable<GraphQLResponse>,
|
|
212
|
+
}): RelayObservable<GraphQLResponse> {
|
|
213
|
+
return this.multiActorEnvironment.executeWithSource(this, options);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
isRequestActive(requestIdentifier: string): boolean {
|
|
217
|
+
return this.multiActorEnvironment.isRequestActive(this, requestIdentifier);
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
isServer(): boolean {
|
|
221
|
+
return this.multiActorEnvironment.isServer();
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
module.exports = ActorSpecificEnvironment;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
* @emails oncall+relay
|
|
8
|
+
* @flow strict-local
|
|
9
|
+
* @format
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
const ACTOR_IDENTIFIER_FIELD_NAME = 'actor_key';
|
|
15
|
+
|
|
16
|
+
import type {ActorIdentifier} from './ActorIdentifier';
|
|
17
|
+
|
|
18
|
+
const {getActorIdentifier} = require('./ActorIdentifier');
|
|
19
|
+
|
|
20
|
+
function getActorIdentifierFromPayload(payload: mixed): ?ActorIdentifier {
|
|
21
|
+
if (
|
|
22
|
+
payload != null &&
|
|
23
|
+
typeof payload === 'object' &&
|
|
24
|
+
typeof payload[ACTOR_IDENTIFIER_FIELD_NAME] === 'string'
|
|
25
|
+
) {
|
|
26
|
+
return getActorIdentifier(payload[ACTOR_IDENTIFIER_FIELD_NAME]);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
module.exports = {
|
|
31
|
+
ACTOR_IDENTIFIER_FIELD_NAME,
|
|
32
|
+
getActorIdentifierFromPayload,
|
|
33
|
+
};
|