relay-runtime 12.0.0 → 13.0.0-rc.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/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 +40 -33
- package/lib/handlers/connection/ConnectionHandler.js +12 -18
- package/lib/handlers/connection/MutationHandlers.js +3 -6
- package/lib/index.js +45 -45
- package/lib/multi-actor-environment/ActorSpecificEnvironment.js +8 -4
- package/lib/multi-actor-environment/MultiActorEnvironment.js +35 -22
- package/lib/multi-actor-environment/index.js +2 -2
- 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 +12 -4
- package/lib/mutations/applyOptimisticMutation.js +6 -6
- package/lib/mutations/commitMutation.js +15 -14
- package/lib/mutations/readUpdatableQuery_EXPERIMENTAL.js +238 -0
- package/lib/mutations/validateMutation.js +6 -6
- package/lib/network/ConvertToExecuteFunction.js +2 -1
- package/lib/network/RelayNetwork.js +3 -2
- package/lib/network/RelayObservable.js +1 -3
- package/lib/network/RelayQueryResponseCache.js +2 -2
- package/lib/network/wrapNetworkWithLogObserver.js +2 -1
- package/lib/query/GraphQLTag.js +2 -1
- package/lib/query/fetchQuery.js +6 -5
- package/lib/query/fetchQuery_DEPRECATED.js +2 -1
- package/lib/store/ClientID.js +7 -1
- package/lib/store/DataChecker.js +16 -17
- package/lib/store/OperationExecutor.js +13 -13
- package/lib/store/RelayConcreteVariables.js +6 -9
- package/lib/store/RelayModernEnvironment.js +66 -42
- package/lib/store/RelayModernFragmentSpecResolver.js +8 -8
- package/lib/store/RelayModernOperationDescriptor.js +2 -1
- package/lib/store/RelayModernRecord.js +12 -11
- package/lib/store/RelayModernSelector.js +14 -8
- package/lib/store/RelayModernStore.js +14 -15
- package/lib/store/RelayPublishQueue.js +11 -5
- package/lib/store/RelayReader.js +130 -37
- package/lib/store/RelayReferenceMarker.js +10 -11
- package/lib/store/RelayResponseNormalizer.js +25 -22
- package/lib/store/RelayStoreReactFlightUtils.js +3 -3
- package/lib/store/RelayStoreSubscriptions.js +6 -4
- package/lib/store/RelayStoreUtils.js +5 -5
- package/lib/store/ResolverCache.js +6 -6
- package/lib/store/ResolverFragments.js +9 -5
- package/lib/store/cloneRelayHandleSourceField.js +5 -4
- package/lib/store/cloneRelayScalarHandleSourceField.js +5 -4
- package/lib/store/createRelayContext.js +3 -1
- package/lib/store/readInlineData.js +6 -2
- package/lib/subscription/requestSubscription.js +5 -5
- package/lib/util/RelayConcreteNode.js +1 -0
- package/lib/util/RelayFeatureFlags.js +7 -1
- 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/getPaginationVariables.js +2 -3
- package/lib/util/getRelayHandleKey.js +2 -2
- package/lib/util/getRequestIdentifier.js +2 -2
- package/multi-actor-environment/ActorSpecificEnvironment.js.flow +27 -19
- package/multi-actor-environment/ActorUtils.js.flow +2 -2
- package/multi-actor-environment/MultiActorEnvironment.js.flow +45 -24
- package/multi-actor-environment/MultiActorEnvironmentTypes.js.flow +27 -11
- package/multi-actor-environment/index.js.flow +1 -2
- 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 +15 -5
- package/mutations/applyOptimisticMutation.js.flow +13 -14
- package/mutations/commitLocalUpdate.js.flow +1 -1
- package/mutations/commitMutation.js.flow +35 -48
- package/mutations/readUpdatableQuery_EXPERIMENTAL.js.flow +309 -0
- package/mutations/validateMutation.js.flow +19 -17
- package/network/ConvertToExecuteFunction.js.flow +2 -2
- package/network/RelayNetwork.js.flow +4 -5
- package/network/RelayObservable.js.flow +1 -3
- package/network/RelayQueryResponseCache.js.flow +3 -3
- package/network/wrapNetworkWithLogObserver.js.flow +8 -7
- package/package.json +1 -1
- 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 +9 -2
- package/store/DataChecker.js.flow +20 -29
- package/store/OperationExecutor.js.flow +54 -62
- package/store/RelayConcreteVariables.js.flow +4 -10
- package/store/RelayModernEnvironment.js.flow +56 -27
- package/store/RelayModernFragmentSpecResolver.js.flow +17 -19
- package/store/RelayModernOperationDescriptor.js.flow +10 -11
- package/store/RelayModernRecord.js.flow +19 -12
- package/store/RelayModernSelector.js.flow +24 -14
- package/store/RelayModernStore.js.flow +21 -24
- package/store/RelayOperationTracker.js.flow +11 -17
- package/store/RelayOptimisticRecordSource.js.flow +2 -2
- package/store/RelayPublishQueue.js.flow +42 -23
- package/store/RelayReader.js.flow +180 -60
- package/store/RelayRecordSource.js.flow +2 -2
- package/store/RelayReferenceMarker.js.flow +12 -15
- package/store/RelayResponseNormalizer.js.flow +43 -41
- package/store/RelayStoreReactFlightUtils.js.flow +3 -4
- package/store/RelayStoreSubscriptions.js.flow +9 -8
- package/store/RelayStoreTypes.js.flow +72 -29
- package/store/RelayStoreUtils.js.flow +8 -9
- package/store/ResolverCache.js.flow +16 -14
- package/store/ResolverFragments.js.flow +15 -22
- 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 +2 -2
- package/store/normalizeRelayPayload.js.flow +6 -7
- package/store/readInlineData.js.flow +7 -8
- package/subscription/requestSubscription.js.flow +16 -24
- package/util/ReaderNode.js.flow +9 -0
- package/util/RelayConcreteNode.js.flow +1 -0
- package/util/RelayFeatureFlags.js.flow +14 -2
- package/util/RelayReplaySubject.js.flow +2 -3
- package/util/RelayRuntimeTypes.js.flow +69 -2
- 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 +5 -7
- package/util/getPaginationVariables.js.flow +5 -9
- package/util/getPendingOperationsForFragment.js.flow +2 -2
- package/util/getRefetchMetadata.js.flow +6 -7
- package/util/getRelayHandleKey.js.flow +1 -2
- package/util/getRequestIdentifier.js.flow +3 -3
- package/util/resolveImmediate.js.flow +1 -1
|
@@ -11,16 +11,6 @@
|
|
|
11
11
|
|
|
12
12
|
'use strict';
|
|
13
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 RelayRecordSource = require('../store/RelayRecordSource');
|
|
20
|
-
|
|
21
|
-
const defaultGetDataID = require('../store/defaultGetDataID');
|
|
22
|
-
const defaultRequiredFieldLogger = require('../store/defaultRequiredFieldLogger');
|
|
23
|
-
|
|
24
14
|
import type {HandlerProvider} from '../handlers/RelayDefaultHandlerProvider';
|
|
25
15
|
import type {GraphQLResponse, PayloadData} from '../network/RelayNetworkTypes';
|
|
26
16
|
import type {INetwork} from '../network/RelayNetworkTypes';
|
|
@@ -31,6 +21,7 @@ import type {
|
|
|
31
21
|
LogFunction,
|
|
32
22
|
MissingFieldHandler,
|
|
33
23
|
MutableRecordSource,
|
|
24
|
+
MutationParameters,
|
|
34
25
|
OperationAvailability,
|
|
35
26
|
OperationDescriptor,
|
|
36
27
|
OperationLoader,
|
|
@@ -54,6 +45,15 @@ import type {
|
|
|
54
45
|
MultiActorStoreUpdater,
|
|
55
46
|
} from './MultiActorEnvironmentTypes';
|
|
56
47
|
|
|
48
|
+
const RelayDefaultHandlerProvider = require('../handlers/RelayDefaultHandlerProvider');
|
|
49
|
+
const RelayObservable = require('../network/RelayObservable');
|
|
50
|
+
const defaultGetDataID = require('../store/defaultGetDataID');
|
|
51
|
+
const defaultRequiredFieldLogger = require('../store/defaultRequiredFieldLogger');
|
|
52
|
+
const OperationExecutor = require('../store/OperationExecutor');
|
|
53
|
+
const RelayModernStore = require('../store/RelayModernStore');
|
|
54
|
+
const RelayRecordSource = require('../store/RelayRecordSource');
|
|
55
|
+
const ActorSpecificEnvironment = require('./ActorSpecificEnvironment');
|
|
56
|
+
|
|
57
57
|
export type MultiActorEnvironmentConfig = $ReadOnly<{
|
|
58
58
|
createConfigNameForActor?: ?(actorIdentifier: ActorIdentifier) => string,
|
|
59
59
|
createNetworkForActor: (actorIdentifier: ActorIdentifier) => INetwork,
|
|
@@ -161,9 +161,7 @@ class MultiActorEnvironment implements IMultiActorEnvironment {
|
|
|
161
161
|
handlers: [],
|
|
162
162
|
defaultActorIdentifier: actorEnvironment.actorIdentifier,
|
|
163
163
|
getSourceForActor: actorIdentifier => {
|
|
164
|
-
return this.forActor(actorIdentifier)
|
|
165
|
-
.getStore()
|
|
166
|
-
.getSource();
|
|
164
|
+
return this.forActor(actorIdentifier).getStore().getSource();
|
|
167
165
|
},
|
|
168
166
|
getTargetForActor: () => {
|
|
169
167
|
return RelayRecordSource.create();
|
|
@@ -189,9 +187,7 @@ class MultiActorEnvironment implements IMultiActorEnvironment {
|
|
|
189
187
|
handlers,
|
|
190
188
|
defaultActorIdentifier: actorEnvironment.actorIdentifier,
|
|
191
189
|
getSourceForActor: actorIdentifier => {
|
|
192
|
-
return this.forActor(actorIdentifier)
|
|
193
|
-
.getStore()
|
|
194
|
-
.getSource();
|
|
190
|
+
return this.forActor(actorIdentifier).getStore().getSource();
|
|
195
191
|
},
|
|
196
192
|
getTargetForActor: actorIdentifier => {
|
|
197
193
|
let target = targets.get(actorIdentifier);
|
|
@@ -274,9 +270,9 @@ class MultiActorEnvironment implements IMultiActorEnvironment {
|
|
|
274
270
|
});
|
|
275
271
|
}
|
|
276
272
|
|
|
277
|
-
applyMutation(
|
|
273
|
+
applyMutation<TMutation: MutationParameters>(
|
|
278
274
|
actorEnvironment: IActorEnvironment,
|
|
279
|
-
optimisticConfig: OptimisticResponseConfig
|
|
275
|
+
optimisticConfig: OptimisticResponseConfig<TMutation>,
|
|
280
276
|
): Disposable {
|
|
281
277
|
const subscription = this._execute(actorEnvironment, {
|
|
282
278
|
createSource: () => RelayObservable.create(_sink => {}),
|
|
@@ -324,13 +320,38 @@ class MultiActorEnvironment implements IMultiActorEnvironment {
|
|
|
324
320
|
}
|
|
325
321
|
|
|
326
322
|
execute(
|
|
323
|
+
actorEnvironment: IActorEnvironment,
|
|
324
|
+
{
|
|
325
|
+
operation,
|
|
326
|
+
}: {
|
|
327
|
+
operation: OperationDescriptor,
|
|
328
|
+
},
|
|
329
|
+
): RelayObservable<GraphQLResponse> {
|
|
330
|
+
return this._execute(actorEnvironment, {
|
|
331
|
+
createSource: () =>
|
|
332
|
+
actorEnvironment
|
|
333
|
+
.getNetwork()
|
|
334
|
+
.execute(
|
|
335
|
+
operation.request.node.params,
|
|
336
|
+
operation.request.variables,
|
|
337
|
+
operation.request.cacheConfig || {},
|
|
338
|
+
null,
|
|
339
|
+
),
|
|
340
|
+
isClientPayload: false,
|
|
341
|
+
operation,
|
|
342
|
+
optimisticConfig: null,
|
|
343
|
+
updater: null,
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
executeSubscription<TMutation: MutationParameters>(
|
|
327
348
|
actorEnvironment: IActorEnvironment,
|
|
328
349
|
{
|
|
329
350
|
operation,
|
|
330
351
|
updater,
|
|
331
352
|
}: {
|
|
332
353
|
operation: OperationDescriptor,
|
|
333
|
-
updater?: ?SelectorStoreUpdater
|
|
354
|
+
updater?: ?SelectorStoreUpdater<TMutation['response']>,
|
|
334
355
|
},
|
|
335
356
|
): RelayObservable<GraphQLResponse> {
|
|
336
357
|
return this._execute(actorEnvironment, {
|
|
@@ -350,7 +371,7 @@ class MultiActorEnvironment implements IMultiActorEnvironment {
|
|
|
350
371
|
});
|
|
351
372
|
}
|
|
352
373
|
|
|
353
|
-
executeMutation(
|
|
374
|
+
executeMutation<TMutation: MutationParameters>(
|
|
354
375
|
actorEnvironment: IActorEnvironment,
|
|
355
376
|
{
|
|
356
377
|
operation,
|
|
@@ -358,7 +379,7 @@ class MultiActorEnvironment implements IMultiActorEnvironment {
|
|
|
358
379
|
optimisticUpdater,
|
|
359
380
|
updater,
|
|
360
381
|
uploadables,
|
|
361
|
-
}: ExecuteMutationConfig
|
|
382
|
+
}: ExecuteMutationConfig<TMutation>,
|
|
362
383
|
): RelayObservable<GraphQLResponse> {
|
|
363
384
|
let optimisticConfig;
|
|
364
385
|
if (optimisticResponse || optimisticUpdater) {
|
|
@@ -414,7 +435,7 @@ class MultiActorEnvironment implements IMultiActorEnvironment {
|
|
|
414
435
|
return this._isServer;
|
|
415
436
|
}
|
|
416
437
|
|
|
417
|
-
_execute(
|
|
438
|
+
_execute<TMutation: MutationParameters>(
|
|
418
439
|
actorEnvironment: IActorEnvironment,
|
|
419
440
|
{
|
|
420
441
|
createSource,
|
|
@@ -426,8 +447,8 @@ class MultiActorEnvironment implements IMultiActorEnvironment {
|
|
|
426
447
|
createSource: () => RelayObservable<GraphQLResponse>,
|
|
427
448
|
isClientPayload: boolean,
|
|
428
449
|
operation: OperationDescriptor,
|
|
429
|
-
optimisticConfig: ?OptimisticResponseConfig
|
|
430
|
-
updater: ?SelectorStoreUpdater
|
|
450
|
+
optimisticConfig: ?OptimisticResponseConfig<TMutation>,
|
|
451
|
+
updater: ?SelectorStoreUpdater<TMutation['response']>,
|
|
431
452
|
|},
|
|
432
453
|
): RelayObservable<GraphQLResponse> {
|
|
433
454
|
return RelayObservable.create(sink => {
|
|
@@ -11,21 +11,22 @@
|
|
|
11
11
|
|
|
12
12
|
'use strict';
|
|
13
13
|
|
|
14
|
-
import type {
|
|
14
|
+
import type {GraphQLResponse, PayloadData} from '../network/RelayNetworkTypes';
|
|
15
15
|
import type RelayObservable from '../network/RelayObservable';
|
|
16
16
|
import type RelayPublishQueue from '../store/RelayPublishQueue';
|
|
17
17
|
import type {
|
|
18
|
+
ExecuteMutationConfig,
|
|
19
|
+
IEnvironment,
|
|
20
|
+
MutationParameters,
|
|
18
21
|
OperationAvailability,
|
|
19
22
|
OperationDescriptor,
|
|
20
23
|
OptimisticResponseConfig,
|
|
21
24
|
OptimisticUpdateFunction,
|
|
25
|
+
RecordSourceProxy,
|
|
22
26
|
SelectorStoreUpdater,
|
|
23
27
|
SingularReaderSelector,
|
|
24
28
|
Snapshot,
|
|
25
29
|
StoreUpdater,
|
|
26
|
-
IEnvironment,
|
|
27
|
-
ExecuteMutationConfig,
|
|
28
|
-
RecordSourceProxy,
|
|
29
30
|
} from '../store/RelayStoreTypes';
|
|
30
31
|
import type {Disposable} from '../util/RelayRuntimeTypes';
|
|
31
32
|
import type {ActorIdentifier} from './ActorIdentifier';
|
|
@@ -138,9 +139,9 @@ export interface IMultiActorEnvironment {
|
|
|
138
139
|
* Apply an optimistic mutation response and/or updater. The mutation can be
|
|
139
140
|
* reverted by calling `dispose()` on the returned value.
|
|
140
141
|
*/
|
|
141
|
-
applyMutation(
|
|
142
|
+
applyMutation<TMutation: MutationParameters>(
|
|
142
143
|
actorEnvironment: IActorEnvironment,
|
|
143
|
-
optimisticConfig: OptimisticResponseConfig
|
|
144
|
+
optimisticConfig: OptimisticResponseConfig<TMutation>,
|
|
144
145
|
): Disposable;
|
|
145
146
|
|
|
146
147
|
/**
|
|
@@ -180,17 +181,32 @@ export interface IMultiActorEnvironment {
|
|
|
180
181
|
* responses may be returned (via `next`) over time followed by either
|
|
181
182
|
* the request completing (`completed`) or an error (`error`).
|
|
182
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
|
+
*
|
|
183
199
|
* Networks/servers that support subscriptions may choose to hold the
|
|
184
200
|
* subscription open indefinitely such that `complete` is not called.
|
|
185
201
|
*
|
|
186
202
|
* Note: Observables are lazy, so calling this method will do nothing until
|
|
187
|
-
* the result is subscribed to: environment.
|
|
203
|
+
* the result is subscribed to: environment.executeSubscription({...}).subscribe({...}).
|
|
188
204
|
*/
|
|
189
|
-
|
|
205
|
+
executeSubscription<TMutation: MutationParameters>(
|
|
190
206
|
actorEnvironment: IActorEnvironment,
|
|
191
207
|
config: {
|
|
192
208
|
operation: OperationDescriptor,
|
|
193
|
-
updater?: ?SelectorStoreUpdater
|
|
209
|
+
updater?: ?SelectorStoreUpdater<TMutation['response']>,
|
|
194
210
|
},
|
|
195
211
|
): RelayObservable<GraphQLResponse>;
|
|
196
212
|
|
|
@@ -204,9 +220,9 @@ export interface IMultiActorEnvironment {
|
|
|
204
220
|
* the result is subscribed to:
|
|
205
221
|
* environment.executeMutation({...}).subscribe({...}).
|
|
206
222
|
*/
|
|
207
|
-
executeMutation(
|
|
223
|
+
executeMutation<TMutation: MutationParameters>(
|
|
208
224
|
actorEnvironment: IActorEnvironment,
|
|
209
|
-
config: ExecuteMutationConfig
|
|
225
|
+
config: ExecuteMutationConfig<TMutation>,
|
|
210
226
|
): RelayObservable<GraphQLResponse>;
|
|
211
227
|
|
|
212
228
|
/**
|
|
@@ -11,9 +11,8 @@
|
|
|
11
11
|
|
|
12
12
|
'use strict';
|
|
13
13
|
|
|
14
|
-
const MultiActorEnvironment = require('./MultiActorEnvironment');
|
|
15
|
-
|
|
16
14
|
const {getActorIdentifier} = require('./ActorIdentifier');
|
|
15
|
+
const MultiActorEnvironment = require('./MultiActorEnvironment');
|
|
17
16
|
|
|
18
17
|
export type {ActorIdentifier} from './ActorIdentifier';
|
|
19
18
|
export type {
|
|
@@ -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
|
*
|
|
@@ -119,6 +122,13 @@ class RelayRecordSourceSelectorProxy implements RecordSourceSelectorProxy {
|
|
|
119
122
|
invalidateStore(): void {
|
|
120
123
|
this.__recordSource.invalidateStore();
|
|
121
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
|
+
}
|
|
122
132
|
}
|
|
123
133
|
|
|
124
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),
|