relay-runtime 12.0.0 → 13.0.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/LICENSE +1 -1
- 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 +2 -2
- package/index.js.flow +43 -34
- 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 +49 -46
- package/lib/multi-actor-environment/ActorIdentifier.js +1 -1
- package/lib/multi-actor-environment/ActorSpecificEnvironment.js +9 -5
- package/lib/multi-actor-environment/ActorUtils.js +1 -1
- package/lib/multi-actor-environment/MultiActorEnvironment.js +36 -23
- package/lib/multi-actor-environment/MultiActorEnvironmentTypes.js +1 -1
- package/lib/multi-actor-environment/index.js +3 -3
- 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 +13 -5
- package/lib/mutations/applyOptimisticMutation.js +7 -7
- package/lib/mutations/commitLocalUpdate.js +1 -1
- package/lib/mutations/commitMutation.js +16 -15
- package/lib/mutations/readUpdatableQuery_EXPERIMENTAL.js +242 -0
- package/lib/mutations/validateMutation.js +7 -7
- 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 +2 -4
- package/lib/network/RelayQueryResponseCache.js +3 -3
- package/lib/network/wrapNetworkWithLogObserver.js +3 -2
- 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 +17 -18
- package/lib/store/OperationExecutor.js +14 -14
- package/lib/store/RelayConcreteVariables.js +7 -10
- package/lib/store/RelayExperimentalGraphResponseHandler.js +153 -0
- package/lib/store/RelayExperimentalGraphResponseTransform.js +391 -0
- package/lib/store/RelayModernEnvironment.js +67 -43
- package/lib/store/RelayModernFragmentSpecResolver.js +9 -9
- package/lib/store/RelayModernOperationDescriptor.js +3 -2
- package/lib/store/RelayModernRecord.js +13 -12
- package/lib/store/RelayModernSelector.js +15 -9
- package/lib/store/RelayModernStore.js +15 -16
- package/lib/store/RelayOperationTracker.js +1 -1
- package/lib/store/RelayOptimisticRecordSource.js +1 -1
- package/lib/store/RelayPublishQueue.js +12 -6
- package/lib/store/RelayReader.js +131 -40
- package/lib/store/RelayRecordSource.js +1 -1
- package/lib/store/RelayRecordState.js +1 -1
- package/lib/store/RelayReferenceMarker.js +11 -12
- package/lib/store/RelayResponseNormalizer.js +26 -23
- package/lib/store/RelayStoreReactFlightUtils.js +4 -4
- package/lib/store/RelayStoreSubscriptions.js +7 -5
- package/lib/store/RelayStoreTypes.js +1 -1
- package/lib/store/RelayStoreUtils.js +6 -6
- package/lib/store/ResolverCache.js +7 -7
- package/lib/store/ResolverFragments.js +12 -8
- 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 +4 -2
- 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 +4 -6
- 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 +2 -1
- package/lib/util/RelayDefaultHandleKey.js +1 -1
- package/lib/util/RelayError.js +1 -1
- package/lib/util/RelayFeatureFlags.js +8 -3
- package/lib/util/RelayProfiler.js +1 -1
- package/lib/util/RelayReplaySubject.js +1 -1
- 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 +1 -1
- package/lib/util/getPaginationVariables.js +3 -4
- package/lib/util/getPendingOperationsForFragment.js +1 -1
- package/lib/util/getRefetchMetadata.js +1 -1
- package/lib/util/getRelayHandleKey.js +3 -3
- package/lib/util/getRequestIdentifier.js +3 -3
- package/lib/util/getValueAtPath.js +1 -1
- package/lib/util/isEmptyObject.js +1 -1
- 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 +1 -1
- 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 +1 -1
- package/multi-actor-environment/ActorIdentifier.js.flow +1 -1
- package/multi-actor-environment/ActorSpecificEnvironment.js.flow +28 -20
- package/multi-actor-environment/ActorUtils.js.flow +3 -3
- package/multi-actor-environment/MultiActorEnvironment.js.flow +46 -25
- package/multi-actor-environment/MultiActorEnvironmentTypes.js.flow +28 -12
- package/multi-actor-environment/index.js.flow +2 -3
- package/mutations/RelayDeclarativeMutationConfig.js.flow +33 -28
- 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 +16 -6
- package/mutations/applyOptimisticMutation.js.flow +14 -15
- package/mutations/commitLocalUpdate.js.flow +2 -2
- package/mutations/commitMutation.js.flow +36 -49
- package/mutations/readUpdatableQuery_EXPERIMENTAL.js.flow +318 -0
- package/mutations/validateMutation.js.flow +20 -18
- 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 -4
- package/network/RelayQueryResponseCache.js.flow +4 -4
- package/network/wrapNetworkWithLogObserver.js.flow +9 -9
- 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 +3 -3
- package/store/ClientID.js.flow +10 -3
- package/store/DataChecker.js.flow +21 -30
- package/store/OperationExecutor.js.flow +55 -63
- package/store/RelayConcreteVariables.js.flow +5 -11
- package/store/RelayExperimentalGraphResponseHandler.js.flow +121 -0
- package/store/RelayExperimentalGraphResponseTransform.js.flow +470 -0
- package/store/RelayModernEnvironment.js.flow +57 -28
- package/store/RelayModernFragmentSpecResolver.js.flow +18 -20
- package/store/RelayModernOperationDescriptor.js.flow +11 -12
- package/store/RelayModernRecord.js.flow +20 -13
- package/store/RelayModernSelector.js.flow +25 -15
- package/store/RelayModernStore.js.flow +22 -26
- package/store/RelayOperationTracker.js.flow +12 -18
- package/store/RelayOptimisticRecordSource.js.flow +3 -3
- package/store/RelayPublishQueue.js.flow +43 -24
- package/store/RelayReader.js.flow +181 -68
- package/store/RelayRecordSource.js.flow +3 -3
- package/store/RelayRecordState.js.flow +1 -1
- package/store/RelayReferenceMarker.js.flow +13 -16
- package/store/RelayResponseNormalizer.js.flow +44 -42
- package/store/RelayStoreReactFlightUtils.js.flow +4 -5
- package/store/RelayStoreSubscriptions.js.flow +10 -9
- package/store/RelayStoreTypes.js.flow +73 -30
- package/store/RelayStoreUtils.js.flow +9 -10
- package/store/ResolverCache.js.flow +17 -15
- package/store/ResolverFragments.js.flow +18 -25
- 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 +3 -3
- 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 +16 -25
- package/util/JSResourceTypes.flow.js.flow +1 -1
- package/util/NormalizationNode.js.flow +1 -1
- package/util/ReaderNode.js.flow +10 -1
- package/util/RelayConcreteNode.js.flow +4 -1
- package/util/RelayDefaultHandleKey.js.flow +1 -1
- package/util/RelayError.js.flow +1 -1
- package/util/RelayFeatureFlags.js.flow +15 -5
- package/util/RelayProfiler.js.flow +1 -1
- package/util/RelayReplaySubject.js.flow +3 -4
- 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 +6 -11
- package/util/getPaginationVariables.js.flow +6 -10
- package/util/getPendingOperationsForFragment.js.flow +3 -3
- package/util/getRefetchMetadata.js.flow +8 -12
- package/util/getRelayHandleKey.js.flow +2 -3
- package/util/getRequestIdentifier.js.flow +4 -4
- package/util/getValueAtPath.js.flow +1 -1
- package/util/isEmptyObject.js.flow +1 -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 +1 -1
- 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 +1 -1
|
@@ -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,18 +12,17 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
const ConnectionHandler = require('../handlers/connection/ConnectionHandler');
|
|
16
|
-
|
|
17
|
-
const warning = require('warning');
|
|
18
|
-
|
|
19
15
|
import type {
|
|
16
|
+
MutationParameters,
|
|
20
17
|
RecordSourceSelectorProxy,
|
|
21
|
-
SelectorData,
|
|
22
18
|
SelectorStoreUpdater,
|
|
23
19
|
} from '../store/RelayStoreTypes';
|
|
24
20
|
import type {ConcreteRequest} from '../util/RelayConcreteNode';
|
|
25
21
|
import type {Variables} from '../util/RelayRuntimeTypes';
|
|
26
22
|
|
|
23
|
+
const ConnectionHandler = require('../handlers/connection/ConnectionHandler');
|
|
24
|
+
const warning = require('warning');
|
|
25
|
+
|
|
27
26
|
const MutationTypes = Object.freeze({
|
|
28
27
|
RANGE_ADD: 'RANGE_ADD',
|
|
29
28
|
RANGE_DELETE: 'RANGE_DELETE',
|
|
@@ -39,7 +38,7 @@ export type RangeOperation = $Values<typeof RangeOperations>;
|
|
|
39
38
|
|
|
40
39
|
type RangeBehaviorsFunction = (connectionArgs: {
|
|
41
40
|
[name: string]: $FlowFixMe,
|
|
42
|
-
|
|
41
|
+
...
|
|
43
42
|
}) => RangeOperation;
|
|
44
43
|
type RangeBehaviorsObject = {[key: string]: RangeOperation, ...};
|
|
45
44
|
export type RangeBehaviors = RangeBehaviorsFunction | RangeBehaviorsObject;
|
|
@@ -84,18 +83,21 @@ export type DeclarativeMutationConfig =
|
|
|
84
83
|
| RangeDeleteConfig
|
|
85
84
|
| NodeDeleteConfig;
|
|
86
85
|
|
|
87
|
-
function convert(
|
|
86
|
+
function convert<TMutation: MutationParameters>(
|
|
88
87
|
configs: Array<DeclarativeMutationConfig>,
|
|
89
88
|
request: ConcreteRequest,
|
|
90
|
-
optimisticUpdater?: ?SelectorStoreUpdater
|
|
91
|
-
updater?: ?SelectorStoreUpdater
|
|
89
|
+
optimisticUpdater?: ?SelectorStoreUpdater<TMutation['response']>,
|
|
90
|
+
updater?: ?SelectorStoreUpdater<TMutation['response']>,
|
|
92
91
|
): {
|
|
93
|
-
optimisticUpdater: SelectorStoreUpdater
|
|
94
|
-
updater: SelectorStoreUpdater
|
|
92
|
+
optimisticUpdater: SelectorStoreUpdater<TMutation['response']>,
|
|
93
|
+
updater: SelectorStoreUpdater<TMutation['response']>,
|
|
95
94
|
...
|
|
96
95
|
} {
|
|
97
|
-
const configOptimisticUpdates
|
|
98
|
-
|
|
96
|
+
const configOptimisticUpdates: Array<
|
|
97
|
+
SelectorStoreUpdater<TMutation['response']>,
|
|
98
|
+
> = optimisticUpdater ? [optimisticUpdater] : [];
|
|
99
|
+
const configUpdates: Array<SelectorStoreUpdater<TMutation['response']>> =
|
|
100
|
+
updater ? [updater] : [];
|
|
99
101
|
configs.forEach(config => {
|
|
100
102
|
switch (config.type) {
|
|
101
103
|
case 'NODE_DELETE':
|
|
@@ -124,13 +126,16 @@ function convert(
|
|
|
124
126
|
return {
|
|
125
127
|
optimisticUpdater: (
|
|
126
128
|
store: RecordSourceSelectorProxy,
|
|
127
|
-
data: ?
|
|
129
|
+
data: ?TMutation['response'],
|
|
128
130
|
) => {
|
|
129
131
|
configOptimisticUpdates.forEach(eachOptimisticUpdater => {
|
|
130
132
|
eachOptimisticUpdater(store, data);
|
|
131
133
|
});
|
|
132
134
|
},
|
|
133
|
-
updater: (
|
|
135
|
+
updater: (
|
|
136
|
+
store: RecordSourceSelectorProxy,
|
|
137
|
+
data: ?TMutation['response'],
|
|
138
|
+
) => {
|
|
134
139
|
configUpdates.forEach(eachUpdater => {
|
|
135
140
|
eachUpdater(store, data);
|
|
136
141
|
});
|
|
@@ -141,13 +146,13 @@ function convert(
|
|
|
141
146
|
function nodeDelete(
|
|
142
147
|
config: NodeDeleteConfig,
|
|
143
148
|
request: ConcreteRequest,
|
|
144
|
-
): ?SelectorStoreUpdater {
|
|
149
|
+
): ?SelectorStoreUpdater<mixed> {
|
|
145
150
|
const {deletedIDFieldName} = config;
|
|
146
151
|
const rootField = getRootField(request);
|
|
147
152
|
if (!rootField) {
|
|
148
153
|
return null;
|
|
149
154
|
}
|
|
150
|
-
return (store: RecordSourceSelectorProxy, data: ?
|
|
155
|
+
return (store: RecordSourceSelectorProxy, data: ?mixed) => {
|
|
151
156
|
const payload = store.getRootField(rootField);
|
|
152
157
|
if (!payload) {
|
|
153
158
|
return;
|
|
@@ -165,7 +170,7 @@ function nodeDelete(
|
|
|
165
170
|
function rangeAdd(
|
|
166
171
|
config: RangeAddConfig,
|
|
167
172
|
request: ConcreteRequest,
|
|
168
|
-
): ?SelectorStoreUpdater {
|
|
173
|
+
): ?SelectorStoreUpdater<mixed> {
|
|
169
174
|
const {parentID, connectionInfo, edgeName} = config;
|
|
170
175
|
if (!parentID) {
|
|
171
176
|
warning(
|
|
@@ -179,7 +184,7 @@ function rangeAdd(
|
|
|
179
184
|
if (!connectionInfo || !rootField) {
|
|
180
185
|
return null;
|
|
181
186
|
}
|
|
182
|
-
return (store: RecordSourceSelectorProxy, data: ?
|
|
187
|
+
return (store: RecordSourceSelectorProxy, data: ?mixed) => {
|
|
183
188
|
const parent = store.get(parentID);
|
|
184
189
|
if (!parent) {
|
|
185
190
|
return;
|
|
@@ -233,13 +238,9 @@ function rangeAdd(
|
|
|
233
238
|
function rangeDelete(
|
|
234
239
|
config: RangeDeleteConfig,
|
|
235
240
|
request: ConcreteRequest,
|
|
236
|
-
): ?SelectorStoreUpdater {
|
|
237
|
-
const {
|
|
238
|
-
|
|
239
|
-
connectionKeys,
|
|
240
|
-
pathToConnection,
|
|
241
|
-
deletedIDFieldName,
|
|
242
|
-
} = config;
|
|
241
|
+
): ?SelectorStoreUpdater<mixed> {
|
|
242
|
+
const {parentID, connectionKeys, pathToConnection, deletedIDFieldName} =
|
|
243
|
+
config;
|
|
243
244
|
if (!parentID) {
|
|
244
245
|
warning(
|
|
245
246
|
false,
|
|
@@ -252,12 +253,16 @@ function rangeDelete(
|
|
|
252
253
|
if (!rootField) {
|
|
253
254
|
return null;
|
|
254
255
|
}
|
|
255
|
-
return (store: RecordSourceSelectorProxy, data: ?
|
|
256
|
+
return (store: RecordSourceSelectorProxy, data: ?mixed) => {
|
|
256
257
|
if (!data) {
|
|
257
258
|
return;
|
|
258
259
|
}
|
|
259
260
|
const deleteIDs = [];
|
|
261
|
+
// the type of data should come from a type parameter associated with ConcreteRequest,
|
|
262
|
+
// but ConcreteRequest does not contain a type parameter. Hence, we use a FlowFixMe.
|
|
263
|
+
// $FlowFixMe[incompatible-use] see above
|
|
260
264
|
let deletedIDField = data[rootField];
|
|
265
|
+
|
|
261
266
|
if (deletedIDField && Array.isArray(deletedIDFieldName)) {
|
|
262
267
|
for (const eachField of deletedIDFieldName) {
|
|
263
268
|
if (deletedIDField && typeof deletedIDField === 'object') {
|
|
@@ -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,17 +12,16 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
const invariant = require('invariant');
|
|
16
|
-
|
|
17
|
-
const {generateClientID} = require('../store/ClientID');
|
|
18
|
-
const {getStableStorageKey} = require('../store/RelayStoreUtils');
|
|
19
|
-
|
|
20
15
|
import type {RecordProxy} from '../store/RelayStoreTypes';
|
|
21
16
|
import type {Arguments} from '../store/RelayStoreUtils';
|
|
22
17
|
import type {DataID} from '../util/RelayRuntimeTypes';
|
|
23
18
|
import type RelayRecordSourceMutator from './RelayRecordSourceMutator';
|
|
24
19
|
import type RelayRecordSourceProxy from './RelayRecordSourceProxy';
|
|
25
20
|
|
|
21
|
+
const {generateClientID} = require('../store/ClientID');
|
|
22
|
+
const {getStableStorageKey} = require('../store/RelayStoreUtils');
|
|
23
|
+
const invariant = require('invariant');
|
|
24
|
+
|
|
26
25
|
/**
|
|
27
26
|
* @internal
|
|
28
27
|
*
|
|
@@ -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,12 +12,6 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
const RelayModernRecord = require('../store/RelayModernRecord');
|
|
16
|
-
|
|
17
|
-
const invariant = require('invariant');
|
|
18
|
-
|
|
19
|
-
const {EXISTENT} = require('../store/RelayRecordState');
|
|
20
|
-
|
|
21
15
|
import type {RecordState} from '../store/RelayRecordState';
|
|
22
16
|
import type {
|
|
23
17
|
MutableRecordSource,
|
|
@@ -26,6 +20,10 @@ import type {
|
|
|
26
20
|
} from '../store/RelayStoreTypes';
|
|
27
21
|
import type {DataID} from '../util/RelayRuntimeTypes';
|
|
28
22
|
|
|
23
|
+
const RelayModernRecord = require('../store/RelayModernRecord');
|
|
24
|
+
const {EXISTENT} = require('../store/RelayRecordState');
|
|
25
|
+
const invariant = require('invariant');
|
|
26
|
+
|
|
29
27
|
/**
|
|
30
28
|
* @internal
|
|
31
29
|
*
|
|
@@ -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,26 +12,28 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
const RelayModernRecord = require('../store/RelayModernRecord');
|
|
16
|
-
const RelayRecordProxy = require('./RelayRecordProxy');
|
|
17
|
-
|
|
18
|
-
const invariant = require('invariant');
|
|
19
|
-
|
|
20
|
-
const {EXISTENT, NONEXISTENT} = require('../store/RelayRecordState');
|
|
21
|
-
const {ROOT_ID, ROOT_TYPE} = require('../store/RelayStoreUtils');
|
|
22
|
-
|
|
23
15
|
import type {HandlerProvider} from '../handlers/RelayDefaultHandlerProvider';
|
|
16
|
+
import type {GraphQLTaggedNode} from '../query/GraphQLTag';
|
|
24
17
|
import type {GetDataID} from '../store/RelayResponseNormalizer';
|
|
25
18
|
import type {
|
|
26
19
|
DataIDSet,
|
|
27
20
|
HandleFieldPayload,
|
|
28
|
-
RecordSource,
|
|
29
21
|
RecordProxy,
|
|
22
|
+
RecordSource,
|
|
30
23
|
RecordSourceProxy,
|
|
31
24
|
} from '../store/RelayStoreTypes';
|
|
32
|
-
import type {DataID} from '../util/RelayRuntimeTypes';
|
|
25
|
+
import type {DataID, OperationType} from '../util/RelayRuntimeTypes';
|
|
33
26
|
import type RelayRecordSourceMutator from './RelayRecordSourceMutator';
|
|
34
27
|
|
|
28
|
+
const RelayModernRecord = require('../store/RelayModernRecord');
|
|
29
|
+
const {EXISTENT, NONEXISTENT} = require('../store/RelayRecordState');
|
|
30
|
+
const {ROOT_ID, ROOT_TYPE} = require('../store/RelayStoreUtils');
|
|
31
|
+
const {
|
|
32
|
+
readUpdatableQuery_EXPERIMENTAL,
|
|
33
|
+
} = require('./readUpdatableQuery_EXPERIMENTAL');
|
|
34
|
+
const RelayRecordProxy = require('./RelayRecordProxy');
|
|
35
|
+
const invariant = require('invariant');
|
|
36
|
+
|
|
35
37
|
/**
|
|
36
38
|
* @internal
|
|
37
39
|
*
|
|
@@ -160,6 +162,13 @@ class RelayRecordSourceProxy implements RecordSourceProxy {
|
|
|
160
162
|
getIDsMarkedForInvalidation(): DataIDSet {
|
|
161
163
|
return this._idsMarkedForInvalidation;
|
|
162
164
|
}
|
|
165
|
+
|
|
166
|
+
readUpdatableQuery_EXPERIMENTAL<TQuery: OperationType>(
|
|
167
|
+
query: GraphQLTaggedNode,
|
|
168
|
+
variables: TQuery['variables'],
|
|
169
|
+
): TQuery['response'] {
|
|
170
|
+
return readUpdatableQuery_EXPERIMENTAL(query, variables, this);
|
|
171
|
+
}
|
|
163
172
|
}
|
|
164
173
|
|
|
165
174
|
module.exports = RelayRecordSourceProxy;
|
|
@@ -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,10 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const {getStorageKey, ROOT_TYPE} = require('../store/RelayStoreUtils');
|
|
18
|
-
|
|
15
|
+
import type {GraphQLTaggedNode} from '../query/GraphQLTag';
|
|
19
16
|
import type {
|
|
20
17
|
RecordProxy,
|
|
21
18
|
RecordSourceProxy,
|
|
@@ -23,9 +20,15 @@ import type {
|
|
|
23
20
|
SingularReaderSelector,
|
|
24
21
|
} from '../store/RelayStoreTypes';
|
|
25
22
|
import type {ReaderLinkedField} from '../util/ReaderNode';
|
|
26
|
-
import type {DataID} from '../util/RelayRuntimeTypes';
|
|
23
|
+
import type {DataID, OperationType} from '../util/RelayRuntimeTypes';
|
|
27
24
|
import type RelayRecordSourceMutator from './RelayRecordSourceMutator';
|
|
28
25
|
|
|
26
|
+
const {ROOT_TYPE, getStorageKey} = require('../store/RelayStoreUtils');
|
|
27
|
+
const {
|
|
28
|
+
readUpdatableQuery_EXPERIMENTAL,
|
|
29
|
+
} = require('./readUpdatableQuery_EXPERIMENTAL');
|
|
30
|
+
const invariant = require('invariant');
|
|
31
|
+
|
|
29
32
|
/**
|
|
30
33
|
* @internal
|
|
31
34
|
*
|
|
@@ -119,6 +122,13 @@ class RelayRecordSourceSelectorProxy implements RecordSourceSelectorProxy {
|
|
|
119
122
|
invalidateStore(): void {
|
|
120
123
|
this.__recordSource.invalidateStore();
|
|
121
124
|
}
|
|
125
|
+
|
|
126
|
+
readUpdatableQuery_EXPERIMENTAL<TQuery: OperationType>(
|
|
127
|
+
query: GraphQLTaggedNode,
|
|
128
|
+
variables: TQuery['variables'],
|
|
129
|
+
): TQuery['response'] {
|
|
130
|
+
return readUpdatableQuery_EXPERIMENTAL(query, variables, this);
|
|
131
|
+
}
|
|
122
132
|
}
|
|
123
133
|
|
|
124
134
|
module.exports = RelayRecordSourceSelectorProxy;
|
|
@@ -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,29 +12,28 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
const RelayDeclarativeMutationConfig = require('./RelayDeclarativeMutationConfig');
|
|
16
|
-
|
|
17
|
-
const invariant = require('invariant');
|
|
18
|
-
const isRelayModernEnvironment = require('../store/isRelayModernEnvironment');
|
|
19
|
-
|
|
20
|
-
const {getRequest} = require('../query/GraphQLTag');
|
|
21
|
-
const {
|
|
22
|
-
createOperationDescriptor,
|
|
23
|
-
} = require('../store/RelayModernOperationDescriptor');
|
|
24
|
-
|
|
25
15
|
import type {GraphQLTaggedNode} from '../query/GraphQLTag';
|
|
26
16
|
import type {
|
|
27
17
|
IEnvironment,
|
|
18
|
+
MutationParameters,
|
|
28
19
|
SelectorStoreUpdater,
|
|
29
20
|
} from '../store/RelayStoreTypes';
|
|
30
21
|
import type {Disposable, Variables} from '../util/RelayRuntimeTypes';
|
|
31
22
|
import type {DeclarativeMutationConfig} from './RelayDeclarativeMutationConfig';
|
|
32
23
|
|
|
33
|
-
|
|
24
|
+
const {getRequest} = require('../query/GraphQLTag');
|
|
25
|
+
const isRelayModernEnvironment = require('../store/isRelayModernEnvironment');
|
|
26
|
+
const {
|
|
27
|
+
createOperationDescriptor,
|
|
28
|
+
} = require('../store/RelayModernOperationDescriptor');
|
|
29
|
+
const RelayDeclarativeMutationConfig = require('./RelayDeclarativeMutationConfig');
|
|
30
|
+
const invariant = require('invariant');
|
|
31
|
+
|
|
32
|
+
export type OptimisticMutationConfig<TMutation: MutationParameters> = {|
|
|
34
33
|
configs?: ?Array<DeclarativeMutationConfig>,
|
|
35
34
|
mutation: GraphQLTaggedNode,
|
|
36
35
|
variables: Variables,
|
|
37
|
-
optimisticUpdater?: ?SelectorStoreUpdater
|
|
36
|
+
optimisticUpdater?: ?SelectorStoreUpdater<TMutation['response']>,
|
|
38
37
|
optimisticResponse?: Object,
|
|
39
38
|
|};
|
|
40
39
|
|
|
@@ -42,9 +41,9 @@ export type OptimisticMutationConfig = {|
|
|
|
42
41
|
* Higher-level helper function to execute a mutation against a specific
|
|
43
42
|
* environment.
|
|
44
43
|
*/
|
|
45
|
-
function applyOptimisticMutation(
|
|
44
|
+
function applyOptimisticMutation<TMutation: MutationParameters>(
|
|
46
45
|
environment: IEnvironment,
|
|
47
|
-
config: OptimisticMutationConfig
|
|
46
|
+
config: OptimisticMutationConfig<TMutation>,
|
|
48
47
|
): Disposable {
|
|
49
48
|
invariant(
|
|
50
49
|
isRelayModernEnvironment(environment),
|
|
@@ -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,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
import type {
|
|
15
|
+
import type {IEnvironment, StoreUpdater} from '../store/RelayStoreTypes';
|
|
16
16
|
|
|
17
17
|
function commitLocalUpdate(
|
|
18
18
|
environment: IEnvironment,
|
|
@@ -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,11 @@
|
|
|
12
12
|
|
|
13
13
|
'use strict';
|
|
14
14
|
|
|
15
|
-
const RelayDeclarativeMutationConfig = require('./RelayDeclarativeMutationConfig');
|
|
16
|
-
|
|
17
|
-
const invariant = require('invariant');
|
|
18
|
-
const isRelayModernEnvironment = require('../store/isRelayModernEnvironment');
|
|
19
|
-
const validateMutation = require('./validateMutation');
|
|
20
|
-
const warning = require('warning');
|
|
21
|
-
|
|
22
|
-
const {getRequest} = require('../query/GraphQLTag');
|
|
23
|
-
const {generateUniqueClientID} = require('../store/ClientID');
|
|
24
|
-
const {
|
|
25
|
-
createOperationDescriptor,
|
|
26
|
-
} = require('../store/RelayModernOperationDescriptor');
|
|
27
|
-
|
|
28
15
|
import type {PayloadError, UploadableMap} from '../network/RelayNetworkTypes';
|
|
29
16
|
import type {GraphQLTaggedNode} from '../query/GraphQLTag';
|
|
30
17
|
import type {
|
|
31
18
|
IEnvironment,
|
|
19
|
+
MutationParameters,
|
|
32
20
|
SelectorStoreUpdater,
|
|
33
21
|
} from '../store/RelayStoreTypes';
|
|
34
22
|
import type {
|
|
@@ -38,57 +26,63 @@ import type {
|
|
|
38
26
|
} from '../util/RelayRuntimeTypes';
|
|
39
27
|
import type {DeclarativeMutationConfig} from './RelayDeclarativeMutationConfig';
|
|
40
28
|
|
|
41
|
-
|
|
29
|
+
const {getRequest} = require('../query/GraphQLTag');
|
|
30
|
+
const {generateUniqueClientID} = require('../store/ClientID');
|
|
31
|
+
const isRelayModernEnvironment = require('../store/isRelayModernEnvironment');
|
|
32
|
+
const {
|
|
33
|
+
createOperationDescriptor,
|
|
34
|
+
} = require('../store/RelayModernOperationDescriptor');
|
|
35
|
+
const RelayDeclarativeMutationConfig = require('./RelayDeclarativeMutationConfig');
|
|
36
|
+
const validateMutation = require('./validateMutation');
|
|
37
|
+
const invariant = require('invariant');
|
|
38
|
+
const warning = require('warning');
|
|
39
|
+
|
|
40
|
+
export type DEPRECATED_MutationConfig<TMutationResponse> = {|
|
|
42
41
|
configs?: Array<DeclarativeMutationConfig>,
|
|
43
42
|
cacheConfig?: CacheConfig,
|
|
44
43
|
mutation: GraphQLTaggedNode,
|
|
45
44
|
variables: Variables,
|
|
46
45
|
uploadables?: UploadableMap,
|
|
47
|
-
onCompleted?: ?(
|
|
46
|
+
onCompleted?: ?(
|
|
47
|
+
response: TMutationResponse,
|
|
48
|
+
errors: ?Array<PayloadError>,
|
|
49
|
+
) => void,
|
|
48
50
|
onError?: ?(error: Error) => void,
|
|
49
51
|
onUnsubscribe?: ?() => void,
|
|
50
|
-
optimisticUpdater?: ?SelectorStoreUpdater
|
|
52
|
+
optimisticUpdater?: ?SelectorStoreUpdater<TMutationResponse>,
|
|
51
53
|
optimisticResponse?: Object,
|
|
52
|
-
updater?: ?SelectorStoreUpdater
|
|
54
|
+
updater?: ?SelectorStoreUpdater<TMutationResponse>,
|
|
53
55
|
|};
|
|
54
56
|
|
|
55
|
-
export type MutationParameters = {|
|
|
56
|
-
+response: {...},
|
|
57
|
-
+variables: interface {},
|
|
58
|
-
+rawResponse?: {...},
|
|
59
|
-
|};
|
|
60
|
-
|
|
61
|
-
export type MutationConfig<T: MutationParameters> = {|
|
|
57
|
+
export type MutationConfig<TMutation: MutationParameters> = {|
|
|
62
58
|
configs?: Array<DeclarativeMutationConfig>,
|
|
63
59
|
cacheConfig?: CacheConfig,
|
|
64
60
|
mutation: GraphQLTaggedNode,
|
|
65
61
|
onError?: ?(error: Error) => void,
|
|
66
62
|
onCompleted?: ?(
|
|
67
|
-
response:
|
|
63
|
+
response: TMutation['response'],
|
|
68
64
|
errors: ?Array<PayloadError>,
|
|
69
65
|
) => void,
|
|
66
|
+
onNext?: ?() => void,
|
|
70
67
|
onUnsubscribe?: ?() => void,
|
|
71
|
-
optimisticResponse?:
|
|
72
|
-
{
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
>,
|
|
79
|
-
optimisticUpdater?: ?SelectorStoreUpdater,
|
|
80
|
-
updater?: ?SelectorStoreUpdater,
|
|
68
|
+
optimisticResponse?: {
|
|
69
|
+
+rawResponse?: {...},
|
|
70
|
+
...TMutation,
|
|
71
|
+
...
|
|
72
|
+
}['rawResponse'],
|
|
73
|
+
optimisticUpdater?: ?SelectorStoreUpdater<TMutation['response']>,
|
|
74
|
+
updater?: ?SelectorStoreUpdater<TMutation['response']>,
|
|
81
75
|
uploadables?: UploadableMap,
|
|
82
|
-
variables:
|
|
76
|
+
variables: TMutation['variables'],
|
|
83
77
|
|};
|
|
84
78
|
|
|
85
79
|
/**
|
|
86
80
|
* Higher-level helper function to execute a mutation against a specific
|
|
87
81
|
* environment.
|
|
88
82
|
*/
|
|
89
|
-
function commitMutation<
|
|
83
|
+
function commitMutation<TMutation: MutationParameters>(
|
|
90
84
|
environment: IEnvironment,
|
|
91
|
-
config: MutationConfig<
|
|
85
|
+
config: MutationConfig<TMutation>,
|
|
92
86
|
): Disposable {
|
|
93
87
|
invariant(
|
|
94
88
|
isRelayModernEnvironment(environment),
|
|
@@ -103,18 +97,10 @@ function commitMutation<T: MutationParameters>(
|
|
|
103
97
|
throw new Error('commitMutation: Expected mutation to be of type request');
|
|
104
98
|
}
|
|
105
99
|
let {optimisticResponse, optimisticUpdater, updater} = config;
|
|
106
|
-
const {
|
|
107
|
-
|
|
108
|
-
cacheConfig,
|
|
109
|
-
onError,
|
|
110
|
-
onUnsubscribe,
|
|
111
|
-
variables,
|
|
112
|
-
uploadables,
|
|
113
|
-
} = config;
|
|
100
|
+
const {configs, cacheConfig, onError, onUnsubscribe, variables, uploadables} =
|
|
101
|
+
config;
|
|
114
102
|
const operation = createOperationDescriptor(
|
|
115
103
|
mutation,
|
|
116
|
-
/* $FlowFixMe[class-object-subtyping] added when improving typing for this
|
|
117
|
-
* parameters */
|
|
118
104
|
variables,
|
|
119
105
|
cacheConfig,
|
|
120
106
|
generateUniqueClientID(),
|
|
@@ -163,6 +149,7 @@ function commitMutation<T: MutationParameters>(
|
|
|
163
149
|
errors.push(...payload.errors);
|
|
164
150
|
}
|
|
165
151
|
}
|
|
152
|
+
config.onNext?.();
|
|
166
153
|
},
|
|
167
154
|
complete: () => {
|
|
168
155
|
const {onCompleted} = config;
|