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
|
@@ -16,22 +16,22 @@ var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/obje
|
|
|
16
16
|
|
|
17
17
|
var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
|
|
18
18
|
|
|
19
|
-
var ActorSpecificEnvironment = require('./ActorSpecificEnvironment');
|
|
20
|
-
|
|
21
|
-
var OperationExecutor = require('../store/OperationExecutor');
|
|
22
|
-
|
|
23
19
|
var RelayDefaultHandlerProvider = require('../handlers/RelayDefaultHandlerProvider');
|
|
24
20
|
|
|
25
|
-
var RelayModernStore = require('../store/RelayModernStore');
|
|
26
|
-
|
|
27
21
|
var RelayObservable = require('../network/RelayObservable');
|
|
28
22
|
|
|
29
|
-
var RelayRecordSource = require('../store/RelayRecordSource');
|
|
30
|
-
|
|
31
23
|
var defaultGetDataID = require('../store/defaultGetDataID');
|
|
32
24
|
|
|
33
25
|
var defaultRequiredFieldLogger = require('../store/defaultRequiredFieldLogger');
|
|
34
26
|
|
|
27
|
+
var OperationExecutor = require('../store/OperationExecutor');
|
|
28
|
+
|
|
29
|
+
var RelayModernStore = require('../store/RelayModernStore');
|
|
30
|
+
|
|
31
|
+
var RelayRecordSource = require('../store/RelayRecordSource');
|
|
32
|
+
|
|
33
|
+
var ActorSpecificEnvironment = require('./ActorSpecificEnvironment');
|
|
34
|
+
|
|
35
35
|
var MultiActorEnvironment = /*#__PURE__*/function () {
|
|
36
36
|
function MultiActorEnvironment(config) {
|
|
37
37
|
var _config$getDataID, _config$logFn, _config$requiredField, _config$treatMissingF, _config$isServer, _config$defaultRender;
|
|
@@ -258,8 +258,7 @@ var MultiActorEnvironment = /*#__PURE__*/function () {
|
|
|
258
258
|
};
|
|
259
259
|
|
|
260
260
|
_proto.execute = function execute(actorEnvironment, _ref) {
|
|
261
|
-
var operation = _ref.operation
|
|
262
|
-
updater = _ref.updater;
|
|
261
|
+
var operation = _ref.operation;
|
|
263
262
|
return this._execute(actorEnvironment, {
|
|
264
263
|
createSource: function createSource() {
|
|
265
264
|
return actorEnvironment.getNetwork().execute(operation.request.node.params, operation.request.variables, operation.request.cacheConfig || {}, null);
|
|
@@ -267,16 +266,30 @@ var MultiActorEnvironment = /*#__PURE__*/function () {
|
|
|
267
266
|
isClientPayload: false,
|
|
268
267
|
operation: operation,
|
|
269
268
|
optimisticConfig: null,
|
|
270
|
-
updater:
|
|
269
|
+
updater: null
|
|
271
270
|
});
|
|
272
271
|
};
|
|
273
272
|
|
|
274
|
-
_proto.
|
|
273
|
+
_proto.executeSubscription = function executeSubscription(actorEnvironment, _ref2) {
|
|
275
274
|
var operation = _ref2.operation,
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
275
|
+
updater = _ref2.updater;
|
|
276
|
+
return this._execute(actorEnvironment, {
|
|
277
|
+
createSource: function createSource() {
|
|
278
|
+
return actorEnvironment.getNetwork().execute(operation.request.node.params, operation.request.variables, operation.request.cacheConfig || {}, null);
|
|
279
|
+
},
|
|
280
|
+
isClientPayload: false,
|
|
281
|
+
operation: operation,
|
|
282
|
+
optimisticConfig: null,
|
|
283
|
+
updater: updater
|
|
284
|
+
});
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
_proto.executeMutation = function executeMutation(actorEnvironment, _ref3) {
|
|
288
|
+
var operation = _ref3.operation,
|
|
289
|
+
optimisticResponse = _ref3.optimisticResponse,
|
|
290
|
+
optimisticUpdater = _ref3.optimisticUpdater,
|
|
291
|
+
updater = _ref3.updater,
|
|
292
|
+
uploadables = _ref3.uploadables;
|
|
280
293
|
var optimisticConfig;
|
|
281
294
|
|
|
282
295
|
if (optimisticResponse || optimisticUpdater) {
|
|
@@ -322,14 +335,14 @@ var MultiActorEnvironment = /*#__PURE__*/function () {
|
|
|
322
335
|
return this._isServer;
|
|
323
336
|
};
|
|
324
337
|
|
|
325
|
-
_proto._execute = function _execute(actorEnvironment,
|
|
338
|
+
_proto._execute = function _execute(actorEnvironment, _ref4) {
|
|
326
339
|
var _this4 = this;
|
|
327
340
|
|
|
328
|
-
var createSource =
|
|
329
|
-
isClientPayload =
|
|
330
|
-
operation =
|
|
331
|
-
optimisticConfig =
|
|
332
|
-
updater =
|
|
341
|
+
var createSource = _ref4.createSource,
|
|
342
|
+
isClientPayload = _ref4.isClientPayload,
|
|
343
|
+
operation = _ref4.operation,
|
|
344
|
+
optimisticConfig = _ref4.optimisticConfig,
|
|
345
|
+
updater = _ref4.updater;
|
|
333
346
|
return RelayObservable.create(function (sink) {
|
|
334
347
|
var executor = OperationExecutor.execute({
|
|
335
348
|
actorIdentifier: actorEnvironment.actorIdentifier,
|
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
*/
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
var MultiActorEnvironment = require('./MultiActorEnvironment');
|
|
14
|
-
|
|
15
13
|
var _require = require('./ActorIdentifier'),
|
|
16
14
|
getActorIdentifier = _require.getActorIdentifier;
|
|
17
15
|
|
|
16
|
+
var MultiActorEnvironment = require('./MultiActorEnvironment');
|
|
17
|
+
|
|
18
18
|
module.exports = {
|
|
19
19
|
MultiActorEnvironment: MultiActorEnvironment,
|
|
20
20
|
getActorIdentifier: getActorIdentifier
|
|
@@ -201,7 +201,10 @@ function rangeDelete(config, request) {
|
|
|
201
201
|
return;
|
|
202
202
|
}
|
|
203
203
|
|
|
204
|
-
var deleteIDs = [];
|
|
204
|
+
var deleteIDs = []; // the type of data should come from a type parameter associated with ConcreteRequest,
|
|
205
|
+
// but ConcreteRequest does not contain a type parameter. Hence, we use a FlowFixMe.
|
|
206
|
+
// $FlowFixMe[incompatible-use] see above
|
|
207
|
+
|
|
205
208
|
var deletedIDField = data[rootField];
|
|
206
209
|
|
|
207
210
|
if (deletedIDField && Array.isArray(deletedIDFieldName)) {
|
|
@@ -10,20 +10,21 @@
|
|
|
10
10
|
// flowlint ambiguous-object-type:error
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
var invariant = require('invariant');
|
|
14
|
-
|
|
15
13
|
var _require = require('../store/ClientID'),
|
|
16
14
|
generateClientID = _require.generateClientID;
|
|
17
15
|
|
|
18
16
|
var _require2 = require('../store/RelayStoreUtils'),
|
|
19
17
|
getStableStorageKey = _require2.getStableStorageKey;
|
|
20
18
|
|
|
19
|
+
var invariant = require('invariant');
|
|
21
20
|
/**
|
|
22
21
|
* @internal
|
|
23
22
|
*
|
|
24
23
|
* A helper class for manipulating a given record from a record source via an
|
|
25
24
|
* imperative/OO-style API.
|
|
26
25
|
*/
|
|
26
|
+
|
|
27
|
+
|
|
27
28
|
var RelayRecordProxy = /*#__PURE__*/function () {
|
|
28
29
|
function RelayRecordProxy(source, mutator, dataID) {
|
|
29
30
|
this._dataID = dataID;
|
|
@@ -12,11 +12,10 @@
|
|
|
12
12
|
|
|
13
13
|
var RelayModernRecord = require('../store/RelayModernRecord');
|
|
14
14
|
|
|
15
|
-
var invariant = require('invariant');
|
|
16
|
-
|
|
17
15
|
var _require = require('../store/RelayRecordState'),
|
|
18
16
|
EXISTENT = _require.EXISTENT;
|
|
19
17
|
|
|
18
|
+
var invariant = require('invariant');
|
|
20
19
|
/**
|
|
21
20
|
* @internal
|
|
22
21
|
*
|
|
@@ -29,6 +28,8 @@ var _require = require('../store/RelayRecordState'),
|
|
|
29
28
|
* - Modifications cause a fresh version of a record to be created in `sink`.
|
|
30
29
|
* These sink records contain only modified fields.
|
|
31
30
|
*/
|
|
31
|
+
|
|
32
|
+
|
|
32
33
|
var RelayRecordSourceMutator = /*#__PURE__*/function () {
|
|
33
34
|
function RelayRecordSourceMutator(base, sink) {
|
|
34
35
|
this.__sources = [sink, base];
|
|
@@ -12,10 +12,6 @@
|
|
|
12
12
|
|
|
13
13
|
var RelayModernRecord = require('../store/RelayModernRecord');
|
|
14
14
|
|
|
15
|
-
var RelayRecordProxy = require('./RelayRecordProxy');
|
|
16
|
-
|
|
17
|
-
var invariant = require('invariant');
|
|
18
|
-
|
|
19
15
|
var _require = require('../store/RelayRecordState'),
|
|
20
16
|
EXISTENT = _require.EXISTENT,
|
|
21
17
|
NONEXISTENT = _require.NONEXISTENT;
|
|
@@ -24,11 +20,19 @@ var _require2 = require('../store/RelayStoreUtils'),
|
|
|
24
20
|
ROOT_ID = _require2.ROOT_ID,
|
|
25
21
|
ROOT_TYPE = _require2.ROOT_TYPE;
|
|
26
22
|
|
|
23
|
+
var _require3 = require('./readUpdatableQuery_EXPERIMENTAL'),
|
|
24
|
+
_readUpdatableQuery_EXPERIMENTAL = _require3.readUpdatableQuery_EXPERIMENTAL;
|
|
25
|
+
|
|
26
|
+
var RelayRecordProxy = require('./RelayRecordProxy');
|
|
27
|
+
|
|
28
|
+
var invariant = require('invariant');
|
|
27
29
|
/**
|
|
28
30
|
* @internal
|
|
29
31
|
*
|
|
30
32
|
* A helper for manipulating a `RecordSource` via an imperative/OO-style API.
|
|
31
33
|
*/
|
|
34
|
+
|
|
35
|
+
|
|
32
36
|
var RelayRecordSourceProxy = /*#__PURE__*/function () {
|
|
33
37
|
function RelayRecordSourceProxy(mutator, getDataID, handlerProvider) {
|
|
34
38
|
this.__mutator = mutator;
|
|
@@ -131,6 +135,10 @@ var RelayRecordSourceProxy = /*#__PURE__*/function () {
|
|
|
131
135
|
return this._idsMarkedForInvalidation;
|
|
132
136
|
};
|
|
133
137
|
|
|
138
|
+
_proto.readUpdatableQuery_EXPERIMENTAL = function readUpdatableQuery_EXPERIMENTAL(query, variables) {
|
|
139
|
+
return _readUpdatableQuery_EXPERIMENTAL(query, variables, this);
|
|
140
|
+
};
|
|
141
|
+
|
|
134
142
|
return RelayRecordSourceProxy;
|
|
135
143
|
}();
|
|
136
144
|
|
|
@@ -10,12 +10,14 @@
|
|
|
10
10
|
// flowlint ambiguous-object-type:error
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
var invariant = require('invariant');
|
|
14
|
-
|
|
15
13
|
var _require = require('../store/RelayStoreUtils'),
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
ROOT_TYPE = _require.ROOT_TYPE,
|
|
15
|
+
getStorageKey = _require.getStorageKey;
|
|
18
16
|
|
|
17
|
+
var _require2 = require('./readUpdatableQuery_EXPERIMENTAL'),
|
|
18
|
+
_readUpdatableQuery_EXPERIMENTAL = _require2.readUpdatableQuery_EXPERIMENTAL;
|
|
19
|
+
|
|
20
|
+
var invariant = require('invariant');
|
|
19
21
|
/**
|
|
20
22
|
* @internal
|
|
21
23
|
*
|
|
@@ -24,6 +26,8 @@ var _require = require('../store/RelayStoreUtils'),
|
|
|
24
26
|
* complex arguments and it can be tedious to re-construct the correct sets of
|
|
25
27
|
* arguments to pass to e.g. `getRoot().getLinkedRecord()`.
|
|
26
28
|
*/
|
|
29
|
+
|
|
30
|
+
|
|
27
31
|
var RelayRecordSourceSelectorProxy = /*#__PURE__*/function () {
|
|
28
32
|
function RelayRecordSourceSelectorProxy(mutator, recordSource, readSelector) {
|
|
29
33
|
this.__mutator = mutator;
|
|
@@ -91,6 +95,10 @@ var RelayRecordSourceSelectorProxy = /*#__PURE__*/function () {
|
|
|
91
95
|
this.__recordSource.invalidateStore();
|
|
92
96
|
};
|
|
93
97
|
|
|
98
|
+
_proto.readUpdatableQuery_EXPERIMENTAL = function readUpdatableQuery_EXPERIMENTAL(query, variables) {
|
|
99
|
+
return _readUpdatableQuery_EXPERIMENTAL(query, variables, this);
|
|
100
|
+
};
|
|
101
|
+
|
|
94
102
|
return RelayRecordSourceSelectorProxy;
|
|
95
103
|
}();
|
|
96
104
|
|
|
@@ -10,18 +10,18 @@
|
|
|
10
10
|
// flowlint ambiguous-object-type:error
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
var RelayDeclarativeMutationConfig = require('./RelayDeclarativeMutationConfig');
|
|
14
|
-
|
|
15
|
-
var invariant = require('invariant');
|
|
16
|
-
|
|
17
|
-
var isRelayModernEnvironment = require('../store/isRelayModernEnvironment');
|
|
18
|
-
|
|
19
13
|
var _require = require('../query/GraphQLTag'),
|
|
20
14
|
getRequest = _require.getRequest;
|
|
21
15
|
|
|
16
|
+
var isRelayModernEnvironment = require('../store/isRelayModernEnvironment');
|
|
17
|
+
|
|
22
18
|
var _require2 = require('../store/RelayModernOperationDescriptor'),
|
|
23
19
|
createOperationDescriptor = _require2.createOperationDescriptor;
|
|
24
20
|
|
|
21
|
+
var RelayDeclarativeMutationConfig = require('./RelayDeclarativeMutationConfig');
|
|
22
|
+
|
|
23
|
+
var invariant = require('invariant');
|
|
24
|
+
|
|
25
25
|
/**
|
|
26
26
|
* Higher-level helper function to execute a mutation against a specific
|
|
27
27
|
* environment.
|
|
@@ -14,25 +14,25 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
14
14
|
|
|
15
15
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
16
16
|
|
|
17
|
-
var RelayDeclarativeMutationConfig = require('./RelayDeclarativeMutationConfig');
|
|
18
|
-
|
|
19
|
-
var invariant = require('invariant');
|
|
20
|
-
|
|
21
|
-
var isRelayModernEnvironment = require('../store/isRelayModernEnvironment');
|
|
22
|
-
|
|
23
|
-
var validateMutation = require('./validateMutation');
|
|
24
|
-
|
|
25
|
-
var warning = require("fbjs/lib/warning");
|
|
26
|
-
|
|
27
17
|
var _require = require('../query/GraphQLTag'),
|
|
28
18
|
getRequest = _require.getRequest;
|
|
29
19
|
|
|
30
20
|
var _require2 = require('../store/ClientID'),
|
|
31
21
|
generateUniqueClientID = _require2.generateUniqueClientID;
|
|
32
22
|
|
|
23
|
+
var isRelayModernEnvironment = require('../store/isRelayModernEnvironment');
|
|
24
|
+
|
|
33
25
|
var _require3 = require('../store/RelayModernOperationDescriptor'),
|
|
34
26
|
createOperationDescriptor = _require3.createOperationDescriptor;
|
|
35
27
|
|
|
28
|
+
var RelayDeclarativeMutationConfig = require('./RelayDeclarativeMutationConfig');
|
|
29
|
+
|
|
30
|
+
var validateMutation = require('./validateMutation');
|
|
31
|
+
|
|
32
|
+
var invariant = require('invariant');
|
|
33
|
+
|
|
34
|
+
var warning = require("fbjs/lib/warning");
|
|
35
|
+
|
|
36
36
|
/**
|
|
37
37
|
* Higher-level helper function to execute a mutation against a specific
|
|
38
38
|
* environment.
|
|
@@ -58,10 +58,7 @@ function commitMutation(environment, config) {
|
|
|
58
58
|
onUnsubscribe = config.onUnsubscribe,
|
|
59
59
|
variables = config.variables,
|
|
60
60
|
uploadables = config.uploadables;
|
|
61
|
-
var operation = createOperationDescriptor(mutation,
|
|
62
|
-
/* $FlowFixMe[class-object-subtyping] added when improving typing for this
|
|
63
|
-
* parameters */
|
|
64
|
-
variables, cacheConfig, generateUniqueClientID()); // TODO: remove this check after we fix flow.
|
|
61
|
+
var operation = createOperationDescriptor(mutation, variables, cacheConfig, generateUniqueClientID()); // TODO: remove this check after we fix flow.
|
|
65
62
|
|
|
66
63
|
if (typeof optimisticResponse === 'function') {
|
|
67
64
|
optimisticResponse = optimisticResponse();
|
|
@@ -90,6 +87,8 @@ function commitMutation(environment, config) {
|
|
|
90
87
|
uploadables: uploadables
|
|
91
88
|
}).subscribe({
|
|
92
89
|
next: function next(payload) {
|
|
90
|
+
var _config$onNext;
|
|
91
|
+
|
|
93
92
|
if (Array.isArray(payload)) {
|
|
94
93
|
payload.forEach(function (item) {
|
|
95
94
|
if (item.errors) {
|
|
@@ -101,6 +100,8 @@ function commitMutation(environment, config) {
|
|
|
101
100
|
errors.push.apply(errors, (0, _toConsumableArray2["default"])(payload.errors));
|
|
102
101
|
}
|
|
103
102
|
}
|
|
103
|
+
|
|
104
|
+
(_config$onNext = config.onNext) === null || _config$onNext === void 0 ? void 0 : _config$onNext.call(config);
|
|
104
105
|
},
|
|
105
106
|
complete: function complete() {
|
|
106
107
|
var onCompleted = config.onCompleted;
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*
|
|
8
|
+
* @emails oncall+relay
|
|
9
|
+
* @format
|
|
10
|
+
*/
|
|
11
|
+
// flowlint ambiguous-object-type:error
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
15
|
+
|
|
16
|
+
var _createForOfIteratorHelper2 = _interopRequireDefault(require("@babel/runtime/helpers/createForOfIteratorHelper"));
|
|
17
|
+
|
|
18
|
+
var _require = require('../query/GraphQLTag'),
|
|
19
|
+
getRequest = _require.getRequest;
|
|
20
|
+
|
|
21
|
+
var _require2 = require('../store/RelayStoreUtils'),
|
|
22
|
+
getArgumentValues = _require2.getArgumentValues;
|
|
23
|
+
|
|
24
|
+
var nonUpdatableKeys = ['id', '__id', '__typename'];
|
|
25
|
+
|
|
26
|
+
function readUpdatableQuery_EXPERIMENTAL(query, variables, proxy) {
|
|
27
|
+
// TODO assert that the concrete request is an updatable query
|
|
28
|
+
var request = getRequest(query);
|
|
29
|
+
var updatableProxy = {};
|
|
30
|
+
updateProxyFromSelections(updatableProxy, proxy.getRoot(), variables, request.fragment.selections, proxy);
|
|
31
|
+
|
|
32
|
+
if (process.env.NODE_ENV !== "production") {
|
|
33
|
+
Object.freeze(updatableProxy);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return updatableProxy;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function updateProxyFromSelections(mutableUpdatableProxy, recordProxy, queryVariables, selections, root) {
|
|
40
|
+
var _selection$alias, _selection$alias2;
|
|
41
|
+
|
|
42
|
+
var _iterator = (0, _createForOfIteratorHelper2["default"])(selections),
|
|
43
|
+
_step;
|
|
44
|
+
|
|
45
|
+
try {
|
|
46
|
+
var _loop = function _loop() {
|
|
47
|
+
var selection = _step.value;
|
|
48
|
+
|
|
49
|
+
switch (selection.kind) {
|
|
50
|
+
case 'LinkedField':
|
|
51
|
+
// Linked fields are assignable if they contain fragment spreads or
|
|
52
|
+
// read-only otherwise.
|
|
53
|
+
var isAssignable = selection.selections.some(function (item) {
|
|
54
|
+
return item.kind === 'FragmentSpread';
|
|
55
|
+
});
|
|
56
|
+
var set = !isAssignable ? undefined : selection.plural ? createSetterForPluralLinkedField(selection, queryVariables, recordProxy, root) : createSetterForSingularLinkedField(selection, queryVariables, recordProxy, root);
|
|
57
|
+
var get = selection.plural ? createGetterForPluralLinkedField(selection, queryVariables, recordProxy, root) : createGetterForSingularLinkedField(selection, queryVariables, recordProxy, root);
|
|
58
|
+
Object.defineProperty(mutableUpdatableProxy, (_selection$alias = selection.alias) !== null && _selection$alias !== void 0 ? _selection$alias : selection.name, {
|
|
59
|
+
get: get,
|
|
60
|
+
set: set
|
|
61
|
+
});
|
|
62
|
+
break;
|
|
63
|
+
|
|
64
|
+
case 'ScalarField':
|
|
65
|
+
var scalarFieldName = (_selection$alias2 = selection.alias) !== null && _selection$alias2 !== void 0 ? _selection$alias2 : selection.name;
|
|
66
|
+
Object.defineProperty(mutableUpdatableProxy, scalarFieldName, {
|
|
67
|
+
get: function get() {
|
|
68
|
+
var _selection$args;
|
|
69
|
+
|
|
70
|
+
var variables = getArgumentValues((_selection$args = selection.args) !== null && _selection$args !== void 0 ? _selection$args : [], queryVariables); // Flow incorrect assumes that the return value for the get method must match
|
|
71
|
+
// the set parameter.
|
|
72
|
+
|
|
73
|
+
return recordProxy.getValue(selection.name, // $FlowFixMe[unclear-type] No good way to type these variables
|
|
74
|
+
variables // $FlowFixMe[unclear-type] Typed by the generated updatable query flow type
|
|
75
|
+
);
|
|
76
|
+
},
|
|
77
|
+
set: nonUpdatableKeys.includes(selection.name) ? undefined : // $FlowFixMe[unclear-type] Typed by the generated updatable query flow type
|
|
78
|
+
function (newValue) {
|
|
79
|
+
var _selection$args2;
|
|
80
|
+
|
|
81
|
+
var variables = getArgumentValues((_selection$args2 = selection.args) !== null && _selection$args2 !== void 0 ? _selection$args2 : [], queryVariables);
|
|
82
|
+
recordProxy.setValue(newValue, selection.name, // $FlowFixMe[unclear-type] No good way to type these variables
|
|
83
|
+
variables);
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
break;
|
|
87
|
+
|
|
88
|
+
case 'InlineFragment':
|
|
89
|
+
if (recordProxy.getType() === selection.type) {
|
|
90
|
+
updateProxyFromSelections(mutableUpdatableProxy, recordProxy, queryVariables, selection.selections, root);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
break;
|
|
94
|
+
|
|
95
|
+
case 'FragmentSpread':
|
|
96
|
+
// Explicitly ignore
|
|
97
|
+
break;
|
|
98
|
+
|
|
99
|
+
default:
|
|
100
|
+
throw new Error('Encountered an unexpected ReaderSelection variant in RelayRecordSourceProxy. This indicates a bug in Relay.');
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
105
|
+
_loop();
|
|
106
|
+
}
|
|
107
|
+
} catch (err) {
|
|
108
|
+
_iterator.e(err);
|
|
109
|
+
} finally {
|
|
110
|
+
_iterator.f();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function createSetterForPluralLinkedField(selection, queryVariables, recordProxy, root) {
|
|
115
|
+
return function set(newValue) {
|
|
116
|
+
var _selection$args3;
|
|
117
|
+
|
|
118
|
+
var variables = getArgumentValues((_selection$args3 = selection.args) !== null && _selection$args3 !== void 0 ? _selection$args3 : [], queryVariables);
|
|
119
|
+
|
|
120
|
+
if (newValue == null) {
|
|
121
|
+
// $FlowFixMe[unclear-type] No good way to type these variables
|
|
122
|
+
recordProxy.setValue(null, selection.name, variables);
|
|
123
|
+
} else {
|
|
124
|
+
var recordProxies = newValue.map(function (item) {
|
|
125
|
+
if (item == null) {
|
|
126
|
+
throw new Error('When assigning an array of items, none of the items should be null or undefined.');
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
var __id = item.__id;
|
|
130
|
+
|
|
131
|
+
if (__id == null) {
|
|
132
|
+
throw new Error('The __id field must be present on each item passed to the setter. This indicates a bug in Relay.');
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
var newValueRecord = root.get(__id);
|
|
136
|
+
|
|
137
|
+
if (newValueRecord == null) {
|
|
138
|
+
throw new Error("Did not find item with data id ".concat(__id, " in the store."));
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return newValueRecord;
|
|
142
|
+
});
|
|
143
|
+
recordProxy.setLinkedRecords(recordProxies, selection.name, // $FlowFixMe[unclear-type] No good way to type these variables
|
|
144
|
+
variables);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function createSetterForSingularLinkedField(selection, queryVariables, recordProxy, root) {
|
|
150
|
+
return function set(newValue) {
|
|
151
|
+
var _selection$args4;
|
|
152
|
+
|
|
153
|
+
var variables = getArgumentValues((_selection$args4 = selection.args) !== null && _selection$args4 !== void 0 ? _selection$args4 : [], queryVariables);
|
|
154
|
+
|
|
155
|
+
if (newValue == null) {
|
|
156
|
+
// $FlowFixMe[unclear-type] No good way to type these variables
|
|
157
|
+
recordProxy.setValue(null, selection.name, variables);
|
|
158
|
+
} else {
|
|
159
|
+
var __id = newValue.__id;
|
|
160
|
+
|
|
161
|
+
if (__id == null) {
|
|
162
|
+
throw new Error('The __id field must be present on the argument. This indicates a bug in Relay.');
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
var newValueRecord = root.get(__id);
|
|
166
|
+
|
|
167
|
+
if (newValueRecord == null) {
|
|
168
|
+
throw new Error("Did not find item with data id ".concat(__id, " in the store."));
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
recordProxy.setLinkedRecord(newValueRecord, selection.name, // $FlowFixMe[unclear-type] No good way to type these variables
|
|
172
|
+
variables);
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function createGetterForPluralLinkedField(selection, queryVariables, recordProxy, root) {
|
|
178
|
+
return function () {
|
|
179
|
+
var _selection$args5;
|
|
180
|
+
|
|
181
|
+
var variables = getArgumentValues((_selection$args5 = selection.args) !== null && _selection$args5 !== void 0 ? _selection$args5 : [], queryVariables);
|
|
182
|
+
var linkedRecords = recordProxy.getLinkedRecords(selection.name, // $FlowFixMe[unclear-type] No good way to type these variables
|
|
183
|
+
variables);
|
|
184
|
+
|
|
185
|
+
if (linkedRecords != null) {
|
|
186
|
+
return linkedRecords.map(function (linkedRecord) {
|
|
187
|
+
if (linkedRecord != null) {
|
|
188
|
+
var updatableProxy = {};
|
|
189
|
+
updateProxyFromSelections(updatableProxy, linkedRecord, queryVariables, selection.selections, root);
|
|
190
|
+
|
|
191
|
+
if (process.env.NODE_ENV !== "production") {
|
|
192
|
+
Object.freeze(updatableProxy);
|
|
193
|
+
} // Flow incorrect assumes that the return value for the get method must match
|
|
194
|
+
// the set parameter.
|
|
195
|
+
// $FlowFixMe[unclear-type] Typed by the generated updatable query flow type
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
return updatableProxy;
|
|
199
|
+
} else {
|
|
200
|
+
return linkedRecord;
|
|
201
|
+
} // $FlowFixMe[unclear-type] Typed by the generated updatable query flow type
|
|
202
|
+
|
|
203
|
+
});
|
|
204
|
+
} else {
|
|
205
|
+
return linkedRecords;
|
|
206
|
+
}
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
function createGetterForSingularLinkedField(selection, queryVariables, recordProxy, root) {
|
|
211
|
+
return function () {
|
|
212
|
+
var _selection$args6;
|
|
213
|
+
|
|
214
|
+
var variables = getArgumentValues((_selection$args6 = selection.args) !== null && _selection$args6 !== void 0 ? _selection$args6 : [], queryVariables);
|
|
215
|
+
var linkedRecord = recordProxy.getLinkedRecord(selection.name, // $FlowFixMe[unclear-type] No good way to type these variables
|
|
216
|
+
variables);
|
|
217
|
+
|
|
218
|
+
if (linkedRecord != null) {
|
|
219
|
+
var updatableProxy = {};
|
|
220
|
+
updateProxyFromSelections(updatableProxy, linkedRecord, queryVariables, selection.selections, root);
|
|
221
|
+
|
|
222
|
+
if (process.env.NODE_ENV !== "production") {
|
|
223
|
+
Object.freeze(updatableProxy);
|
|
224
|
+
} // Flow incorrect assumes that the return value for the get method must match
|
|
225
|
+
// the set parameter.
|
|
226
|
+
// $FlowFixMe[unclear-type] Typed by the generated updatable query flow type
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
return updatableProxy;
|
|
230
|
+
} else {
|
|
231
|
+
return linkedRecord;
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
module.exports = {
|
|
237
|
+
readUpdatableQuery_EXPERIMENTAL: readUpdatableQuery_EXPERIMENTAL
|
|
238
|
+
};
|
|
@@ -14,16 +14,11 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
14
14
|
|
|
15
15
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
16
16
|
|
|
17
|
-
var warning = require("fbjs/lib/warning"); // $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
21
|
-
|
|
22
17
|
var _require = require('../util/RelayConcreteNode'),
|
|
23
18
|
ACTOR_CHANGE = _require.ACTOR_CHANGE,
|
|
24
|
-
CONDITION = _require.CONDITION,
|
|
25
19
|
CLIENT_COMPONENT = _require.CLIENT_COMPONENT,
|
|
26
20
|
CLIENT_EXTENSION = _require.CLIENT_EXTENSION,
|
|
21
|
+
CONDITION = _require.CONDITION,
|
|
27
22
|
DEFER = _require.DEFER,
|
|
28
23
|
FLIGHT_FIELD = _require.FLIGHT_FIELD,
|
|
29
24
|
FRAGMENT_SPREAD = _require.FRAGMENT_SPREAD,
|
|
@@ -36,6 +31,11 @@ var _require = require('../util/RelayConcreteNode'),
|
|
|
36
31
|
STREAM = _require.STREAM,
|
|
37
32
|
TYPE_DISCRIMINATOR = _require.TYPE_DISCRIMINATOR;
|
|
38
33
|
|
|
34
|
+
var warning = require("fbjs/lib/warning");
|
|
35
|
+
|
|
36
|
+
// $FlowFixMe[method-unbinding] added when improving typing for this parameters
|
|
37
|
+
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
38
|
+
|
|
39
39
|
var validateMutation = function validateMutation() {};
|
|
40
40
|
|
|
41
41
|
if (process.env.NODE_ENV !== "production") {
|
|
@@ -11,10 +11,11 @@
|
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
13
|
var RelayObservable = require('./RelayObservable');
|
|
14
|
-
|
|
15
14
|
/**
|
|
16
15
|
* Converts a FetchFunction into an ExecuteFunction for use by RelayNetwork.
|
|
17
16
|
*/
|
|
17
|
+
|
|
18
|
+
|
|
18
19
|
function convertFetch(fn) {
|
|
19
20
|
return function fetch(request, variables, cacheConfig, uploadables, logRequestInfo) {
|
|
20
21
|
var result = fn(request, variables, cacheConfig, uploadables, logRequestInfo); // Note: We allow FetchFunction to directly return Error to indicate
|
|
@@ -10,15 +10,16 @@
|
|
|
10
10
|
// flowlint ambiguous-object-type:error
|
|
11
11
|
'use strict';
|
|
12
12
|
|
|
13
|
-
var invariant = require('invariant');
|
|
14
|
-
|
|
15
13
|
var _require = require('./ConvertToExecuteFunction'),
|
|
16
14
|
convertFetch = _require.convertFetch;
|
|
17
15
|
|
|
16
|
+
var invariant = require('invariant');
|
|
18
17
|
/**
|
|
19
18
|
* Creates an implementation of the `Network` interface defined in
|
|
20
19
|
* `RelayNetworkTypes` given `fetch` and `subscribe` functions.
|
|
21
20
|
*/
|
|
21
|
+
|
|
22
|
+
|
|
22
23
|
function create(fetchFn, subscribe) {
|
|
23
24
|
// Convert to functions that returns RelayObservable.
|
|
24
25
|
var observeFetch = convertFetch(fetchFn);
|
|
@@ -332,15 +332,13 @@ var RelayObservable = /*#__PURE__*/function () {
|
|
|
332
332
|
if (subscriptions.length === 0) {
|
|
333
333
|
sink.complete();
|
|
334
334
|
}
|
|
335
|
-
}
|
|
336
|
-
|
|
335
|
+
}
|
|
337
336
|
|
|
338
337
|
_this7.subscribe({
|
|
339
338
|
start: start,
|
|
340
339
|
next: function next(value) {
|
|
341
340
|
try {
|
|
342
341
|
if (!sink.closed) {
|
|
343
|
-
// $FlowFixMe[incompatible-call]
|
|
344
342
|
RelayObservable.from(fn(value)).subscribe({
|
|
345
343
|
start: start,
|
|
346
344
|
next: sink.next,
|
|
@@ -14,10 +14,10 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
14
14
|
|
|
15
15
|
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
|
|
16
16
|
|
|
17
|
-
var invariant = require('invariant');
|
|
18
|
-
|
|
19
17
|
var stableCopy = require('../util/stableCopy');
|
|
20
18
|
|
|
19
|
+
var invariant = require('invariant');
|
|
20
|
+
|
|
21
21
|
/**
|
|
22
22
|
* A cache for storing query responses, featuring:
|
|
23
23
|
* - `get` with TTL
|