relay-runtime 0.0.0-main-d543a7a5 → 0.0.0-main-c844a5ba
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.
|
@@ -483,8 +483,7 @@ class RelayReader {
|
|
|
483
483
|
if (!RelayFeatureFlags.ENABLE_RELAY_RESOLVERS) {
|
|
484
484
|
throw new Error('Relay Resolver fields are not yet supported.');
|
|
485
485
|
}
|
|
486
|
-
this._readResolverField(selection.field, record, data);
|
|
487
|
-
break;
|
|
486
|
+
return this._readResolverField(selection.field, record, data);
|
|
488
487
|
default:
|
|
489
488
|
(selection.field.kind: empty);
|
|
490
489
|
invariant(
|
|
@@ -499,7 +498,7 @@ class RelayReader {
|
|
|
499
498
|
field: ReaderRelayResolver,
|
|
500
499
|
record: Record,
|
|
501
500
|
data: SelectorData,
|
|
502
|
-
):
|
|
501
|
+
): mixed {
|
|
503
502
|
const {resolverModule, fragment} = field;
|
|
504
503
|
const storageKey = getStorageKey(field, this._variables);
|
|
505
504
|
const resolverID = ClientID.generateClientID(
|
|
@@ -575,6 +574,7 @@ class RelayReader {
|
|
|
575
574
|
|
|
576
575
|
const applicationName = field.alias ?? field.name;
|
|
577
576
|
data[applicationName] = result;
|
|
577
|
+
return result;
|
|
578
578
|
}
|
|
579
579
|
|
|
580
580
|
_readClientEdge(
|
|
@@ -16,6 +16,12 @@
|
|
|
16
16
|
import type {RequestParameters} 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
|
parameters: RequestParameters,
|
|
@@ -25,7 +31,30 @@ function withProvidedVariables(
|
|
|
25
31
|
const operationVariables = {};
|
|
26
32
|
Object.assign(operationVariables, userSuppliedVariables);
|
|
27
33
|
Object.keys(providedVariables).forEach((varName: string) => {
|
|
28
|
-
|
|
34
|
+
const providerFunction = providedVariables[varName].get;
|
|
35
|
+
const providerResult = providerFunction();
|
|
36
|
+
|
|
37
|
+
// people like to ignore these warnings, so use the cache to
|
|
38
|
+
// enforce that we only compute the value the first time
|
|
39
|
+
if (!debugCache.has(providerFunction)) {
|
|
40
|
+
debugCache.set(providerFunction, providerResult);
|
|
41
|
+
operationVariables[varName] = providerResult;
|
|
42
|
+
} else {
|
|
43
|
+
const cachedResult = debugCache.get(providerFunction);
|
|
44
|
+
|
|
45
|
+
if (__DEV__) {
|
|
46
|
+
warning(
|
|
47
|
+
areEqual(providerResult, cachedResult),
|
|
48
|
+
'Relay: Expected function `%s` for provider `%s` to be a pure function, ' +
|
|
49
|
+
'but got conflicting return values `%s` and `%s`',
|
|
50
|
+
providerFunction.name,
|
|
51
|
+
varName,
|
|
52
|
+
providerResult,
|
|
53
|
+
cachedResult,
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
operationVariables[varName] = cachedResult;
|
|
57
|
+
}
|
|
29
58
|
});
|
|
30
59
|
return operationVariables;
|
|
31
60
|
} else {
|