relay-runtime 10.1.3 → 11.0.2
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 +60 -0
- package/handlers/connection/MutationHandlers.js.flow +28 -0
- package/index.js +1 -1
- package/index.js.flow +9 -3
- package/lib/handlers/RelayDefaultHandlerProvider.js +1 -1
- package/lib/handlers/connection/ConnectionHandler.js +68 -6
- package/lib/handlers/connection/MutationHandlers.js +67 -8
- package/lib/index.js +3 -0
- package/lib/multi-actor-environment/ActorIdentifier.js +23 -0
- package/lib/multi-actor-environment/ActorSpecificEnvironment.js +108 -0
- package/lib/multi-actor-environment/MultiActorEnvironment.js +156 -0
- package/lib/multi-actor-environment/MultiActorEnvironmentTypes.js +11 -0
- package/lib/multi-actor-environment/index.js +17 -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 +1 -1
- package/lib/mutations/applyOptimisticMutation.js +1 -1
- package/lib/mutations/commitMutation.js +1 -1
- package/lib/mutations/validateMutation.js +36 -15
- package/lib/network/RelayNetwork.js +1 -1
- package/lib/network/RelayQueryResponseCache.js +3 -2
- package/lib/query/GraphQLTag.js +1 -1
- package/lib/query/fetchQuery.js +129 -13
- package/lib/query/fetchQueryInternal.js +3 -4
- package/lib/query/fetchQuery_DEPRECATED.js +39 -0
- package/lib/store/DataChecker.js +26 -14
- package/lib/store/{RelayModernQueryExecutor.js → OperationExecutor.js} +117 -47
- package/lib/store/RelayConcreteVariables.js +8 -4
- package/lib/store/RelayModernEnvironment.js +105 -136
- package/lib/store/RelayModernFragmentSpecResolver.js +16 -9
- package/lib/store/RelayModernRecord.js +1 -1
- package/lib/store/RelayModernSelector.js +1 -1
- package/lib/store/RelayModernStore.js +19 -20
- package/lib/store/RelayOperationTracker.js +55 -49
- package/lib/store/RelayPublishQueue.js +9 -5
- package/lib/store/RelayReader.js +68 -14
- package/lib/store/RelayReferenceMarker.js +28 -14
- package/lib/store/RelayResponseNormalizer.js +109 -15
- package/lib/store/RelayStoreReactFlightUtils.js +6 -4
- package/lib/store/RelayStoreSubscriptions.js +18 -8
- package/lib/store/RelayStoreSubscriptionsUsingMapByID.js +90 -30
- package/lib/store/RelayStoreUtils.js +3 -2
- package/lib/store/ResolverFragments.js +57 -0
- package/lib/store/cloneRelayHandleSourceField.js +1 -1
- package/lib/store/cloneRelayScalarHandleSourceField.js +1 -1
- package/lib/store/createFragmentSpecResolver.js +2 -2
- package/lib/store/createRelayContext.js +1 -1
- package/lib/store/defaultGetDataID.js +3 -1
- package/lib/store/hasOverlappingIDs.js +11 -3
- package/lib/store/readInlineData.js +1 -1
- package/lib/subscription/requestSubscription.js +33 -5
- package/lib/util/RelayConcreteNode.js +2 -0
- package/lib/util/RelayFeatureFlags.js +8 -3
- package/lib/util/RelayProfiler.js +17 -187
- package/lib/util/RelayReplaySubject.js +1 -1
- package/lib/util/deepFreeze.js +1 -0
- package/lib/util/getRelayHandleKey.js +1 -1
- package/lib/util/getRequestIdentifier.js +1 -1
- package/multi-actor-environment/ActorIdentifier.js.flow +27 -0
- package/multi-actor-environment/ActorSpecificEnvironment.js.flow +189 -0
- package/multi-actor-environment/MultiActorEnvironment.js.flow +233 -0
- package/multi-actor-environment/MultiActorEnvironmentTypes.js.flow +196 -0
- package/multi-actor-environment/index.js.flow +24 -0
- package/mutations/RelayRecordSourceProxy.js.flow +3 -2
- package/mutations/commitMutation.js.flow +1 -1
- package/mutations/validateMutation.js.flow +40 -15
- package/network/RelayNetworkTypes.js.flow +31 -11
- package/network/RelayQueryResponseCache.js.flow +2 -1
- package/package.json +3 -2
- package/query/fetchQuery.js.flow +147 -20
- package/query/fetchQueryInternal.js.flow +2 -3
- package/query/fetchQuery_DEPRECATED.js.flow +47 -0
- package/relay-runtime.js +2 -2
- package/relay-runtime.min.js +2 -2
- package/store/DataChecker.js.flow +23 -15
- package/store/{RelayModernQueryExecutor.js.flow → OperationExecutor.js.flow} +128 -40
- package/store/RelayConcreteVariables.js.flow +5 -0
- package/store/RelayModernEnvironment.js.flow +100 -130
- package/store/RelayModernFragmentSpecResolver.js.flow +30 -8
- package/store/RelayModernStore.js.flow +28 -24
- package/store/RelayOperationTracker.js.flow +69 -56
- package/store/RelayPublishQueue.js.flow +7 -4
- package/store/RelayReader.js.flow +63 -11
- package/store/RelayRecordSource.js.flow +3 -3
- package/store/RelayRecordSourceMapImpl.js.flow +6 -2
- package/store/RelayReferenceMarker.js.flow +28 -18
- package/store/RelayResponseNormalizer.js.flow +134 -23
- package/store/RelayStoreReactFlightUtils.js.flow +9 -4
- package/store/RelayStoreSubscriptions.js.flow +22 -7
- package/store/RelayStoreSubscriptionsUsingMapByID.js.flow +36 -12
- package/store/RelayStoreTypes.js.flow +51 -22
- package/store/RelayStoreUtils.js.flow +2 -1
- package/store/ResolverFragments.js.flow +125 -0
- package/store/createFragmentSpecResolver.js.flow +2 -0
- package/store/defaultGetDataID.js.flow +3 -1
- package/store/hasOverlappingIDs.js.flow +11 -9
- package/subscription/requestSubscription.js.flow +25 -2
- package/util/NormalizationNode.js.flow +13 -0
- package/util/ReaderNode.js.flow +14 -1
- package/util/RelayConcreteNode.js.flow +2 -0
- package/util/RelayFeatureFlags.js.flow +12 -2
- package/util/RelayProfiler.js.flow +22 -194
- package/util/RelayRuntimeTypes.js.flow +4 -5
- package/util/deepFreeze.js.flow +2 -1
- package/util/isEmptyObject.js.flow +1 -1
|
@@ -0,0 +1,233 @@
|
|
|
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 ActorSpecificEnvironment = require('./ActorSpecificEnvironment');
|
|
15
|
+
const OperationExecutor = require('../store/OperationExecutor');
|
|
16
|
+
const RelayDefaultHandlerProvider = require('../handlers/RelayDefaultHandlerProvider');
|
|
17
|
+
const RelayModernStore = require('../store/RelayModernStore');
|
|
18
|
+
const RelayObservable = require('../network/RelayObservable');
|
|
19
|
+
const RelayPublishQueue = require('../store/RelayPublishQueue');
|
|
20
|
+
const RelayRecordSource = require('../store/RelayRecordSource');
|
|
21
|
+
|
|
22
|
+
const defaultGetDataID = require('../store/defaultGetDataID');
|
|
23
|
+
|
|
24
|
+
import type {HandlerProvider} from '../handlers/RelayDefaultHandlerProvider';
|
|
25
|
+
import type {GraphQLResponse, PayloadData} from '../network/RelayNetworkTypes';
|
|
26
|
+
import type {INetwork} from '../network/RelayNetworkTypes';
|
|
27
|
+
import type {ActiveState} from '../store/OperationExecutor';
|
|
28
|
+
import type {GetDataID} from '../store/RelayResponseNormalizer';
|
|
29
|
+
import type {
|
|
30
|
+
IEnvironment,
|
|
31
|
+
OptimisticResponseConfig,
|
|
32
|
+
OptimisticUpdateFunction,
|
|
33
|
+
OperationDescriptor,
|
|
34
|
+
OperationAvailability,
|
|
35
|
+
Snapshot,
|
|
36
|
+
SelectorStoreUpdater,
|
|
37
|
+
SingularReaderSelector,
|
|
38
|
+
StoreUpdater,
|
|
39
|
+
RequiredFieldLogger,
|
|
40
|
+
ExecuteMutationConfig,
|
|
41
|
+
LogFunction,
|
|
42
|
+
} from '../store/RelayStoreTypes';
|
|
43
|
+
import type {Disposable} from '../util/RelayRuntimeTypes';
|
|
44
|
+
import type {ActorIdentifier} from './ActorIdentifier';
|
|
45
|
+
import type {
|
|
46
|
+
IActorEnvironment,
|
|
47
|
+
IMultiActorEnvironment,
|
|
48
|
+
} from './MultiActorEnvironmentTypes';
|
|
49
|
+
|
|
50
|
+
function todo(what: string) {
|
|
51
|
+
throw new Error(`Not implementd: ${what}`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export type MultiActorEnvironmentConfig = $ReadOnly<{
|
|
55
|
+
createNetworkForActor: (actorIdentifier: ActorIdentifier) => INetwork,
|
|
56
|
+
getDataID?: GetDataID,
|
|
57
|
+
handlerProvider?: HandlerProvider,
|
|
58
|
+
logFn: LogFunction,
|
|
59
|
+
requiredFieldLogger: RequiredFieldLogger,
|
|
60
|
+
treatMissingFieldsAsNull?: boolean,
|
|
61
|
+
}>;
|
|
62
|
+
|
|
63
|
+
class MultiActorEnvironment implements IMultiActorEnvironment {
|
|
64
|
+
+_actorEnvironments: Map<ActorIdentifier, IActorEnvironment>;
|
|
65
|
+
+_createNetworkForActor: (actorIdentifier: ActorIdentifier) => INetwork;
|
|
66
|
+
+_getDataID: GetDataID;
|
|
67
|
+
+_handlerProvider: HandlerProvider;
|
|
68
|
+
+_logFn: LogFunction;
|
|
69
|
+
+_operationExecutions: Map<string, ActiveState>;
|
|
70
|
+
+_requiredFieldLogger: RequiredFieldLogger;
|
|
71
|
+
+_treatMissingFieldsAsNull: boolean;
|
|
72
|
+
|
|
73
|
+
constructor(config: MultiActorEnvironmentConfig) {
|
|
74
|
+
this._actorEnvironments = new Map();
|
|
75
|
+
this._createNetworkForActor = config.createNetworkForActor;
|
|
76
|
+
this._getDataID = config.getDataID ?? defaultGetDataID;
|
|
77
|
+
this._handlerProvider = config.handlerProvider
|
|
78
|
+
? config.handlerProvider
|
|
79
|
+
: RelayDefaultHandlerProvider;
|
|
80
|
+
this._logFn = config.logFn;
|
|
81
|
+
this._operationExecutions = new Map();
|
|
82
|
+
this._requiredFieldLogger = config.requiredFieldLogger;
|
|
83
|
+
this._treatMissingFieldsAsNull = config.treatMissingFieldsAsNull ?? false;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* This method will create an actor specfic environment. It will create a new instance
|
|
88
|
+
* and store it in the internal maps. If will return a memozied version
|
|
89
|
+
* of the environment if we already created one for actor.
|
|
90
|
+
*/
|
|
91
|
+
forActor(actorIdentifier: ActorIdentifier): IEnvironment & IActorEnvironment {
|
|
92
|
+
const environment = this._actorEnvironments.get(actorIdentifier);
|
|
93
|
+
if (environment == null) {
|
|
94
|
+
const newEnvironment = new ActorSpecificEnvironment({
|
|
95
|
+
actorIdentifier,
|
|
96
|
+
multiActorEnvironment: this,
|
|
97
|
+
logFn: this._logFn,
|
|
98
|
+
requiredFieldLogger: this._requiredFieldLogger,
|
|
99
|
+
store: new RelayModernStore(RelayRecordSource.create()),
|
|
100
|
+
network: this._createNetworkForActor(actorIdentifier),
|
|
101
|
+
});
|
|
102
|
+
this._actorEnvironments.set(actorIdentifier, newEnvironment);
|
|
103
|
+
return newEnvironment;
|
|
104
|
+
} else {
|
|
105
|
+
return environment;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
check(
|
|
110
|
+
actorIdentifier: ActorIdentifier,
|
|
111
|
+
operation: OperationDescriptor,
|
|
112
|
+
): OperationAvailability {
|
|
113
|
+
return todo('check');
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
subscribe(
|
|
117
|
+
actorIdentifier: ActorIdentifier,
|
|
118
|
+
snapshot: Snapshot,
|
|
119
|
+
callback: (snapshot: Snapshot) => void,
|
|
120
|
+
): Disposable {
|
|
121
|
+
return todo('subscribe');
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
retain(
|
|
125
|
+
actorIdentifier: ActorIdentifier,
|
|
126
|
+
operation: OperationDescriptor,
|
|
127
|
+
): Disposable {
|
|
128
|
+
return todo('retain');
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
applyUpdate(
|
|
132
|
+
actorIdentifier: ActorIdentifier,
|
|
133
|
+
optimisticUpdate: OptimisticUpdateFunction,
|
|
134
|
+
): Disposable {
|
|
135
|
+
return todo('applyUpdate');
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
applyMutation(
|
|
139
|
+
actorIdentifier: ActorIdentifier,
|
|
140
|
+
optimisticConfig: OptimisticResponseConfig,
|
|
141
|
+
): Disposable {
|
|
142
|
+
return todo('applyMutation');
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
commitUpdate(actorIdentifier: ActorIdentifier, updater: StoreUpdater): void {
|
|
146
|
+
return todo('commitUpdate');
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
commitPayload(
|
|
150
|
+
actorIdentifier: ActorIdentifier,
|
|
151
|
+
operationDescriptor: OperationDescriptor,
|
|
152
|
+
payload: PayloadData,
|
|
153
|
+
): void {
|
|
154
|
+
return todo('commitPayload');
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
lookup(
|
|
158
|
+
actorIdentifier: ActorIdentifier,
|
|
159
|
+
selector: SingularReaderSelector,
|
|
160
|
+
): Snapshot {
|
|
161
|
+
return todo('lookup');
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
execute(
|
|
165
|
+
actorIdentifier: ActorIdentifier,
|
|
166
|
+
config: {
|
|
167
|
+
operation: OperationDescriptor,
|
|
168
|
+
updater?: ?SelectorStoreUpdater,
|
|
169
|
+
},
|
|
170
|
+
): RelayObservable<GraphQLResponse> {
|
|
171
|
+
const {operation, updater} = config;
|
|
172
|
+
return RelayObservable.create(sink => {
|
|
173
|
+
const actorEnvironemnt = this.forActor(actorIdentifier);
|
|
174
|
+
const source = actorEnvironemnt
|
|
175
|
+
.getNetwork()
|
|
176
|
+
.execute(
|
|
177
|
+
operation.request.node.params,
|
|
178
|
+
operation.request.variables,
|
|
179
|
+
operation.request.cacheConfig || {},
|
|
180
|
+
null,
|
|
181
|
+
);
|
|
182
|
+
const executor = OperationExecutor.execute({
|
|
183
|
+
operation,
|
|
184
|
+
operationExecutions: this._operationExecutions,
|
|
185
|
+
operationLoader: null,
|
|
186
|
+
optimisticConfig: null,
|
|
187
|
+
publishQueue: new RelayPublishQueue(
|
|
188
|
+
actorEnvironemnt.getStore(),
|
|
189
|
+
this._handlerProvider,
|
|
190
|
+
this._getDataID,
|
|
191
|
+
),
|
|
192
|
+
reactFlightPayloadDeserializer: null,
|
|
193
|
+
reactFlightServerErrorHandler: null,
|
|
194
|
+
scheduler: null,
|
|
195
|
+
sink,
|
|
196
|
+
source,
|
|
197
|
+
store: actorEnvironemnt.getStore(),
|
|
198
|
+
updater,
|
|
199
|
+
operationTracker: actorEnvironemnt.getOperationTracker(),
|
|
200
|
+
getDataID: this._getDataID,
|
|
201
|
+
treatMissingFieldsAsNull: this._treatMissingFieldsAsNull,
|
|
202
|
+
shouldProcessClientComponents: false,
|
|
203
|
+
});
|
|
204
|
+
return () => executor.cancel();
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
executeMutation(
|
|
209
|
+
actorIdentifier: ActorIdentifier,
|
|
210
|
+
config: ExecuteMutationConfig,
|
|
211
|
+
): RelayObservable<GraphQLResponse> {
|
|
212
|
+
return todo('executeMutation');
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
executeWithSource(
|
|
216
|
+
actorIdentifier: ActorIdentifier,
|
|
217
|
+
config: {
|
|
218
|
+
operation: OperationDescriptor,
|
|
219
|
+
source: RelayObservable<GraphQLResponse>,
|
|
220
|
+
},
|
|
221
|
+
): RelayObservable<GraphQLResponse> {
|
|
222
|
+
return todo('executeWithSource');
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
isRequestActive(
|
|
226
|
+
actorIdentifier: ActorIdentifier,
|
|
227
|
+
requestIdentifier: string,
|
|
228
|
+
): boolean {
|
|
229
|
+
return todo('isRequestActive');
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
module.exports = MultiActorEnvironment;
|
|
@@ -0,0 +1,196 @@
|
|
|
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 {PayloadData, GraphQLResponse} from '../network/RelayNetworkTypes';
|
|
15
|
+
import type RelayObservable from '../network/RelayObservable';
|
|
16
|
+
import type {
|
|
17
|
+
OperationAvailability,
|
|
18
|
+
OperationDescriptor,
|
|
19
|
+
OptimisticResponseConfig,
|
|
20
|
+
OptimisticUpdateFunction,
|
|
21
|
+
SelectorStoreUpdater,
|
|
22
|
+
SingularReaderSelector,
|
|
23
|
+
Snapshot,
|
|
24
|
+
StoreUpdater,
|
|
25
|
+
IEnvironment,
|
|
26
|
+
ExecuteMutationConfig,
|
|
27
|
+
} from '../store/RelayStoreTypes';
|
|
28
|
+
import type {Disposable} from '../util/RelayRuntimeTypes';
|
|
29
|
+
import type {ActorIdentifier} from './ActorIdentifier';
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Interface of actor specific sub-environment
|
|
33
|
+
*/
|
|
34
|
+
export interface IActorEnvironment extends IEnvironment {
|
|
35
|
+
/**
|
|
36
|
+
* Reference to the main MultiActorEnvironment that handles
|
|
37
|
+
* the network execution/and responsible for network integration
|
|
38
|
+
*/
|
|
39
|
+
+multiActorEnvironment: IMultiActorEnvironment;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Identifier of the actor for the current active environment
|
|
43
|
+
*/
|
|
44
|
+
+actorIdentifier: ActorIdentifier;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Interface for the main (or parent) multi-actor environment that contains
|
|
49
|
+
* the map of individual actor-specific sub-environments. These sub-environments
|
|
50
|
+
* implement the Relay IEnvironment interface.
|
|
51
|
+
*/
|
|
52
|
+
export interface IMultiActorEnvironment {
|
|
53
|
+
/**
|
|
54
|
+
* A factory of actor-specific environments.
|
|
55
|
+
*/
|
|
56
|
+
forActor(actorIdentifier: ActorIdentifier): IActorEnvironment;
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Determine if the operation can be resolved with data in the store (i.e. no
|
|
60
|
+
* fields are missing).
|
|
61
|
+
*
|
|
62
|
+
* Note that this operation effectively "executes" the selector against the
|
|
63
|
+
* cache and therefore takes time proportional to the size/complexity of the
|
|
64
|
+
* selector.
|
|
65
|
+
*/
|
|
66
|
+
check(
|
|
67
|
+
actorIdentifier: ActorIdentifier,
|
|
68
|
+
operation: OperationDescriptor,
|
|
69
|
+
): OperationAvailability;
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Subscribe to changes to the results of a selector. The callback is called
|
|
73
|
+
* when data has been committed to the store that would cause the results of
|
|
74
|
+
* the snapshot's selector to change.
|
|
75
|
+
*/
|
|
76
|
+
subscribe(
|
|
77
|
+
actorIdentifier: ActorIdentifier,
|
|
78
|
+
snapshot: Snapshot,
|
|
79
|
+
callback: (snapshot: Snapshot) => void,
|
|
80
|
+
): Disposable;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Ensure that all the records necessary to fulfill the given selector are
|
|
84
|
+
* retained in-memory. The records will not be eligible for garbage collection
|
|
85
|
+
* until the returned reference is disposed.
|
|
86
|
+
*/
|
|
87
|
+
retain(
|
|
88
|
+
actorIdentifier: ActorIdentifier,
|
|
89
|
+
operation: OperationDescriptor,
|
|
90
|
+
): Disposable;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Apply an optimistic update to the environment. The mutation can be reverted
|
|
94
|
+
* by calling `dispose()` on the returned value.
|
|
95
|
+
*/
|
|
96
|
+
applyUpdate(
|
|
97
|
+
actorIdentifier: ActorIdentifier,
|
|
98
|
+
optimisticUpdate: OptimisticUpdateFunction,
|
|
99
|
+
): Disposable;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Apply an optimistic mutation response and/or updater. The mutation can be
|
|
103
|
+
* reverted by calling `dispose()` on the returned value.
|
|
104
|
+
*/
|
|
105
|
+
applyMutation(
|
|
106
|
+
actorIdentifier: ActorIdentifier,
|
|
107
|
+
optimisticConfig: OptimisticResponseConfig,
|
|
108
|
+
): Disposable;
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Commit an updater to the environment. This mutation cannot be reverted and
|
|
112
|
+
* should therefore not be used for optimistic updates. This is mainly
|
|
113
|
+
* intended for updating fields from client schema extensions.
|
|
114
|
+
*/
|
|
115
|
+
commitUpdate(actorIdentifier: ActorIdentifier, updater: StoreUpdater): void;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Commit a payload to the environment using the given operation selector.
|
|
119
|
+
*/
|
|
120
|
+
commitPayload(
|
|
121
|
+
actorIdentifier: ActorIdentifier,
|
|
122
|
+
operationDescriptor: OperationDescriptor,
|
|
123
|
+
payload: PayloadData,
|
|
124
|
+
): void;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Read the results of a selector from in-memory records in the store.
|
|
128
|
+
*/
|
|
129
|
+
lookup(
|
|
130
|
+
actorIdentifier: ActorIdentifier,
|
|
131
|
+
selector: SingularReaderSelector,
|
|
132
|
+
): Snapshot;
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Send a query to the server with Observer semantics: one or more
|
|
136
|
+
* responses may be returned (via `next`) over time followed by either
|
|
137
|
+
* the request completing (`completed`) or an error (`error`).
|
|
138
|
+
*
|
|
139
|
+
* Networks/servers that support subscriptions may choose to hold the
|
|
140
|
+
* subscription open indefinitely such that `complete` is not called.
|
|
141
|
+
*
|
|
142
|
+
* Note: Observables are lazy, so calling this method will do nothing until
|
|
143
|
+
* the result is subscribed to: environment.execute({...}).subscribe({...}).
|
|
144
|
+
*/
|
|
145
|
+
execute(
|
|
146
|
+
actorIdentifier: ActorIdentifier,
|
|
147
|
+
config: {
|
|
148
|
+
operation: OperationDescriptor,
|
|
149
|
+
updater?: ?SelectorStoreUpdater,
|
|
150
|
+
},
|
|
151
|
+
): RelayObservable<GraphQLResponse>;
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Returns an Observable of GraphQLResponse resulting from executing the
|
|
155
|
+
* provided Mutation operation, the result of which is then normalized and
|
|
156
|
+
* committed to the publish queue along with an optional optimistic response
|
|
157
|
+
* or updater.
|
|
158
|
+
*
|
|
159
|
+
* Note: Observables are lazy, so calling this method will do nothing until
|
|
160
|
+
* the result is subscribed to:
|
|
161
|
+
* environment.executeMutation({...}).subscribe({...}).
|
|
162
|
+
*/
|
|
163
|
+
executeMutation(
|
|
164
|
+
actorIdentifier: ActorIdentifier,
|
|
165
|
+
config: ExecuteMutationConfig,
|
|
166
|
+
): RelayObservable<GraphQLResponse>;
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* Returns an Observable of GraphQLResponse resulting from executing the
|
|
170
|
+
* provided Query or Subscription operation responses, the result of which is
|
|
171
|
+
* then normalized and committed to the publish queue.
|
|
172
|
+
*
|
|
173
|
+
* Note: Observables are lazy, so calling this method will do nothing until
|
|
174
|
+
* the result is subscribed to:
|
|
175
|
+
* environment.executeWithSource({...}).subscribe({...}).
|
|
176
|
+
*/
|
|
177
|
+
executeWithSource(
|
|
178
|
+
actorIdentifier: ActorIdentifier,
|
|
179
|
+
{
|
|
180
|
+
operation: OperationDescriptor,
|
|
181
|
+
source: RelayObservable<GraphQLResponse>,
|
|
182
|
+
},
|
|
183
|
+
): RelayObservable<GraphQLResponse>;
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Returns true if a request is currently "active", meaning it's currently
|
|
187
|
+
* actively receiving payloads or downloading modules, and has not received
|
|
188
|
+
* a final payload yet. Note that a request might still be pending (or "in flight")
|
|
189
|
+
* without actively receiving payload, for example a live query or an
|
|
190
|
+
* active GraphQL subscription
|
|
191
|
+
*/
|
|
192
|
+
isRequestActive(
|
|
193
|
+
actorIdentifier: ActorIdentifier,
|
|
194
|
+
requestIdentifier: string,
|
|
195
|
+
): boolean;
|
|
196
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
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 MultiActorEnvironment = require('./MultiActorEnvironment');
|
|
15
|
+
|
|
16
|
+
export type {ActorIdentifier} from './ActorIdentifier';
|
|
17
|
+
export type {
|
|
18
|
+
IActorEnvironment,
|
|
19
|
+
IMultiActorEnvironment,
|
|
20
|
+
} from './MultiActorEnvironmentTypes';
|
|
21
|
+
|
|
22
|
+
module.exports = {
|
|
23
|
+
MultiActorEnvironment,
|
|
24
|
+
};
|
|
@@ -23,6 +23,7 @@ const {ROOT_ID, ROOT_TYPE} = require('../store/RelayStoreUtils');
|
|
|
23
23
|
import type {HandlerProvider} from '../handlers/RelayDefaultHandlerProvider';
|
|
24
24
|
import type {GetDataID} from '../store/RelayResponseNormalizer';
|
|
25
25
|
import type {
|
|
26
|
+
DataIDSet,
|
|
26
27
|
HandleFieldPayload,
|
|
27
28
|
RecordSource,
|
|
28
29
|
RecordProxy,
|
|
@@ -42,7 +43,7 @@ class RelayRecordSourceProxy implements RecordSourceProxy {
|
|
|
42
43
|
_proxies: {[dataID: DataID]: ?RelayRecordProxy, ...};
|
|
43
44
|
_getDataID: GetDataID;
|
|
44
45
|
_invalidatedStore: boolean;
|
|
45
|
-
_idsMarkedForInvalidation:
|
|
46
|
+
_idsMarkedForInvalidation: DataIDSet;
|
|
46
47
|
|
|
47
48
|
constructor(
|
|
48
49
|
mutator: RelayRecordSourceMutator,
|
|
@@ -156,7 +157,7 @@ class RelayRecordSourceProxy implements RecordSourceProxy {
|
|
|
156
157
|
this._idsMarkedForInvalidation.add(dataID);
|
|
157
158
|
}
|
|
158
159
|
|
|
159
|
-
getIDsMarkedForInvalidation():
|
|
160
|
+
getIDsMarkedForInvalidation(): DataIDSet {
|
|
160
161
|
return this._idsMarkedForInvalidation;
|
|
161
162
|
}
|
|
162
163
|
}
|
|
@@ -32,6 +32,23 @@ const warning = require('warning');
|
|
|
32
32
|
|
|
33
33
|
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
34
34
|
|
|
35
|
+
const {
|
|
36
|
+
CONDITION,
|
|
37
|
+
CLIENT_COMPONENT,
|
|
38
|
+
CLIENT_EXTENSION,
|
|
39
|
+
DEFER,
|
|
40
|
+
FLIGHT_FIELD,
|
|
41
|
+
FRAGMENT_SPREAD,
|
|
42
|
+
INLINE_FRAGMENT,
|
|
43
|
+
LINKED_FIELD,
|
|
44
|
+
LINKED_HANDLE,
|
|
45
|
+
MODULE_IMPORT,
|
|
46
|
+
SCALAR_FIELD,
|
|
47
|
+
SCALAR_HANDLE,
|
|
48
|
+
STREAM,
|
|
49
|
+
TYPE_DISCRIMINATOR,
|
|
50
|
+
} = require('../util/RelayConcreteNode');
|
|
51
|
+
|
|
35
52
|
let validateMutation = () => {};
|
|
36
53
|
if (__DEV__) {
|
|
37
54
|
const addFieldToDiff = (path: string, diff: Object, isScalar) => {
|
|
@@ -96,14 +113,22 @@ if (__DEV__) {
|
|
|
96
113
|
context: ValidationContext,
|
|
97
114
|
) => {
|
|
98
115
|
switch (selection.kind) {
|
|
99
|
-
case
|
|
116
|
+
case CONDITION:
|
|
100
117
|
validateSelections(optimisticResponse, selection.selections, context);
|
|
101
118
|
return;
|
|
102
|
-
case
|
|
103
|
-
case
|
|
104
|
-
|
|
119
|
+
case CLIENT_COMPONENT:
|
|
120
|
+
case FRAGMENT_SPREAD:
|
|
121
|
+
validateSelections(
|
|
122
|
+
optimisticResponse,
|
|
123
|
+
selection.fragment.selections,
|
|
124
|
+
context,
|
|
125
|
+
);
|
|
126
|
+
return;
|
|
127
|
+
case SCALAR_FIELD:
|
|
128
|
+
case LINKED_FIELD:
|
|
129
|
+
case FLIGHT_FIELD:
|
|
105
130
|
return validateField(optimisticResponse, selection, context);
|
|
106
|
-
case
|
|
131
|
+
case INLINE_FRAGMENT:
|
|
107
132
|
const type = selection.type;
|
|
108
133
|
const isConcreteType = selection.abstractKey == null;
|
|
109
134
|
selection.selections.forEach(subselection => {
|
|
@@ -113,18 +138,18 @@ if (__DEV__) {
|
|
|
113
138
|
validateSelection(optimisticResponse, subselection, context);
|
|
114
139
|
});
|
|
115
140
|
return;
|
|
116
|
-
case
|
|
141
|
+
case CLIENT_EXTENSION:
|
|
117
142
|
selection.selections.forEach(subselection => {
|
|
118
143
|
validateSelection(optimisticResponse, subselection, context);
|
|
119
144
|
});
|
|
120
145
|
return;
|
|
121
|
-
case
|
|
146
|
+
case MODULE_IMPORT:
|
|
122
147
|
return validateModuleImport(context);
|
|
123
|
-
case
|
|
124
|
-
case
|
|
125
|
-
case
|
|
126
|
-
case
|
|
127
|
-
case
|
|
148
|
+
case LINKED_HANDLE:
|
|
149
|
+
case SCALAR_HANDLE:
|
|
150
|
+
case DEFER:
|
|
151
|
+
case STREAM:
|
|
152
|
+
case TYPE_DISCRIMINATOR: {
|
|
128
153
|
// TODO(T35864292) - Add missing validations for these types
|
|
129
154
|
return;
|
|
130
155
|
}
|
|
@@ -147,12 +172,12 @@ if (__DEV__) {
|
|
|
147
172
|
const path = `${context.path}.${fieldName}`;
|
|
148
173
|
context.visitedPaths.add(path);
|
|
149
174
|
switch (field.kind) {
|
|
150
|
-
case
|
|
175
|
+
case SCALAR_FIELD:
|
|
151
176
|
if (hasOwnProperty.call(optimisticResponse, fieldName) === false) {
|
|
152
177
|
addFieldToDiff(path, context.missingDiff, true);
|
|
153
178
|
}
|
|
154
179
|
return;
|
|
155
|
-
case
|
|
180
|
+
case LINKED_FIELD:
|
|
156
181
|
const selections = field.selections;
|
|
157
182
|
if (
|
|
158
183
|
optimisticResponse[fieldName] === null ||
|
|
@@ -188,7 +213,7 @@ if (__DEV__) {
|
|
|
188
213
|
return;
|
|
189
214
|
}
|
|
190
215
|
}
|
|
191
|
-
case
|
|
216
|
+
case FLIGHT_FIELD:
|
|
192
217
|
if (
|
|
193
218
|
optimisticResponse[fieldName] === null ||
|
|
194
219
|
(hasOwnProperty.call(optimisticResponse, fieldName) &&
|
|
@@ -20,14 +20,15 @@ import type RelayObservable, {ObservableFromValue} from './RelayObservable';
|
|
|
20
20
|
* An interface for fetching the data for one or more (possibly interdependent)
|
|
21
21
|
* queries.
|
|
22
22
|
*/
|
|
23
|
-
export
|
|
24
|
-
execute: ExecuteFunction
|
|
25
|
-
|
|
23
|
+
export interface INetwork {
|
|
24
|
+
+execute: ExecuteFunction;
|
|
25
|
+
}
|
|
26
|
+
|
|
26
27
|
export type LogRequestInfoFunction = mixed => void;
|
|
27
28
|
|
|
28
|
-
export type PayloadData = {[key: string]: mixed
|
|
29
|
+
export type PayloadData = interface {[key: string]: mixed};
|
|
29
30
|
|
|
30
|
-
export type PayloadError = {
|
|
31
|
+
export type PayloadError = interface {
|
|
31
32
|
message: string,
|
|
32
33
|
locations?: Array<{
|
|
33
34
|
line: number,
|
|
@@ -36,14 +37,13 @@ export type PayloadError = {
|
|
|
36
37
|
}>,
|
|
37
38
|
// Not officially part of the spec, but used at Facebook
|
|
38
39
|
severity?: 'CRITICAL' | 'ERROR' | 'WARNING',
|
|
39
|
-
...
|
|
40
40
|
};
|
|
41
41
|
|
|
42
42
|
export type PayloadExtensions = {[key: string]: mixed, ...};
|
|
43
43
|
|
|
44
44
|
/**
|
|
45
45
|
* The shape of a GraphQL response as dictated by the
|
|
46
|
-
* [spec](https://graphql.
|
|
46
|
+
* [spec](https://spec.graphql.org/June2018/#sec-Response-Format).
|
|
47
47
|
*/
|
|
48
48
|
export type GraphQLResponseWithData = {|
|
|
49
49
|
+data: PayloadData,
|
|
@@ -120,7 +120,7 @@ export type SubscribeFunction = (
|
|
|
120
120
|
) => RelayObservable<GraphQLResponse>;
|
|
121
121
|
|
|
122
122
|
export type Uploadable = File | Blob;
|
|
123
|
-
export type UploadableMap = {[key: string]: Uploadable
|
|
123
|
+
export type UploadableMap = interface {[key: string]: Uploadable};
|
|
124
124
|
|
|
125
125
|
/**
|
|
126
126
|
* React Flight tree created on the server.
|
|
@@ -132,14 +132,34 @@ export type ReactFlightPayloadQuery = {|
|
|
|
132
132
|
+response: GraphQLSingularResponse,
|
|
133
133
|
+variables: Variables,
|
|
134
134
|
|};
|
|
135
|
+
export type ReactFlightPayloadFragment = {|
|
|
136
|
+
+__id: string,
|
|
137
|
+
+__typename: string,
|
|
138
|
+
+module: mixed,
|
|
139
|
+
+response: GraphQLSingularResponse,
|
|
140
|
+
+variables: Variables,
|
|
141
|
+
|};
|
|
142
|
+
export type ReactFlightServerError = {
|
|
143
|
+
+message: string,
|
|
144
|
+
+stack: string,
|
|
145
|
+
...
|
|
146
|
+
};
|
|
135
147
|
/**
|
|
136
148
|
* Data that is returned by a Flight compliant GraphQL server.
|
|
137
149
|
*
|
|
138
|
-
* -
|
|
139
|
-
*
|
|
150
|
+
* - status: string representing status of the server response.
|
|
151
|
+
* - tree: React Server Components written into a row protocol that can be later
|
|
152
|
+
* read on the client. If this is null, this indicates that no rows were
|
|
153
|
+
* were written on the server.
|
|
140
154
|
* - queries: an array of queries that the server preloaded for the client.
|
|
155
|
+
* - errors: an array of errors that were encountered while rendering the
|
|
156
|
+
* Server Component.
|
|
157
|
+
* - fragments: an array of fragments that the server preloaded for the client.
|
|
141
158
|
*/
|
|
142
159
|
export type ReactFlightPayloadData = {|
|
|
143
|
-
+
|
|
160
|
+
+status: string,
|
|
161
|
+
+tree: ?Array<ReactFlightServerTree>,
|
|
144
162
|
+queries: Array<ReactFlightPayloadQuery>,
|
|
163
|
+
+errors: Array<ReactFlightServerError>,
|
|
164
|
+
+fragments: Array<ReactFlightPayloadFragment>,
|
|
145
165
|
|};
|