relay-runtime 1.3.0 → 1.5.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 +16 -26
- package/index.js +3 -6
- package/lib/ConvertToExecuteFunction.js +73 -0
- package/lib/RelayConcreteNode.js +31 -14
- package/lib/RelayConcreteVariables.js +11 -6
- package/lib/RelayConnectionHandler.js +2 -4
- package/lib/RelayConnectionInterface.js +3 -5
- package/lib/RelayCore.js +4 -6
- package/lib/RelayDataLoader.js +2 -4
- package/lib/RelayDeclarativeMutationConfig.js +316 -0
- package/lib/RelayDefaultHandleKey.js +2 -4
- package/lib/RelayDefaultHandlerProvider.js +2 -4
- package/lib/RelayError.js +2 -6
- package/lib/RelayInMemoryRecordSource.js +2 -4
- package/lib/RelayInternalTypes.js +2 -5
- package/lib/RelayInternals.js +2 -5
- package/lib/RelayMarkSweepStore.js +22 -5
- package/lib/RelayMetricsRecorder.js +9 -9
- package/lib/RelayMockRenderer.js +3 -8
- package/lib/RelayModernEnvironment.js +120 -135
- package/lib/RelayModernFragmentSpecResolver.js +81 -55
- package/lib/RelayModernGraphQLTag.js +8 -17
- package/lib/RelayModernOperationSelector.js +8 -8
- package/lib/RelayModernRecord.js +8 -8
- package/lib/RelayModernSelector.js +54 -43
- package/lib/RelayNetwork.js +9 -11
- package/lib/RelayNetworkDebug.js +4 -7
- package/lib/RelayNetworkLogger.js +2 -4
- package/lib/RelayNetworkLoggerTransaction.js +18 -20
- package/lib/RelayNetworkTypes.js +2 -4
- package/lib/RelayObservable.js +193 -120
- package/lib/RelayProfiler.js +7 -7
- package/lib/RelayPublishQueue.js +17 -9
- package/lib/RelayQueryCaching.js +2 -5
- package/lib/RelayQueryResponseCache.js +3 -5
- package/lib/RelayReader.js +18 -8
- package/lib/RelayRecordProxy.js +12 -11
- package/lib/RelayRecordSourceMutator.js +9 -9
- package/lib/RelayRecordSourceProxy.js +15 -13
- package/lib/RelayRecordSourceSelectorProxy.js +2 -4
- package/lib/RelayRecordState.js +2 -4
- package/lib/RelayReferenceMarker.js +2 -4
- package/lib/RelayResponseNormalizer.js +34 -25
- package/lib/RelayRuntime.js +25 -14
- package/lib/RelayRuntimeTypes.js +22 -0
- package/lib/RelayShallowMock.js +4 -7
- package/lib/RelayStoreTypes.js +2 -4
- package/lib/RelayStoreUtils.js +66 -26
- package/lib/RelayTaskQueue.js +2 -5
- package/lib/RelayTypes.js +2 -5
- package/lib/RelayViewerHandler.js +4 -5
- package/lib/applyRelayModernOptimisticMutation.js +9 -8
- package/lib/cloneRelayHandleSourceField.js +4 -11
- package/lib/commitLocalUpdate.js +2 -4
- package/lib/commitRelayModernMutation.js +24 -22
- package/lib/createRelayNetworkLogger.js +25 -27
- package/lib/dedent.js +2 -5
- package/lib/deepFreeze.js +3 -5
- package/lib/deferrableFragmentKey.js +21 -0
- package/lib/fetchRelayModernQuery.js +13 -21
- package/lib/generateRelayClientID.js +2 -4
- package/lib/getRelayHandleKey.js +2 -4
- package/lib/hasOverlappingIDs.js +2 -4
- package/lib/isCompatibleRelayFragmentType.js +2 -5
- package/lib/isPromise.js +2 -5
- package/lib/isRelayModernEnvironment.js +2 -4
- package/lib/isScalarAndEqual.js +3 -5
- package/lib/normalizePayload.js +10 -13
- package/lib/normalizeRelayPayload.js +8 -5
- package/lib/recycleNodesInto.js +2 -4
- package/lib/relayUnstableBatchedUpdates.js +2 -5
- package/lib/relayUnstableBatchedUpdates.native.js +2 -5
- package/lib/requestRelaySubscription.js +20 -34
- package/lib/simpleClone.js +2 -4
- package/lib/stableCopy.js +35 -0
- package/lib/testEditDistance.js +2 -5
- package/lib/throwFailedPromise.js +2 -5
- package/package.json +4 -5
- package/relay-runtime.js +2307 -2665
- package/relay-runtime.min.js +6 -9
- package/ARCHITECTURE.md +0 -232
- package/PATENTS +0 -33
- package/lib/ConvertToObserveFunction.js +0 -39
- package/lib/RelayDebugger.js +0 -199
- package/lib/RelayRecordSourceInspector.js +0 -289
- package/lib/RelayStoreProxyDebugger.js +0 -44
- package/lib/formatStorageKey.js +0 -37
- package/lib/prettyStringify.js +0 -35
- package/lib/setRelayModernMutationConfigs.js +0 -302
- package/lib/stableJSONStringify.js +0 -45
package/LICENSE
CHANGED
|
@@ -1,31 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
For Relay software
|
|
1
|
+
MIT License
|
|
4
2
|
|
|
5
3
|
Copyright (c) 2013-present, Facebook, Inc.
|
|
6
|
-
All rights reserved.
|
|
7
|
-
|
|
8
|
-
Redistribution and use in source and binary forms, with or without modification,
|
|
9
|
-
are permitted provided that the following conditions are met:
|
|
10
|
-
|
|
11
|
-
* Redistributions of source code must retain the above copyright notice, this
|
|
12
|
-
list of conditions and the following disclaimer.
|
|
13
4
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
17
11
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
prior written permission.
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
21
14
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
30
|
-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
31
|
-
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/index.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Relay v1.
|
|
2
|
+
* Relay v1.5.0
|
|
3
3
|
*
|
|
4
4
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
5
|
-
* All rights reserved.
|
|
6
|
-
*
|
|
7
|
-
* This source code is licensed under the BSD-style license found in the
|
|
8
|
-
* LICENSE file in the root directory of this source tree. An additional grant
|
|
9
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
10
5
|
*
|
|
6
|
+
* This source code is licensed under the MIT license found in the
|
|
7
|
+
* LICENSE file in the root directory of this source tree.
|
|
11
8
|
*/
|
|
12
9
|
|
|
13
10
|
module.exports = require('./lib/RelayRuntime.js');
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2013-present, Facebook, Inc.
|
|
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
|
+
* @providesModule ConvertToExecuteFunction
|
|
8
|
+
*
|
|
9
|
+
* @format
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Converts a FetchFunction into an ExecuteFunction for use by RelayNetwork.
|
|
16
|
+
*/
|
|
17
|
+
function convertFetch(fn) {
|
|
18
|
+
return function fetch(request, variables, cacheConfig, uploadables) {
|
|
19
|
+
var result = fn(request, variables, cacheConfig, uploadables);
|
|
20
|
+
// Note: We allow FetchFunction to directly return Error to indicate
|
|
21
|
+
// a failure to fetch. To avoid handling this special case throughout the
|
|
22
|
+
// Relay codebase, it is explicitly handled here.
|
|
23
|
+
if (result instanceof Error) {
|
|
24
|
+
return require('./RelayObservable').create(function (sink) {
|
|
25
|
+
return sink.error(result);
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return require('./RelayObservable').from(result).map(function (value) {
|
|
29
|
+
return convertToExecutePayload(request, variables, value);
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Converts a SubscribeFunction into an ExecuteFunction for use by RelayNetwork.
|
|
36
|
+
*/
|
|
37
|
+
function convertSubscribe(fn) {
|
|
38
|
+
return function subscribe(operation, variables, cacheConfig) {
|
|
39
|
+
return require('./RelayObservable').fromLegacy(function (observer) {
|
|
40
|
+
return fn(operation, variables, cacheConfig, observer);
|
|
41
|
+
}).map(function (value) {
|
|
42
|
+
return convertToExecutePayload(operation, variables, value);
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Given a value which might be a plain GraphQLResponse, coerce to always return
|
|
49
|
+
* an ExecutePayload. A GraphQLResponse may be returned directly from older or
|
|
50
|
+
* simpler Relay Network implementations.
|
|
51
|
+
*/
|
|
52
|
+
function convertToExecutePayload(request, variables, value) {
|
|
53
|
+
if (!value.data && !value.errors && value.response) {
|
|
54
|
+
if (!value.operation) {
|
|
55
|
+
require('fbjs/lib/warning')(false, 'ConvertToExecuteFunction: execute payload contains response but ' + 'is missing operation.');
|
|
56
|
+
return createExecutePayload(request, variables, value.response);
|
|
57
|
+
}
|
|
58
|
+
return value;
|
|
59
|
+
}
|
|
60
|
+
return createExecutePayload(request, variables, value);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function createExecutePayload(request, variables, response) {
|
|
64
|
+
if (request.kind === require('./RelayConcreteNode').BATCH_REQUEST) {
|
|
65
|
+
throw new Error('ConvertToExecuteFunction: Batch request must return ExecutePayload.');
|
|
66
|
+
}
|
|
67
|
+
return { operation: request.operation, variables: variables, response: response };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
module.exports = {
|
|
71
|
+
convertFetch: convertFetch,
|
|
72
|
+
convertSubscribe: convertSubscribe
|
|
73
|
+
};
|
package/lib/RelayConcreteNode.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
3
|
-
* All rights reserved.
|
|
4
3
|
*
|
|
5
|
-
* This source code is licensed under the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
6
|
*
|
|
9
7
|
* @providesModule RelayConcreteNode
|
|
10
8
|
*
|
|
@@ -14,19 +12,27 @@
|
|
|
14
12
|
'use strict';
|
|
15
13
|
|
|
16
14
|
/**
|
|
17
|
-
* Represents a
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
15
|
+
* Represents a common GraphQL request with `text` (or persisted `id`) can be
|
|
16
|
+
* used to execute it, an `operation` containing information to normalize the
|
|
17
|
+
* results, and a `fragment` derived from that operation to read the response
|
|
18
|
+
* data (masking data from child fragments).
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* An experimental wrapper around many operations to request in a batched
|
|
23
|
+
* network request. The composed indivual GraphQL requests should be submitted
|
|
24
|
+
* as a single networked request, e.g. in the case of deferred nodes or
|
|
25
|
+
* for streaming connections that are represented as distinct compiled concrete
|
|
26
|
+
* operations but are still conceptually tied to one source operation.
|
|
21
27
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
* are part of the same batch, e.g. in the case of deferred nodes or
|
|
25
|
-
* for streaming connections that are represented as distinct concrete roots but
|
|
26
|
-
* are still conceptually tied to one source query.
|
|
28
|
+
* Individual requests within the batch may contain data describing their
|
|
29
|
+
* dependencies on other requests or themselves.
|
|
27
30
|
*/
|
|
28
31
|
var RelayConcreteNode = {
|
|
32
|
+
BATCH_REQUEST: 'BatchRequest',
|
|
29
33
|
CONDITION: 'Condition',
|
|
34
|
+
DEFERRABLE_FRAGMENT_SPREAD: 'DeferrableFragmentSpread',
|
|
35
|
+
DEFERRABLE_OPERATION: 'DeferrableOperation',
|
|
30
36
|
FRAGMENT: 'Fragment',
|
|
31
37
|
FRAGMENT_SPREAD: 'FragmentSpread',
|
|
32
38
|
INLINE_FRAGMENT: 'InlineFragment',
|
|
@@ -34,11 +40,22 @@ var RelayConcreteNode = {
|
|
|
34
40
|
LINKED_HANDLE: 'LinkedHandle',
|
|
35
41
|
LITERAL: 'Literal',
|
|
36
42
|
LOCAL_ARGUMENT: 'LocalArgument',
|
|
37
|
-
|
|
43
|
+
OPERATION: 'Operation',
|
|
38
44
|
ROOT_ARGUMENT: 'RootArgument',
|
|
45
|
+
REQUEST: 'Request',
|
|
39
46
|
SCALAR_FIELD: 'ScalarField',
|
|
40
47
|
SCALAR_HANDLE: 'ScalarHandle',
|
|
41
48
|
VARIABLE: 'Variable'
|
|
42
49
|
};
|
|
50
|
+
/**
|
|
51
|
+
* Represents a single operation used to processing and normalize runtime
|
|
52
|
+
* request results.
|
|
53
|
+
*/
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Argument in the provided operation to be derived via the results of
|
|
57
|
+
* other requests in the batch.
|
|
58
|
+
*/
|
|
59
|
+
|
|
43
60
|
|
|
44
61
|
module.exports = RelayConcreteNode;
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
3
|
-
* All rights reserved.
|
|
4
3
|
*
|
|
5
|
-
* This source code is licensed under the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
6
|
*
|
|
9
7
|
*
|
|
10
8
|
* @providesModule RelayConcreteVariables
|
|
@@ -36,7 +34,14 @@ function getFragmentVariables(fragment, rootVariables, argumentVariables) {
|
|
|
36
34
|
variables[definition.name] = definition.defaultValue;
|
|
37
35
|
break;
|
|
38
36
|
case 'RootArgument':
|
|
39
|
-
|
|
37
|
+
if (!rootVariables.hasOwnProperty(definition.name)) {
|
|
38
|
+
/*
|
|
39
|
+
* A temporary fix to mute false alarm in cases where the root argument is stripped
|
|
40
|
+
* off by the compiler due to a conditional directive, we do not need this argument
|
|
41
|
+
* when tryiny to read the data from the store.
|
|
42
|
+
*/
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
40
45
|
variables[definition.name] = rootVariables[definition.name];
|
|
41
46
|
break;
|
|
42
47
|
default:
|
|
@@ -54,7 +59,7 @@ function getFragmentVariables(fragment, rootVariables, argumentVariables) {
|
|
|
54
59
|
*/
|
|
55
60
|
function getOperationVariables(operation, variables) {
|
|
56
61
|
var operationVariables = {};
|
|
57
|
-
operation.
|
|
62
|
+
operation.argumentDefinitions.forEach(function (def) {
|
|
58
63
|
var value = def.defaultValue;
|
|
59
64
|
if (variables[def.name] != null) {
|
|
60
65
|
value = variables[def.name];
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
3
|
-
* All rights reserved.
|
|
4
3
|
*
|
|
5
|
-
* This source code is licensed under the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
6
|
*
|
|
9
7
|
* @providesModule RelayConnectionHandler
|
|
10
8
|
*
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
3
|
-
* All rights reserved.
|
|
4
3
|
*
|
|
5
|
-
* This source code is licensed under the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
6
|
*
|
|
9
7
|
* @providesModule RelayConnectionInterface
|
|
10
8
|
*
|
|
@@ -90,7 +88,7 @@ var RelayConnectionInterface = {
|
|
|
90
88
|
getDefaultPageInfo: function getDefaultPageInfo() {
|
|
91
89
|
var _ref;
|
|
92
90
|
|
|
93
|
-
return _ref = {}, (0, _defineProperty3['default'])(_ref, config.END_CURSOR,
|
|
91
|
+
return _ref = {}, (0, _defineProperty3['default'])(_ref, config.END_CURSOR, null), (0, _defineProperty3['default'])(_ref, config.HAS_NEXT_PAGE, false), (0, _defineProperty3['default'])(_ref, config.HAS_PREV_PAGE, false), (0, _defineProperty3['default'])(_ref, config.START_CURSOR, null), _ref;
|
|
94
92
|
}
|
|
95
93
|
};
|
|
96
94
|
|
package/lib/RelayCore.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
3
|
-
* All rights reserved.
|
|
4
3
|
*
|
|
5
|
-
* This source code is licensed under the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
6
|
*
|
|
9
7
|
* @providesModule RelayCore
|
|
10
8
|
*
|
|
@@ -15,7 +13,7 @@
|
|
|
15
13
|
|
|
16
14
|
var _require = require('./RelayModernGraphQLTag'),
|
|
17
15
|
getFragment = _require.getFragment,
|
|
18
|
-
|
|
16
|
+
getRequest = _require.getRequest;
|
|
19
17
|
|
|
20
18
|
var _require2 = require('./RelayModernOperationSelector'),
|
|
21
19
|
createOperationSelector = _require2.createOperationSelector;
|
|
@@ -46,7 +44,7 @@ module.exports = {
|
|
|
46
44
|
createOperationSelector: createOperationSelector,
|
|
47
45
|
getDataIDsFromObject: getDataIDsFromObject,
|
|
48
46
|
getFragment: getFragment,
|
|
49
|
-
|
|
47
|
+
getRequest: getRequest,
|
|
50
48
|
getSelector: getSelector,
|
|
51
49
|
getSelectorList: getSelectorList,
|
|
52
50
|
getSelectorsFromObject: getSelectorsFromObject,
|
package/lib/RelayDataLoader.js
CHANGED
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
3
|
-
* All rights reserved.
|
|
4
3
|
*
|
|
5
|
-
* This source code is licensed under the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
6
|
*
|
|
9
7
|
* @providesModule RelayDataLoader
|
|
10
8
|
*
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2013-present, Facebook, Inc.
|
|
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
|
+
* @providesModule RelayDeclarativeMutationConfig
|
|
8
|
+
*
|
|
9
|
+
* @format
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
'use strict';
|
|
13
|
+
|
|
14
|
+
var MutationTypes = Object.freeze({
|
|
15
|
+
RANGE_ADD: 'RANGE_ADD',
|
|
16
|
+
RANGE_DELETE: 'RANGE_DELETE',
|
|
17
|
+
NODE_DELETE: 'NODE_DELETE',
|
|
18
|
+
FIELDS_CHANGE: 'FIELDS_CHANGE',
|
|
19
|
+
REQUIRED_CHILDREN: 'REQUIRED_CHILDREN'
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
var RangeOperations = Object.freeze({
|
|
24
|
+
APPEND: 'append',
|
|
25
|
+
IGNORE: 'ignore',
|
|
26
|
+
PREPEND: 'prepend',
|
|
27
|
+
REFETCH: 'refetch', // legacy only
|
|
28
|
+
REMOVE: 'remove' // legacy only
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// Unused in Relay Modern
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
// Unused in Relay Modern
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
function convert(configs, request, optimisticUpdater, updater) {
|
|
38
|
+
var configOptimisticUpdates = optimisticUpdater ? [optimisticUpdater] : [];
|
|
39
|
+
var configUpdates = updater ? [updater] : [];
|
|
40
|
+
configs.forEach(function (config) {
|
|
41
|
+
switch (config.type) {
|
|
42
|
+
case 'NODE_DELETE':
|
|
43
|
+
var nodeDeleteResult = nodeDelete(config, request);
|
|
44
|
+
if (nodeDeleteResult) {
|
|
45
|
+
configOptimisticUpdates.push(nodeDeleteResult);
|
|
46
|
+
configUpdates.push(nodeDeleteResult);
|
|
47
|
+
}
|
|
48
|
+
break;
|
|
49
|
+
case 'RANGE_ADD':
|
|
50
|
+
var rangeAddResult = rangeAdd(config, request);
|
|
51
|
+
if (rangeAddResult) {
|
|
52
|
+
configOptimisticUpdates.push(rangeAddResult);
|
|
53
|
+
configUpdates.push(rangeAddResult);
|
|
54
|
+
}
|
|
55
|
+
break;
|
|
56
|
+
case 'RANGE_DELETE':
|
|
57
|
+
var rangeDeleteResult = rangeDelete(config, request);
|
|
58
|
+
if (rangeDeleteResult) {
|
|
59
|
+
configOptimisticUpdates.push(rangeDeleteResult);
|
|
60
|
+
configUpdates.push(rangeDeleteResult);
|
|
61
|
+
}
|
|
62
|
+
break;
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
return {
|
|
66
|
+
optimisticUpdater: function optimisticUpdater(store, data) {
|
|
67
|
+
configOptimisticUpdates.forEach(function (eachOptimisticUpdater) {
|
|
68
|
+
eachOptimisticUpdater(store, data);
|
|
69
|
+
});
|
|
70
|
+
},
|
|
71
|
+
updater: function updater(store, data) {
|
|
72
|
+
configUpdates.forEach(function (eachUpdater) {
|
|
73
|
+
eachUpdater(store, data);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function nodeDelete(config, request) {
|
|
80
|
+
var deletedIDFieldName = config.deletedIDFieldName;
|
|
81
|
+
|
|
82
|
+
var rootField = getRootField(request);
|
|
83
|
+
if (!rootField) {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
return function (store, data) {
|
|
87
|
+
var payload = store.getRootField(rootField);
|
|
88
|
+
if (!payload) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
var deleteID = payload.getValue(deletedIDFieldName);
|
|
92
|
+
var deleteIDs = Array.isArray(deleteID) ? deleteID : [deleteID];
|
|
93
|
+
deleteIDs.forEach(function (id) {
|
|
94
|
+
if (id && typeof id === 'string') {
|
|
95
|
+
store['delete'](id);
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function rangeAdd(config, request) {
|
|
102
|
+
var parentID = config.parentID,
|
|
103
|
+
connectionInfo = config.connectionInfo,
|
|
104
|
+
edgeName = config.edgeName;
|
|
105
|
+
|
|
106
|
+
if (!parentID) {
|
|
107
|
+
require('fbjs/lib/warning')(false, 'RelayDeclarativeMutationConfig: For mutation config RANGE_ADD ' + 'to work you must include a parentID');
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
var rootField = getRootField(request);
|
|
111
|
+
if (!connectionInfo || !rootField) {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
return function (store, data) {
|
|
115
|
+
var parent = store.get(parentID);
|
|
116
|
+
if (!parent) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
var payload = store.getRootField(rootField);
|
|
120
|
+
if (!payload) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
var serverEdge = payload.getLinkedRecord(edgeName);
|
|
124
|
+
var _iteratorNormalCompletion = true;
|
|
125
|
+
var _didIteratorError = false;
|
|
126
|
+
var _iteratorError = undefined;
|
|
127
|
+
|
|
128
|
+
try {
|
|
129
|
+
for (var _iterator = connectionInfo[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
|
130
|
+
var info = _step.value;
|
|
131
|
+
|
|
132
|
+
if (!serverEdge) {
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
var connection = require('./RelayConnectionHandler').getConnection(parent, info.key, info.filters);
|
|
136
|
+
if (!connection) {
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
var clientEdge = require('./RelayConnectionHandler').buildConnectionEdge(store, connection, serverEdge);
|
|
140
|
+
if (!clientEdge) {
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
switch (info.rangeBehavior) {
|
|
144
|
+
case 'append':
|
|
145
|
+
require('./RelayConnectionHandler').insertEdgeAfter(connection, clientEdge);
|
|
146
|
+
break;
|
|
147
|
+
case 'ignore':
|
|
148
|
+
// Do nothing
|
|
149
|
+
break;
|
|
150
|
+
case 'prepend':
|
|
151
|
+
require('./RelayConnectionHandler').insertEdgeBefore(connection, clientEdge);
|
|
152
|
+
break;
|
|
153
|
+
default:
|
|
154
|
+
require('fbjs/lib/warning')(false, 'RelayDeclarativeMutationConfig: RANGE_ADD range behavior `%s` ' + 'will not work as expected in RelayModern, supported range ' + "behaviors are 'append', 'prepend', and 'ignore'.", info.rangeBehavior);
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
} catch (err) {
|
|
159
|
+
_didIteratorError = true;
|
|
160
|
+
_iteratorError = err;
|
|
161
|
+
} finally {
|
|
162
|
+
try {
|
|
163
|
+
if (!_iteratorNormalCompletion && _iterator['return']) {
|
|
164
|
+
_iterator['return']();
|
|
165
|
+
}
|
|
166
|
+
} finally {
|
|
167
|
+
if (_didIteratorError) {
|
|
168
|
+
throw _iteratorError;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function rangeDelete(config, request) {
|
|
176
|
+
var parentID = config.parentID,
|
|
177
|
+
connectionKeys = config.connectionKeys,
|
|
178
|
+
pathToConnection = config.pathToConnection,
|
|
179
|
+
deletedIDFieldName = config.deletedIDFieldName;
|
|
180
|
+
|
|
181
|
+
if (!parentID) {
|
|
182
|
+
require('fbjs/lib/warning')(false, 'RelayDeclarativeMutationConfig: For mutation config RANGE_DELETE ' + 'to work you must include a parentID');
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
var rootField = getRootField(request);
|
|
186
|
+
if (!rootField) {
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
return function (store, data) {
|
|
190
|
+
if (!data) {
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
var deleteIDs = [];
|
|
194
|
+
var deletedIDField = data[rootField];
|
|
195
|
+
if (deletedIDField && Array.isArray(deletedIDFieldName)) {
|
|
196
|
+
var _iteratorNormalCompletion2 = true;
|
|
197
|
+
var _didIteratorError2 = false;
|
|
198
|
+
var _iteratorError2 = undefined;
|
|
199
|
+
|
|
200
|
+
try {
|
|
201
|
+
for (var _iterator2 = deletedIDFieldName[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
|
202
|
+
var eachField = _step2.value;
|
|
203
|
+
|
|
204
|
+
if (deletedIDField && typeof deletedIDField === 'object') {
|
|
205
|
+
deletedIDField = deletedIDField[eachField];
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
} catch (err) {
|
|
209
|
+
_didIteratorError2 = true;
|
|
210
|
+
_iteratorError2 = err;
|
|
211
|
+
} finally {
|
|
212
|
+
try {
|
|
213
|
+
if (!_iteratorNormalCompletion2 && _iterator2['return']) {
|
|
214
|
+
_iterator2['return']();
|
|
215
|
+
}
|
|
216
|
+
} finally {
|
|
217
|
+
if (_didIteratorError2) {
|
|
218
|
+
throw _iteratorError2;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (Array.isArray(deletedIDField)) {
|
|
224
|
+
deletedIDField.forEach(function (idObject) {
|
|
225
|
+
if (idObject && idObject.id && typeof idObject === 'object' && typeof idObject.id === 'string') {
|
|
226
|
+
deleteIDs.push(idObject.id);
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
} else if (deletedIDField && deletedIDField.id && typeof deletedIDField.id === 'string') {
|
|
230
|
+
deleteIDs.push(deletedIDField.id);
|
|
231
|
+
}
|
|
232
|
+
} else if (deletedIDField && typeof deletedIDFieldName === 'string' && typeof deletedIDField === 'object') {
|
|
233
|
+
deletedIDField = deletedIDField[deletedIDFieldName];
|
|
234
|
+
if (typeof deletedIDField === 'string') {
|
|
235
|
+
deleteIDs.push(deletedIDField);
|
|
236
|
+
} else if (Array.isArray(deletedIDField)) {
|
|
237
|
+
deletedIDField.forEach(function (id) {
|
|
238
|
+
if (typeof id === 'string') {
|
|
239
|
+
deleteIDs.push(id);
|
|
240
|
+
}
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
deleteNode(parentID, connectionKeys, pathToConnection, store, deleteIDs);
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function deleteNode(parentID, connectionKeys, pathToConnection, store, deleteIDs) {
|
|
249
|
+
require('fbjs/lib/warning')(connectionKeys, 'RelayDeclarativeMutationConfig: RANGE_DELETE must provide a ' + 'connectionKeys');
|
|
250
|
+
var parent = store.get(parentID);
|
|
251
|
+
if (!parent) {
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
if (pathToConnection.length < 2) {
|
|
255
|
+
require('fbjs/lib/warning')(false, 'RelayDeclarativeMutationConfig: RANGE_DELETE ' + 'pathToConnection must include at least parent and connection');
|
|
256
|
+
return;
|
|
257
|
+
}
|
|
258
|
+
var recordProxy = parent;
|
|
259
|
+
for (var i = 1; i < pathToConnection.length - 1; i++) {
|
|
260
|
+
if (recordProxy) {
|
|
261
|
+
recordProxy = recordProxy.getLinkedRecord(pathToConnection[i]);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
// Should never enter loop except edge cases
|
|
265
|
+
if (!connectionKeys || !recordProxy) {
|
|
266
|
+
require('fbjs/lib/warning')(false, 'RelayDeclarativeMutationConfig: RANGE_DELETE ' + 'pathToConnection is incorrect. Unable to find connection with ' + 'parentID: %s and path: %s', parentID, pathToConnection.toString());
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
var _iteratorNormalCompletion3 = true;
|
|
270
|
+
var _didIteratorError3 = false;
|
|
271
|
+
var _iteratorError3 = undefined;
|
|
272
|
+
|
|
273
|
+
try {
|
|
274
|
+
var _loop = function _loop() {
|
|
275
|
+
var key = _step3.value;
|
|
276
|
+
|
|
277
|
+
var connection = require('./RelayConnectionHandler').getConnection(recordProxy, key.key, key.filters);
|
|
278
|
+
if (connection) {
|
|
279
|
+
deleteIDs.forEach(function (deleteID) {
|
|
280
|
+
require('./RelayConnectionHandler').deleteNode(connection, deleteID);
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
for (var _iterator3 = connectionKeys[Symbol.iterator](), _step3; !(_iteratorNormalCompletion3 = (_step3 = _iterator3.next()).done); _iteratorNormalCompletion3 = true) {
|
|
286
|
+
_loop();
|
|
287
|
+
}
|
|
288
|
+
} catch (err) {
|
|
289
|
+
_didIteratorError3 = true;
|
|
290
|
+
_iteratorError3 = err;
|
|
291
|
+
} finally {
|
|
292
|
+
try {
|
|
293
|
+
if (!_iteratorNormalCompletion3 && _iterator3['return']) {
|
|
294
|
+
_iterator3['return']();
|
|
295
|
+
}
|
|
296
|
+
} finally {
|
|
297
|
+
if (_didIteratorError3) {
|
|
298
|
+
throw _iteratorError3;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function getRootField(request) {
|
|
305
|
+
if (request.fragment.selections && request.fragment.selections.length > 0 && request.fragment.selections[0].kind === 'LinkedField') {
|
|
306
|
+
return request.fragment.selections[0].name;
|
|
307
|
+
}
|
|
308
|
+
return null;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
module.exports = {
|
|
312
|
+
MutationTypes: MutationTypes,
|
|
313
|
+
RangeOperations: RangeOperations,
|
|
314
|
+
|
|
315
|
+
convert: convert
|
|
316
|
+
};
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
3
|
-
* All rights reserved.
|
|
4
3
|
*
|
|
5
|
-
* This source code is licensed under the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
6
|
*
|
|
9
7
|
* @providesModule RelayDefaultHandleKey
|
|
10
8
|
*
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
3
|
-
* All rights reserved.
|
|
4
3
|
*
|
|
5
|
-
* This source code is licensed under the
|
|
6
|
-
* LICENSE file in the root directory of this source tree.
|
|
7
|
-
* of patent rights can be found in the PATENTS file in the same directory.
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
8
6
|
*
|
|
9
7
|
* @providesModule RelayDefaultHandlerProvider
|
|
10
8
|
*
|