-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
MultiActorEnvironmentTypes.js
261 lines (236 loc) · 8.06 KB
/
MultiActorEnvironmentTypes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @emails oncall+relay
* @flow strict-local
* @format
*/
'use strict';
import type {GraphQLResponse, PayloadData} from '../network/RelayNetworkTypes';
import type RelayObservable from '../network/RelayObservable';
import type RelayPublishQueue from '../store/RelayPublishQueue';
import type {
ExecuteMutationConfig,
IEnvironment,
MutationParameters,
OperationAvailability,
OperationDescriptor,
OptimisticResponseConfig,
OptimisticUpdateFunction,
RecordSourceProxy,
SelectorStoreUpdater,
SingularReaderSelector,
Snapshot,
StoreUpdater,
} from '../store/RelayStoreTypes';
import type {Disposable} from '../util/RelayRuntimeTypes';
import type {ActorIdentifier} from './ActorIdentifier';
export type MultiActorStoreUpdater = (
actorIdentifier: ActorIdentifier,
environment: IActorEnvironment,
store: RecordSourceProxy,
) => void;
/**
* Interface of actor specific sub-environment
*/
export interface IActorEnvironment extends IEnvironment {
/**
* Reference to the main MultiActorEnvironment that handles
* the network execution/and responsible for network integration
*/
+multiActorEnvironment: IMultiActorEnvironment;
/**
* Identifier of the actor for the current active environment
*/
+actorIdentifier: ActorIdentifier;
/**
* TODO: this needs to move the the MultiActorEnvironment with different API.
*/
getPublishQueue(): RelayPublishQueue;
/**
* Optional. A human-readable identifier of the environment.
* This value should be visible in the dev tools.
*/
+configName: ?string;
}
/**
* Interface for the main (or parent) multi-actor environment that contains
* the map of individual actor-specific sub-environments. These sub-environments
* implement the Relay IEnvironment interface.
*/
export interface IMultiActorEnvironment {
/**
* A factory of actor-specific environments.
*/
forActor(actorIdentifier: ActorIdentifier): IActorEnvironment;
/**
* Determine if the operation can be resolved with data in the store (i.e. no
* fields are missing).
*
* Note that this operation effectively "executes" the selector against the
* cache and therefore takes time proportional to the size/complexity of the
* selector.
*/
check(
actorEnvironment: IActorEnvironment,
operation: OperationDescriptor,
): OperationAvailability;
/**
* Subscribe to changes to the results of a selector. The callback is called
* when data has been committed to the store that would cause the results of
* the snapshot's selector to change.
*/
subscribe(
actorEnvironment: IActorEnvironment,
snapshot: Snapshot,
callback: (snapshot: Snapshot) => void,
): Disposable;
/**
* Ensure that all the records necessary to fulfill the given selector are
* retained in-memory. The records will not be eligible for garbage collection
* until the returned reference is disposed.
*/
retain(
actorEnvironment: IActorEnvironment,
operation: OperationDescriptor,
): Disposable;
/**
* Apply an optimistic update to the environment. The mutation can be reverted
* by calling `dispose()` on the returned value.
*/
applyUpdate(
actorEnvironment: IActorEnvironment,
optimisticUpdate: OptimisticUpdateFunction,
): Disposable;
/**
* Revert updates for the `update` function.
*/
revertUpdate(
actorEnvironment: IActorEnvironment,
update: OptimisticUpdateFunction,
): void;
/**
* Revert updates for the `update` function, and apply the `replacement` update.
*/
replaceUpdate(
actorEnvironment: IActorEnvironment,
update: OptimisticUpdateFunction,
replacement: OptimisticUpdateFunction,
): void;
/**
* Apply an optimistic mutation response and/or updater. The mutation can be
* reverted by calling `dispose()` on the returned value.
*/
applyMutation<TMutation: MutationParameters>(
actorEnvironment: IActorEnvironment,
optimisticConfig: OptimisticResponseConfig<TMutation>,
): Disposable;
/**
* Commit an updater to the environment. This mutation cannot be reverted and
* should therefore not be used for optimistic updates. This is mainly
* intended for updating fields from client schema extensions.
*/
commitUpdate(
actorEnvironment: IActorEnvironment,
updater: StoreUpdater,
): void;
/**
* Commit store updates for each actor-specific environment known to MultiActorEnvironment
*/
commitMultiActorUpdate(updater: MultiActorStoreUpdater): void;
/**
* Commit a payload to the environment using the given operation selector.
*/
commitPayload(
actorEnvironment: IActorEnvironment,
operationDescriptor: OperationDescriptor,
payload: PayloadData,
): void;
/**
* Read the results of a selector from in-memory records in the store.
*/
lookup(
actorEnvironment: IActorEnvironment,
selector: SingularReaderSelector,
): Snapshot;
/**
* Send a query to the server with Observer semantics: one or more
* responses may be returned (via `next`) over time followed by either
* the request completing (`completed`) or an error (`error`).
*
* Note: Observables are lazy, so calling this method will do nothing until
* the result is subscribed to: environment.execute({...}).subscribe({...}).
*/
execute(
actorEnvironment: IActorEnvironment,
config: {
operation: OperationDescriptor,
},
): RelayObservable<GraphQLResponse>;
/**
* Send a subscription to the server with Observer semantics: one or more
* responses may be returned (via `next`) over time followed by either
* the request completing (`completed`) or an error (`error`).
*
* Networks/servers that support subscriptions may choose to hold the
* subscription open indefinitely such that `complete` is not called.
*
* Note: Observables are lazy, so calling this method will do nothing until
* the result is subscribed to: environment.executeSubscription({...}).subscribe({...}).
*/
executeSubscription<TMutation: MutationParameters>(
actorEnvironment: IActorEnvironment,
config: {
operation: OperationDescriptor,
updater?: ?SelectorStoreUpdater<$ElementType<TMutation, 'response'>>,
},
): RelayObservable<GraphQLResponse>;
/**
* Returns an Observable of GraphQLResponse resulting from executing the
* provided Mutation operation, the result of which is then normalized and
* committed to the publish queue along with an optional optimistic response
* or updater.
*
* Note: Observables are lazy, so calling this method will do nothing until
* the result is subscribed to:
* environment.executeMutation({...}).subscribe({...}).
*/
executeMutation<TMutation: MutationParameters>(
actorEnvironment: IActorEnvironment,
config: ExecuteMutationConfig<TMutation>,
): RelayObservable<GraphQLResponse>;
/**
* Returns an Observable of GraphQLResponse resulting from executing the
* provided Query or Subscription operation responses, the result of which is
* then normalized and committed to the publish queue.
*
* Note: Observables are lazy, so calling this method will do nothing until
* the result is subscribed to:
* environment.executeWithSource({...}).subscribe({...}).
*/
executeWithSource(
actorEnvironment: IActorEnvironment,
{
operation: OperationDescriptor,
source: RelayObservable<GraphQLResponse>,
},
): RelayObservable<GraphQLResponse>;
/**
* Returns true if a request is currently "active", meaning it's currently
* actively receiving payloads or downloading modules, and has not received
* a final payload yet. Note that a request might still be pending (or "in flight")
* without actively receiving payload, for example a live query or an
* active GraphQL subscription
*/
isRequestActive(
actorEnvironment: IActorEnvironment,
requestIdentifier: string,
): boolean;
/**
* Returns `true` if execute in the server environment
*/
isServer(): boolean;
}