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.
Files changed (34) hide show
  1. package/README.md +1 -4
  2. package/index.js +1 -1
  3. package/lib/mutations/readUpdatableQuery_EXPERIMENTAL.js +2 -2
  4. package/lib/mutations/validateMutation.js +11 -1
  5. package/lib/network/RelayNetwork.js +1 -1
  6. package/lib/store/RelayConcreteVariables.js +1 -2
  7. package/lib/store/RelayExperimentalGraphResponseTransform.js +34 -2
  8. package/lib/store/RelayModernOperationDescriptor.js +1 -1
  9. package/lib/store/RelayPublishQueue.js +4 -2
  10. package/lib/store/RelayReader.js +55 -13
  11. package/lib/store/RelayStoreUtils.js +1 -0
  12. package/lib/store/ResolverCache.js +10 -2
  13. package/lib/util/withProvidedVariables.js +23 -3
  14. package/mutations/commitMutation.js.flow +8 -19
  15. package/mutations/readUpdatableQuery_EXPERIMENTAL.js.flow +2 -2
  16. package/mutations/validateMutation.js.flow +14 -2
  17. package/network/RelayNetwork.js.flow +4 -1
  18. package/network/RelayNetworkTypes.js.flow +1 -1
  19. package/package.json +6 -2
  20. package/relay-runtime.js +2 -2
  21. package/relay-runtime.min.js +2 -2
  22. package/store/RelayConcreteVariables.js.flow +2 -3
  23. package/store/RelayExperimentalGraphResponseTransform.js.flow +35 -1
  24. package/store/RelayModernOperationDescriptor.js.flow +1 -1
  25. package/store/RelayPublishQueue.js.flow +8 -1
  26. package/store/RelayReader.js.flow +78 -31
  27. package/store/RelayStoreTypes.js.flow +3 -2
  28. package/store/RelayStoreUtils.js.flow +1 -0
  29. package/store/ResolverCache.js.flow +18 -5
  30. package/subscription/requestSubscription.js.flow +7 -12
  31. package/util/NormalizationNode.js.flow +16 -16
  32. package/util/ReaderNode.js.flow +15 -15
  33. package/util/RelayConcreteNode.js.flow +4 -2
  34. package/util/withProvidedVariables.js.flow +32 -4
@@ -13,19 +13,47 @@
13
13
 
14
14
  'use strict';
15
15
 
16
- import type {RequestParameters} from './RelayConcreteNode';
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
- parameters: RequestParameters,
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
- operationVariables[varName] = providedVariables[varName].get();
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 {