relay-runtime 7.0.0 → 9.1.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 +34 -0
- package/handlers/connection/ConnectionHandler.js.flow +549 -0
- package/handlers/connection/ConnectionInterface.js.flow +92 -0
- package/index.js +1 -1
- package/index.js.flow +314 -0
- package/lib/handlers/RelayDefaultHandlerProvider.js +3 -2
- package/lib/handlers/connection/{RelayConnectionHandler.js → ConnectionHandler.js} +34 -35
- package/lib/handlers/connection/{RelayConnectionInterface.js → ConnectionInterface.js} +3 -30
- package/lib/index.js +29 -27
- package/lib/mutations/RelayDeclarativeMutationConfig.js +30 -52
- package/lib/mutations/RelayRecordProxy.js +6 -3
- package/lib/mutations/RelayRecordSourceMutator.js +3 -9
- package/lib/mutations/RelayRecordSourceProxy.js +21 -24
- package/lib/mutations/RelayRecordSourceSelectorProxy.js +18 -14
- package/lib/mutations/applyOptimisticMutation.js +2 -1
- package/lib/mutations/commitLocalUpdate.js +1 -0
- package/lib/mutations/commitMutation.js +26 -8
- package/lib/mutations/validateMutation.js +21 -11
- package/lib/network/ConvertToExecuteFunction.js +1 -0
- package/lib/network/RelayNetwork.js +1 -0
- package/lib/network/RelayNetworkTypes.js +1 -0
- package/lib/network/RelayObservable.js +10 -9
- package/lib/network/RelayQueryResponseCache.js +9 -7
- package/lib/query/{RelayModernGraphQLTag.js → GraphQLTag.js} +15 -8
- package/lib/query/fetchQuery.js +2 -1
- package/lib/query/fetchQueryInternal.js +30 -20
- package/lib/store/ClientID.js +1 -0
- package/lib/store/DataChecker.js +47 -97
- package/lib/store/RelayConcreteVariables.js +7 -2
- package/lib/store/RelayModernEnvironment.js +82 -41
- package/lib/store/RelayModernFragmentSpecResolver.js +61 -21
- package/lib/store/RelayModernOperationDescriptor.js +2 -1
- package/lib/store/RelayModernQueryExecutor.js +476 -333
- package/lib/store/RelayModernRecord.js +39 -9
- package/lib/store/RelayModernSelector.js +2 -1
- package/lib/store/RelayModernStore.js +359 -371
- package/lib/store/RelayOperationTracker.js +36 -78
- package/lib/store/RelayOptimisticRecordSource.js +8 -5
- package/lib/store/RelayPublishQueue.js +66 -53
- package/lib/store/RelayReader.js +2 -24
- package/lib/store/RelayRecordSource.js +3 -9
- package/lib/store/RelayRecordSourceMapImpl.js +14 -18
- package/lib/store/RelayRecordState.js +1 -0
- package/lib/store/RelayReferenceMarker.js +8 -58
- package/lib/store/RelayResponseNormalizer.js +15 -144
- package/lib/store/RelayStoreTypes.js +1 -0
- package/lib/store/RelayStoreUtils.js +34 -10
- package/lib/store/StoreInspector.js +11 -5
- package/lib/store/ViewerPattern.js +1 -0
- package/lib/store/cloneRelayHandleSourceField.js +1 -0
- package/lib/store/createFragmentSpecResolver.js +1 -0
- package/lib/store/createRelayContext.js +1 -0
- package/lib/store/defaultGetDataID.js +1 -0
- package/lib/store/hasOverlappingIDs.js +1 -0
- package/lib/store/isRelayModernEnvironment.js +1 -0
- package/lib/store/normalizeRelayPayload.js +8 -4
- package/lib/store/readInlineData.js +2 -1
- package/lib/subscription/requestSubscription.js +6 -3
- package/lib/util/JSResourceTypes.flow.js +12 -0
- package/lib/util/NormalizationNode.js +1 -0
- package/lib/util/ReaderNode.js +1 -0
- package/lib/util/RelayConcreteNode.js +3 -0
- package/lib/util/RelayDefaultHandleKey.js +1 -0
- package/lib/util/RelayError.js +2 -1
- package/lib/util/RelayFeatureFlags.js +3 -2
- package/lib/util/RelayProfiler.js +1 -0
- package/lib/util/RelayReplaySubject.js +2 -3
- package/lib/util/RelayRuntimeTypes.js +1 -0
- package/lib/util/createPayloadFor3DField.js +34 -0
- package/lib/util/deepFreeze.js +1 -0
- package/lib/util/generateID.js +1 -0
- package/lib/util/getFragmentIdentifier.js +1 -0
- package/lib/util/getRelayHandleKey.js +1 -0
- package/lib/util/getRequestIdentifier.js +1 -0
- package/lib/util/isPromise.js +1 -0
- package/lib/util/isScalarAndEqual.js +1 -0
- package/lib/util/recycleNodesInto.js +1 -0
- package/lib/util/resolveImmediate.js +1 -0
- package/lib/util/stableCopy.js +1 -0
- package/mutations/RelayDeclarativeMutationConfig.js.flow +380 -0
- package/mutations/RelayRecordProxy.js.flow +165 -0
- package/mutations/RelayRecordSourceMutator.js.flow +238 -0
- package/mutations/RelayRecordSourceProxy.js.flow +164 -0
- package/mutations/RelayRecordSourceSelectorProxy.js.flow +119 -0
- package/mutations/applyOptimisticMutation.js.flow +76 -0
- package/mutations/commitLocalUpdate.js.flow +24 -0
- package/mutations/commitMutation.js.flow +184 -0
- package/mutations/validateMutation.js.flow +211 -0
- package/network/ConvertToExecuteFunction.js.flow +49 -0
- package/network/RelayNetwork.js.flow +84 -0
- package/network/RelayNetworkTypes.js.flow +123 -0
- package/network/RelayObservable.js.flow +634 -0
- package/network/RelayQueryResponseCache.js.flow +111 -0
- package/package.json +1 -1
- package/query/GraphQLTag.js.flow +166 -0
- package/query/fetchQuery.js.flow +47 -0
- package/query/fetchQueryInternal.js.flow +349 -0
- package/relay-runtime.js +2 -2
- package/relay-runtime.min.js +2 -2
- package/store/ClientID.js.flow +43 -0
- package/store/DataChecker.js.flow +426 -0
- package/store/RelayConcreteVariables.js.flow +96 -0
- package/store/RelayModernEnvironment.js.flow +526 -0
- package/store/RelayModernFragmentSpecResolver.js.flow +426 -0
- package/store/RelayModernOperationDescriptor.js.flow +88 -0
- package/store/RelayModernQueryExecutor.js.flow +1327 -0
- package/store/RelayModernRecord.js.flow +403 -0
- package/store/RelayModernSelector.js.flow +444 -0
- package/store/RelayModernStore.js.flow +757 -0
- package/store/RelayOperationTracker.js.flow +164 -0
- package/store/RelayOptimisticRecordSource.js.flow +119 -0
- package/store/RelayPublishQueue.js.flow +401 -0
- package/store/RelayReader.js.flow +376 -0
- package/store/RelayRecordSource.js.flow +29 -0
- package/store/RelayRecordSourceMapImpl.js.flow +87 -0
- package/store/RelayRecordState.js.flow +37 -0
- package/store/RelayReferenceMarker.js.flow +236 -0
- package/store/RelayResponseNormalizer.js.flow +556 -0
- package/store/RelayStoreTypes.js.flow +873 -0
- package/store/RelayStoreUtils.js.flow +218 -0
- package/store/StoreInspector.js.flow +173 -0
- package/store/ViewerPattern.js.flow +26 -0
- package/store/cloneRelayHandleSourceField.js.flow +66 -0
- package/store/createFragmentSpecResolver.js.flow +55 -0
- package/store/createRelayContext.js.flow +44 -0
- package/store/defaultGetDataID.js.flow +27 -0
- package/store/hasOverlappingIDs.js.flow +34 -0
- package/store/isRelayModernEnvironment.js.flow +27 -0
- package/store/normalizeRelayPayload.js.flow +51 -0
- package/store/readInlineData.js.flow +75 -0
- package/subscription/requestSubscription.js.flow +100 -0
- package/util/JSResourceTypes.flow.js.flow +20 -0
- package/util/NormalizationNode.js.flow +191 -0
- package/util/ReaderNode.js.flow +208 -0
- package/util/RelayConcreteNode.js.flow +80 -0
- package/util/RelayDefaultHandleKey.js.flow +17 -0
- package/util/RelayError.js.flow +33 -0
- package/util/RelayFeatureFlags.js.flow +30 -0
- package/util/RelayProfiler.js.flow +284 -0
- package/util/RelayReplaySubject.js.flow +134 -0
- package/util/RelayRuntimeTypes.js.flow +70 -0
- package/util/createPayloadFor3DField.js.flow +43 -0
- package/util/deepFreeze.js.flow +36 -0
- package/util/generateID.js.flow +21 -0
- package/util/getFragmentIdentifier.js.flow +52 -0
- package/util/getRelayHandleKey.js.flow +41 -0
- package/util/getRequestIdentifier.js.flow +41 -0
- package/util/isPromise.js.flow +21 -0
- package/util/isScalarAndEqual.js.flow +26 -0
- package/util/recycleNodesInto.js.flow +80 -0
- package/util/resolveImmediate.js.flow +30 -0
- package/util/stableCopy.js.flow +35 -0
- package/lib/handlers/RelayDefaultMissingFieldHandlers.js +0 -26
- package/lib/store/RelayConnection.js +0 -36
- package/lib/store/RelayConnectionResolver.js +0 -177
- package/lib/store/RelayRecordSourceObjectImpl.js +0 -78
- package/lib/util/getFragmentSpecIdentifier.js +0 -26
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
* @flow strict
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
// flowlint ambiguous-object-type:error
|
|
12
|
+
|
|
13
|
+
'use strict';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Recursively "deep" freezes the supplied object.
|
|
17
|
+
*
|
|
18
|
+
* For convenience, and for consistency with the behavior of `Object.freeze`,
|
|
19
|
+
* returns the now-frozen original object.
|
|
20
|
+
*/
|
|
21
|
+
function deepFreeze<T: {...}>(object: T): T {
|
|
22
|
+
Object.freeze(object);
|
|
23
|
+
Object.getOwnPropertyNames(object).forEach(name => {
|
|
24
|
+
const property = object[name];
|
|
25
|
+
if (
|
|
26
|
+
property &&
|
|
27
|
+
typeof property === 'object' &&
|
|
28
|
+
!Object.isFrozen(property)
|
|
29
|
+
) {
|
|
30
|
+
deepFreeze(property);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
return object;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
module.exports = deepFreeze;
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
* @flow strict
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
// flowlint ambiguous-object-type:error
|
|
12
|
+
|
|
13
|
+
'use strict';
|
|
14
|
+
|
|
15
|
+
let id = 100000;
|
|
16
|
+
|
|
17
|
+
function generateID(): number {
|
|
18
|
+
return id++;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = generateID;
|
|
@@ -0,0 +1,52 @@
|
|
|
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
|
+
* @flow strict-local
|
|
8
|
+
* @format
|
|
9
|
+
* @emails oncall+relay
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
// flowlint ambiguous-object-type:error
|
|
13
|
+
|
|
14
|
+
'use strict';
|
|
15
|
+
|
|
16
|
+
const stableCopy = require('./stableCopy');
|
|
17
|
+
|
|
18
|
+
const {
|
|
19
|
+
getDataIDsFromFragment,
|
|
20
|
+
getVariablesFromFragment,
|
|
21
|
+
getSelector,
|
|
22
|
+
} = require('../store/RelayModernSelector');
|
|
23
|
+
|
|
24
|
+
import type {ReaderFragment} from './ReaderNode';
|
|
25
|
+
|
|
26
|
+
function getFragmentIdentifier(
|
|
27
|
+
fragmentNode: ReaderFragment,
|
|
28
|
+
fragmentRef: mixed,
|
|
29
|
+
): string {
|
|
30
|
+
const selector = getSelector(fragmentNode, fragmentRef);
|
|
31
|
+
const fragmentOwnerIdentifier =
|
|
32
|
+
selector == null
|
|
33
|
+
? 'null'
|
|
34
|
+
: selector.kind === 'SingularReaderSelector'
|
|
35
|
+
? selector.owner.identifier
|
|
36
|
+
: '[' +
|
|
37
|
+
selector.selectors.map(sel => sel.owner.identifier).join(',') +
|
|
38
|
+
']';
|
|
39
|
+
const fragmentVariables = getVariablesFromFragment(fragmentNode, fragmentRef);
|
|
40
|
+
const dataIDs = getDataIDsFromFragment(fragmentNode, fragmentRef);
|
|
41
|
+
return (
|
|
42
|
+
fragmentOwnerIdentifier +
|
|
43
|
+
'/' +
|
|
44
|
+
fragmentNode.name +
|
|
45
|
+
'/' +
|
|
46
|
+
JSON.stringify(stableCopy(fragmentVariables)) +
|
|
47
|
+
'/' +
|
|
48
|
+
(JSON.stringify(dataIDs) ?? 'missing')
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
module.exports = getFragmentIdentifier;
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
* @flow
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
// flowlint ambiguous-object-type:error
|
|
12
|
+
|
|
13
|
+
'use strict';
|
|
14
|
+
|
|
15
|
+
const invariant = require('invariant');
|
|
16
|
+
|
|
17
|
+
const {DEFAULT_HANDLE_KEY} = require('./RelayDefaultHandleKey');
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @internal
|
|
21
|
+
*
|
|
22
|
+
* Helper to create a unique name for a handle field based on the handle name, handle key and
|
|
23
|
+
* source field.
|
|
24
|
+
*/
|
|
25
|
+
function getRelayHandleKey(
|
|
26
|
+
handleName: string,
|
|
27
|
+
key: ?string,
|
|
28
|
+
fieldName: ?string,
|
|
29
|
+
): string {
|
|
30
|
+
if (key && key !== DEFAULT_HANDLE_KEY) {
|
|
31
|
+
return `__${key}_${handleName}`;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
invariant(
|
|
35
|
+
fieldName != null,
|
|
36
|
+
'getRelayHandleKey: Expected either `fieldName` or `key` in `handle` to be provided',
|
|
37
|
+
);
|
|
38
|
+
return `__${fieldName}_${handleName}`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
module.exports = getRelayHandleKey;
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
* @flow strict-local
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
// flowlint ambiguous-object-type:error
|
|
12
|
+
|
|
13
|
+
'use strict';
|
|
14
|
+
|
|
15
|
+
const invariant = require('invariant');
|
|
16
|
+
const stableCopy = require('./stableCopy');
|
|
17
|
+
|
|
18
|
+
import type {RequestParameters} from './RelayConcreteNode';
|
|
19
|
+
import type {Variables} from './RelayRuntimeTypes';
|
|
20
|
+
|
|
21
|
+
export opaque type RequestIdentifier: string = string;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Returns a stable identifier for the given pair of `RequestParameters` +
|
|
25
|
+
* variables.
|
|
26
|
+
*/
|
|
27
|
+
function getRequestIdentifier(
|
|
28
|
+
parameters: RequestParameters,
|
|
29
|
+
variables: Variables,
|
|
30
|
+
): RequestIdentifier {
|
|
31
|
+
const requestID = parameters.id != null ? parameters.id : parameters.text;
|
|
32
|
+
invariant(
|
|
33
|
+
requestID != null,
|
|
34
|
+
'getRequestIdentifier: Expected request `%s` to have either a ' +
|
|
35
|
+
'valid `id` or `text` property',
|
|
36
|
+
parameters.name,
|
|
37
|
+
);
|
|
38
|
+
return requestID + JSON.stringify(stableCopy(variables));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
module.exports = getRequestIdentifier;
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
* @flow strict
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
// flowlint ambiguous-object-type:error
|
|
12
|
+
|
|
13
|
+
'use strict';
|
|
14
|
+
|
|
15
|
+
declare function isPromise(p: mixed): boolean %checks(p instanceof Promise);
|
|
16
|
+
|
|
17
|
+
function isPromise(p: $FlowFixMe): boolean {
|
|
18
|
+
return !!p && typeof p.then === 'function';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = isPromise;
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
* @flow strict
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
// flowlint ambiguous-object-type:error
|
|
12
|
+
|
|
13
|
+
'use strict';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* A fast test to determine if two values are equal scalars:
|
|
17
|
+
* - compares scalars such as booleans, strings, numbers by value
|
|
18
|
+
* - compares functions by identity
|
|
19
|
+
* - returns false for complex values, since these cannot be cheaply tested for
|
|
20
|
+
* equality (use `areEquals` instead)
|
|
21
|
+
*/
|
|
22
|
+
function isScalarAndEqual(valueA: mixed, valueB: mixed): boolean {
|
|
23
|
+
return valueA === valueB && (valueA === null || typeof valueA !== 'object');
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
module.exports = isScalarAndEqual;
|
|
@@ -0,0 +1,80 @@
|
|
|
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
|
+
* @flow strict
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
// flowlint ambiguous-object-type:error
|
|
12
|
+
|
|
13
|
+
'use strict';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Recycles subtrees from `prevData` by replacing equal subtrees in `nextData`.
|
|
17
|
+
*/
|
|
18
|
+
function recycleNodesInto<T>(prevData: T, nextData: T): T {
|
|
19
|
+
if (
|
|
20
|
+
prevData === nextData ||
|
|
21
|
+
typeof prevData !== 'object' ||
|
|
22
|
+
!prevData ||
|
|
23
|
+
typeof nextData !== 'object' ||
|
|
24
|
+
!nextData
|
|
25
|
+
) {
|
|
26
|
+
return nextData;
|
|
27
|
+
}
|
|
28
|
+
let canRecycle = false;
|
|
29
|
+
|
|
30
|
+
// Assign local variables to preserve Flow type refinement.
|
|
31
|
+
const prevArray = Array.isArray(prevData) ? prevData : null;
|
|
32
|
+
const nextArray = Array.isArray(nextData) ? nextData : null;
|
|
33
|
+
if (prevArray && nextArray) {
|
|
34
|
+
canRecycle =
|
|
35
|
+
nextArray.reduce((wasEqual, nextItem, ii) => {
|
|
36
|
+
const prevValue = prevArray[ii];
|
|
37
|
+
const nextValue = recycleNodesInto(prevValue, nextItem);
|
|
38
|
+
if (nextValue !== nextArray[ii]) {
|
|
39
|
+
if (__DEV__) {
|
|
40
|
+
if (!Object.isFrozen(nextArray)) {
|
|
41
|
+
nextArray[ii] = nextValue;
|
|
42
|
+
}
|
|
43
|
+
} else {
|
|
44
|
+
nextArray[ii] = nextValue;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return wasEqual && nextValue === prevArray[ii];
|
|
48
|
+
}, true) && prevArray.length === nextArray.length;
|
|
49
|
+
} else if (!prevArray && !nextArray) {
|
|
50
|
+
// Assign local variables to preserve Flow type refinement.
|
|
51
|
+
const prevObject = prevData;
|
|
52
|
+
const nextObject = nextData;
|
|
53
|
+
const prevKeys = Object.keys(prevObject);
|
|
54
|
+
const nextKeys = Object.keys(nextObject);
|
|
55
|
+
canRecycle =
|
|
56
|
+
nextKeys.reduce((wasEqual, key) => {
|
|
57
|
+
const prevValue = prevObject[key];
|
|
58
|
+
const nextValue = recycleNodesInto(prevValue, nextObject[key]);
|
|
59
|
+
if (nextValue !== nextObject[key]) {
|
|
60
|
+
if (__DEV__) {
|
|
61
|
+
if (!Object.isFrozen(nextObject)) {
|
|
62
|
+
/* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This
|
|
63
|
+
* comment suppresses an error found when Flow v0.98 was deployed.
|
|
64
|
+
* To see the error delete this comment and run Flow. */
|
|
65
|
+
nextObject[key] = nextValue;
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
/* $FlowFixMe(>=0.98.0 site=www,mobile,react_native_fb,oss) This comment
|
|
69
|
+
* suppresses an error found when Flow v0.98 was deployed. To see
|
|
70
|
+
* the error delete this comment and run Flow. */
|
|
71
|
+
nextObject[key] = nextValue;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return wasEqual && nextValue === prevObject[key];
|
|
75
|
+
}, true) && prevKeys.length === nextKeys.length;
|
|
76
|
+
}
|
|
77
|
+
return canRecycle ? prevData : nextData;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
module.exports = recycleNodesInto;
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
* @flow strict-local
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
// flowlint ambiguous-object-type:error
|
|
12
|
+
|
|
13
|
+
'use strict';
|
|
14
|
+
|
|
15
|
+
var resolvedPromise = Promise.resolve();
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* An alternative to setImmediate based on Promise.
|
|
19
|
+
*/
|
|
20
|
+
function resolveImmediate(callback: () => void) {
|
|
21
|
+
resolvedPromise.then(callback).catch(throwNext);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function throwNext(error) {
|
|
25
|
+
setTimeout(() => {
|
|
26
|
+
throw error;
|
|
27
|
+
}, 0);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
module.exports = resolveImmediate;
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
* @flow
|
|
8
|
+
* @format
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
// flowlint ambiguous-object-type:error
|
|
12
|
+
|
|
13
|
+
'use strict';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Creates a copy of the provided value, ensuring any nested objects have their
|
|
17
|
+
* keys sorted such that equivalent values would have identical JSON.stringify
|
|
18
|
+
* results.
|
|
19
|
+
*/
|
|
20
|
+
function stableCopy<T: mixed>(value: T): T {
|
|
21
|
+
if (!value || typeof value !== 'object') {
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
if (Array.isArray(value)) {
|
|
25
|
+
return value.map(stableCopy);
|
|
26
|
+
}
|
|
27
|
+
const keys = Object.keys(value).sort();
|
|
28
|
+
const stable = {};
|
|
29
|
+
for (let i = 0; i < keys.length; i++) {
|
|
30
|
+
stable[keys[i]] = stableCopy(value[keys[i]]);
|
|
31
|
+
}
|
|
32
|
+
return (stable: any);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
module.exports = stableCopy;
|
|
@@ -1,26 +0,0 @@
|
|
|
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
|
-
* @format
|
|
9
|
-
*/
|
|
10
|
-
'use strict';
|
|
11
|
-
|
|
12
|
-
var _require = require('../store/RelayStoreUtils'),
|
|
13
|
-
ROOT_TYPE = _require.ROOT_TYPE;
|
|
14
|
-
|
|
15
|
-
var _require2 = require('../store/ViewerPattern'),
|
|
16
|
-
VIEWER_ID = _require2.VIEWER_ID;
|
|
17
|
-
|
|
18
|
-
var missingViewerFieldHandler = {
|
|
19
|
-
kind: 'linked',
|
|
20
|
-
handle: function handle(field, record, argValues) {
|
|
21
|
-
if (record != null && record.__typename === ROOT_TYPE && field.name === 'viewer') {
|
|
22
|
-
return VIEWER_ID;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
};
|
|
26
|
-
module.exports = [missingViewerFieldHandler];
|
|
@@ -1,36 +0,0 @@
|
|
|
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
|
-
* @format
|
|
9
|
-
*/
|
|
10
|
-
'use strict';
|
|
11
|
-
|
|
12
|
-
// Intentionally inexact
|
|
13
|
-
// Note: The phantom TEdge type allows propagation of the `edges` field
|
|
14
|
-
// selections.
|
|
15
|
-
// eslint-disable-next-line no-unused-vars
|
|
16
|
-
var CONNECTION_KEY = '__connection';
|
|
17
|
-
var CONNECTION_TYPENAME = '__ConnectionRecord';
|
|
18
|
-
|
|
19
|
-
function createConnectionID(parentID, label) {
|
|
20
|
-
return "connection:".concat(parentID, ":").concat(label);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function createConnectionRecord(connectionID) {
|
|
24
|
-
return {
|
|
25
|
-
__id: connectionID,
|
|
26
|
-
__typename: '__ConnectionRecord',
|
|
27
|
-
events: []
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
module.exports = {
|
|
32
|
-
createConnectionID: createConnectionID,
|
|
33
|
-
createConnectionRecord: createConnectionRecord,
|
|
34
|
-
CONNECTION_KEY: CONNECTION_KEY,
|
|
35
|
-
CONNECTION_TYPENAME: CONNECTION_TYPENAME
|
|
36
|
-
};
|
|
@@ -1,177 +0,0 @@
|
|
|
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
|
-
* @format
|
|
9
|
-
*/
|
|
10
|
-
'use strict';
|
|
11
|
-
|
|
12
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
13
|
-
|
|
14
|
-
var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread"));
|
|
15
|
-
|
|
16
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
17
|
-
|
|
18
|
-
var invariant = require("fbjs/lib/invariant");
|
|
19
|
-
|
|
20
|
-
var ConnectionResolver = {
|
|
21
|
-
initialize: function initialize() {
|
|
22
|
-
return {
|
|
23
|
-
edges: [],
|
|
24
|
-
pageInfo: {
|
|
25
|
-
endCursor: null,
|
|
26
|
-
hasNextPage: null,
|
|
27
|
-
hasPrevPage: null,
|
|
28
|
-
startCursor: null
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
},
|
|
32
|
-
reduce: function reduce(state, event) {
|
|
33
|
-
var nextEdges = [];
|
|
34
|
-
var nextPageInfo = (0, _objectSpread2["default"])({}, state.pageInfo);
|
|
35
|
-
var seenNodes = new Set();
|
|
36
|
-
|
|
37
|
-
function pushEdge(edge) {
|
|
38
|
-
if (edge != null && edge.node != null && !seenNodes.has(edge.node.__id)) {
|
|
39
|
-
seenNodes.add(edge.node.__id);
|
|
40
|
-
nextEdges.push(edge);
|
|
41
|
-
return edge;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
if (event.kind === 'update') {
|
|
46
|
-
state.edges.forEach(function (edge) {
|
|
47
|
-
var nextEdge = event.edgeData.hasOwnProperty(edge.__id) ? event.edgeData[edge.__id] : edge;
|
|
48
|
-
pushEdge(nextEdge);
|
|
49
|
-
});
|
|
50
|
-
} else if (event.kind === 'fetch') {
|
|
51
|
-
var eventPageInfo = event.pageInfo;
|
|
52
|
-
|
|
53
|
-
if (event.args.after != null) {
|
|
54
|
-
var _ref, _ref2;
|
|
55
|
-
|
|
56
|
-
if (event.args.after !== state.pageInfo.endCursor) {
|
|
57
|
-
return state;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
state.edges.forEach(function (edge) {
|
|
61
|
-
pushEdge(edge);
|
|
62
|
-
});
|
|
63
|
-
event.edges.forEach(function (nextEdge) {
|
|
64
|
-
pushEdge(nextEdge);
|
|
65
|
-
});
|
|
66
|
-
nextPageInfo.endCursor = (_ref = eventPageInfo === null || eventPageInfo === void 0 ? void 0 : eventPageInfo.endCursor) !== null && _ref !== void 0 ? _ref : nextPageInfo.endCursor;
|
|
67
|
-
nextPageInfo.hasNextPage = (_ref2 = eventPageInfo === null || eventPageInfo === void 0 ? void 0 : eventPageInfo.hasNextPage) !== null && _ref2 !== void 0 ? _ref2 : nextPageInfo.hasNextPage;
|
|
68
|
-
} else if (event.args.before != null) {
|
|
69
|
-
var _ref3, _ref4;
|
|
70
|
-
|
|
71
|
-
if (event.args.before !== state.pageInfo.startCursor) {
|
|
72
|
-
return state;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
event.edges.forEach(function (nextEdge) {
|
|
76
|
-
pushEdge(nextEdge);
|
|
77
|
-
});
|
|
78
|
-
state.edges.forEach(function (edge) {
|
|
79
|
-
pushEdge(edge);
|
|
80
|
-
});
|
|
81
|
-
nextPageInfo.startCursor = (_ref3 = eventPageInfo === null || eventPageInfo === void 0 ? void 0 : eventPageInfo.startCursor) !== null && _ref3 !== void 0 ? _ref3 : nextPageInfo.startCursor;
|
|
82
|
-
nextPageInfo.hasPrevPage = (_ref4 = eventPageInfo === null || eventPageInfo === void 0 ? void 0 : eventPageInfo.hasPrevPage) !== null && _ref4 !== void 0 ? _ref4 : nextPageInfo.hasPrevPage;
|
|
83
|
-
} else if (event.args.before == null && event.args.after == null) {
|
|
84
|
-
event.edges.forEach(function (nextEdge) {
|
|
85
|
-
pushEdge(nextEdge);
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
if (eventPageInfo != null) {
|
|
89
|
-
nextPageInfo = eventPageInfo;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
} else if (event.kind === 'insert') {
|
|
93
|
-
state.edges.forEach(function (edge) {
|
|
94
|
-
pushEdge(edge);
|
|
95
|
-
});
|
|
96
|
-
var nextEdge = pushEdge(event.edge);
|
|
97
|
-
|
|
98
|
-
if (nextEdge != null) {
|
|
99
|
-
var _nextEdge$cursor;
|
|
100
|
-
|
|
101
|
-
nextPageInfo.endCursor = (_nextEdge$cursor = nextEdge.cursor) !== null && _nextEdge$cursor !== void 0 ? _nextEdge$cursor : nextPageInfo.endCursor;
|
|
102
|
-
}
|
|
103
|
-
} else if (event.kind === 'stream.edge') {
|
|
104
|
-
if (event.args.after != null) {
|
|
105
|
-
if (event.index === 0 && state.pageInfo.endCursor != null && event.args.after !== state.pageInfo.endCursor) {
|
|
106
|
-
return state;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
state.edges.forEach(function (edge) {
|
|
110
|
-
pushEdge(edge);
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
var _nextEdge = pushEdge(event.edge);
|
|
114
|
-
|
|
115
|
-
if (_nextEdge) {
|
|
116
|
-
var _nextEdge$cursor2;
|
|
117
|
-
|
|
118
|
-
nextPageInfo.endCursor = (_nextEdge$cursor2 = _nextEdge.cursor) !== null && _nextEdge$cursor2 !== void 0 ? _nextEdge$cursor2 : nextPageInfo.endCursor;
|
|
119
|
-
}
|
|
120
|
-
} else if (event.args.before != null) {
|
|
121
|
-
if (event.index === 0 && state.pageInfo.startCursor != null && event.args.before !== state.pageInfo.startCursor) {
|
|
122
|
-
return state;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
var _nextEdge2 = pushEdge(event.edge);
|
|
126
|
-
|
|
127
|
-
if (_nextEdge2) {
|
|
128
|
-
var _nextEdge$cursor3;
|
|
129
|
-
|
|
130
|
-
nextPageInfo.startCursor = (_nextEdge$cursor3 = _nextEdge2.cursor) !== null && _nextEdge$cursor3 !== void 0 ? _nextEdge$cursor3 : nextPageInfo.startCursor;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
state.edges.forEach(function (edge) {
|
|
134
|
-
pushEdge(edge);
|
|
135
|
-
});
|
|
136
|
-
} else if (event.args.after == null || event.args.before == null) {
|
|
137
|
-
state.edges.forEach(function (edge) {
|
|
138
|
-
pushEdge(edge);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
var _nextEdge3 = pushEdge(event.edge);
|
|
142
|
-
|
|
143
|
-
if (_nextEdge3 != null) {
|
|
144
|
-
var _nextEdge$cursor4;
|
|
145
|
-
|
|
146
|
-
nextPageInfo.endCursor = (_nextEdge$cursor4 = _nextEdge3.cursor) !== null && _nextEdge$cursor4 !== void 0 ? _nextEdge$cursor4 : nextPageInfo.endCursor;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
} else if (event.kind === 'stream.pageInfo') {
|
|
150
|
-
nextEdges.push.apply(nextEdges, (0, _toConsumableArray2["default"])(state.edges));
|
|
151
|
-
|
|
152
|
-
if (event.args.after != null) {
|
|
153
|
-
var _event$pageInfo$endCu;
|
|
154
|
-
|
|
155
|
-
nextPageInfo.endCursor = (_event$pageInfo$endCu = event.pageInfo.endCursor) !== null && _event$pageInfo$endCu !== void 0 ? _event$pageInfo$endCu : nextPageInfo.endCursor;
|
|
156
|
-
nextPageInfo.hasNextPage = !!event.pageInfo.hasNextPage;
|
|
157
|
-
} else if (event.args.before != null) {
|
|
158
|
-
var _event$pageInfo$start;
|
|
159
|
-
|
|
160
|
-
nextPageInfo.startCursor = (_event$pageInfo$start = event.pageInfo.startCursor) !== null && _event$pageInfo$start !== void 0 ? _event$pageInfo$start : nextPageInfo.startCursor;
|
|
161
|
-
nextPageInfo.hasPrevPage = !!event.pageInfo.hasPrevPage;
|
|
162
|
-
} else {
|
|
163
|
-
// stream refetch
|
|
164
|
-
nextPageInfo = event.pageInfo;
|
|
165
|
-
}
|
|
166
|
-
} else {
|
|
167
|
-
event;
|
|
168
|
-
!false ? process.env.NODE_ENV !== "production" ? invariant(false, 'ConnectionResolver-test: Unexpected event kind `%s`.', event.kind) : invariant(false) : void 0;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
return {
|
|
172
|
-
edges: nextEdges,
|
|
173
|
-
pageInfo: nextPageInfo
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
};
|
|
177
|
-
module.exports = ConnectionResolver;
|