relay-runtime 11.0.2 → 13.0.0-rc.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/README.md +67 -0
- package/handlers/RelayDefaultHandlerProvider.js.flow +3 -3
- package/handlers/connection/ConnectionHandler.js.flow +9 -18
- package/handlers/connection/ConnectionInterface.js.flow +1 -1
- package/handlers/connection/MutationHandlers.js.flow +8 -12
- package/index.js +1 -1
- package/index.js.flow +57 -35
- package/lib/handlers/RelayDefaultHandlerProvider.js +1 -1
- package/lib/handlers/connection/ConnectionHandler.js +13 -19
- package/lib/handlers/connection/ConnectionInterface.js +1 -1
- package/lib/handlers/connection/MutationHandlers.js +4 -7
- package/lib/index.js +59 -44
- package/lib/multi-actor-environment/ActorIdentifier.js +12 -2
- package/lib/multi-actor-environment/ActorSpecificEnvironment.js +64 -20
- package/lib/multi-actor-environment/ActorUtils.js +27 -0
- package/lib/multi-actor-environment/MultiActorEnvironment.js +324 -61
- package/lib/multi-actor-environment/MultiActorEnvironmentTypes.js +1 -1
- package/lib/multi-actor-environment/index.js +6 -2
- package/lib/mutations/RelayDeclarativeMutationConfig.js +5 -2
- package/lib/mutations/RelayRecordProxy.js +4 -3
- package/lib/mutations/RelayRecordSourceMutator.js +4 -3
- package/lib/mutations/RelayRecordSourceProxy.js +13 -5
- package/lib/mutations/RelayRecordSourceSelectorProxy.js +19 -6
- package/lib/mutations/applyOptimisticMutation.js +7 -7
- package/lib/mutations/commitLocalUpdate.js +1 -1
- package/lib/mutations/commitMutation.js +15 -11
- package/lib/mutations/readUpdatableQuery_EXPERIMENTAL.js +242 -0
- package/lib/mutations/validateMutation.js +11 -6
- package/lib/network/ConvertToExecuteFunction.js +3 -2
- package/lib/network/RelayNetwork.js +4 -3
- package/lib/network/RelayNetworkTypes.js +1 -1
- package/lib/network/RelayObservable.js +1 -1
- package/lib/network/RelayQueryResponseCache.js +22 -6
- package/lib/network/wrapNetworkWithLogObserver.js +79 -0
- package/lib/query/GraphQLTag.js +3 -2
- package/lib/query/PreloadableQueryRegistry.js +1 -1
- package/lib/query/fetchQuery.js +7 -6
- package/lib/query/fetchQueryInternal.js +1 -1
- package/lib/query/fetchQuery_DEPRECATED.js +3 -2
- package/lib/store/ClientID.js +8 -2
- package/lib/store/DataChecker.js +124 -55
- package/lib/store/OperationExecutor.js +489 -215
- package/lib/store/RelayConcreteVariables.js +27 -9
- package/lib/store/RelayExperimentalGraphResponseHandler.js +153 -0
- package/lib/store/RelayExperimentalGraphResponseTransform.js +391 -0
- package/lib/store/RelayModernEnvironment.js +100 -120
- package/lib/store/RelayModernFragmentSpecResolver.js +53 -27
- package/lib/store/RelayModernOperationDescriptor.js +3 -2
- package/lib/store/RelayModernRecord.js +48 -13
- package/lib/store/RelayModernSelector.js +15 -9
- package/lib/store/RelayModernStore.js +56 -23
- package/lib/store/RelayOperationTracker.js +34 -24
- package/lib/store/RelayOptimisticRecordSource.js +1 -1
- package/lib/store/RelayPublishQueue.js +35 -11
- package/lib/store/RelayReader.js +257 -72
- package/lib/store/RelayRecordSource.js +88 -4
- package/lib/store/RelayRecordState.js +1 -1
- package/lib/store/RelayReferenceMarker.js +34 -22
- package/lib/store/RelayResponseNormalizer.js +172 -96
- package/lib/store/RelayStoreReactFlightUtils.js +5 -11
- package/lib/store/RelayStoreSubscriptions.js +15 -10
- package/lib/store/RelayStoreTypes.js +1 -1
- package/lib/store/RelayStoreUtils.js +13 -8
- package/lib/store/ResolverCache.js +213 -0
- package/lib/store/ResolverFragments.js +10 -6
- package/lib/store/StoreInspector.js +1 -1
- package/lib/store/TypeID.js +1 -1
- package/lib/store/ViewerPattern.js +1 -1
- package/lib/store/cloneRelayHandleSourceField.js +6 -5
- package/lib/store/cloneRelayScalarHandleSourceField.js +6 -5
- package/lib/store/createFragmentSpecResolver.js +1 -1
- package/lib/store/createRelayContext.js +5 -3
- package/lib/store/defaultGetDataID.js +1 -1
- package/lib/store/defaultRequiredFieldLogger.js +1 -1
- package/lib/store/hasOverlappingIDs.js +1 -1
- package/lib/store/isRelayModernEnvironment.js +1 -1
- package/lib/store/normalizeRelayPayload.js +1 -1
- package/lib/store/readInlineData.js +7 -3
- package/lib/subscription/requestSubscription.js +32 -34
- package/lib/util/JSResourceTypes.flow.js +1 -1
- package/lib/util/NormalizationNode.js +1 -1
- package/lib/util/ReaderNode.js +1 -1
- package/lib/util/RelayConcreteNode.js +3 -1
- package/lib/util/RelayDefaultHandleKey.js +1 -1
- package/lib/util/RelayError.js +1 -1
- package/lib/util/RelayFeatureFlags.js +10 -7
- package/lib/util/RelayProfiler.js +1 -1
- package/lib/util/RelayReplaySubject.js +22 -7
- package/lib/util/RelayRuntimeTypes.js +1 -7
- package/lib/util/StringInterner.js +71 -0
- package/lib/util/createPayloadFor3DField.js +1 -1
- package/lib/util/deepFreeze.js +1 -1
- package/lib/util/generateID.js +1 -1
- package/lib/util/getAllRootVariables.js +29 -0
- package/lib/util/getFragmentIdentifier.js +16 -8
- package/lib/util/getOperation.js +3 -2
- 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 +3 -3
- package/lib/util/getRequestIdentifier.js +3 -3
- package/lib/util/getValueAtPath.js +51 -0
- package/lib/util/isEmptyObject.js +2 -2
- package/lib/util/isPromise.js +1 -1
- package/lib/util/isScalarAndEqual.js +1 -1
- package/lib/util/recycleNodesInto.js +1 -1
- package/lib/util/registerEnvironmentWithDevTools.js +26 -0
- package/lib/util/reportMissingRequiredFields.js +1 -1
- package/lib/util/resolveImmediate.js +1 -1
- package/lib/util/stableCopy.js +1 -1
- package/lib/util/withDuration.js +31 -0
- package/multi-actor-environment/ActorIdentifier.js.flow +18 -2
- package/multi-actor-environment/ActorSpecificEnvironment.js.flow +94 -58
- package/multi-actor-environment/ActorUtils.js.flow +33 -0
- package/multi-actor-environment/MultiActorEnvironment.js.flow +366 -93
- package/multi-actor-environment/MultiActorEnvironmentTypes.js.flow +88 -23
- package/multi-actor-environment/index.js.flow +3 -1
- package/mutations/RelayDeclarativeMutationConfig.js.flow +33 -27
- package/mutations/RelayRecordProxy.js.flow +5 -6
- package/mutations/RelayRecordSourceMutator.js.flow +5 -7
- package/mutations/RelayRecordSourceProxy.js.flow +20 -11
- package/mutations/RelayRecordSourceSelectorProxy.js.flow +23 -8
- package/mutations/applyOptimisticMutation.js.flow +14 -15
- package/mutations/commitLocalUpdate.js.flow +2 -2
- package/mutations/commitMutation.js.flow +36 -47
- package/mutations/readUpdatableQuery_EXPERIMENTAL.js.flow +318 -0
- package/mutations/validateMutation.js.flow +27 -17
- package/network/ConvertToExecuteFunction.js.flow +3 -3
- package/network/RelayNetwork.js.flow +5 -6
- package/network/RelayNetworkTypes.js.flow +1 -1
- package/network/RelayObservable.js.flow +2 -2
- package/network/RelayQueryResponseCache.js.flow +35 -22
- package/network/wrapNetworkWithLogObserver.js.flow +99 -0
- package/package.json +2 -2
- package/query/GraphQLTag.js.flow +11 -11
- package/query/PreloadableQueryRegistry.js.flow +5 -3
- package/query/fetchQuery.js.flow +19 -19
- package/query/fetchQueryInternal.js.flow +7 -10
- package/query/fetchQuery_DEPRECATED.js.flow +7 -7
- package/relay-runtime.js +2 -2
- package/relay-runtime.min.js +2 -2
- package/store/ClientID.js.flow +15 -4
- package/store/DataChecker.js.flow +142 -60
- package/store/OperationExecutor.js.flow +575 -320
- package/store/RelayConcreteVariables.js.flow +28 -9
- package/store/RelayExperimentalGraphResponseHandler.js.flow +121 -0
- package/store/RelayExperimentalGraphResponseTransform.js.flow +470 -0
- package/store/RelayModernEnvironment.js.flow +91 -115
- package/store/RelayModernFragmentSpecResolver.js.flow +56 -32
- package/store/RelayModernOperationDescriptor.js.flow +13 -8
- package/store/RelayModernRecord.js.flow +68 -12
- package/store/RelayModernSelector.js.flow +25 -15
- package/store/RelayModernStore.js.flow +67 -32
- package/store/RelayOperationTracker.js.flow +60 -44
- package/store/RelayOptimisticRecordSource.js.flow +3 -3
- package/store/RelayPublishQueue.js.flow +74 -32
- package/store/RelayReader.js.flow +319 -100
- package/store/RelayRecordSource.js.flow +73 -7
- package/store/RelayRecordState.js.flow +1 -1
- package/store/RelayReferenceMarker.js.flow +41 -27
- package/store/RelayResponseNormalizer.js.flow +204 -86
- package/store/RelayStoreReactFlightUtils.js.flow +5 -12
- package/store/RelayStoreSubscriptions.js.flow +20 -12
- package/store/RelayStoreTypes.js.flow +200 -41
- package/store/RelayStoreUtils.js.flow +25 -12
- package/store/ResolverCache.js.flow +249 -0
- package/store/ResolverFragments.js.flow +16 -20
- package/store/StoreInspector.js.flow +3 -3
- package/store/TypeID.js.flow +2 -2
- package/store/ViewerPattern.js.flow +3 -3
- package/store/cloneRelayHandleSourceField.js.flow +6 -7
- package/store/cloneRelayScalarHandleSourceField.js.flow +6 -7
- package/store/createFragmentSpecResolver.js.flow +4 -5
- package/store/createRelayContext.js.flow +4 -4
- package/store/defaultGetDataID.js.flow +1 -1
- package/store/defaultRequiredFieldLogger.js.flow +1 -1
- package/store/hasOverlappingIDs.js.flow +1 -1
- package/store/isRelayModernEnvironment.js.flow +1 -1
- package/store/normalizeRelayPayload.js.flow +7 -8
- package/store/readInlineData.js.flow +8 -9
- package/subscription/requestSubscription.js.flow +55 -51
- package/util/JSResourceTypes.flow.js.flow +1 -1
- package/util/NormalizationNode.js.flow +11 -4
- package/util/ReaderNode.js.flow +25 -2
- package/util/RelayConcreteNode.js.flow +5 -1
- package/util/RelayDefaultHandleKey.js.flow +1 -1
- package/util/RelayError.js.flow +1 -1
- package/util/RelayFeatureFlags.js.flow +23 -15
- package/util/RelayProfiler.js.flow +1 -1
- package/util/RelayReplaySubject.js.flow +10 -10
- package/util/RelayRuntimeTypes.js.flow +70 -3
- package/util/StringInterner.js.flow +69 -0
- package/util/createPayloadFor3DField.js.flow +4 -4
- package/util/deepFreeze.js.flow +1 -1
- package/util/generateID.js.flow +1 -1
- package/util/getAllRootVariables.js.flow +36 -0
- package/util/getFragmentIdentifier.js.flow +28 -16
- package/util/getOperation.js.flow +3 -3
- package/util/getPaginationMetadata.js.flow +69 -0
- package/util/getPaginationVariables.js.flow +108 -0
- package/util/getPendingOperationsForFragment.js.flow +62 -0
- package/util/getRefetchMetadata.js.flow +76 -0
- package/util/getRelayHandleKey.js.flow +2 -3
- package/util/getRequestIdentifier.js.flow +4 -4
- package/util/getValueAtPath.js.flow +46 -0
- package/util/isEmptyObject.js.flow +2 -1
- package/util/isPromise.js.flow +1 -1
- package/util/isScalarAndEqual.js.flow +1 -1
- package/util/recycleNodesInto.js.flow +1 -1
- package/util/registerEnvironmentWithDevTools.js.flow +33 -0
- package/util/reportMissingRequiredFields.js.flow +1 -1
- package/util/resolveImmediate.js.flow +2 -2
- package/util/stableCopy.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
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -12,23 +12,30 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
+
import type {
|
|
16
|
+
ActorIdentifier,
|
|
17
|
+
IActorEnvironment,
|
|
18
|
+
} from '../multi-actor-environment';
|
|
15
19
|
import type {
|
|
16
20
|
GraphQLResponse,
|
|
17
21
|
INetwork,
|
|
18
22
|
PayloadData,
|
|
19
23
|
PayloadError,
|
|
20
|
-
ReactFlightServerTree,
|
|
21
24
|
ReactFlightServerError,
|
|
25
|
+
ReactFlightServerTree,
|
|
22
26
|
UploadableMap,
|
|
23
27
|
} from '../network/RelayNetworkTypes';
|
|
24
28
|
import type RelayObservable from '../network/RelayObservable';
|
|
29
|
+
import type {GraphQLTaggedNode} from '../query/GraphQLTag';
|
|
30
|
+
import type {RequestIdentifier} from '../util/getRequestIdentifier';
|
|
25
31
|
import type {
|
|
32
|
+
NormalizationArgument,
|
|
26
33
|
NormalizationLinkedField,
|
|
27
34
|
NormalizationRootNode,
|
|
28
35
|
NormalizationScalarField,
|
|
29
36
|
NormalizationSelectableNode,
|
|
30
37
|
} from '../util/NormalizationNode';
|
|
31
|
-
import type {ReaderFragment} from '../util/ReaderNode';
|
|
38
|
+
import type {ReaderClientEdge, ReaderFragment} from '../util/ReaderNode';
|
|
32
39
|
import type {
|
|
33
40
|
ConcreteRequest,
|
|
34
41
|
RequestParameters,
|
|
@@ -37,17 +44,23 @@ import type {
|
|
|
37
44
|
CacheConfig,
|
|
38
45
|
DataID,
|
|
39
46
|
Disposable,
|
|
47
|
+
OperationType,
|
|
40
48
|
RenderPolicy,
|
|
41
49
|
Variables,
|
|
42
50
|
} from '../util/RelayRuntimeTypes';
|
|
43
|
-
import type {RequestIdentifier} from '../util/getRequestIdentifier';
|
|
44
51
|
import type {InvalidationState} from './RelayModernStore';
|
|
45
52
|
import type RelayOperationTracker from './RelayOperationTracker';
|
|
46
53
|
import type {RecordState} from './RelayRecordState';
|
|
47
54
|
|
|
48
|
-
export opaque type
|
|
55
|
+
export opaque type FragmentType = empty;
|
|
49
56
|
export type OperationTracker = RelayOperationTracker;
|
|
50
57
|
|
|
58
|
+
export type MutationParameters = {|
|
|
59
|
+
+response: {...},
|
|
60
|
+
+variables: interface {},
|
|
61
|
+
+rawResponse?: {...},
|
|
62
|
+
|};
|
|
63
|
+
|
|
51
64
|
/*
|
|
52
65
|
* An individual cached graph object.
|
|
53
66
|
*/
|
|
@@ -69,6 +82,7 @@ export type SingularReaderSelector = {|
|
|
|
69
82
|
+kind: 'SingularReaderSelector',
|
|
70
83
|
+dataID: DataID,
|
|
71
84
|
+isWithinUnmatchedTypeRefinement: boolean,
|
|
85
|
+
+clientEdgeTraversalPath: ClientEdgeTraversalPath | null,
|
|
72
86
|
+node: ReaderFragment,
|
|
73
87
|
+owner: RequestDescriptor,
|
|
74
88
|
+variables: Variables,
|
|
@@ -107,12 +121,26 @@ export type MissingRequiredFields =
|
|
|
107
121
|
| {|action: 'THROW', field: MissingRequiredField|}
|
|
108
122
|
| {|action: 'LOG', fields: Array<MissingRequiredField>|};
|
|
109
123
|
|
|
124
|
+
export type ClientEdgeTraversalInfo = {|
|
|
125
|
+
+readerClientEdge: ReaderClientEdge,
|
|
126
|
+
+clientEdgeDestinationID: DataID,
|
|
127
|
+
|};
|
|
128
|
+
|
|
129
|
+
export type ClientEdgeTraversalPath =
|
|
130
|
+
$ReadOnlyArray<ClientEdgeTraversalInfo | null>;
|
|
131
|
+
|
|
132
|
+
export type MissingClientEdgeRequestInfo = {|
|
|
133
|
+
+request: ConcreteRequest,
|
|
134
|
+
+clientEdgeDestinationID: DataID,
|
|
135
|
+
|};
|
|
136
|
+
|
|
110
137
|
/**
|
|
111
138
|
* A representation of a selector and its results at a particular point in time.
|
|
112
139
|
*/
|
|
113
140
|
export type Snapshot = {|
|
|
114
141
|
+data: ?SelectorData,
|
|
115
142
|
+isMissingData: boolean,
|
|
143
|
+
+missingClientEdges: null | $ReadOnlyArray<MissingClientEdgeRequestInfo>,
|
|
116
144
|
+seenRecords: DataIDSet,
|
|
117
145
|
+selector: SingularReaderSelector,
|
|
118
146
|
+missingRequiredFields: ?MissingRequiredFields,
|
|
@@ -144,6 +172,9 @@ export type Props = {[key: string]: mixed, ...};
|
|
|
144
172
|
*/
|
|
145
173
|
export type RelayContext = {|
|
|
146
174
|
environment: IEnvironment,
|
|
175
|
+
getEnvironmentForActor?: ?(
|
|
176
|
+
actorIdentifier: ActorIdentifier,
|
|
177
|
+
) => IActorEnvironment,
|
|
147
178
|
|};
|
|
148
179
|
|
|
149
180
|
/**
|
|
@@ -190,7 +221,7 @@ export interface FragmentSpecResolver {
|
|
|
190
221
|
* Subscribe to resolver updates.
|
|
191
222
|
* Overrides existing callback (if one has been specified).
|
|
192
223
|
*/
|
|
193
|
-
setCallback(callback: () => void): void;
|
|
224
|
+
setCallback(props: Props, callback: () => void): void;
|
|
194
225
|
}
|
|
195
226
|
|
|
196
227
|
/**
|
|
@@ -216,8 +247,10 @@ export interface MutableRecordSource extends RecordSource {
|
|
|
216
247
|
}
|
|
217
248
|
|
|
218
249
|
export type CheckOptions = {|
|
|
219
|
-
target: MutableRecordSource,
|
|
220
250
|
handlers: $ReadOnlyArray<MissingFieldHandler>,
|
|
251
|
+
defaultActorIdentifier: ActorIdentifier,
|
|
252
|
+
getTargetForActor: (actorIdentifier: ActorIdentifier) => MutableRecordSource,
|
|
253
|
+
getSourceForActor: (actorIdentifier: ActorIdentifier) => RecordSource,
|
|
221
254
|
|};
|
|
222
255
|
|
|
223
256
|
export type OperationAvailability =
|
|
@@ -332,6 +365,11 @@ export interface Store {
|
|
|
332
365
|
invalidationState: InvalidationState,
|
|
333
366
|
callback: () => void,
|
|
334
367
|
): Disposable;
|
|
368
|
+
|
|
369
|
+
/**
|
|
370
|
+
* Get the current write epoch
|
|
371
|
+
*/
|
|
372
|
+
getEpoch(): number;
|
|
335
373
|
}
|
|
336
374
|
|
|
337
375
|
export interface StoreSubscriptions {
|
|
@@ -359,7 +397,7 @@ export interface StoreSubscriptions {
|
|
|
359
397
|
/**
|
|
360
398
|
* Notifies each subscription if the snapshot for the subscription selector has changed.
|
|
361
399
|
* Mutates the updatedOwners array with any owners (RequestDescriptors) associated
|
|
362
|
-
* with the subscriptions that were
|
|
400
|
+
* with the subscriptions that were notified; i.e. the owners affected by the changes.
|
|
363
401
|
*/
|
|
364
402
|
updateSubscriptions(
|
|
365
403
|
source: RecordSource,
|
|
@@ -427,6 +465,10 @@ export interface RecordSourceProxy {
|
|
|
427
465
|
get(dataID: DataID): ?RecordProxy;
|
|
428
466
|
getRoot(): RecordProxy;
|
|
429
467
|
invalidateStore(): void;
|
|
468
|
+
readUpdatableQuery_EXPERIMENTAL<TQuery: OperationType>(
|
|
469
|
+
query: GraphQLTaggedNode,
|
|
470
|
+
variables: TQuery['variables'],
|
|
471
|
+
): TQuery['response'];
|
|
430
472
|
}
|
|
431
473
|
|
|
432
474
|
export interface ReadOnlyRecordSourceProxy {
|
|
@@ -445,6 +487,23 @@ export interface RecordSourceSelectorProxy extends RecordSourceProxy {
|
|
|
445
487
|
}
|
|
446
488
|
|
|
447
489
|
export type LogEvent =
|
|
490
|
+
| {|
|
|
491
|
+
+name: 'suspense.fragment',
|
|
492
|
+
+data: mixed,
|
|
493
|
+
+fragment: ReaderFragment,
|
|
494
|
+
+isRelayHooks: boolean,
|
|
495
|
+
+isMissingData: boolean,
|
|
496
|
+
+isPromiseCached: boolean,
|
|
497
|
+
+pendingOperations: $ReadOnlyArray<RequestDescriptor>,
|
|
498
|
+
|}
|
|
499
|
+
| {|
|
|
500
|
+
+name: 'suspense.query',
|
|
501
|
+
+fetchPolicy: string,
|
|
502
|
+
+isPromiseCached: boolean,
|
|
503
|
+
+operation: OperationDescriptor,
|
|
504
|
+
+queryAvailability: ?OperationAvailability,
|
|
505
|
+
+renderPolicy: RenderPolicy,
|
|
506
|
+
|}
|
|
448
507
|
| {|
|
|
449
508
|
+name: 'queryresource.fetch',
|
|
450
509
|
// ID of this query resource request and will be the same
|
|
@@ -456,7 +515,7 @@ export type LogEvent =
|
|
|
456
515
|
// FetchPolicy from Relay Hooks
|
|
457
516
|
+fetchPolicy: string,
|
|
458
517
|
// RenderPolicy from Relay Hooks
|
|
459
|
-
+renderPolicy:
|
|
518
|
+
+renderPolicy: RenderPolicy,
|
|
460
519
|
+queryAvailability: OperationAvailability,
|
|
461
520
|
+shouldFetch: boolean,
|
|
462
521
|
|}
|
|
@@ -468,33 +527,67 @@ export type LogEvent =
|
|
|
468
527
|
|}
|
|
469
528
|
| {|
|
|
470
529
|
+name: 'network.info',
|
|
471
|
-
+
|
|
530
|
+
+networkRequestId: number,
|
|
472
531
|
+info: mixed,
|
|
473
532
|
|}
|
|
474
533
|
| {|
|
|
475
534
|
+name: 'network.start',
|
|
476
|
-
+
|
|
535
|
+
+networkRequestId: number,
|
|
477
536
|
+params: RequestParameters,
|
|
478
537
|
+variables: Variables,
|
|
479
538
|
+cacheConfig: CacheConfig,
|
|
480
539
|
|}
|
|
481
540
|
| {|
|
|
482
541
|
+name: 'network.next',
|
|
483
|
-
+
|
|
542
|
+
+networkRequestId: number,
|
|
484
543
|
+response: GraphQLResponse,
|
|
485
544
|
|}
|
|
486
545
|
| {|
|
|
487
546
|
+name: 'network.error',
|
|
488
|
-
+
|
|
547
|
+
+networkRequestId: number,
|
|
489
548
|
+error: Error,
|
|
490
549
|
|}
|
|
491
550
|
| {|
|
|
492
551
|
+name: 'network.complete',
|
|
493
|
-
+
|
|
552
|
+
+networkRequestId: number,
|
|
494
553
|
|}
|
|
495
554
|
| {|
|
|
496
555
|
+name: 'network.unsubscribe',
|
|
497
|
-
+
|
|
556
|
+
+networkRequestId: number,
|
|
557
|
+
|}
|
|
558
|
+
| {|
|
|
559
|
+
+name: 'execute.start',
|
|
560
|
+
+executeId: number,
|
|
561
|
+
+params: RequestParameters,
|
|
562
|
+
+variables: Variables,
|
|
563
|
+
+cacheConfig: CacheConfig,
|
|
564
|
+
|}
|
|
565
|
+
| {|
|
|
566
|
+
+name: 'execute.next',
|
|
567
|
+
+executeId: number,
|
|
568
|
+
+response: GraphQLResponse,
|
|
569
|
+
+duration: number,
|
|
570
|
+
|}
|
|
571
|
+
| {|
|
|
572
|
+
+name: 'execute.async.module',
|
|
573
|
+
+executeId: number,
|
|
574
|
+
+operationName: string,
|
|
575
|
+
+duration: number,
|
|
576
|
+
|}
|
|
577
|
+
| {|
|
|
578
|
+
+name: 'execute.flight.payload_deserialize',
|
|
579
|
+
+executeId: number,
|
|
580
|
+
+operationName: string,
|
|
581
|
+
+duration: number,
|
|
582
|
+
|}
|
|
583
|
+
| {|
|
|
584
|
+
+name: 'execute.error',
|
|
585
|
+
+executeId: number,
|
|
586
|
+
+error: Error,
|
|
587
|
+
|}
|
|
588
|
+
| {|
|
|
589
|
+
+name: 'execute.complete',
|
|
590
|
+
+executeId: number,
|
|
498
591
|
|}
|
|
499
592
|
| {|
|
|
500
593
|
+name: 'store.publish',
|
|
@@ -584,11 +677,26 @@ export interface IEnvironment {
|
|
|
584
677
|
*/
|
|
585
678
|
applyUpdate(optimisticUpdate: OptimisticUpdateFunction): Disposable;
|
|
586
679
|
|
|
680
|
+
/**
|
|
681
|
+
* Revert updates for the `update` function.
|
|
682
|
+
*/
|
|
683
|
+
revertUpdate(update: OptimisticUpdateFunction): void;
|
|
684
|
+
|
|
685
|
+
/**
|
|
686
|
+
* Revert updates for the `update` function, and apply the `replacement` update.
|
|
687
|
+
*/
|
|
688
|
+
replaceUpdate(
|
|
689
|
+
update: OptimisticUpdateFunction,
|
|
690
|
+
replacement: OptimisticUpdateFunction,
|
|
691
|
+
): void;
|
|
692
|
+
|
|
587
693
|
/**
|
|
588
694
|
* Apply an optimistic mutation response and/or updater. The mutation can be
|
|
589
695
|
* reverted by calling `dispose()` on the returned value.
|
|
590
696
|
*/
|
|
591
|
-
applyMutation
|
|
697
|
+
applyMutation<TMutation: MutationParameters>(
|
|
698
|
+
optimisticConfig: OptimisticResponseConfig<TMutation>,
|
|
699
|
+
): Disposable;
|
|
592
700
|
|
|
593
701
|
/**
|
|
594
702
|
* Commit an updater to the environment. This mutation cannot be reverted and
|
|
@@ -637,15 +745,27 @@ export interface IEnvironment {
|
|
|
637
745
|
* responses may be returned (via `next`) over time followed by either
|
|
638
746
|
* the request completing (`completed`) or an error (`error`).
|
|
639
747
|
*
|
|
748
|
+
* Note: Observables are lazy, so calling this method will do nothing until
|
|
749
|
+
* the result is subscribed to: environment.execute({...}).subscribe({...}).
|
|
750
|
+
*/
|
|
751
|
+
execute(config: {|
|
|
752
|
+
operation: OperationDescriptor,
|
|
753
|
+
|}): RelayObservable<GraphQLResponse>;
|
|
754
|
+
|
|
755
|
+
/**
|
|
756
|
+
* Send a subscription to the server with Observer semantics: one or more
|
|
757
|
+
* responses may be returned (via `next`) over time followed by either
|
|
758
|
+
* the request completing (`completed`) or an error (`error`).
|
|
759
|
+
*
|
|
640
760
|
* Networks/servers that support subscriptions may choose to hold the
|
|
641
761
|
* subscription open indefinitely such that `complete` is not called.
|
|
642
762
|
*
|
|
643
763
|
* Note: Observables are lazy, so calling this method will do nothing until
|
|
644
|
-
* the result is subscribed to: environment.
|
|
764
|
+
* the result is subscribed to: environment.executeSubscription({...}).subscribe({...}).
|
|
645
765
|
*/
|
|
646
|
-
|
|
766
|
+
executeSubscription<TMutation: MutationParameters>(config: {|
|
|
647
767
|
operation: OperationDescriptor,
|
|
648
|
-
updater?: ?SelectorStoreUpdater
|
|
768
|
+
updater?: ?SelectorStoreUpdater<TMutation['response']>,
|
|
649
769
|
|}): RelayObservable<GraphQLResponse>;
|
|
650
770
|
|
|
651
771
|
/**
|
|
@@ -658,14 +778,14 @@ export interface IEnvironment {
|
|
|
658
778
|
* the result is subscribed to:
|
|
659
779
|
* environment.executeMutation({...}).subscribe({...}).
|
|
660
780
|
*/
|
|
661
|
-
executeMutation(
|
|
662
|
-
config: ExecuteMutationConfig
|
|
781
|
+
executeMutation<TMutation: MutationParameters>(
|
|
782
|
+
config: ExecuteMutationConfig<TMutation>,
|
|
663
783
|
): RelayObservable<GraphQLResponse>;
|
|
664
784
|
|
|
665
785
|
/**
|
|
666
786
|
* Returns an Observable of GraphQLResponse resulting from executing the
|
|
667
787
|
* provided Query or Subscription operation responses, the result of which is
|
|
668
|
-
* then normalized and
|
|
788
|
+
* then normalized and committed to the publish queue.
|
|
669
789
|
*
|
|
670
790
|
* Note: Observables are lazy, so calling this method will do nothing until
|
|
671
791
|
* the result is subscribed to:
|
|
@@ -706,7 +826,7 @@ export interface IEnvironment {
|
|
|
706
826
|
export type ModuleImportPointer = {
|
|
707
827
|
+__fragmentPropName: ?string,
|
|
708
828
|
+__module_component: mixed,
|
|
709
|
-
+$
|
|
829
|
+
+$fragmentSpreads: mixed,
|
|
710
830
|
...
|
|
711
831
|
};
|
|
712
832
|
|
|
@@ -750,6 +870,7 @@ export type HandleFieldPayload = {|
|
|
|
750
870
|
* with a `@module` fragment spread, or a Flight field's:
|
|
751
871
|
*
|
|
752
872
|
* ## @module Fragment Spread
|
|
873
|
+
* - args: Local arguments from the parent
|
|
753
874
|
* - data: The GraphQL response value for the @match field.
|
|
754
875
|
* - dataID: The ID of the store object linked to by the @match field.
|
|
755
876
|
* - operationReference: A reference to a generated module containing the
|
|
@@ -777,14 +898,48 @@ export type HandleFieldPayload = {|
|
|
|
777
898
|
* root data.
|
|
778
899
|
*/
|
|
779
900
|
export type ModuleImportPayload = {|
|
|
901
|
+
+kind: 'ModuleImportPayload',
|
|
902
|
+
+args: ?$ReadOnlyArray<NormalizationArgument>,
|
|
780
903
|
+data: PayloadData,
|
|
781
904
|
+dataID: DataID,
|
|
782
905
|
+operationReference: mixed,
|
|
783
906
|
+path: $ReadOnlyArray<string>,
|
|
784
907
|
+typeName: string,
|
|
785
908
|
+variables: Variables,
|
|
909
|
+
+actorIdentifier: ?ActorIdentifier,
|
|
786
910
|
|};
|
|
787
911
|
|
|
912
|
+
/**
|
|
913
|
+
* A payload that represents data necessary to process the results of an object
|
|
914
|
+
* with experimental actor change directive.
|
|
915
|
+
*
|
|
916
|
+
* - data: The GraphQL response value for the actor change field.
|
|
917
|
+
* - dataID: The ID of the store object linked to by the actor change field.
|
|
918
|
+
* - node: NormalizationLinkedField, where the actor change directive is used
|
|
919
|
+
* - path: to a field in the response
|
|
920
|
+
* - variables: Query variables.
|
|
921
|
+
* - typeName: the type that matched.
|
|
922
|
+
*
|
|
923
|
+
* The dataID, variables, and fragmentName can be used to create a Selector
|
|
924
|
+
* which can in turn be used to normalize and publish the data. The dataID and
|
|
925
|
+
* typeName can also be used to construct a root record for normalization.
|
|
926
|
+
*/
|
|
927
|
+
export type ActorPayload = {|
|
|
928
|
+
+kind: 'ActorPayload',
|
|
929
|
+
+data: PayloadData,
|
|
930
|
+
+dataID: DataID,
|
|
931
|
+
+node: NormalizationLinkedField,
|
|
932
|
+
+path: $ReadOnlyArray<string>,
|
|
933
|
+
+typeName: string,
|
|
934
|
+
+variables: Variables,
|
|
935
|
+
+actorIdentifier: ActorIdentifier,
|
|
936
|
+
|};
|
|
937
|
+
|
|
938
|
+
/**
|
|
939
|
+
* Union type of possible payload followups we may handle during normalization.
|
|
940
|
+
*/
|
|
941
|
+
export type FollowupPayload = ModuleImportPayload | ActorPayload;
|
|
942
|
+
|
|
788
943
|
/**
|
|
789
944
|
* Data emitted after processing a Defer or Stream node during normalization
|
|
790
945
|
* that describes how to process the corresponding response chunk when it
|
|
@@ -797,6 +952,7 @@ export type DeferPlaceholder = {|
|
|
|
797
952
|
+path: $ReadOnlyArray<string>,
|
|
798
953
|
+selector: NormalizationSelector,
|
|
799
954
|
+typeName: string,
|
|
955
|
+
+actorIdentifier: ?ActorIdentifier,
|
|
800
956
|
|};
|
|
801
957
|
export type StreamPlaceholder = {|
|
|
802
958
|
+kind: 'stream',
|
|
@@ -805,6 +961,7 @@ export type StreamPlaceholder = {|
|
|
|
805
961
|
+parentID: DataID,
|
|
806
962
|
+node: NormalizationSelectableNode,
|
|
807
963
|
+variables: Variables,
|
|
964
|
+
+actorIdentifier: ?ActorIdentifier,
|
|
808
965
|
|};
|
|
809
966
|
export type IncrementalDataPlaceholder = DeferPlaceholder | StreamPlaceholder;
|
|
810
967
|
|
|
@@ -838,35 +995,33 @@ export type StoreUpdater = (store: RecordSourceProxy) => void;
|
|
|
838
995
|
* order to easily access the root fields of a query/mutation as well as a
|
|
839
996
|
* second argument of the response object of the mutation.
|
|
840
997
|
*/
|
|
841
|
-
export type SelectorStoreUpdater = (
|
|
998
|
+
export type SelectorStoreUpdater<-TMutationResponse> = (
|
|
842
999
|
store: RecordSourceSelectorProxy,
|
|
843
|
-
|
|
844
|
-
// product code.
|
|
845
|
-
data: $FlowFixMe,
|
|
1000
|
+
data: ?TMutationResponse,
|
|
846
1001
|
) => void;
|
|
847
1002
|
|
|
848
1003
|
/**
|
|
849
1004
|
* A set of configs that can be used to apply an optimistic update into the
|
|
850
1005
|
* store.
|
|
851
1006
|
*/
|
|
852
|
-
export type OptimisticUpdate =
|
|
1007
|
+
export type OptimisticUpdate<TMutation: MutationParameters> =
|
|
853
1008
|
| OptimisticUpdateFunction
|
|
854
|
-
| OptimisticUpdateRelayPayload
|
|
1009
|
+
| OptimisticUpdateRelayPayload<TMutation>;
|
|
855
1010
|
|
|
856
1011
|
export type OptimisticUpdateFunction = {|
|
|
857
1012
|
+storeUpdater: StoreUpdater,
|
|
858
1013
|
|};
|
|
859
1014
|
|
|
860
|
-
export type OptimisticUpdateRelayPayload = {|
|
|
1015
|
+
export type OptimisticUpdateRelayPayload<TMutation: MutationParameters> = {|
|
|
861
1016
|
+operation: OperationDescriptor,
|
|
862
1017
|
+payload: RelayResponsePayload,
|
|
863
|
-
+updater: ?SelectorStoreUpdater
|
|
1018
|
+
+updater: ?SelectorStoreUpdater<TMutation['response']>,
|
|
864
1019
|
|};
|
|
865
1020
|
|
|
866
|
-
export type OptimisticResponseConfig = {|
|
|
1021
|
+
export type OptimisticResponseConfig<TMutation: MutationParameters> = {|
|
|
867
1022
|
+operation: OperationDescriptor,
|
|
868
1023
|
+response: ?PayloadData,
|
|
869
|
-
+updater: ?SelectorStoreUpdater
|
|
1024
|
+
+updater: ?SelectorStoreUpdater<TMutation['response']>,
|
|
870
1025
|
|};
|
|
871
1026
|
|
|
872
1027
|
/**
|
|
@@ -926,7 +1081,7 @@ export type RelayResponsePayload = {|
|
|
|
926
1081
|
+errors: ?Array<PayloadError>,
|
|
927
1082
|
+fieldPayloads: ?Array<HandleFieldPayload>,
|
|
928
1083
|
+incrementalPlaceholders: ?Array<IncrementalDataPlaceholder>,
|
|
929
|
-
+
|
|
1084
|
+
+followupPayloads: ?Array<FollowupPayload>,
|
|
930
1085
|
+source: MutableRecordSource,
|
|
931
1086
|
+isFinal: boolean,
|
|
932
1087
|
|};
|
|
@@ -934,11 +1089,11 @@ export type RelayResponsePayload = {|
|
|
|
934
1089
|
/**
|
|
935
1090
|
* Configuration on the executeMutation(...).
|
|
936
1091
|
*/
|
|
937
|
-
export type ExecuteMutationConfig = {|
|
|
1092
|
+
export type ExecuteMutationConfig<TMutation: MutationParameters> = {|
|
|
938
1093
|
operation: OperationDescriptor,
|
|
939
|
-
optimisticUpdater?: ?SelectorStoreUpdater
|
|
1094
|
+
optimisticUpdater?: ?SelectorStoreUpdater<TMutation['response']>,
|
|
940
1095
|
optimisticResponse?: ?Object,
|
|
941
|
-
updater?: ?SelectorStoreUpdater
|
|
1096
|
+
updater?: ?SelectorStoreUpdater<TMutation['response']>,
|
|
942
1097
|
uploadables?: ?UploadableMap,
|
|
943
1098
|
|};
|
|
944
1099
|
|
|
@@ -949,12 +1104,16 @@ export interface PublishQueue {
|
|
|
949
1104
|
/**
|
|
950
1105
|
* Schedule applying an optimistic updates on the next `run()`.
|
|
951
1106
|
*/
|
|
952
|
-
applyUpdate
|
|
1107
|
+
applyUpdate<TMutation: MutationParameters>(
|
|
1108
|
+
updater: OptimisticUpdate<TMutation>,
|
|
1109
|
+
): void;
|
|
953
1110
|
|
|
954
1111
|
/**
|
|
955
1112
|
* Schedule reverting an optimistic updates on the next `run()`.
|
|
956
1113
|
*/
|
|
957
|
-
revertUpdate
|
|
1114
|
+
revertUpdate<TMutation: MutationParameters>(
|
|
1115
|
+
updater: OptimisticUpdate<TMutation>,
|
|
1116
|
+
): void;
|
|
958
1117
|
|
|
959
1118
|
/**
|
|
960
1119
|
* Schedule a revert of all optimistic updates on the next `run()`.
|
|
@@ -964,10 +1123,10 @@ export interface PublishQueue {
|
|
|
964
1123
|
/**
|
|
965
1124
|
* Schedule applying a payload to the store on the next `run()`.
|
|
966
1125
|
*/
|
|
967
|
-
commitPayload(
|
|
1126
|
+
commitPayload<TMutation: MutationParameters>(
|
|
968
1127
|
operation: OperationDescriptor,
|
|
969
1128
|
payload: RelayResponsePayload,
|
|
970
|
-
updater?: ?SelectorStoreUpdater
|
|
1129
|
+
updater?: ?SelectorStoreUpdater<TMutation['response']>,
|
|
971
1130
|
): void;
|
|
972
1131
|
|
|
973
1132
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright (c)
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
@@ -12,20 +12,23 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
const RelayConcreteNode = require('../util/RelayConcreteNode');
|
|
16
|
-
|
|
17
|
-
const getRelayHandleKey = require('../util/getRelayHandleKey');
|
|
18
|
-
const invariant = require('invariant');
|
|
19
|
-
const stableCopy = require('../util/stableCopy');
|
|
20
|
-
|
|
21
15
|
import type {
|
|
22
|
-
NormalizationHandle,
|
|
23
16
|
NormalizationArgument,
|
|
24
17
|
NormalizationField,
|
|
18
|
+
NormalizationHandle,
|
|
25
19
|
} from '../util/NormalizationNode';
|
|
26
|
-
import type {
|
|
20
|
+
import type {
|
|
21
|
+
ReaderActorChange,
|
|
22
|
+
ReaderArgument,
|
|
23
|
+
ReaderField,
|
|
24
|
+
} from '../util/ReaderNode';
|
|
27
25
|
import type {Variables} from '../util/RelayRuntimeTypes';
|
|
28
26
|
|
|
27
|
+
const getRelayHandleKey = require('../util/getRelayHandleKey');
|
|
28
|
+
const RelayConcreteNode = require('../util/RelayConcreteNode');
|
|
29
|
+
const stableCopy = require('../util/stableCopy');
|
|
30
|
+
const invariant = require('invariant');
|
|
31
|
+
|
|
29
32
|
export type Arguments = interface {+[string]: mixed};
|
|
30
33
|
|
|
31
34
|
const {VARIABLE, LITERAL, OBJECT_VALUE, LIST_VALUE} = RelayConcreteNode;
|
|
@@ -121,14 +124,19 @@ function getHandleStorageKey(
|
|
|
121
124
|
* used here for consistency.
|
|
122
125
|
*/
|
|
123
126
|
function getStorageKey(
|
|
124
|
-
field:
|
|
127
|
+
field:
|
|
128
|
+
| NormalizationField
|
|
129
|
+
| NormalizationHandle
|
|
130
|
+
| ReaderField
|
|
131
|
+
| ReaderActorChange,
|
|
125
132
|
variables: Variables,
|
|
126
133
|
): string {
|
|
127
134
|
if (field.storageKey) {
|
|
128
135
|
// TODO T23663664: Handle nodes do not yet define a static storageKey.
|
|
129
136
|
return (field: $FlowFixMe).storageKey;
|
|
130
137
|
}
|
|
131
|
-
const
|
|
138
|
+
const args = typeof field.args === 'undefined' ? undefined : field.args;
|
|
139
|
+
const name = field.name;
|
|
132
140
|
return args && args.length !== 0
|
|
133
141
|
? formatStorageKey(name, getArgumentValues(args, variables))
|
|
134
142
|
: name;
|
|
@@ -178,7 +186,6 @@ function getStableVariableValue(name: string, variables: Variables): mixed {
|
|
|
178
186
|
'getVariableValue(): Undefined variable `%s`.',
|
|
179
187
|
name,
|
|
180
188
|
);
|
|
181
|
-
// $FlowFixMe[cannot-write]
|
|
182
189
|
return stableCopy(variables[name]);
|
|
183
190
|
}
|
|
184
191
|
|
|
@@ -194,6 +201,8 @@ function getModuleOperationKey(documentName: string): string {
|
|
|
194
201
|
* Constants shared by all implementations of RecordSource/MutableRecordSource/etc.
|
|
195
202
|
*/
|
|
196
203
|
const RelayStoreUtils = {
|
|
204
|
+
ACTOR_IDENTIFIER_KEY: '__actorIdentifier',
|
|
205
|
+
CLIENT_EDGE_TRAVERSAL_PATH: '__clientEdgeTraversalPath',
|
|
197
206
|
FRAGMENTS_KEY: '__fragments',
|
|
198
207
|
FRAGMENT_OWNER_KEY: '__fragmentOwner',
|
|
199
208
|
FRAGMENT_PROP_NAME_KEY: '__fragmentPropName',
|
|
@@ -206,6 +215,10 @@ const RelayStoreUtils = {
|
|
|
206
215
|
TYPENAME_KEY: '__typename',
|
|
207
216
|
INVALIDATED_AT_KEY: '__invalidated_at',
|
|
208
217
|
IS_WITHIN_UNMATCHED_TYPE_REFINEMENT: '__isWithinUnmatchedTypeRefinement',
|
|
218
|
+
RELAY_RESOLVER_VALUE_KEY: '__resolverValue',
|
|
219
|
+
RELAY_RESOLVER_INVALIDATION_KEY: '__resolverValueMayBeInvalid',
|
|
220
|
+
RELAY_RESOLVER_INPUTS_KEY: '__resolverInputValues',
|
|
221
|
+
RELAY_RESOLVER_READER_SELECTOR_KEY: '__resolverReaderSelector',
|
|
209
222
|
|
|
210
223
|
formatStorageKey,
|
|
211
224
|
getArgumentValue,
|