relay-runtime 11.0.2 → 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/index.js +1 -1
- package/index.js.flow +16 -1
- package/lib/index.js +15 -0
- package/lib/multi-actor-environment/ActorIdentifier.js +11 -1
- package/lib/multi-actor-environment/ActorSpecificEnvironment.js +59 -19
- package/lib/multi-actor-environment/ActorUtils.js +27 -0
- package/lib/multi-actor-environment/MultiActorEnvironment.js +305 -55
- package/lib/multi-actor-environment/index.js +5 -1
- package/lib/mutations/RelayRecordSourceSelectorProxy.js +6 -1
- package/lib/mutations/commitMutation.js +4 -1
- package/lib/mutations/validateMutation.js +6 -1
- package/lib/network/RelayObservable.js +3 -1
- package/lib/network/RelayQueryResponseCache.js +19 -3
- package/lib/network/wrapNetworkWithLogObserver.js +78 -0
- package/lib/store/DataChecker.js +110 -40
- package/lib/store/OperationExecutor.js +478 -204
- package/lib/store/RelayConcreteVariables.js +21 -0
- package/lib/store/RelayModernEnvironment.js +41 -85
- package/lib/store/RelayModernFragmentSpecResolver.js +48 -22
- package/lib/store/RelayModernRecord.js +35 -1
- package/lib/store/RelayModernStore.js +48 -14
- package/lib/store/RelayOperationTracker.js +33 -23
- package/lib/store/RelayPublishQueue.js +23 -5
- package/lib/store/RelayReader.js +138 -44
- package/lib/store/RelayRecordSource.js +87 -3
- package/lib/store/RelayReferenceMarker.js +28 -15
- package/lib/store/RelayResponseNormalizer.js +164 -91
- package/lib/store/RelayStoreReactFlightUtils.js +1 -7
- package/lib/store/RelayStoreSubscriptions.js +8 -5
- package/lib/store/RelayStoreUtils.js +7 -2
- package/lib/store/ResolverCache.js +213 -0
- package/lib/store/ResolverFragments.js +1 -1
- package/lib/store/createRelayContext.js +1 -1
- package/lib/subscription/requestSubscription.js +27 -29
- package/lib/util/RelayConcreteNode.js +1 -0
- package/lib/util/RelayFeatureFlags.js +3 -5
- package/lib/util/RelayReplaySubject.js +21 -6
- 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/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 +17 -1
- package/multi-actor-environment/ActorSpecificEnvironment.js.flow +72 -44
- package/multi-actor-environment/ActorUtils.js.flow +33 -0
- package/multi-actor-environment/MultiActorEnvironment.js.flow +332 -80
- package/multi-actor-environment/MultiActorEnvironmentTypes.js.flow +61 -12
- package/multi-actor-environment/index.js.flow +3 -0
- package/mutations/RelayRecordSourceSelectorProxy.js.flow +7 -2
- package/mutations/commitMutation.js.flow +2 -0
- package/mutations/validateMutation.js.flow +8 -0
- package/network/RelayObservable.js.flow +2 -0
- package/network/RelayQueryResponseCache.js.flow +31 -18
- package/network/wrapNetworkWithLogObserver.js.flow +99 -0
- package/package.json +1 -1
- 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 +126 -35
- package/store/OperationExecutor.js.flow +528 -265
- package/store/RelayConcreteVariables.js.flow +26 -1
- package/store/RelayModernEnvironment.js.flow +41 -94
- 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 +50 -12
- package/store/RelayOperationTracker.js.flow +56 -34
- package/store/RelayPublishQueue.js.flow +31 -8
- package/store/RelayReader.js.flow +148 -42
- package/store/RelayRecordSource.js.flow +72 -6
- package/store/RelayReferenceMarker.js.flow +29 -12
- package/store/RelayResponseNormalizer.js.flow +164 -48
- package/store/RelayStoreReactFlightUtils.js.flow +1 -7
- package/store/RelayStoreSubscriptions.js.flow +10 -3
- package/store/RelayStoreTypes.js.flow +128 -12
- package/store/RelayStoreUtils.js.flow +17 -3
- package/store/ResolverCache.js.flow +247 -0
- package/store/ResolverFragments.js.flow +6 -3
- package/store/createRelayContext.js.flow +1 -1
- package/subscription/requestSubscription.js.flow +41 -29
- package/util/NormalizationNode.js.flow +10 -3
- package/util/ReaderNode.js.flow +15 -1
- package/util/RelayConcreteNode.js.flow +1 -0
- package/util/RelayFeatureFlags.js.flow +8 -10
- package/util/RelayReplaySubject.js.flow +7 -6
- 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 +1 -0
- 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
|
@@ -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;
|
|
@@ -16,12 +16,28 @@
|
|
|
16
16
|
*/
|
|
17
17
|
export opaque type ActorIdentifier = string;
|
|
18
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
|
+
|
|
19
34
|
module.exports = {
|
|
35
|
+
assertInternalActorIndentifier,
|
|
20
36
|
getActorIdentifier(actorID: string): ActorIdentifier {
|
|
21
37
|
return (actorID: ActorIdentifier);
|
|
22
38
|
},
|
|
23
|
-
|
|
24
39
|
getDefaultActorIdentifier(): ActorIdentifier {
|
|
25
40
|
throw new Error('Not Implemented');
|
|
26
41
|
},
|
|
42
|
+
INTERNAL_ACTOR_IDENTIFIER_DO_NOT_USE,
|
|
27
43
|
};
|
|
@@ -12,7 +12,13 @@
|
|
|
12
12
|
'use strict';
|
|
13
13
|
|
|
14
14
|
const RelayOperationTracker = require('../store/RelayOperationTracker');
|
|
15
|
+
const RelayPublishQueue = require('../store/RelayPublishQueue');
|
|
15
16
|
|
|
17
|
+
const defaultGetDataID = require('../store/defaultGetDataID');
|
|
18
|
+
const registerEnvironmentWithDevTools = require('../util/registerEnvironmentWithDevTools');
|
|
19
|
+
const wrapNetworkWithLogObserver = require('../network/wrapNetworkWithLogObserver');
|
|
20
|
+
|
|
21
|
+
import type {HandlerProvider} from '../handlers/RelayDefaultHandlerProvider';
|
|
16
22
|
import type {GraphQLResponse, PayloadData} from '../network/RelayNetworkTypes';
|
|
17
23
|
import type {INetwork} from '../network/RelayNetworkTypes';
|
|
18
24
|
import type RelayObservable from '../network/RelayObservable';
|
|
@@ -38,12 +44,11 @@ import type {
|
|
|
38
44
|
IMultiActorEnvironment,
|
|
39
45
|
} from './MultiActorEnvironmentTypes';
|
|
40
46
|
|
|
41
|
-
function todo() {
|
|
42
|
-
throw new Error('Not implementd');
|
|
43
|
-
}
|
|
44
|
-
|
|
45
47
|
export type ActorSpecificEnvironmentConfig = $ReadOnly<{
|
|
46
48
|
actorIdentifier: ActorIdentifier,
|
|
49
|
+
configName: ?string,
|
|
50
|
+
defaultRenderPolicy: RenderPolicy,
|
|
51
|
+
handlerProvider: HandlerProvider,
|
|
47
52
|
logFn: LogFunction,
|
|
48
53
|
multiActorEnvironment: IMultiActorEnvironment,
|
|
49
54
|
network: INetwork,
|
|
@@ -52,18 +57,20 @@ export type ActorSpecificEnvironmentConfig = $ReadOnly<{
|
|
|
52
57
|
}>;
|
|
53
58
|
|
|
54
59
|
class ActorSpecificEnvironment implements IActorEnvironment {
|
|
55
|
-
+options: mixed;
|
|
56
60
|
__log: LogFunction;
|
|
57
|
-
|
|
58
|
-
+_store: Store;
|
|
61
|
+
+_defaultRenderPolicy: RenderPolicy;
|
|
59
62
|
+_network: INetwork;
|
|
60
63
|
+_operationTracker: OperationTracker;
|
|
61
|
-
|
|
62
|
-
|
|
64
|
+
+_publishQueue: RelayPublishQueue;
|
|
65
|
+
+_store: Store;
|
|
63
66
|
+actorIdentifier: ActorIdentifier;
|
|
67
|
+
+configName: ?string;
|
|
64
68
|
+multiActorEnvironment: IMultiActorEnvironment;
|
|
69
|
+
+options: mixed;
|
|
70
|
+
requiredFieldLogger: RequiredFieldLogger;
|
|
65
71
|
|
|
66
72
|
constructor(config: ActorSpecificEnvironmentConfig) {
|
|
73
|
+
this.configName = config.configName;
|
|
67
74
|
this.actorIdentifier = config.actorIdentifier;
|
|
68
75
|
this.multiActorEnvironment = config.multiActorEnvironment;
|
|
69
76
|
|
|
@@ -71,51 +78,81 @@ class ActorSpecificEnvironment implements IActorEnvironment {
|
|
|
71
78
|
this.requiredFieldLogger = config.requiredFieldLogger;
|
|
72
79
|
this._operationTracker = new RelayOperationTracker();
|
|
73
80
|
this._store = config.store;
|
|
74
|
-
this._network = config.network;
|
|
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;
|
|
75
110
|
}
|
|
76
111
|
|
|
77
112
|
UNSTABLE_getDefaultRenderPolicy(): RenderPolicy {
|
|
78
|
-
return
|
|
113
|
+
return this._defaultRenderPolicy;
|
|
79
114
|
}
|
|
80
115
|
|
|
81
116
|
applyMutation(optimisticConfig: OptimisticResponseConfig): Disposable {
|
|
82
|
-
return this.multiActorEnvironment.applyMutation(
|
|
83
|
-
this.actorIdentifier,
|
|
84
|
-
optimisticConfig,
|
|
85
|
-
);
|
|
117
|
+
return this.multiActorEnvironment.applyMutation(this, optimisticConfig);
|
|
86
118
|
}
|
|
87
119
|
|
|
88
120
|
applyUpdate(optimisticUpdate: OptimisticUpdateFunction): Disposable {
|
|
89
|
-
return this.multiActorEnvironment.applyUpdate(
|
|
90
|
-
|
|
121
|
+
return this.multiActorEnvironment.applyUpdate(this, optimisticUpdate);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
revertUpdate(optimisticUpdate: OptimisticUpdateFunction): void {
|
|
125
|
+
return this.multiActorEnvironment.revertUpdate(this, optimisticUpdate);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
replaceUpdate(
|
|
129
|
+
optimisticUpdate: OptimisticUpdateFunction,
|
|
130
|
+
replacementUpdate: OptimisticUpdateFunction,
|
|
131
|
+
): void {
|
|
132
|
+
return this.multiActorEnvironment.replaceUpdate(
|
|
133
|
+
this,
|
|
91
134
|
optimisticUpdate,
|
|
135
|
+
replacementUpdate,
|
|
92
136
|
);
|
|
93
137
|
}
|
|
94
138
|
|
|
95
139
|
check(operation: OperationDescriptor): OperationAvailability {
|
|
96
|
-
return this.multiActorEnvironment.check(this
|
|
140
|
+
return this.multiActorEnvironment.check(this, operation);
|
|
97
141
|
}
|
|
98
142
|
|
|
99
143
|
subscribe(
|
|
100
144
|
snapshot: Snapshot,
|
|
101
145
|
callback: (snapshot: Snapshot) => void,
|
|
102
146
|
): Disposable {
|
|
103
|
-
return this.multiActorEnvironment.subscribe(
|
|
104
|
-
this.actorIdentifier,
|
|
105
|
-
snapshot,
|
|
106
|
-
callback,
|
|
107
|
-
);
|
|
147
|
+
return this.multiActorEnvironment.subscribe(this, snapshot, callback);
|
|
108
148
|
}
|
|
109
149
|
|
|
110
150
|
retain(operation: OperationDescriptor): Disposable {
|
|
111
|
-
return this.multiActorEnvironment.retain(this
|
|
151
|
+
return this.multiActorEnvironment.retain(this, operation);
|
|
112
152
|
}
|
|
113
153
|
|
|
114
154
|
commitUpdate(updater: StoreUpdater): void {
|
|
115
|
-
return this.multiActorEnvironment.commitUpdate(
|
|
116
|
-
this.actorIdentifier,
|
|
117
|
-
updater,
|
|
118
|
-
);
|
|
155
|
+
return this.multiActorEnvironment.commitUpdate(this, updater);
|
|
119
156
|
}
|
|
120
157
|
|
|
121
158
|
/**
|
|
@@ -126,7 +163,7 @@ class ActorSpecificEnvironment implements IActorEnvironment {
|
|
|
126
163
|
payload: PayloadData,
|
|
127
164
|
): void {
|
|
128
165
|
return this.multiActorEnvironment.commitPayload(
|
|
129
|
-
this
|
|
166
|
+
this,
|
|
130
167
|
operationDescriptor,
|
|
131
168
|
payload,
|
|
132
169
|
);
|
|
@@ -145,44 +182,35 @@ class ActorSpecificEnvironment implements IActorEnvironment {
|
|
|
145
182
|
}
|
|
146
183
|
|
|
147
184
|
lookup(selector: SingularReaderSelector): Snapshot {
|
|
148
|
-
return this.multiActorEnvironment.lookup(this
|
|
185
|
+
return this.multiActorEnvironment.lookup(this, selector);
|
|
149
186
|
}
|
|
150
187
|
|
|
151
188
|
execute(config: {
|
|
152
189
|
operation: OperationDescriptor,
|
|
153
190
|
updater?: ?SelectorStoreUpdater,
|
|
154
191
|
}): RelayObservable<GraphQLResponse> {
|
|
155
|
-
return this.multiActorEnvironment.execute(this
|
|
192
|
+
return this.multiActorEnvironment.execute(this, config);
|
|
156
193
|
}
|
|
157
194
|
|
|
158
195
|
executeMutation(
|
|
159
196
|
options: ExecuteMutationConfig,
|
|
160
197
|
): RelayObservable<GraphQLResponse> {
|
|
161
|
-
return this.multiActorEnvironment.executeMutation(
|
|
162
|
-
this.actorIdentifier,
|
|
163
|
-
options,
|
|
164
|
-
);
|
|
198
|
+
return this.multiActorEnvironment.executeMutation(this, options);
|
|
165
199
|
}
|
|
166
200
|
|
|
167
201
|
executeWithSource(options: {
|
|
168
202
|
operation: OperationDescriptor,
|
|
169
203
|
source: RelayObservable<GraphQLResponse>,
|
|
170
204
|
}): RelayObservable<GraphQLResponse> {
|
|
171
|
-
return this.multiActorEnvironment.executeWithSource(
|
|
172
|
-
this.actorIdentifier,
|
|
173
|
-
options,
|
|
174
|
-
);
|
|
205
|
+
return this.multiActorEnvironment.executeWithSource(this, options);
|
|
175
206
|
}
|
|
176
207
|
|
|
177
208
|
isRequestActive(requestIdentifier: string): boolean {
|
|
178
|
-
return this.multiActorEnvironment.isRequestActive(
|
|
179
|
-
this.actorIdentifier,
|
|
180
|
-
requestIdentifier,
|
|
181
|
-
);
|
|
209
|
+
return this.multiActorEnvironment.isRequestActive(this, requestIdentifier);
|
|
182
210
|
}
|
|
183
211
|
|
|
184
212
|
isServer(): boolean {
|
|
185
|
-
return
|
|
213
|
+
return this.multiActorEnvironment.isServer();
|
|
186
214
|
}
|
|
187
215
|
}
|
|
188
216
|
|
|
@@ -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
|
+
const {getActorIdentifier} = require('./ActorIdentifier');
|
|
17
|
+
|
|
18
|
+
import type {ActorIdentifier} from './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
|
+
};
|