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,26 +12,25 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
const deepFreeze = require('../util/deepFreeze');
|
|
16
|
-
const getRequestIdentifier = require('../util/getRequestIdentifier');
|
|
17
|
-
|
|
18
|
-
const {getOperationVariables} = require('./RelayConcreteVariables');
|
|
19
|
-
const {
|
|
20
|
-
createNormalizationSelector,
|
|
21
|
-
createReaderSelector,
|
|
22
|
-
} = require('./RelayModernSelector');
|
|
23
|
-
const {ROOT_ID} = require('./RelayStoreUtils');
|
|
24
|
-
|
|
25
15
|
import type {ConcreteRequest} from '../util/RelayConcreteNode';
|
|
26
16
|
import type {
|
|
27
17
|
CacheConfig,
|
|
28
18
|
DataID,
|
|
19
|
+
OperationType,
|
|
29
20
|
Variables,
|
|
30
21
|
VariablesOf,
|
|
31
|
-
OperationType,
|
|
32
22
|
} from '../util/RelayRuntimeTypes';
|
|
33
23
|
import type {OperationDescriptor, RequestDescriptor} from './RelayStoreTypes';
|
|
34
24
|
|
|
25
|
+
const deepFreeze = require('../util/deepFreeze');
|
|
26
|
+
const getRequestIdentifier = require('../util/getRequestIdentifier');
|
|
27
|
+
const {getOperationVariables} = require('./RelayConcreteVariables');
|
|
28
|
+
const {
|
|
29
|
+
createNormalizationSelector,
|
|
30
|
+
createReaderSelector,
|
|
31
|
+
} = require('./RelayModernSelector');
|
|
32
|
+
const {ROOT_ID} = require('./RelayStoreUtils');
|
|
33
|
+
|
|
35
34
|
/**
|
|
36
35
|
* Creates an instance of the `OperationDescriptor` type defined in
|
|
37
36
|
* `RelayStoreTypes` given an operation and some variables. The input variables
|
|
@@ -12,25 +12,24 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const warning = require('warning');
|
|
15
|
+
import type {ActorIdentifier} from '../multi-actor-environment/ActorIdentifier';
|
|
16
|
+
import type {DataID} from '../util/RelayRuntimeTypes';
|
|
17
|
+
import type {Record} from './RelayStoreTypes';
|
|
19
18
|
|
|
19
|
+
const deepFreeze = require('../util/deepFreeze');
|
|
20
20
|
const {isClientID} = require('./ClientID');
|
|
21
21
|
const {
|
|
22
22
|
ACTOR_IDENTIFIER_KEY,
|
|
23
23
|
ID_KEY,
|
|
24
|
+
INVALIDATED_AT_KEY,
|
|
24
25
|
REF_KEY,
|
|
25
26
|
REFS_KEY,
|
|
26
|
-
TYPENAME_KEY,
|
|
27
|
-
INVALIDATED_AT_KEY,
|
|
28
27
|
ROOT_ID,
|
|
28
|
+
TYPENAME_KEY,
|
|
29
29
|
} = require('./RelayStoreUtils');
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
import type {Record} from './RelayStoreTypes';
|
|
30
|
+
const areEqual = require('areEqual');
|
|
31
|
+
const invariant = require('invariant');
|
|
32
|
+
const warning = require('warning');
|
|
34
33
|
|
|
35
34
|
/**
|
|
36
35
|
* @public
|
|
@@ -174,10 +173,14 @@ function getLinkedRecordID(record: Record, storageKey: string): ?DataID {
|
|
|
174
173
|
invariant(
|
|
175
174
|
typeof link === 'object' && link && typeof link[REF_KEY] === 'string',
|
|
176
175
|
'RelayModernRecord.getLinkedRecordID(): Expected `%s.%s` to be a linked ID, ' +
|
|
177
|
-
'was `%s
|
|
176
|
+
'was `%s`.%s',
|
|
178
177
|
record[ID_KEY],
|
|
179
178
|
storageKey,
|
|
180
179
|
JSON.stringify(link),
|
|
180
|
+
typeof link === 'object' && link[REFS_KEY] !== undefined
|
|
181
|
+
? ' It appears to be a plural linked record: did you mean to call ' +
|
|
182
|
+
'getLinkedRecords() instead of getLinkedRecord()?'
|
|
183
|
+
: '',
|
|
181
184
|
);
|
|
182
185
|
return link[REF_KEY];
|
|
183
186
|
}
|
|
@@ -199,10 +202,14 @@ function getLinkedRecordIDs(
|
|
|
199
202
|
invariant(
|
|
200
203
|
typeof links === 'object' && Array.isArray(links[REFS_KEY]),
|
|
201
204
|
'RelayModernRecord.getLinkedRecordIDs(): Expected `%s.%s` to contain an array ' +
|
|
202
|
-
'of linked IDs, got `%s
|
|
205
|
+
'of linked IDs, got `%s`.%s',
|
|
203
206
|
record[ID_KEY],
|
|
204
207
|
storageKey,
|
|
205
208
|
JSON.stringify(links),
|
|
209
|
+
typeof links === 'object' && links[REF_KEY] !== undefined
|
|
210
|
+
? ' It appears to be a singular linked record: did you mean to call ' +
|
|
211
|
+
'getLinkedRecord() instead of getLinkedRecords()?'
|
|
212
|
+
: '',
|
|
206
213
|
);
|
|
207
214
|
// assume items of the array are ids
|
|
208
215
|
return (links[REFS_KEY]: any);
|
|
@@ -12,22 +12,11 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
const areEqual = require('areEqual');
|
|
16
|
-
const invariant = require('invariant');
|
|
17
|
-
const warning = require('warning');
|
|
18
|
-
|
|
19
|
-
const {getFragmentVariables} = require('./RelayConcreteVariables');
|
|
20
|
-
const {
|
|
21
|
-
FRAGMENT_OWNER_KEY,
|
|
22
|
-
FRAGMENTS_KEY,
|
|
23
|
-
ID_KEY,
|
|
24
|
-
IS_WITHIN_UNMATCHED_TYPE_REFINEMENT,
|
|
25
|
-
} = require('./RelayStoreUtils');
|
|
26
|
-
|
|
27
15
|
import type {NormalizationSelectableNode} from '../util/NormalizationNode';
|
|
28
16
|
import type {ReaderFragment} from '../util/ReaderNode';
|
|
29
17
|
import type {DataID, Variables} from '../util/RelayRuntimeTypes';
|
|
30
18
|
import type {
|
|
19
|
+
ClientEdgeTraversalPath,
|
|
31
20
|
NormalizationSelector,
|
|
32
21
|
PluralReaderSelector,
|
|
33
22
|
ReaderSelector,
|
|
@@ -35,6 +24,18 @@ import type {
|
|
|
35
24
|
SingularReaderSelector,
|
|
36
25
|
} from './RelayStoreTypes';
|
|
37
26
|
|
|
27
|
+
const {getFragmentVariables} = require('./RelayConcreteVariables');
|
|
28
|
+
const {
|
|
29
|
+
CLIENT_EDGE_TRAVERSAL_PATH,
|
|
30
|
+
FRAGMENT_OWNER_KEY,
|
|
31
|
+
FRAGMENTS_KEY,
|
|
32
|
+
ID_KEY,
|
|
33
|
+
IS_WITHIN_UNMATCHED_TYPE_REFINEMENT,
|
|
34
|
+
} = require('./RelayStoreUtils');
|
|
35
|
+
const areEqual = require('areEqual');
|
|
36
|
+
const invariant = require('invariant');
|
|
37
|
+
const warning = require('warning');
|
|
38
|
+
|
|
38
39
|
/**
|
|
39
40
|
* @public
|
|
40
41
|
*
|
|
@@ -80,6 +81,7 @@ function getSingularSelector(
|
|
|
80
81
|
const mixedOwner = item[FRAGMENT_OWNER_KEY];
|
|
81
82
|
const isWithinUnmatchedTypeRefinement =
|
|
82
83
|
item[IS_WITHIN_UNMATCHED_TYPE_REFINEMENT] === true;
|
|
84
|
+
const mixedClientEdgeTraversalPath = item[CLIENT_EDGE_TRAVERSAL_PATH];
|
|
83
85
|
if (
|
|
84
86
|
typeof dataID === 'string' &&
|
|
85
87
|
typeof fragments === 'object' &&
|
|
@@ -87,22 +89,28 @@ function getSingularSelector(
|
|
|
87
89
|
typeof fragments[fragment.name] === 'object' &&
|
|
88
90
|
fragments[fragment.name] !== null &&
|
|
89
91
|
typeof mixedOwner === 'object' &&
|
|
90
|
-
mixedOwner !== null
|
|
92
|
+
mixedOwner !== null &&
|
|
93
|
+
(mixedClientEdgeTraversalPath == null ||
|
|
94
|
+
Array.isArray(mixedClientEdgeTraversalPath))
|
|
91
95
|
) {
|
|
92
96
|
const owner: RequestDescriptor = (mixedOwner: $FlowFixMe);
|
|
93
|
-
const
|
|
97
|
+
const clientEdgeTraversalPath: ?ClientEdgeTraversalPath =
|
|
98
|
+
(mixedClientEdgeTraversalPath: $FlowFixMe);
|
|
94
99
|
|
|
100
|
+
const argumentVariables = fragments[fragment.name];
|
|
95
101
|
const fragmentVariables = getFragmentVariables(
|
|
96
102
|
fragment,
|
|
97
103
|
owner.variables,
|
|
98
104
|
argumentVariables,
|
|
99
105
|
);
|
|
106
|
+
|
|
100
107
|
return createReaderSelector(
|
|
101
108
|
fragment,
|
|
102
109
|
dataID,
|
|
103
110
|
fragmentVariables,
|
|
104
111
|
owner,
|
|
105
112
|
isWithinUnmatchedTypeRefinement,
|
|
113
|
+
clientEdgeTraversalPath,
|
|
106
114
|
);
|
|
107
115
|
}
|
|
108
116
|
|
|
@@ -419,11 +427,13 @@ function createReaderSelector(
|
|
|
419
427
|
variables: Variables,
|
|
420
428
|
request: RequestDescriptor,
|
|
421
429
|
isWithinUnmatchedTypeRefinement: boolean = false,
|
|
430
|
+
clientEdgeTraversalPath: ?ClientEdgeTraversalPath,
|
|
422
431
|
): SingularReaderSelector {
|
|
423
432
|
return {
|
|
424
433
|
kind: 'SingularReaderSelector',
|
|
425
434
|
dataID,
|
|
426
435
|
isWithinUnmatchedTypeRefinement,
|
|
436
|
+
clientEdgeTraversalPath: clientEdgeTraversalPath ?? null,
|
|
427
437
|
node: fragment,
|
|
428
438
|
variables,
|
|
429
439
|
owner: request,
|
|
@@ -12,34 +12,13 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
const DataChecker = require('./DataChecker');
|
|
16
|
-
const RelayFeatureFlags = require('../util/RelayFeatureFlags');
|
|
17
|
-
const RelayModernRecord = require('./RelayModernRecord');
|
|
18
|
-
const RelayOptimisticRecordSource = require('./RelayOptimisticRecordSource');
|
|
19
|
-
const RelayReader = require('./RelayReader');
|
|
20
|
-
const RelayReferenceMarker = require('./RelayReferenceMarker');
|
|
21
|
-
const RelayStoreReactFlightUtils = require('./RelayStoreReactFlightUtils');
|
|
22
|
-
const RelayStoreSubscriptions = require('./RelayStoreSubscriptions');
|
|
23
|
-
const RelayStoreUtils = require('./RelayStoreUtils');
|
|
24
|
-
|
|
25
|
-
const deepFreeze = require('../util/deepFreeze');
|
|
26
|
-
const defaultGetDataID = require('./defaultGetDataID');
|
|
27
|
-
const invariant = require('invariant');
|
|
28
|
-
const resolveImmediate = require('../util/resolveImmediate');
|
|
29
|
-
|
|
30
|
-
const {
|
|
31
|
-
INTERNAL_ACTOR_IDENTIFIER_DO_NOT_USE,
|
|
32
|
-
assertInternalActorIndentifier,
|
|
33
|
-
} = require('../multi-actor-environment/ActorIdentifier');
|
|
34
|
-
const {ROOT_ID, ROOT_TYPE} = require('./RelayStoreUtils');
|
|
35
|
-
const {RecordResolverCache} = require('./ResolverCache');
|
|
36
|
-
|
|
37
15
|
import type {ActorIdentifier} from '../multi-actor-environment/ActorIdentifier';
|
|
38
16
|
import type {DataID, Disposable} from '../util/RelayRuntimeTypes';
|
|
39
17
|
import type {Availability} from './DataChecker';
|
|
40
18
|
import type {GetDataID} from './RelayResponseNormalizer';
|
|
41
19
|
import type {
|
|
42
20
|
CheckOptions,
|
|
21
|
+
DataIDSet,
|
|
43
22
|
LogFunction,
|
|
44
23
|
MutableRecordSource,
|
|
45
24
|
OperationAvailability,
|
|
@@ -52,10 +31,29 @@ import type {
|
|
|
52
31
|
Snapshot,
|
|
53
32
|
Store,
|
|
54
33
|
StoreSubscriptions,
|
|
55
|
-
DataIDSet,
|
|
56
34
|
} from './RelayStoreTypes';
|
|
57
35
|
import type {ResolverCache} from './ResolverCache';
|
|
58
36
|
|
|
37
|
+
const {
|
|
38
|
+
INTERNAL_ACTOR_IDENTIFIER_DO_NOT_USE,
|
|
39
|
+
assertInternalActorIndentifier,
|
|
40
|
+
} = require('../multi-actor-environment/ActorIdentifier');
|
|
41
|
+
const deepFreeze = require('../util/deepFreeze');
|
|
42
|
+
const RelayFeatureFlags = require('../util/RelayFeatureFlags');
|
|
43
|
+
const resolveImmediate = require('../util/resolveImmediate');
|
|
44
|
+
const DataChecker = require('./DataChecker');
|
|
45
|
+
const defaultGetDataID = require('./defaultGetDataID');
|
|
46
|
+
const RelayModernRecord = require('./RelayModernRecord');
|
|
47
|
+
const RelayOptimisticRecordSource = require('./RelayOptimisticRecordSource');
|
|
48
|
+
const RelayReader = require('./RelayReader');
|
|
49
|
+
const RelayReferenceMarker = require('./RelayReferenceMarker');
|
|
50
|
+
const RelayStoreReactFlightUtils = require('./RelayStoreReactFlightUtils');
|
|
51
|
+
const RelayStoreSubscriptions = require('./RelayStoreSubscriptions');
|
|
52
|
+
const RelayStoreUtils = require('./RelayStoreUtils');
|
|
53
|
+
const {ROOT_ID, ROOT_TYPE} = require('./RelayStoreUtils');
|
|
54
|
+
const {RecordResolverCache} = require('./ResolverCache');
|
|
55
|
+
const invariant = require('invariant');
|
|
56
|
+
|
|
59
57
|
export opaque type InvalidationState = {|
|
|
60
58
|
dataIDs: $ReadOnlyArray<DataID>,
|
|
61
59
|
invalidations: Map<DataID, ?number>,
|
|
@@ -715,7 +713,6 @@ function updateTargetFromSource(
|
|
|
715
713
|
currentWriteEpoch,
|
|
716
714
|
);
|
|
717
715
|
invalidatedRecordIDs.add(dataID);
|
|
718
|
-
// $FlowFixMe[incompatible-call]
|
|
719
716
|
target.set(dataID, nextRecord);
|
|
720
717
|
});
|
|
721
718
|
}
|
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
const invariant = require('invariant');
|
|
16
|
-
|
|
17
15
|
import type {RequestDescriptor} from './RelayStoreTypes';
|
|
18
16
|
|
|
17
|
+
const invariant = require('invariant');
|
|
18
|
+
|
|
19
19
|
class RelayOperationTracker {
|
|
20
20
|
_ownersToPendingOperations: Map<string, Map<string, RequestDescriptor>>;
|
|
21
21
|
_pendingOperationsToOwners: Map<string, Set<string>>;
|
|
@@ -49,9 +49,8 @@ class RelayOperationTracker {
|
|
|
49
49
|
const newlyAffectedOwnersIdentifier = new Set();
|
|
50
50
|
for (const owner of affectedOwners) {
|
|
51
51
|
const ownerIdentifier = owner.identifier;
|
|
52
|
-
const pendingOperationsAffectingOwner =
|
|
53
|
-
ownerIdentifier
|
|
54
|
-
);
|
|
52
|
+
const pendingOperationsAffectingOwner =
|
|
53
|
+
this._ownersToPendingOperations.get(ownerIdentifier);
|
|
55
54
|
if (pendingOperationsAffectingOwner != null) {
|
|
56
55
|
// In this case the `ownerIdentifier` already affected by some operations
|
|
57
56
|
// We just need to detect, is it the same operation that we already
|
|
@@ -113,9 +112,8 @@ class RelayOperationTracker {
|
|
|
113
112
|
// and some other operations
|
|
114
113
|
const updatedOwnersIdentifier = new Set();
|
|
115
114
|
for (const ownerIdentifier of affectedOwnersIdentifier) {
|
|
116
|
-
const pendingOperationsAffectingOwner =
|
|
117
|
-
ownerIdentifier
|
|
118
|
-
);
|
|
115
|
+
const pendingOperationsAffectingOwner =
|
|
116
|
+
this._ownersToPendingOperations.get(ownerIdentifier);
|
|
119
117
|
if (!pendingOperationsAffectingOwner) {
|
|
120
118
|
continue;
|
|
121
119
|
}
|
|
@@ -151,16 +149,13 @@ class RelayOperationTracker {
|
|
|
151
149
|
this._ownersToPendingPromise.delete(ownerIdentifier);
|
|
152
150
|
}
|
|
153
151
|
|
|
154
|
-
getPendingOperationsAffectingOwner(
|
|
155
|
-
owner: RequestDescriptor,
|
|
156
|
-
): {|
|
|
152
|
+
getPendingOperationsAffectingOwner(owner: RequestDescriptor): {|
|
|
157
153
|
promise: Promise<void>,
|
|
158
154
|
pendingOperations: $ReadOnlyArray<RequestDescriptor>,
|
|
159
155
|
|} | null {
|
|
160
156
|
const ownerIdentifier = owner.identifier;
|
|
161
|
-
const pendingOperationsForOwner =
|
|
162
|
-
ownerIdentifier
|
|
163
|
-
);
|
|
157
|
+
const pendingOperationsForOwner =
|
|
158
|
+
this._ownersToPendingOperations.get(ownerIdentifier);
|
|
164
159
|
if (
|
|
165
160
|
pendingOperationsForOwner == null ||
|
|
166
161
|
pendingOperationsForOwner.size === 0
|
|
@@ -168,9 +163,8 @@ class RelayOperationTracker {
|
|
|
168
163
|
return null;
|
|
169
164
|
}
|
|
170
165
|
|
|
171
|
-
const cachedPromiseEntry =
|
|
172
|
-
ownerIdentifier
|
|
173
|
-
);
|
|
166
|
+
const cachedPromiseEntry =
|
|
167
|
+
this._ownersToPendingPromise.get(ownerIdentifier);
|
|
174
168
|
if (cachedPromiseEntry != null) {
|
|
175
169
|
return {
|
|
176
170
|
promise: cachedPromiseEntry.promise,
|
|
@@ -12,8 +12,6 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
const RelayRecordSource = require('./RelayRecordSource');
|
|
16
|
-
|
|
17
15
|
import type {DataID} from '../util/RelayRuntimeTypes';
|
|
18
16
|
import type {RecordState} from './RelayRecordState';
|
|
19
17
|
import type {
|
|
@@ -22,6 +20,8 @@ import type {
|
|
|
22
20
|
RecordSource,
|
|
23
21
|
} from './RelayStoreTypes';
|
|
24
22
|
|
|
23
|
+
const RelayRecordSource = require('./RelayRecordSource');
|
|
24
|
+
|
|
25
25
|
const UNPUBLISH_RECORD_SENTINEL = Object.freeze({
|
|
26
26
|
__UNPUBLISH_RECORD_SENTINEL: true,
|
|
27
27
|
});
|
|
@@ -12,19 +12,11 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
const RelayReader = require('./RelayReader');
|
|
16
|
-
const RelayRecordSource = require('./RelayRecordSource');
|
|
17
|
-
const RelayRecordSourceMutator = require('../mutations/RelayRecordSourceMutator');
|
|
18
|
-
const RelayRecordSourceProxy = require('../mutations/RelayRecordSourceProxy');
|
|
19
|
-
const RelayRecordSourceSelectorProxy = require('../mutations/RelayRecordSourceSelectorProxy');
|
|
20
|
-
|
|
21
|
-
const invariant = require('invariant');
|
|
22
|
-
const warning = require('warning');
|
|
23
|
-
|
|
24
15
|
import type {HandlerProvider} from '../handlers/RelayDefaultHandlerProvider';
|
|
25
16
|
import type {Disposable} from '../util/RelayRuntimeTypes';
|
|
26
17
|
import type {GetDataID} from './RelayResponseNormalizer';
|
|
27
18
|
import type {
|
|
19
|
+
MutationParameters,
|
|
28
20
|
OperationDescriptor,
|
|
29
21
|
OptimisticUpdate,
|
|
30
22
|
PublishQueue,
|
|
@@ -38,12 +30,23 @@ import type {
|
|
|
38
30
|
StoreUpdater,
|
|
39
31
|
} from './RelayStoreTypes';
|
|
40
32
|
|
|
41
|
-
|
|
42
|
-
|
|
33
|
+
const RelayRecordSourceMutator = require('../mutations/RelayRecordSourceMutator');
|
|
34
|
+
const RelayRecordSourceProxy = require('../mutations/RelayRecordSourceProxy');
|
|
35
|
+
const RelayRecordSourceSelectorProxy = require('../mutations/RelayRecordSourceSelectorProxy');
|
|
36
|
+
const RelayReader = require('./RelayReader');
|
|
37
|
+
const RelayRecordSource = require('./RelayRecordSource');
|
|
38
|
+
const invariant = require('invariant');
|
|
39
|
+
const warning = require('warning');
|
|
40
|
+
|
|
41
|
+
type PendingCommit<TMutation: MutationParameters> =
|
|
42
|
+
| PendingRelayPayload<TMutation>
|
|
43
|
+
| PendingRecordSource
|
|
44
|
+
| PendingUpdater;
|
|
45
|
+
type PendingRelayPayload<TMutation: MutationParameters> = {|
|
|
43
46
|
+kind: 'payload',
|
|
44
47
|
+operation: OperationDescriptor,
|
|
45
48
|
+payload: RelayResponsePayload,
|
|
46
|
-
+updater: ?SelectorStoreUpdater
|
|
49
|
+
+updater: ?SelectorStoreUpdater<TMutation['response']>,
|
|
47
50
|
|};
|
|
48
51
|
type PendingRecordSource = {|
|
|
49
52
|
+kind: 'source',
|
|
@@ -79,12 +82,19 @@ class RelayPublishQueue implements PublishQueue {
|
|
|
79
82
|
// updates performing a rebase.
|
|
80
83
|
_pendingBackupRebase: boolean;
|
|
81
84
|
// Payloads to apply or Sources to publish to the store with the next `run()`.
|
|
82
|
-
|
|
85
|
+
// $FlowFixMe[unclear-type] See explanation below.
|
|
86
|
+
_pendingData: Set<PendingCommit<any>>;
|
|
83
87
|
// Optimistic updaters to add with the next `run()`.
|
|
84
|
-
|
|
88
|
+
// $FlowFixMe[unclear-type] See explanation below.
|
|
89
|
+
_pendingOptimisticUpdates: Set<OptimisticUpdate<any>>;
|
|
85
90
|
// Optimistic updaters that are already added and might be rerun in order to
|
|
86
91
|
// rebase them.
|
|
87
|
-
|
|
92
|
+
// $FlowFixMe[unclear-type] See explanation below.
|
|
93
|
+
_appliedOptimisticUpdates: Set<OptimisticUpdate<any>>;
|
|
94
|
+
// For _pendingOptimisticUpdates, _appliedOptimisticUpdates, and _pendingData,
|
|
95
|
+
// we want to parametrize by "any" since the type is effectively
|
|
96
|
+
// "the union of all T's that PublishQueue's methods were called with".
|
|
97
|
+
|
|
88
98
|
// Garbage collection hold, should rerun gc on dispose
|
|
89
99
|
_gcHold: ?Disposable;
|
|
90
100
|
_isRunning: ?boolean;
|
|
@@ -108,7 +118,9 @@ class RelayPublishQueue implements PublishQueue {
|
|
|
108
118
|
/**
|
|
109
119
|
* Schedule applying an optimistic updates on the next `run()`.
|
|
110
120
|
*/
|
|
111
|
-
applyUpdate
|
|
121
|
+
applyUpdate<TMutation: MutationParameters>(
|
|
122
|
+
updater: OptimisticUpdate<TMutation>,
|
|
123
|
+
): void {
|
|
112
124
|
invariant(
|
|
113
125
|
!this._appliedOptimisticUpdates.has(updater) &&
|
|
114
126
|
!this._pendingOptimisticUpdates.has(updater),
|
|
@@ -121,7 +133,9 @@ class RelayPublishQueue implements PublishQueue {
|
|
|
121
133
|
/**
|
|
122
134
|
* Schedule reverting an optimistic updates on the next `run()`.
|
|
123
135
|
*/
|
|
124
|
-
revertUpdate
|
|
136
|
+
revertUpdate<TMutation: MutationParameters>(
|
|
137
|
+
updater: OptimisticUpdate<TMutation>,
|
|
138
|
+
): void {
|
|
125
139
|
if (this._pendingOptimisticUpdates.has(updater)) {
|
|
126
140
|
// Reverted before it was applied
|
|
127
141
|
this._pendingOptimisticUpdates.delete(updater);
|
|
@@ -143,10 +157,10 @@ class RelayPublishQueue implements PublishQueue {
|
|
|
143
157
|
/**
|
|
144
158
|
* Schedule applying a payload to the store on the next `run()`.
|
|
145
159
|
*/
|
|
146
|
-
commitPayload(
|
|
160
|
+
commitPayload<TMutation: MutationParameters>(
|
|
147
161
|
operation: OperationDescriptor,
|
|
148
162
|
payload: RelayResponsePayload,
|
|
149
|
-
updater?: ?SelectorStoreUpdater
|
|
163
|
+
updater?: ?SelectorStoreUpdater<TMutation['response']>,
|
|
150
164
|
): void {
|
|
151
165
|
this._pendingBackupRebase = true;
|
|
152
166
|
this._pendingData.add({
|
|
@@ -253,7 +267,9 @@ class RelayPublishQueue implements PublishQueue {
|
|
|
253
267
|
* _publishSourceFromPayload will return a boolean indicating if the
|
|
254
268
|
* publish caused the store to be globally invalidated.
|
|
255
269
|
*/
|
|
256
|
-
_publishSourceFromPayload
|
|
270
|
+
_publishSourceFromPayload<TMutation: MutationParameters>(
|
|
271
|
+
pendingPayload: PendingRelayPayload<TMutation>,
|
|
272
|
+
): boolean {
|
|
257
273
|
const {payload, operation, updater} = pendingPayload;
|
|
258
274
|
const {source, fieldPayloads} = payload;
|
|
259
275
|
const mutator = new RelayRecordSourceMutator(
|
|
@@ -291,7 +307,8 @@ class RelayPublishQueue implements PublishQueue {
|
|
|
291
307
|
const selectorData = lookupSelector(source, selector);
|
|
292
308
|
updater(recordSourceSelectorProxy, selectorData);
|
|
293
309
|
}
|
|
294
|
-
const idsMarkedForInvalidation =
|
|
310
|
+
const idsMarkedForInvalidation =
|
|
311
|
+
recordSourceProxy.getIDsMarkedForInvalidation();
|
|
295
312
|
this._store.publish(source, idsMarkedForInvalidation);
|
|
296
313
|
return recordSourceProxy.isStoreMarkedForInvalidation();
|
|
297
314
|
}
|
|
@@ -332,7 +349,8 @@ class RelayPublishQueue implements PublishQueue {
|
|
|
332
349
|
);
|
|
333
350
|
invalidatedStore =
|
|
334
351
|
invalidatedStore || recordSourceProxy.isStoreMarkedForInvalidation();
|
|
335
|
-
const idsMarkedForInvalidation =
|
|
352
|
+
const idsMarkedForInvalidation =
|
|
353
|
+
recordSourceProxy.getIDsMarkedForInvalidation();
|
|
336
354
|
|
|
337
355
|
this._store.publish(sink, idsMarkedForInvalidation);
|
|
338
356
|
}
|
|
@@ -355,7 +373,8 @@ class RelayPublishQueue implements PublishQueue {
|
|
|
355
373
|
this._handlerProvider,
|
|
356
374
|
);
|
|
357
375
|
|
|
358
|
-
|
|
376
|
+
// $FlowFixMe[unclear-type] see explanation above.
|
|
377
|
+
const processUpdate = (optimisticUpdate: OptimisticUpdate<any>) => {
|
|
359
378
|
if (optimisticUpdate.storeUpdater) {
|
|
360
379
|
const {storeUpdater} = optimisticUpdate;
|
|
361
380
|
applyWithGuard(
|