relay-runtime 13.0.1 → 13.1.1
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/README.md +1 -4
- package/index.js +1 -1
- package/lib/mutations/readUpdatableQuery_EXPERIMENTAL.js +2 -2
- package/lib/mutations/validateMutation.js +11 -1
- package/lib/network/RelayNetwork.js +1 -1
- package/lib/store/RelayConcreteVariables.js +1 -2
- package/lib/store/RelayExperimentalGraphResponseTransform.js +34 -2
- package/lib/store/RelayModernOperationDescriptor.js +1 -1
- package/lib/store/RelayPublishQueue.js +4 -2
- package/lib/store/RelayReader.js +55 -13
- package/lib/store/RelayStoreUtils.js +1 -0
- package/lib/store/ResolverCache.js +10 -2
- package/lib/util/withProvidedVariables.js +23 -3
- package/mutations/commitMutation.js.flow +8 -19
- package/mutations/readUpdatableQuery_EXPERIMENTAL.js.flow +2 -2
- package/mutations/validateMutation.js.flow +14 -2
- package/network/RelayNetwork.js.flow +4 -1
- package/network/RelayNetworkTypes.js.flow +1 -1
- package/package.json +6 -2
- package/relay-runtime.js +2 -2
- package/relay-runtime.min.js +2 -2
- package/store/RelayConcreteVariables.js.flow +2 -3
- package/store/RelayExperimentalGraphResponseTransform.js.flow +35 -1
- package/store/RelayModernOperationDescriptor.js.flow +1 -1
- package/store/RelayPublishQueue.js.flow +8 -1
- package/store/RelayReader.js.flow +78 -31
- package/store/RelayStoreTypes.js.flow +3 -2
- package/store/RelayStoreUtils.js.flow +1 -0
- package/store/ResolverCache.js.flow +18 -5
- package/subscription/requestSubscription.js.flow +7 -12
- package/util/NormalizationNode.js.flow +16 -16
- package/util/ReaderNode.js.flow +15 -15
- package/util/RelayConcreteNode.js.flow +4 -2
- package/util/withProvidedVariables.js.flow +32 -4
|
@@ -13,19 +13,47 @@
|
|
|
13
13
|
|
|
14
14
|
'use strict';
|
|
15
15
|
|
|
16
|
-
import type {
|
|
16
|
+
import type {ProvidedVariablesType} from './RelayConcreteNode';
|
|
17
17
|
import type {Variables} from './RelayRuntimeTypes';
|
|
18
18
|
|
|
19
|
+
const areEqual = require('areEqual');
|
|
20
|
+
const warning = require('warning');
|
|
21
|
+
|
|
22
|
+
const WEAKMAP_SUPPORTED = typeof WeakMap === 'function';
|
|
23
|
+
const debugCache = WEAKMAP_SUPPORTED ? new WeakMap() : new Map();
|
|
24
|
+
|
|
19
25
|
function withProvidedVariables(
|
|
20
26
|
userSuppliedVariables: Variables,
|
|
21
|
-
|
|
27
|
+
providedVariables: ?ProvidedVariablesType,
|
|
22
28
|
): Variables {
|
|
23
|
-
const providedVariables = parameters.providedVariables;
|
|
24
29
|
if (providedVariables != null) {
|
|
25
30
|
const operationVariables = {};
|
|
26
31
|
Object.assign(operationVariables, userSuppliedVariables);
|
|
27
32
|
Object.keys(providedVariables).forEach((varName: string) => {
|
|
28
|
-
|
|
33
|
+
const providerFunction = providedVariables[varName].get;
|
|
34
|
+
const providerResult = providerFunction();
|
|
35
|
+
|
|
36
|
+
// people like to ignore these warnings, so use the cache to
|
|
37
|
+
// enforce that we only compute the value the first time
|
|
38
|
+
if (!debugCache.has(providerFunction)) {
|
|
39
|
+
debugCache.set(providerFunction, providerResult);
|
|
40
|
+
operationVariables[varName] = providerResult;
|
|
41
|
+
} else {
|
|
42
|
+
const cachedResult = debugCache.get(providerFunction);
|
|
43
|
+
|
|
44
|
+
if (__DEV__) {
|
|
45
|
+
warning(
|
|
46
|
+
areEqual(providerResult, cachedResult),
|
|
47
|
+
'Relay: Expected function `%s` for provider `%s` to be a pure function, ' +
|
|
48
|
+
'but got conflicting return values `%s` and `%s`',
|
|
49
|
+
providerFunction.name,
|
|
50
|
+
varName,
|
|
51
|
+
providerResult,
|
|
52
|
+
cachedResult,
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
operationVariables[varName] = cachedResult;
|
|
56
|
+
}
|
|
29
57
|
});
|
|
30
58
|
return operationVariables;
|
|
31
59
|
} else {
|