relay-runtime 13.0.0 → 13.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.
Files changed (40) hide show
  1. package/README.md +1 -4
  2. package/index.js +1 -1
  3. package/index.js.flow +2 -0
  4. package/lib/index.js +4 -1
  5. package/lib/mutations/readUpdatableQuery_EXPERIMENTAL.js +22 -17
  6. package/lib/mutations/validateMutation.js +11 -1
  7. package/lib/network/RelayNetwork.js +7 -3
  8. package/lib/query/fetchQuery.js +3 -0
  9. package/lib/store/RelayConcreteVariables.js +12 -3
  10. package/lib/store/RelayExperimentalGraphResponseTransform.js +34 -2
  11. package/lib/store/RelayModernOperationDescriptor.js +1 -1
  12. package/lib/store/RelayPublishQueue.js +4 -2
  13. package/lib/store/RelayReader.js +55 -13
  14. package/lib/store/RelayStoreUtils.js +1 -0
  15. package/lib/store/ResolverCache.js +10 -2
  16. package/lib/util/withProvidedVariables.js +49 -0
  17. package/mutations/commitMutation.js.flow +8 -19
  18. package/mutations/readUpdatableQuery_EXPERIMENTAL.js.flow +47 -49
  19. package/mutations/validateMutation.js.flow +14 -2
  20. package/network/RelayNetwork.js.flow +10 -3
  21. package/network/RelayNetworkTypes.js.flow +1 -1
  22. package/package.json +6 -2
  23. package/query/fetchQuery.js.flow +9 -7
  24. package/relay-runtime.js +2 -2
  25. package/relay-runtime.min.js +2 -2
  26. package/store/RelayConcreteVariables.js.flow +12 -2
  27. package/store/RelayExperimentalGraphResponseTransform.js.flow +35 -1
  28. package/store/RelayModernOperationDescriptor.js.flow +5 -1
  29. package/store/RelayPublishQueue.js.flow +8 -1
  30. package/store/RelayReader.js.flow +78 -31
  31. package/store/RelayStoreTypes.js.flow +3 -2
  32. package/store/RelayStoreUtils.js.flow +1 -0
  33. package/store/ResolverCache.js.flow +18 -5
  34. package/subscription/requestSubscription.js.flow +7 -12
  35. package/util/NormalizationNode.js.flow +16 -16
  36. package/util/ReaderNode.js.flow +15 -15
  37. package/util/RelayConcreteNode.js.flow +4 -2
  38. package/util/withProvidedVariables.js.flow +64 -0
  39. package/lib/util/getAllRootVariables.js +0 -29
  40. package/util/getAllRootVariables.js.flow +0 -36
@@ -35,6 +35,8 @@ export type NormalizationRootNode =
35
35
  | ConcreteRequest
36
36
  | NormalizationSplitOperation;
37
37
 
38
+ export type ProvidedVariablesType = {+[key: string]: {|get(): mixed|}};
39
+
38
40
  /**
39
41
  * Contains the parameters required for executing a GraphQL request.
40
42
  * The operation can either be provided as a persisted `id` or `text`. If given
@@ -48,7 +50,7 @@ export type RequestParameters =
48
50
  // common fields
49
51
  +name: string,
50
52
  +operationKind: 'mutation' | 'query' | 'subscription',
51
- +providedVariables?: {[key: string]: {|get(): mixed|}},
53
+ +providedVariables?: ProvidedVariablesType,
52
54
  +metadata: {[key: string]: mixed, ...},
53
55
  |}
54
56
  | {|
@@ -58,7 +60,7 @@ export type RequestParameters =
58
60
  // common fields
59
61
  +name: string,
60
62
  +operationKind: 'mutation' | 'query' | 'subscription',
61
- +providedVariables?: {[key: string]: {|get(): mixed|}},
63
+ +providedVariables?: ProvidedVariablesType,
62
64
  +metadata: {[key: string]: mixed, ...},
63
65
  |};
64
66
 
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Copyright (c) Meta Platforms, Inc. and 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
+ import type {ProvidedVariablesType} from './RelayConcreteNode';
17
+ import type {Variables} from './RelayRuntimeTypes';
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
+
25
+ function withProvidedVariables(
26
+ userSuppliedVariables: Variables,
27
+ providedVariables: ?ProvidedVariablesType,
28
+ ): Variables {
29
+ if (providedVariables != null) {
30
+ const operationVariables = {};
31
+ Object.assign(operationVariables, userSuppliedVariables);
32
+ Object.keys(providedVariables).forEach((varName: string) => {
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
+ }
57
+ });
58
+ return operationVariables;
59
+ } else {
60
+ return userSuppliedVariables;
61
+ }
62
+ }
63
+
64
+ module.exports = withProvidedVariables;
@@ -1,29 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and 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
- * @emails oncall+relay
10
- */
11
- // flowlint ambiguous-object-type:error
12
- 'use strict';
13
-
14
- function getAllRootVariables(userSuppliedVariables, parameters) {
15
- var providedVariables = parameters.providedVariables;
16
-
17
- if (providedVariables != null) {
18
- var allVariables = {};
19
- Object.assign(allVariables, userSuppliedVariables);
20
- Object.keys(providedVariables).forEach(function (varName) {
21
- allVariables[varName] = providedVariables[varName].get();
22
- });
23
- return allVariables;
24
- } else {
25
- return userSuppliedVariables;
26
- }
27
- }
28
-
29
- module.exports = getAllRootVariables;
@@ -1,36 +0,0 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and 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
- import type {RequestParameters} from './RelayConcreteNode';
17
- import type {Variables} from './RelayRuntimeTypes';
18
-
19
- function getAllRootVariables(
20
- userSuppliedVariables: Variables,
21
- parameters: RequestParameters,
22
- ): Variables {
23
- const providedVariables = parameters.providedVariables;
24
- if (providedVariables != null) {
25
- const allVariables = {};
26
- Object.assign(allVariables, userSuppliedVariables);
27
- Object.keys(providedVariables).forEach((varName: string) => {
28
- allVariables[varName] = providedVariables[varName].get();
29
- });
30
- return allVariables;
31
- } else {
32
- return userSuppliedVariables;
33
- }
34
- }
35
-
36
- module.exports = getAllRootVariables;