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
|
@@ -0,0 +1,261 @@
|
|
|
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 {GraphQLResponse, PayloadData} from '../network/RelayNetworkTypes';
|
|
15
|
+
import type RelayObservable from '../network/RelayObservable';
|
|
16
|
+
import type RelayPublishQueue from '../store/RelayPublishQueue';
|
|
17
|
+
import type {
|
|
18
|
+
ExecuteMutationConfig,
|
|
19
|
+
IEnvironment,
|
|
20
|
+
MutationParameters,
|
|
21
|
+
OperationAvailability,
|
|
22
|
+
OperationDescriptor,
|
|
23
|
+
OptimisticResponseConfig,
|
|
24
|
+
OptimisticUpdateFunction,
|
|
25
|
+
RecordSourceProxy,
|
|
26
|
+
SelectorStoreUpdater,
|
|
27
|
+
SingularReaderSelector,
|
|
28
|
+
Snapshot,
|
|
29
|
+
StoreUpdater,
|
|
30
|
+
} from '../store/RelayStoreTypes';
|
|
31
|
+
import type {Disposable} from '../util/RelayRuntimeTypes';
|
|
32
|
+
import type {ActorIdentifier} from './ActorIdentifier';
|
|
33
|
+
|
|
34
|
+
export type MultiActorStoreUpdater = (
|
|
35
|
+
actorIdentifier: ActorIdentifier,
|
|
36
|
+
environment: IActorEnvironment,
|
|
37
|
+
store: RecordSourceProxy,
|
|
38
|
+
) => void;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Interface of actor specific sub-environment
|
|
42
|
+
*/
|
|
43
|
+
export interface IActorEnvironment extends IEnvironment {
|
|
44
|
+
/**
|
|
45
|
+
* Reference to the main MultiActorEnvironment that handles
|
|
46
|
+
* the network execution/and responsible for network integration
|
|
47
|
+
*/
|
|
48
|
+
+multiActorEnvironment: IMultiActorEnvironment;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Identifier of the actor for the current active environment
|
|
52
|
+
*/
|
|
53
|
+
+actorIdentifier: ActorIdentifier;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* TODO: this needs to move the the MultiActorEnvironment with different API.
|
|
57
|
+
*/
|
|
58
|
+
getPublishQueue(): RelayPublishQueue;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Optional. A human-readable identifier of the environment.
|
|
62
|
+
* This value should be visible in the dev tools.
|
|
63
|
+
*/
|
|
64
|
+
+configName: ?string;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Interface for the main (or parent) multi-actor environment that contains
|
|
69
|
+
* the map of individual actor-specific sub-environments. These sub-environments
|
|
70
|
+
* implement the Relay IEnvironment interface.
|
|
71
|
+
*/
|
|
72
|
+
export interface IMultiActorEnvironment {
|
|
73
|
+
/**
|
|
74
|
+
* A factory of actor-specific environments.
|
|
75
|
+
*/
|
|
76
|
+
forActor(actorIdentifier: ActorIdentifier): IActorEnvironment;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Determine if the operation can be resolved with data in the store (i.e. no
|
|
80
|
+
* fields are missing).
|
|
81
|
+
*
|
|
82
|
+
* Note that this operation effectively "executes" the selector against the
|
|
83
|
+
* cache and therefore takes time proportional to the size/complexity of the
|
|
84
|
+
* selector.
|
|
85
|
+
*/
|
|
86
|
+
check(
|
|
87
|
+
actorEnvironment: IActorEnvironment,
|
|
88
|
+
operation: OperationDescriptor,
|
|
89
|
+
): OperationAvailability;
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Subscribe to changes to the results of a selector. The callback is called
|
|
93
|
+
* when data has been committed to the store that would cause the results of
|
|
94
|
+
* the snapshot's selector to change.
|
|
95
|
+
*/
|
|
96
|
+
subscribe(
|
|
97
|
+
actorEnvironment: IActorEnvironment,
|
|
98
|
+
snapshot: Snapshot,
|
|
99
|
+
callback: (snapshot: Snapshot) => void,
|
|
100
|
+
): Disposable;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Ensure that all the records necessary to fulfill the given selector are
|
|
104
|
+
* retained in-memory. The records will not be eligible for garbage collection
|
|
105
|
+
* until the returned reference is disposed.
|
|
106
|
+
*/
|
|
107
|
+
retain(
|
|
108
|
+
actorEnvironment: IActorEnvironment,
|
|
109
|
+
operation: OperationDescriptor,
|
|
110
|
+
): Disposable;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Apply an optimistic update to the environment. The mutation can be reverted
|
|
114
|
+
* by calling `dispose()` on the returned value.
|
|
115
|
+
*/
|
|
116
|
+
applyUpdate(
|
|
117
|
+
actorEnvironment: IActorEnvironment,
|
|
118
|
+
optimisticUpdate: OptimisticUpdateFunction,
|
|
119
|
+
): Disposable;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Revert updates for the `update` function.
|
|
123
|
+
*/
|
|
124
|
+
revertUpdate(
|
|
125
|
+
actorEnvironment: IActorEnvironment,
|
|
126
|
+
update: OptimisticUpdateFunction,
|
|
127
|
+
): void;
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Revert updates for the `update` function, and apply the `replacement` update.
|
|
131
|
+
*/
|
|
132
|
+
replaceUpdate(
|
|
133
|
+
actorEnvironment: IActorEnvironment,
|
|
134
|
+
update: OptimisticUpdateFunction,
|
|
135
|
+
replacement: OptimisticUpdateFunction,
|
|
136
|
+
): void;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Apply an optimistic mutation response and/or updater. The mutation can be
|
|
140
|
+
* reverted by calling `dispose()` on the returned value.
|
|
141
|
+
*/
|
|
142
|
+
applyMutation<TMutation: MutationParameters>(
|
|
143
|
+
actorEnvironment: IActorEnvironment,
|
|
144
|
+
optimisticConfig: OptimisticResponseConfig<TMutation>,
|
|
145
|
+
): Disposable;
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Commit an updater to the environment. This mutation cannot be reverted and
|
|
149
|
+
* should therefore not be used for optimistic updates. This is mainly
|
|
150
|
+
* intended for updating fields from client schema extensions.
|
|
151
|
+
*/
|
|
152
|
+
commitUpdate(
|
|
153
|
+
actorEnvironment: IActorEnvironment,
|
|
154
|
+
updater: StoreUpdater,
|
|
155
|
+
): void;
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Commit store updates for each actor-specific environment known to MultiActorEnvironment
|
|
159
|
+
*/
|
|
160
|
+
commitMultiActorUpdate(updater: MultiActorStoreUpdater): void;
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Commit a payload to the environment using the given operation selector.
|
|
164
|
+
*/
|
|
165
|
+
commitPayload(
|
|
166
|
+
actorEnvironment: IActorEnvironment,
|
|
167
|
+
operationDescriptor: OperationDescriptor,
|
|
168
|
+
payload: PayloadData,
|
|
169
|
+
): void;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Read the results of a selector from in-memory records in the store.
|
|
173
|
+
*/
|
|
174
|
+
lookup(
|
|
175
|
+
actorEnvironment: IActorEnvironment,
|
|
176
|
+
selector: SingularReaderSelector,
|
|
177
|
+
): Snapshot;
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Send a query to the server with Observer semantics: one or more
|
|
181
|
+
* responses may be returned (via `next`) over time followed by either
|
|
182
|
+
* the request completing (`completed`) or an error (`error`).
|
|
183
|
+
*
|
|
184
|
+
* Note: Observables are lazy, so calling this method will do nothing until
|
|
185
|
+
* the result is subscribed to: environment.execute({...}).subscribe({...}).
|
|
186
|
+
*/
|
|
187
|
+
execute(
|
|
188
|
+
actorEnvironment: IActorEnvironment,
|
|
189
|
+
config: {
|
|
190
|
+
operation: OperationDescriptor,
|
|
191
|
+
},
|
|
192
|
+
): RelayObservable<GraphQLResponse>;
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Send a subscription to the server with Observer semantics: one or more
|
|
196
|
+
* responses may be returned (via `next`) over time followed by either
|
|
197
|
+
* the request completing (`completed`) or an error (`error`).
|
|
198
|
+
*
|
|
199
|
+
* Networks/servers that support subscriptions may choose to hold the
|
|
200
|
+
* subscription open indefinitely such that `complete` is not called.
|
|
201
|
+
*
|
|
202
|
+
* Note: Observables are lazy, so calling this method will do nothing until
|
|
203
|
+
* the result is subscribed to: environment.executeSubscription({...}).subscribe({...}).
|
|
204
|
+
*/
|
|
205
|
+
executeSubscription<TMutation: MutationParameters>(
|
|
206
|
+
actorEnvironment: IActorEnvironment,
|
|
207
|
+
config: {
|
|
208
|
+
operation: OperationDescriptor,
|
|
209
|
+
updater?: ?SelectorStoreUpdater<TMutation['response']>,
|
|
210
|
+
},
|
|
211
|
+
): RelayObservable<GraphQLResponse>;
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Returns an Observable of GraphQLResponse resulting from executing the
|
|
215
|
+
* provided Mutation operation, the result of which is then normalized and
|
|
216
|
+
* committed to the publish queue along with an optional optimistic response
|
|
217
|
+
* or updater.
|
|
218
|
+
*
|
|
219
|
+
* Note: Observables are lazy, so calling this method will do nothing until
|
|
220
|
+
* the result is subscribed to:
|
|
221
|
+
* environment.executeMutation({...}).subscribe({...}).
|
|
222
|
+
*/
|
|
223
|
+
executeMutation<TMutation: MutationParameters>(
|
|
224
|
+
actorEnvironment: IActorEnvironment,
|
|
225
|
+
config: ExecuteMutationConfig<TMutation>,
|
|
226
|
+
): RelayObservable<GraphQLResponse>;
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Returns an Observable of GraphQLResponse resulting from executing the
|
|
230
|
+
* provided Query or Subscription operation responses, the result of which is
|
|
231
|
+
* then normalized and committed to the publish queue.
|
|
232
|
+
*
|
|
233
|
+
* Note: Observables are lazy, so calling this method will do nothing until
|
|
234
|
+
* the result is subscribed to:
|
|
235
|
+
* environment.executeWithSource({...}).subscribe({...}).
|
|
236
|
+
*/
|
|
237
|
+
executeWithSource(
|
|
238
|
+
actorEnvironment: IActorEnvironment,
|
|
239
|
+
{
|
|
240
|
+
operation: OperationDescriptor,
|
|
241
|
+
source: RelayObservable<GraphQLResponse>,
|
|
242
|
+
},
|
|
243
|
+
): RelayObservable<GraphQLResponse>;
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Returns true if a request is currently "active", meaning it's currently
|
|
247
|
+
* actively receiving payloads or downloading modules, and has not received
|
|
248
|
+
* a final payload yet. Note that a request might still be pending (or "in flight")
|
|
249
|
+
* without actively receiving payload, for example a live query or an
|
|
250
|
+
* active GraphQL subscription
|
|
251
|
+
*/
|
|
252
|
+
isRequestActive(
|
|
253
|
+
actorEnvironment: IActorEnvironment,
|
|
254
|
+
requestIdentifier: string,
|
|
255
|
+
): boolean;
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* Returns `true` if execute in the server environment
|
|
259
|
+
*/
|
|
260
|
+
isServer(): boolean;
|
|
261
|
+
}
|
|
@@ -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
|
+
* @emails oncall+relay
|
|
8
|
+
* @flow strict-local
|
|
9
|
+
* @format
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
const {getActorIdentifier} = require('./ActorIdentifier');
|
|
15
|
+
const MultiActorEnvironment = require('./MultiActorEnvironment');
|
|
16
|
+
|
|
17
|
+
export type {ActorIdentifier} from './ActorIdentifier';
|
|
18
|
+
export type {
|
|
19
|
+
IActorEnvironment,
|
|
20
|
+
IMultiActorEnvironment,
|
|
21
|
+
} from './MultiActorEnvironmentTypes';
|
|
22
|
+
|
|
23
|
+
module.exports = {
|
|
24
|
+
MultiActorEnvironment,
|
|
25
|
+
getActorIdentifier,
|
|
26
|
+
};
|
|
@@ -12,11 +12,8 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
const ConnectionHandler = require('../handlers/connection/ConnectionHandler');
|
|
16
|
-
|
|
17
|
-
const warning = require('warning');
|
|
18
|
-
|
|
19
15
|
import type {
|
|
16
|
+
MutationParameters,
|
|
20
17
|
RecordSourceSelectorProxy,
|
|
21
18
|
SelectorData,
|
|
22
19
|
SelectorStoreUpdater,
|
|
@@ -24,6 +21,9 @@ import type {
|
|
|
24
21
|
import type {ConcreteRequest} from '../util/RelayConcreteNode';
|
|
25
22
|
import type {Variables} from '../util/RelayRuntimeTypes';
|
|
26
23
|
|
|
24
|
+
const ConnectionHandler = require('../handlers/connection/ConnectionHandler');
|
|
25
|
+
const warning = require('warning');
|
|
26
|
+
|
|
27
27
|
const MutationTypes = Object.freeze({
|
|
28
28
|
RANGE_ADD: 'RANGE_ADD',
|
|
29
29
|
RANGE_DELETE: 'RANGE_DELETE',
|
|
@@ -39,7 +39,7 @@ export type RangeOperation = $Values<typeof RangeOperations>;
|
|
|
39
39
|
|
|
40
40
|
type RangeBehaviorsFunction = (connectionArgs: {
|
|
41
41
|
[name: string]: $FlowFixMe,
|
|
42
|
-
|
|
42
|
+
...
|
|
43
43
|
}) => RangeOperation;
|
|
44
44
|
type RangeBehaviorsObject = {[key: string]: RangeOperation, ...};
|
|
45
45
|
export type RangeBehaviors = RangeBehaviorsFunction | RangeBehaviorsObject;
|
|
@@ -84,18 +84,21 @@ export type DeclarativeMutationConfig =
|
|
|
84
84
|
| RangeDeleteConfig
|
|
85
85
|
| NodeDeleteConfig;
|
|
86
86
|
|
|
87
|
-
function convert(
|
|
87
|
+
function convert<TMutation: MutationParameters>(
|
|
88
88
|
configs: Array<DeclarativeMutationConfig>,
|
|
89
89
|
request: ConcreteRequest,
|
|
90
|
-
optimisticUpdater?: ?SelectorStoreUpdater
|
|
91
|
-
updater?: ?SelectorStoreUpdater
|
|
90
|
+
optimisticUpdater?: ?SelectorStoreUpdater<TMutation['response']>,
|
|
91
|
+
updater?: ?SelectorStoreUpdater<TMutation['response']>,
|
|
92
92
|
): {
|
|
93
|
-
optimisticUpdater: SelectorStoreUpdater
|
|
94
|
-
updater: SelectorStoreUpdater
|
|
93
|
+
optimisticUpdater: SelectorStoreUpdater<TMutation['response']>,
|
|
94
|
+
updater: SelectorStoreUpdater<TMutation['response']>,
|
|
95
95
|
...
|
|
96
96
|
} {
|
|
97
|
-
const configOptimisticUpdates
|
|
98
|
-
|
|
97
|
+
const configOptimisticUpdates: Array<
|
|
98
|
+
SelectorStoreUpdater<TMutation['response']>,
|
|
99
|
+
> = optimisticUpdater ? [optimisticUpdater] : [];
|
|
100
|
+
const configUpdates: Array<SelectorStoreUpdater<TMutation['response']>> =
|
|
101
|
+
updater ? [updater] : [];
|
|
99
102
|
configs.forEach(config => {
|
|
100
103
|
switch (config.type) {
|
|
101
104
|
case 'NODE_DELETE':
|
|
@@ -124,13 +127,16 @@ function convert(
|
|
|
124
127
|
return {
|
|
125
128
|
optimisticUpdater: (
|
|
126
129
|
store: RecordSourceSelectorProxy,
|
|
127
|
-
data: ?
|
|
130
|
+
data: ?TMutation['response'],
|
|
128
131
|
) => {
|
|
129
132
|
configOptimisticUpdates.forEach(eachOptimisticUpdater => {
|
|
130
133
|
eachOptimisticUpdater(store, data);
|
|
131
134
|
});
|
|
132
135
|
},
|
|
133
|
-
updater: (
|
|
136
|
+
updater: (
|
|
137
|
+
store: RecordSourceSelectorProxy,
|
|
138
|
+
data: ?TMutation['response'],
|
|
139
|
+
) => {
|
|
134
140
|
configUpdates.forEach(eachUpdater => {
|
|
135
141
|
eachUpdater(store, data);
|
|
136
142
|
});
|
|
@@ -141,13 +147,13 @@ function convert(
|
|
|
141
147
|
function nodeDelete(
|
|
142
148
|
config: NodeDeleteConfig,
|
|
143
149
|
request: ConcreteRequest,
|
|
144
|
-
): ?SelectorStoreUpdater {
|
|
150
|
+
): ?SelectorStoreUpdater<mixed> {
|
|
145
151
|
const {deletedIDFieldName} = config;
|
|
146
152
|
const rootField = getRootField(request);
|
|
147
153
|
if (!rootField) {
|
|
148
154
|
return null;
|
|
149
155
|
}
|
|
150
|
-
return (store: RecordSourceSelectorProxy, data: ?
|
|
156
|
+
return (store: RecordSourceSelectorProxy, data: ?mixed) => {
|
|
151
157
|
const payload = store.getRootField(rootField);
|
|
152
158
|
if (!payload) {
|
|
153
159
|
return;
|
|
@@ -165,7 +171,7 @@ function nodeDelete(
|
|
|
165
171
|
function rangeAdd(
|
|
166
172
|
config: RangeAddConfig,
|
|
167
173
|
request: ConcreteRequest,
|
|
168
|
-
): ?SelectorStoreUpdater {
|
|
174
|
+
): ?SelectorStoreUpdater<mixed> {
|
|
169
175
|
const {parentID, connectionInfo, edgeName} = config;
|
|
170
176
|
if (!parentID) {
|
|
171
177
|
warning(
|
|
@@ -179,7 +185,7 @@ function rangeAdd(
|
|
|
179
185
|
if (!connectionInfo || !rootField) {
|
|
180
186
|
return null;
|
|
181
187
|
}
|
|
182
|
-
return (store: RecordSourceSelectorProxy, data: ?
|
|
188
|
+
return (store: RecordSourceSelectorProxy, data: ?mixed) => {
|
|
183
189
|
const parent = store.get(parentID);
|
|
184
190
|
if (!parent) {
|
|
185
191
|
return;
|
|
@@ -233,13 +239,9 @@ function rangeAdd(
|
|
|
233
239
|
function rangeDelete(
|
|
234
240
|
config: RangeDeleteConfig,
|
|
235
241
|
request: ConcreteRequest,
|
|
236
|
-
): ?SelectorStoreUpdater {
|
|
237
|
-
const {
|
|
238
|
-
|
|
239
|
-
connectionKeys,
|
|
240
|
-
pathToConnection,
|
|
241
|
-
deletedIDFieldName,
|
|
242
|
-
} = config;
|
|
242
|
+
): ?SelectorStoreUpdater<mixed> {
|
|
243
|
+
const {parentID, connectionKeys, pathToConnection, deletedIDFieldName} =
|
|
244
|
+
config;
|
|
243
245
|
if (!parentID) {
|
|
244
246
|
warning(
|
|
245
247
|
false,
|
|
@@ -252,12 +254,16 @@ function rangeDelete(
|
|
|
252
254
|
if (!rootField) {
|
|
253
255
|
return null;
|
|
254
256
|
}
|
|
255
|
-
return (store: RecordSourceSelectorProxy, data: ?
|
|
257
|
+
return (store: RecordSourceSelectorProxy, data: ?mixed) => {
|
|
256
258
|
if (!data) {
|
|
257
259
|
return;
|
|
258
260
|
}
|
|
259
261
|
const deleteIDs = [];
|
|
262
|
+
// the type of data should come from a type parameter associated with ConcreteRequest,
|
|
263
|
+
// but ConcreteRequest does not contain a type parameter. Hence, we use a FlowFixMe.
|
|
264
|
+
// $FlowFixMe[incompatible-use] see above
|
|
260
265
|
let deletedIDField = data[rootField];
|
|
266
|
+
|
|
261
267
|
if (deletedIDField && Array.isArray(deletedIDFieldName)) {
|
|
262
268
|
for (const eachField of deletedIDFieldName) {
|
|
263
269
|
if (deletedIDField && typeof deletedIDField === 'object') {
|
|
@@ -12,17 +12,16 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
const invariant = require('invariant');
|
|
16
|
-
|
|
17
|
-
const {generateClientID} = require('../store/ClientID');
|
|
18
|
-
const {getStableStorageKey} = require('../store/RelayStoreUtils');
|
|
19
|
-
|
|
20
15
|
import type {RecordProxy} from '../store/RelayStoreTypes';
|
|
21
16
|
import type {Arguments} from '../store/RelayStoreUtils';
|
|
22
17
|
import type {DataID} from '../util/RelayRuntimeTypes';
|
|
23
18
|
import type RelayRecordSourceMutator from './RelayRecordSourceMutator';
|
|
24
19
|
import type RelayRecordSourceProxy from './RelayRecordSourceProxy';
|
|
25
20
|
|
|
21
|
+
const {generateClientID} = require('../store/ClientID');
|
|
22
|
+
const {getStableStorageKey} = require('../store/RelayStoreUtils');
|
|
23
|
+
const invariant = require('invariant');
|
|
24
|
+
|
|
26
25
|
/**
|
|
27
26
|
* @internal
|
|
28
27
|
*
|
|
@@ -12,12 +12,6 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
const RelayModernRecord = require('../store/RelayModernRecord');
|
|
16
|
-
|
|
17
|
-
const invariant = require('invariant');
|
|
18
|
-
|
|
19
|
-
const {EXISTENT} = require('../store/RelayRecordState');
|
|
20
|
-
|
|
21
15
|
import type {RecordState} from '../store/RelayRecordState';
|
|
22
16
|
import type {
|
|
23
17
|
MutableRecordSource,
|
|
@@ -26,6 +20,10 @@ import type {
|
|
|
26
20
|
} from '../store/RelayStoreTypes';
|
|
27
21
|
import type {DataID} from '../util/RelayRuntimeTypes';
|
|
28
22
|
|
|
23
|
+
const RelayModernRecord = require('../store/RelayModernRecord');
|
|
24
|
+
const {EXISTENT} = require('../store/RelayRecordState');
|
|
25
|
+
const invariant = require('invariant');
|
|
26
|
+
|
|
29
27
|
/**
|
|
30
28
|
* @internal
|
|
31
29
|
*
|
|
@@ -12,26 +12,28 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
const RelayModernRecord = require('../store/RelayModernRecord');
|
|
16
|
-
const RelayRecordProxy = require('./RelayRecordProxy');
|
|
17
|
-
|
|
18
|
-
const invariant = require('invariant');
|
|
19
|
-
|
|
20
|
-
const {EXISTENT, NONEXISTENT} = require('../store/RelayRecordState');
|
|
21
|
-
const {ROOT_ID, ROOT_TYPE} = require('../store/RelayStoreUtils');
|
|
22
|
-
|
|
23
15
|
import type {HandlerProvider} from '../handlers/RelayDefaultHandlerProvider';
|
|
16
|
+
import type {GraphQLTaggedNode} from '../query/GraphQLTag';
|
|
24
17
|
import type {GetDataID} from '../store/RelayResponseNormalizer';
|
|
25
18
|
import type {
|
|
26
19
|
DataIDSet,
|
|
27
20
|
HandleFieldPayload,
|
|
28
|
-
RecordSource,
|
|
29
21
|
RecordProxy,
|
|
22
|
+
RecordSource,
|
|
30
23
|
RecordSourceProxy,
|
|
31
24
|
} from '../store/RelayStoreTypes';
|
|
32
|
-
import type {DataID} from '../util/RelayRuntimeTypes';
|
|
25
|
+
import type {DataID, OperationType} from '../util/RelayRuntimeTypes';
|
|
33
26
|
import type RelayRecordSourceMutator from './RelayRecordSourceMutator';
|
|
34
27
|
|
|
28
|
+
const RelayModernRecord = require('../store/RelayModernRecord');
|
|
29
|
+
const {EXISTENT, NONEXISTENT} = require('../store/RelayRecordState');
|
|
30
|
+
const {ROOT_ID, ROOT_TYPE} = require('../store/RelayStoreUtils');
|
|
31
|
+
const {
|
|
32
|
+
readUpdatableQuery_EXPERIMENTAL,
|
|
33
|
+
} = require('./readUpdatableQuery_EXPERIMENTAL');
|
|
34
|
+
const RelayRecordProxy = require('./RelayRecordProxy');
|
|
35
|
+
const invariant = require('invariant');
|
|
36
|
+
|
|
35
37
|
/**
|
|
36
38
|
* @internal
|
|
37
39
|
*
|
|
@@ -160,6 +162,13 @@ class RelayRecordSourceProxy implements RecordSourceProxy {
|
|
|
160
162
|
getIDsMarkedForInvalidation(): DataIDSet {
|
|
161
163
|
return this._idsMarkedForInvalidation;
|
|
162
164
|
}
|
|
165
|
+
|
|
166
|
+
readUpdatableQuery_EXPERIMENTAL<TQuery: OperationType>(
|
|
167
|
+
query: GraphQLTaggedNode,
|
|
168
|
+
variables: TQuery['variables'],
|
|
169
|
+
): TQuery['response'] {
|
|
170
|
+
return readUpdatableQuery_EXPERIMENTAL(query, variables, this);
|
|
171
|
+
}
|
|
163
172
|
}
|
|
164
173
|
|
|
165
174
|
module.exports = RelayRecordSourceProxy;
|
|
@@ -12,10 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const {getStorageKey, ROOT_TYPE} = require('../store/RelayStoreUtils');
|
|
18
|
-
|
|
15
|
+
import type {GraphQLTaggedNode} from '../query/GraphQLTag';
|
|
19
16
|
import type {
|
|
20
17
|
RecordProxy,
|
|
21
18
|
RecordSourceProxy,
|
|
@@ -23,9 +20,15 @@ import type {
|
|
|
23
20
|
SingularReaderSelector,
|
|
24
21
|
} from '../store/RelayStoreTypes';
|
|
25
22
|
import type {ReaderLinkedField} from '../util/ReaderNode';
|
|
26
|
-
import type {DataID} from '../util/RelayRuntimeTypes';
|
|
23
|
+
import type {DataID, OperationType} from '../util/RelayRuntimeTypes';
|
|
27
24
|
import type RelayRecordSourceMutator from './RelayRecordSourceMutator';
|
|
28
25
|
|
|
26
|
+
const {ROOT_TYPE, getStorageKey} = require('../store/RelayStoreUtils');
|
|
27
|
+
const {
|
|
28
|
+
readUpdatableQuery_EXPERIMENTAL,
|
|
29
|
+
} = require('./readUpdatableQuery_EXPERIMENTAL');
|
|
30
|
+
const invariant = require('invariant');
|
|
31
|
+
|
|
29
32
|
/**
|
|
30
33
|
* @internal
|
|
31
34
|
*
|
|
@@ -78,10 +81,15 @@ class RelayRecordSourceSelectorProxy implements RecordSourceSelectorProxy {
|
|
|
78
81
|
fieldName: string,
|
|
79
82
|
plural: boolean,
|
|
80
83
|
): ReaderLinkedField {
|
|
81
|
-
|
|
84
|
+
let field = selector.node.selections.find(
|
|
82
85
|
selection =>
|
|
83
|
-
selection.kind === 'LinkedField' && selection.name === fieldName
|
|
86
|
+
(selection.kind === 'LinkedField' && selection.name === fieldName) ||
|
|
87
|
+
(selection.kind === 'RequiredField' &&
|
|
88
|
+
selection.field.name === fieldName),
|
|
84
89
|
);
|
|
90
|
+
if (field && field.kind === 'RequiredField') {
|
|
91
|
+
field = field.field;
|
|
92
|
+
}
|
|
85
93
|
invariant(
|
|
86
94
|
field && field.kind === 'LinkedField',
|
|
87
95
|
'RelayRecordSourceSelectorProxy#getRootField(): Cannot find root ' +
|
|
@@ -114,6 +122,13 @@ class RelayRecordSourceSelectorProxy implements RecordSourceSelectorProxy {
|
|
|
114
122
|
invalidateStore(): void {
|
|
115
123
|
this.__recordSource.invalidateStore();
|
|
116
124
|
}
|
|
125
|
+
|
|
126
|
+
readUpdatableQuery_EXPERIMENTAL<TQuery: OperationType>(
|
|
127
|
+
query: GraphQLTaggedNode,
|
|
128
|
+
variables: TQuery['variables'],
|
|
129
|
+
): TQuery['response'] {
|
|
130
|
+
return readUpdatableQuery_EXPERIMENTAL(query, variables, this);
|
|
131
|
+
}
|
|
117
132
|
}
|
|
118
133
|
|
|
119
134
|
module.exports = RelayRecordSourceSelectorProxy;
|
|
@@ -12,29 +12,28 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
const RelayDeclarativeMutationConfig = require('./RelayDeclarativeMutationConfig');
|
|
16
|
-
|
|
17
|
-
const invariant = require('invariant');
|
|
18
|
-
const isRelayModernEnvironment = require('../store/isRelayModernEnvironment');
|
|
19
|
-
|
|
20
|
-
const {getRequest} = require('../query/GraphQLTag');
|
|
21
|
-
const {
|
|
22
|
-
createOperationDescriptor,
|
|
23
|
-
} = require('../store/RelayModernOperationDescriptor');
|
|
24
|
-
|
|
25
15
|
import type {GraphQLTaggedNode} from '../query/GraphQLTag';
|
|
26
16
|
import type {
|
|
27
17
|
IEnvironment,
|
|
18
|
+
MutationParameters,
|
|
28
19
|
SelectorStoreUpdater,
|
|
29
20
|
} from '../store/RelayStoreTypes';
|
|
30
21
|
import type {Disposable, Variables} from '../util/RelayRuntimeTypes';
|
|
31
22
|
import type {DeclarativeMutationConfig} from './RelayDeclarativeMutationConfig';
|
|
32
23
|
|
|
33
|
-
|
|
24
|
+
const {getRequest} = require('../query/GraphQLTag');
|
|
25
|
+
const isRelayModernEnvironment = require('../store/isRelayModernEnvironment');
|
|
26
|
+
const {
|
|
27
|
+
createOperationDescriptor,
|
|
28
|
+
} = require('../store/RelayModernOperationDescriptor');
|
|
29
|
+
const RelayDeclarativeMutationConfig = require('./RelayDeclarativeMutationConfig');
|
|
30
|
+
const invariant = require('invariant');
|
|
31
|
+
|
|
32
|
+
export type OptimisticMutationConfig<TMutation: MutationParameters> = {|
|
|
34
33
|
configs?: ?Array<DeclarativeMutationConfig>,
|
|
35
34
|
mutation: GraphQLTaggedNode,
|
|
36
35
|
variables: Variables,
|
|
37
|
-
optimisticUpdater?: ?SelectorStoreUpdater
|
|
36
|
+
optimisticUpdater?: ?SelectorStoreUpdater<TMutation['response']>,
|
|
38
37
|
optimisticResponse?: Object,
|
|
39
38
|
|};
|
|
40
39
|
|
|
@@ -42,9 +41,9 @@ export type OptimisticMutationConfig = {|
|
|
|
42
41
|
* Higher-level helper function to execute a mutation against a specific
|
|
43
42
|
* environment.
|
|
44
43
|
*/
|
|
45
|
-
function applyOptimisticMutation(
|
|
44
|
+
function applyOptimisticMutation<TMutation: MutationParameters>(
|
|
46
45
|
environment: IEnvironment,
|
|
47
|
-
config: OptimisticMutationConfig
|
|
46
|
+
config: OptimisticMutationConfig<TMutation>,
|
|
48
47
|
): Disposable {
|
|
49
48
|
invariant(
|
|
50
49
|
isRelayModernEnvironment(environment),
|