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
|
@@ -12,18 +12,11 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
const RelayFeatureFlags = require('../util/RelayFeatureFlags');
|
|
16
|
-
const RelayReader = require('./RelayReader');
|
|
17
|
-
|
|
18
|
-
const deepFreeze = require('../util/deepFreeze');
|
|
19
|
-
const hasOverlappingIDs = require('./hasOverlappingIDs');
|
|
20
|
-
const recycleNodesInto = require('../util/recycleNodesInto');
|
|
21
|
-
|
|
22
15
|
import type {Disposable} from '../util/RelayRuntimeTypes';
|
|
23
16
|
import type {
|
|
17
|
+
DataIDSet,
|
|
24
18
|
LogFunction,
|
|
25
19
|
OperationDescriptor,
|
|
26
|
-
DataIDSet,
|
|
27
20
|
RecordSource,
|
|
28
21
|
RequestDescriptor,
|
|
29
22
|
Snapshot,
|
|
@@ -31,6 +24,12 @@ import type {
|
|
|
31
24
|
} from './RelayStoreTypes';
|
|
32
25
|
import type {ResolverCache} from './ResolverCache';
|
|
33
26
|
|
|
27
|
+
const deepFreeze = require('../util/deepFreeze');
|
|
28
|
+
const recycleNodesInto = require('../util/recycleNodesInto');
|
|
29
|
+
const RelayFeatureFlags = require('../util/RelayFeatureFlags');
|
|
30
|
+
const hasOverlappingIDs = require('./hasOverlappingIDs');
|
|
31
|
+
const RelayReader = require('./RelayReader');
|
|
32
|
+
|
|
34
33
|
type Subscription = {|
|
|
35
34
|
callback: (snapshot: Snapshot) => void,
|
|
36
35
|
snapshot: Snapshot,
|
|
@@ -102,6 +101,7 @@ class RelayStoreSubscriptions implements StoreSubscriptions {
|
|
|
102
101
|
subscription.snapshot = {
|
|
103
102
|
data: subscription.snapshot.data,
|
|
104
103
|
isMissingData: backup.isMissingData,
|
|
104
|
+
missingClientEdges: backup.missingClientEdges,
|
|
105
105
|
seenRecords: backup.seenRecords,
|
|
106
106
|
selector: backup.selector,
|
|
107
107
|
missingRequiredFields: backup.missingRequiredFields,
|
|
@@ -163,6 +163,7 @@ class RelayStoreSubscriptions implements StoreSubscriptions {
|
|
|
163
163
|
nextSnapshot = ({
|
|
164
164
|
data: nextData,
|
|
165
165
|
isMissingData: nextSnapshot.isMissingData,
|
|
166
|
+
missingClientEdges: nextSnapshot.missingClientEdges,
|
|
166
167
|
seenRecords: nextSnapshot.seenRecords,
|
|
167
168
|
selector: nextSnapshot.selector,
|
|
168
169
|
missingRequiredFields: nextSnapshot.missingRequiredFields,
|
|
@@ -21,19 +21,21 @@ import type {
|
|
|
21
21
|
INetwork,
|
|
22
22
|
PayloadData,
|
|
23
23
|
PayloadError,
|
|
24
|
-
ReactFlightServerTree,
|
|
25
24
|
ReactFlightServerError,
|
|
25
|
+
ReactFlightServerTree,
|
|
26
26
|
UploadableMap,
|
|
27
27
|
} from '../network/RelayNetworkTypes';
|
|
28
28
|
import type RelayObservable from '../network/RelayObservable';
|
|
29
|
+
import type {GraphQLTaggedNode} from '../query/GraphQLTag';
|
|
30
|
+
import type {RequestIdentifier} from '../util/getRequestIdentifier';
|
|
29
31
|
import type {
|
|
32
|
+
NormalizationArgument,
|
|
30
33
|
NormalizationLinkedField,
|
|
31
34
|
NormalizationRootNode,
|
|
32
35
|
NormalizationScalarField,
|
|
33
36
|
NormalizationSelectableNode,
|
|
34
|
-
NormalizationArgument,
|
|
35
37
|
} from '../util/NormalizationNode';
|
|
36
|
-
import type {ReaderFragment} from '../util/ReaderNode';
|
|
38
|
+
import type {ReaderClientEdge, ReaderFragment} from '../util/ReaderNode';
|
|
37
39
|
import type {
|
|
38
40
|
ConcreteRequest,
|
|
39
41
|
RequestParameters,
|
|
@@ -42,17 +44,23 @@ import type {
|
|
|
42
44
|
CacheConfig,
|
|
43
45
|
DataID,
|
|
44
46
|
Disposable,
|
|
47
|
+
OperationType,
|
|
45
48
|
RenderPolicy,
|
|
46
49
|
Variables,
|
|
47
50
|
} from '../util/RelayRuntimeTypes';
|
|
48
|
-
import type {RequestIdentifier} from '../util/getRequestIdentifier';
|
|
49
51
|
import type {InvalidationState} from './RelayModernStore';
|
|
50
52
|
import type RelayOperationTracker from './RelayOperationTracker';
|
|
51
53
|
import type {RecordState} from './RelayRecordState';
|
|
52
54
|
|
|
53
|
-
export opaque type
|
|
55
|
+
export opaque type FragmentType = empty;
|
|
54
56
|
export type OperationTracker = RelayOperationTracker;
|
|
55
57
|
|
|
58
|
+
export type MutationParameters = {|
|
|
59
|
+
+response: {...},
|
|
60
|
+
+variables: interface {},
|
|
61
|
+
+rawResponse?: {...},
|
|
62
|
+
|};
|
|
63
|
+
|
|
56
64
|
/*
|
|
57
65
|
* An individual cached graph object.
|
|
58
66
|
*/
|
|
@@ -74,6 +82,7 @@ export type SingularReaderSelector = {|
|
|
|
74
82
|
+kind: 'SingularReaderSelector',
|
|
75
83
|
+dataID: DataID,
|
|
76
84
|
+isWithinUnmatchedTypeRefinement: boolean,
|
|
85
|
+
+clientEdgeTraversalPath: ClientEdgeTraversalPath | null,
|
|
77
86
|
+node: ReaderFragment,
|
|
78
87
|
+owner: RequestDescriptor,
|
|
79
88
|
+variables: Variables,
|
|
@@ -112,12 +121,26 @@ export type MissingRequiredFields =
|
|
|
112
121
|
| {|action: 'THROW', field: MissingRequiredField|}
|
|
113
122
|
| {|action: 'LOG', fields: Array<MissingRequiredField>|};
|
|
114
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
|
+
|
|
115
137
|
/**
|
|
116
138
|
* A representation of a selector and its results at a particular point in time.
|
|
117
139
|
*/
|
|
118
140
|
export type Snapshot = {|
|
|
119
141
|
+data: ?SelectorData,
|
|
120
142
|
+isMissingData: boolean,
|
|
143
|
+
+missingClientEdges: null | $ReadOnlyArray<MissingClientEdgeRequestInfo>,
|
|
121
144
|
+seenRecords: DataIDSet,
|
|
122
145
|
+selector: SingularReaderSelector,
|
|
123
146
|
+missingRequiredFields: ?MissingRequiredFields,
|
|
@@ -442,6 +465,10 @@ export interface RecordSourceProxy {
|
|
|
442
465
|
get(dataID: DataID): ?RecordProxy;
|
|
443
466
|
getRoot(): RecordProxy;
|
|
444
467
|
invalidateStore(): void;
|
|
468
|
+
readUpdatableQuery_EXPERIMENTAL<TQuery: OperationType>(
|
|
469
|
+
query: GraphQLTaggedNode,
|
|
470
|
+
variables: TQuery['variables'],
|
|
471
|
+
): TQuery['response'];
|
|
445
472
|
}
|
|
446
473
|
|
|
447
474
|
export interface ReadOnlyRecordSourceProxy {
|
|
@@ -667,7 +694,9 @@ export interface IEnvironment {
|
|
|
667
694
|
* Apply an optimistic mutation response and/or updater. The mutation can be
|
|
668
695
|
* reverted by calling `dispose()` on the returned value.
|
|
669
696
|
*/
|
|
670
|
-
applyMutation
|
|
697
|
+
applyMutation<TMutation: MutationParameters>(
|
|
698
|
+
optimisticConfig: OptimisticResponseConfig<TMutation>,
|
|
699
|
+
): Disposable;
|
|
671
700
|
|
|
672
701
|
/**
|
|
673
702
|
* Commit an updater to the environment. This mutation cannot be reverted and
|
|
@@ -716,15 +745,27 @@ export interface IEnvironment {
|
|
|
716
745
|
* responses may be returned (via `next`) over time followed by either
|
|
717
746
|
* the request completing (`completed`) or an error (`error`).
|
|
718
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
|
+
*
|
|
719
760
|
* Networks/servers that support subscriptions may choose to hold the
|
|
720
761
|
* subscription open indefinitely such that `complete` is not called.
|
|
721
762
|
*
|
|
722
763
|
* Note: Observables are lazy, so calling this method will do nothing until
|
|
723
|
-
* the result is subscribed to: environment.
|
|
764
|
+
* the result is subscribed to: environment.executeSubscription({...}).subscribe({...}).
|
|
724
765
|
*/
|
|
725
|
-
|
|
766
|
+
executeSubscription<TMutation: MutationParameters>(config: {|
|
|
726
767
|
operation: OperationDescriptor,
|
|
727
|
-
updater?: ?SelectorStoreUpdater
|
|
768
|
+
updater?: ?SelectorStoreUpdater<TMutation['response']>,
|
|
728
769
|
|}): RelayObservable<GraphQLResponse>;
|
|
729
770
|
|
|
730
771
|
/**
|
|
@@ -737,8 +778,8 @@ export interface IEnvironment {
|
|
|
737
778
|
* the result is subscribed to:
|
|
738
779
|
* environment.executeMutation({...}).subscribe({...}).
|
|
739
780
|
*/
|
|
740
|
-
executeMutation(
|
|
741
|
-
config: ExecuteMutationConfig
|
|
781
|
+
executeMutation<TMutation: MutationParameters>(
|
|
782
|
+
config: ExecuteMutationConfig<TMutation>,
|
|
742
783
|
): RelayObservable<GraphQLResponse>;
|
|
743
784
|
|
|
744
785
|
/**
|
|
@@ -785,7 +826,7 @@ export interface IEnvironment {
|
|
|
785
826
|
export type ModuleImportPointer = {
|
|
786
827
|
+__fragmentPropName: ?string,
|
|
787
828
|
+__module_component: mixed,
|
|
788
|
-
+$
|
|
829
|
+
+$fragmentSpreads: mixed,
|
|
789
830
|
...
|
|
790
831
|
};
|
|
791
832
|
|
|
@@ -954,35 +995,33 @@ export type StoreUpdater = (store: RecordSourceProxy) => void;
|
|
|
954
995
|
* order to easily access the root fields of a query/mutation as well as a
|
|
955
996
|
* second argument of the response object of the mutation.
|
|
956
997
|
*/
|
|
957
|
-
export type SelectorStoreUpdater = (
|
|
998
|
+
export type SelectorStoreUpdater<-TMutationResponse> = (
|
|
958
999
|
store: RecordSourceSelectorProxy,
|
|
959
|
-
|
|
960
|
-
// product code.
|
|
961
|
-
data: $FlowFixMe,
|
|
1000
|
+
data: ?TMutationResponse,
|
|
962
1001
|
) => void;
|
|
963
1002
|
|
|
964
1003
|
/**
|
|
965
1004
|
* A set of configs that can be used to apply an optimistic update into the
|
|
966
1005
|
* store.
|
|
967
1006
|
*/
|
|
968
|
-
export type OptimisticUpdate =
|
|
1007
|
+
export type OptimisticUpdate<TMutation: MutationParameters> =
|
|
969
1008
|
| OptimisticUpdateFunction
|
|
970
|
-
| OptimisticUpdateRelayPayload
|
|
1009
|
+
| OptimisticUpdateRelayPayload<TMutation>;
|
|
971
1010
|
|
|
972
1011
|
export type OptimisticUpdateFunction = {|
|
|
973
1012
|
+storeUpdater: StoreUpdater,
|
|
974
1013
|
|};
|
|
975
1014
|
|
|
976
|
-
export type OptimisticUpdateRelayPayload = {|
|
|
1015
|
+
export type OptimisticUpdateRelayPayload<TMutation: MutationParameters> = {|
|
|
977
1016
|
+operation: OperationDescriptor,
|
|
978
1017
|
+payload: RelayResponsePayload,
|
|
979
|
-
+updater: ?SelectorStoreUpdater
|
|
1018
|
+
+updater: ?SelectorStoreUpdater<TMutation['response']>,
|
|
980
1019
|
|};
|
|
981
1020
|
|
|
982
|
-
export type OptimisticResponseConfig = {|
|
|
1021
|
+
export type OptimisticResponseConfig<TMutation: MutationParameters> = {|
|
|
983
1022
|
+operation: OperationDescriptor,
|
|
984
1023
|
+response: ?PayloadData,
|
|
985
|
-
+updater: ?SelectorStoreUpdater
|
|
1024
|
+
+updater: ?SelectorStoreUpdater<TMutation['response']>,
|
|
986
1025
|
|};
|
|
987
1026
|
|
|
988
1027
|
/**
|
|
@@ -1050,11 +1089,11 @@ export type RelayResponsePayload = {|
|
|
|
1050
1089
|
/**
|
|
1051
1090
|
* Configuration on the executeMutation(...).
|
|
1052
1091
|
*/
|
|
1053
|
-
export type ExecuteMutationConfig = {|
|
|
1092
|
+
export type ExecuteMutationConfig<TMutation: MutationParameters> = {|
|
|
1054
1093
|
operation: OperationDescriptor,
|
|
1055
|
-
optimisticUpdater?: ?SelectorStoreUpdater
|
|
1094
|
+
optimisticUpdater?: ?SelectorStoreUpdater<TMutation['response']>,
|
|
1056
1095
|
optimisticResponse?: ?Object,
|
|
1057
|
-
updater?: ?SelectorStoreUpdater
|
|
1096
|
+
updater?: ?SelectorStoreUpdater<TMutation['response']>,
|
|
1058
1097
|
uploadables?: ?UploadableMap,
|
|
1059
1098
|
|};
|
|
1060
1099
|
|
|
@@ -1065,12 +1104,16 @@ export interface PublishQueue {
|
|
|
1065
1104
|
/**
|
|
1066
1105
|
* Schedule applying an optimistic updates on the next `run()`.
|
|
1067
1106
|
*/
|
|
1068
|
-
applyUpdate
|
|
1107
|
+
applyUpdate<TMutation: MutationParameters>(
|
|
1108
|
+
updater: OptimisticUpdate<TMutation>,
|
|
1109
|
+
): void;
|
|
1069
1110
|
|
|
1070
1111
|
/**
|
|
1071
1112
|
* Schedule reverting an optimistic updates on the next `run()`.
|
|
1072
1113
|
*/
|
|
1073
|
-
revertUpdate
|
|
1114
|
+
revertUpdate<TMutation: MutationParameters>(
|
|
1115
|
+
updater: OptimisticUpdate<TMutation>,
|
|
1116
|
+
): void;
|
|
1074
1117
|
|
|
1075
1118
|
/**
|
|
1076
1119
|
* Schedule a revert of all optimistic updates on the next `run()`.
|
|
@@ -1080,10 +1123,10 @@ export interface PublishQueue {
|
|
|
1080
1123
|
/**
|
|
1081
1124
|
* Schedule applying a payload to the store on the next `run()`.
|
|
1082
1125
|
*/
|
|
1083
|
-
commitPayload(
|
|
1126
|
+
commitPayload<TMutation: MutationParameters>(
|
|
1084
1127
|
operation: OperationDescriptor,
|
|
1085
1128
|
payload: RelayResponsePayload,
|
|
1086
|
-
updater?: ?SelectorStoreUpdater
|
|
1129
|
+
updater?: ?SelectorStoreUpdater<TMutation['response']>,
|
|
1087
1130
|
): void;
|
|
1088
1131
|
|
|
1089
1132
|
/**
|
|
@@ -12,24 +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
20
|
import type {
|
|
21
|
+
ReaderActorChange,
|
|
27
22
|
ReaderArgument,
|
|
28
23
|
ReaderField,
|
|
29
|
-
ReaderActorChange,
|
|
30
24
|
} from '../util/ReaderNode';
|
|
31
25
|
import type {Variables} from '../util/RelayRuntimeTypes';
|
|
32
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
|
+
|
|
33
32
|
export type Arguments = interface {+[string]: mixed};
|
|
34
33
|
|
|
35
34
|
const {VARIABLE, LITERAL, OBJECT_VALUE, LIST_VALUE} = RelayConcreteNode;
|
|
@@ -187,7 +186,6 @@ function getStableVariableValue(name: string, variables: Variables): mixed {
|
|
|
187
186
|
'getVariableValue(): Undefined variable `%s`.',
|
|
188
187
|
name,
|
|
189
188
|
);
|
|
190
|
-
// $FlowFixMe[cannot-write]
|
|
191
189
|
return stableCopy(variables[name]);
|
|
192
190
|
}
|
|
193
191
|
|
|
@@ -204,6 +202,7 @@ function getModuleOperationKey(documentName: string): string {
|
|
|
204
202
|
*/
|
|
205
203
|
const RelayStoreUtils = {
|
|
206
204
|
ACTOR_IDENTIFIER_KEY: '__actorIdentifier',
|
|
205
|
+
CLIENT_EDGE_TRAVERSAL_PATH: '__clientEdgeTraversalPath',
|
|
207
206
|
FRAGMENTS_KEY: '__fragments',
|
|
208
207
|
FRAGMENT_OWNER_KEY: '__fragmentOwner',
|
|
209
208
|
FRAGMENT_PROP_NAME_KEY: '__fragmentPropName',
|
|
@@ -12,27 +12,25 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
import type {ReaderRelayResolver} from '../util/ReaderNode';
|
|
16
|
+
import type {DataID, Variables} from '../util/RelayRuntimeTypes';
|
|
17
|
+
import type {
|
|
18
|
+
MutableRecordSource,
|
|
19
|
+
Record,
|
|
20
|
+
SingularReaderSelector,
|
|
21
|
+
} from './RelayStoreTypes';
|
|
16
22
|
|
|
17
23
|
const recycleNodesInto = require('../util/recycleNodesInto');
|
|
18
|
-
const warning = require('warning');
|
|
19
|
-
|
|
20
24
|
const {generateClientID} = require('./ClientID');
|
|
25
|
+
const RelayModernRecord = require('./RelayModernRecord');
|
|
21
26
|
const {
|
|
22
|
-
RELAY_RESOLVER_VALUE_KEY,
|
|
23
|
-
RELAY_RESOLVER_INVALIDATION_KEY,
|
|
24
27
|
RELAY_RESOLVER_INPUTS_KEY,
|
|
28
|
+
RELAY_RESOLVER_INVALIDATION_KEY,
|
|
25
29
|
RELAY_RESOLVER_READER_SELECTOR_KEY,
|
|
30
|
+
RELAY_RESOLVER_VALUE_KEY,
|
|
26
31
|
getStorageKey,
|
|
27
32
|
} = require('./RelayStoreUtils');
|
|
28
|
-
|
|
29
|
-
import type {ReaderRelayResolver} from '../util/ReaderNode';
|
|
30
|
-
import type {DataID, Variables} from '../util/RelayRuntimeTypes';
|
|
31
|
-
import type {
|
|
32
|
-
MutableRecordSource,
|
|
33
|
-
Record,
|
|
34
|
-
SingularReaderSelector,
|
|
35
|
-
} from './RelayStoreTypes';
|
|
33
|
+
const warning = require('warning');
|
|
36
34
|
|
|
37
35
|
type ResolverID = string;
|
|
38
36
|
|
|
@@ -73,7 +71,11 @@ class NoopResolverCache implements ResolverCache {
|
|
|
73
71
|
invalidateDataIDs(updatedDataIDs: Set<DataID>): void {}
|
|
74
72
|
}
|
|
75
73
|
|
|
76
|
-
function addDependencyEdge(
|
|
74
|
+
function addDependencyEdge(
|
|
75
|
+
edges: Map<ResolverID, Set<DataID>> | Map<DataID, Set<ResolverID>>,
|
|
76
|
+
from: ResolverID | DataID,
|
|
77
|
+
to: ResolverID | DataID,
|
|
78
|
+
): void {
|
|
77
79
|
let set = edges.get(from);
|
|
78
80
|
if (!set) {
|
|
79
81
|
set = new Set();
|
|
@@ -12,26 +12,19 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
import type {GraphQLTaggedNode} from '../query/GraphQLTag';
|
|
16
|
+
import type {FragmentType, SingularReaderSelector} from './RelayStoreTypes';
|
|
16
17
|
|
|
17
18
|
const {getFragment} = require('../query/GraphQLTag');
|
|
18
19
|
const {getSelector} = require('./RelayModernSelector');
|
|
19
|
-
|
|
20
|
-
import type {GraphQLTaggedNode} from '../query/GraphQLTag';
|
|
21
|
-
import type {
|
|
22
|
-
FragmentReference,
|
|
23
|
-
SingularReaderSelector,
|
|
24
|
-
} from './RelayStoreTypes';
|
|
20
|
+
const invariant = require('invariant');
|
|
25
21
|
|
|
26
22
|
// When we call the user-supplied resolver function, it will in turn call
|
|
27
23
|
// `readFragment`, but that's a global function -- it needs information
|
|
28
24
|
// about what resolver is being executed, which is supplied by putting the
|
|
29
25
|
// info on this stack before we call the resolver function.
|
|
30
26
|
type ResolverContext = {|
|
|
31
|
-
getDataForResolverFragment: (
|
|
32
|
-
SingularReaderSelector,
|
|
33
|
-
FragmentReference,
|
|
34
|
-
) => mixed,
|
|
27
|
+
getDataForResolverFragment: (SingularReaderSelector, FragmentType) => mixed,
|
|
35
28
|
|};
|
|
36
29
|
const contextStack: Array<ResolverContext> = [];
|
|
37
30
|
|
|
@@ -54,17 +47,17 @@ function withResolverContext<T>(context: ResolverContext, cb: () => T): T {
|
|
|
54
47
|
// - array of nullable if the privoided ref type is an array of nullable refs
|
|
55
48
|
|
|
56
49
|
declare function readFragment<
|
|
57
|
-
TKey: {+$data?: mixed, +$
|
|
50
|
+
TKey: {+$data?: mixed, +$fragmentSpreads: FragmentType, ...},
|
|
58
51
|
>(
|
|
59
52
|
fragmentInput: GraphQLTaggedNode,
|
|
60
|
-
|
|
53
|
+
fragmentKey: TKey,
|
|
61
54
|
): $Call<<TFragmentData>({+$data?: TFragmentData, ...}) => TFragmentData, TKey>;
|
|
62
55
|
|
|
63
56
|
declare function readFragment<
|
|
64
|
-
TKey: ?{+$data?: mixed, +$
|
|
57
|
+
TKey: ?{+$data?: mixed, +$fragmentSpreads: FragmentType, ...},
|
|
65
58
|
>(
|
|
66
59
|
fragmentInput: GraphQLTaggedNode,
|
|
67
|
-
|
|
60
|
+
fragmentKey: TKey,
|
|
68
61
|
): $Call<
|
|
69
62
|
<TFragmentData>(?{+$data?: TFragmentData, ...}) => ?TFragmentData,
|
|
70
63
|
TKey,
|
|
@@ -73,12 +66,12 @@ declare function readFragment<
|
|
|
73
66
|
declare function readFragment<
|
|
74
67
|
TKey: $ReadOnlyArray<{
|
|
75
68
|
+$data?: mixed,
|
|
76
|
-
+$
|
|
69
|
+
+$fragmentSpreads: FragmentType,
|
|
77
70
|
...
|
|
78
71
|
}>,
|
|
79
72
|
>(
|
|
80
73
|
fragmentInput: GraphQLTaggedNode,
|
|
81
|
-
|
|
74
|
+
fragmentKey: TKey,
|
|
82
75
|
): $Call<
|
|
83
76
|
<TFragmentData>(
|
|
84
77
|
$ReadOnlyArray<{+$data?: TFragmentData, ...}>,
|
|
@@ -89,12 +82,12 @@ declare function readFragment<
|
|
|
89
82
|
declare function readFragment<
|
|
90
83
|
TKey: ?$ReadOnlyArray<{
|
|
91
84
|
+$data?: mixed,
|
|
92
|
-
+$
|
|
85
|
+
+$fragmentSpreads: FragmentType,
|
|
93
86
|
...
|
|
94
87
|
}>,
|
|
95
88
|
>(
|
|
96
89
|
fragmentInput: GraphQLTaggedNode,
|
|
97
|
-
|
|
90
|
+
fragmentKey: TKey,
|
|
98
91
|
): $Call<
|
|
99
92
|
<TFragmentData>(
|
|
100
93
|
?$ReadOnlyArray<{+$data?: TFragmentData, ...}>,
|
|
@@ -104,7 +97,7 @@ declare function readFragment<
|
|
|
104
97
|
|
|
105
98
|
function readFragment(
|
|
106
99
|
fragmentInput: GraphQLTaggedNode,
|
|
107
|
-
|
|
100
|
+
fragmentKey: FragmentType,
|
|
108
101
|
): mixed {
|
|
109
102
|
if (!contextStack.length) {
|
|
110
103
|
throw new Error(
|
|
@@ -113,7 +106,7 @@ function readFragment(
|
|
|
113
106
|
}
|
|
114
107
|
const context = contextStack[contextStack.length - 1];
|
|
115
108
|
const fragmentNode = getFragment(fragmentInput);
|
|
116
|
-
const fragmentSelector = getSelector(fragmentNode,
|
|
109
|
+
const fragmentSelector = getSelector(fragmentNode, fragmentKey);
|
|
117
110
|
invariant(
|
|
118
111
|
fragmentSelector != null,
|
|
119
112
|
`Expected a selector for the fragment of the resolver ${fragmentNode.name}, but got null.`,
|
|
@@ -122,7 +115,7 @@ function readFragment(
|
|
|
122
115
|
fragmentSelector.kind === 'SingularReaderSelector',
|
|
123
116
|
`Expected a singular reader selector for the fragment of the resolver ${fragmentNode.name}, but it was plural.`,
|
|
124
117
|
);
|
|
125
|
-
return context.getDataForResolverFragment(fragmentSelector,
|
|
118
|
+
return context.getDataForResolverFragment(fragmentSelector, fragmentKey);
|
|
126
119
|
}
|
|
127
120
|
|
|
128
121
|
module.exports = {readFragment, withResolverContext};
|
|
@@ -56,7 +56,7 @@ if (__DEV__) {
|
|
|
56
56
|
const keyStyle = {style: 'rgb(136, 19, 145)'};
|
|
57
57
|
const nullStyle = {style: 'color: #777'};
|
|
58
58
|
|
|
59
|
-
const reference = (object, config) => {
|
|
59
|
+
const reference = (object, config: void) => {
|
|
60
60
|
return object == null
|
|
61
61
|
? ['span', nullStyle, 'undefined']
|
|
62
62
|
: ['object', {object, config}];
|
|
@@ -100,7 +100,7 @@ if (__DEV__) {
|
|
|
100
100
|
}
|
|
101
101
|
return renderRecordHeader(obj);
|
|
102
102
|
},
|
|
103
|
-
hasBody(obj) {
|
|
103
|
+
hasBody(obj: $FlowFixMe) {
|
|
104
104
|
return true;
|
|
105
105
|
},
|
|
106
106
|
body(obj) {
|
package/store/TypeID.js.flow
CHANGED
|
@@ -12,11 +12,11 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
+
import type {DataID} from '../util/RelayRuntimeTypes';
|
|
16
|
+
|
|
15
17
|
const {generateClientID} = require('./ClientID');
|
|
16
18
|
const {ROOT_ID} = require('./RelayStoreUtils');
|
|
17
19
|
|
|
18
|
-
import type {DataID} from 'relay-runtime/util/RelayRuntimeTypes';
|
|
19
|
-
|
|
20
20
|
const VIEWER_ID: DataID = generateClientID(ROOT_ID, 'viewer');
|
|
21
21
|
const VIEWER_TYPE = 'Viewer';
|
|
22
22
|
|
|
@@ -12,12 +12,6 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
const areEqual = require('areEqual');
|
|
16
|
-
const invariant = require('invariant');
|
|
17
|
-
|
|
18
|
-
const {LINKED_FIELD} = require('../util/RelayConcreteNode');
|
|
19
|
-
const {getHandleStorageKey} = require('./RelayStoreUtils');
|
|
20
|
-
|
|
21
15
|
import type {
|
|
22
16
|
NormalizationLinkedField,
|
|
23
17
|
NormalizationSelection,
|
|
@@ -25,6 +19,11 @@ import type {
|
|
|
25
19
|
import type {NormalizationLinkedHandle} from '../util/NormalizationNode';
|
|
26
20
|
import type {Variables} from '../util/RelayRuntimeTypes';
|
|
27
21
|
|
|
22
|
+
const {LINKED_FIELD} = require('../util/RelayConcreteNode');
|
|
23
|
+
const {getHandleStorageKey} = require('./RelayStoreUtils');
|
|
24
|
+
const areEqual = require('areEqual');
|
|
25
|
+
const invariant = require('invariant');
|
|
26
|
+
|
|
28
27
|
/**
|
|
29
28
|
* @private
|
|
30
29
|
*
|
|
@@ -12,12 +12,6 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
const areEqual = require('areEqual');
|
|
16
|
-
const invariant = require('invariant');
|
|
17
|
-
|
|
18
|
-
const {SCALAR_FIELD} = require('../util/RelayConcreteNode');
|
|
19
|
-
const {getHandleStorageKey} = require('./RelayStoreUtils');
|
|
20
|
-
|
|
21
15
|
import type {
|
|
22
16
|
NormalizationScalarField,
|
|
23
17
|
NormalizationSelection,
|
|
@@ -25,6 +19,11 @@ import type {
|
|
|
25
19
|
import type {NormalizationScalarHandle} from '../util/NormalizationNode';
|
|
26
20
|
import type {Variables} from '../util/RelayRuntimeTypes';
|
|
27
21
|
|
|
22
|
+
const {SCALAR_FIELD} = require('../util/RelayConcreteNode');
|
|
23
|
+
const {getHandleStorageKey} = require('./RelayStoreUtils');
|
|
24
|
+
const areEqual = require('areEqual');
|
|
25
|
+
const invariant = require('invariant');
|
|
26
|
+
|
|
28
27
|
/**
|
|
29
28
|
* @private
|
|
30
29
|
*
|
|
@@ -12,10 +12,6 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
const RelayModernFragmentSpecResolver = require('./RelayModernFragmentSpecResolver');
|
|
16
|
-
|
|
17
|
-
const warning = require('warning');
|
|
18
|
-
|
|
19
15
|
import type {
|
|
20
16
|
FragmentMap,
|
|
21
17
|
FragmentSpecResolver,
|
|
@@ -23,6 +19,9 @@ import type {
|
|
|
23
19
|
RelayContext,
|
|
24
20
|
} from './RelayStoreTypes';
|
|
25
21
|
|
|
22
|
+
const RelayModernFragmentSpecResolver = require('./RelayModernFragmentSpecResolver');
|
|
23
|
+
const warning = require('warning');
|
|
24
|
+
|
|
26
25
|
function createFragmentSpecResolver(
|
|
27
26
|
context: RelayContext,
|
|
28
27
|
containerName: string,
|
|
@@ -12,11 +12,11 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
const invariant = require('invariant');
|
|
16
|
-
|
|
17
15
|
import type {RelayContext} from './RelayStoreTypes.js';
|
|
18
16
|
import typeof {createContext} from 'react';
|
|
19
17
|
|
|
18
|
+
const invariant = require('invariant');
|
|
19
|
+
|
|
20
20
|
// Ideally, we'd just import the type of the react module, but this causes Flow
|
|
21
21
|
// problems.
|
|
22
22
|
type React = {
|
|
@@ -12,19 +12,18 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
const RelayModernRecord = require('./RelayModernRecord');
|
|
16
|
-
const RelayRecordSource = require('./RelayRecordSource');
|
|
17
|
-
const RelayResponseNormalizer = require('./RelayResponseNormalizer');
|
|
18
|
-
|
|
19
|
-
const {ROOT_TYPE} = require('./RelayStoreUtils');
|
|
20
|
-
|
|
21
15
|
import type {PayloadData, PayloadError} from '../network/RelayNetworkTypes';
|
|
22
16
|
import type {NormalizationOptions} from './RelayResponseNormalizer';
|
|
23
17
|
import type {
|
|
24
|
-
RelayResponsePayload,
|
|
25
18
|
NormalizationSelector,
|
|
19
|
+
RelayResponsePayload,
|
|
26
20
|
} from './RelayStoreTypes';
|
|
27
21
|
|
|
22
|
+
const RelayModernRecord = require('./RelayModernRecord');
|
|
23
|
+
const RelayRecordSource = require('./RelayRecordSource');
|
|
24
|
+
const RelayResponseNormalizer = require('./RelayResponseNormalizer');
|
|
25
|
+
const {ROOT_TYPE} = require('./RelayStoreUtils');
|
|
26
|
+
|
|
28
27
|
function normalizeRelayPayload(
|
|
29
28
|
selector: NormalizationSelector,
|
|
30
29
|
payload: PayloadData,
|