relay-runtime 12.0.0 → 13.0.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 (216) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +67 -0
  3. package/handlers/RelayDefaultHandlerProvider.js.flow +3 -3
  4. package/handlers/connection/ConnectionHandler.js.flow +9 -18
  5. package/handlers/connection/ConnectionInterface.js.flow +1 -1
  6. package/handlers/connection/MutationHandlers.js.flow +8 -12
  7. package/index.js +2 -2
  8. package/index.js.flow +43 -34
  9. package/lib/handlers/RelayDefaultHandlerProvider.js +1 -1
  10. package/lib/handlers/connection/ConnectionHandler.js +13 -19
  11. package/lib/handlers/connection/ConnectionInterface.js +1 -1
  12. package/lib/handlers/connection/MutationHandlers.js +4 -7
  13. package/lib/index.js +49 -46
  14. package/lib/multi-actor-environment/ActorIdentifier.js +1 -1
  15. package/lib/multi-actor-environment/ActorSpecificEnvironment.js +9 -5
  16. package/lib/multi-actor-environment/ActorUtils.js +1 -1
  17. package/lib/multi-actor-environment/MultiActorEnvironment.js +36 -23
  18. package/lib/multi-actor-environment/MultiActorEnvironmentTypes.js +1 -1
  19. package/lib/multi-actor-environment/index.js +3 -3
  20. package/lib/mutations/RelayDeclarativeMutationConfig.js +5 -2
  21. package/lib/mutations/RelayRecordProxy.js +4 -3
  22. package/lib/mutations/RelayRecordSourceMutator.js +4 -3
  23. package/lib/mutations/RelayRecordSourceProxy.js +13 -5
  24. package/lib/mutations/RelayRecordSourceSelectorProxy.js +13 -5
  25. package/lib/mutations/applyOptimisticMutation.js +7 -7
  26. package/lib/mutations/commitLocalUpdate.js +1 -1
  27. package/lib/mutations/commitMutation.js +16 -15
  28. package/lib/mutations/readUpdatableQuery_EXPERIMENTAL.js +242 -0
  29. package/lib/mutations/validateMutation.js +7 -7
  30. package/lib/network/ConvertToExecuteFunction.js +3 -2
  31. package/lib/network/RelayNetwork.js +4 -3
  32. package/lib/network/RelayNetworkTypes.js +1 -1
  33. package/lib/network/RelayObservable.js +2 -4
  34. package/lib/network/RelayQueryResponseCache.js +3 -3
  35. package/lib/network/wrapNetworkWithLogObserver.js +3 -2
  36. package/lib/query/GraphQLTag.js +3 -2
  37. package/lib/query/PreloadableQueryRegistry.js +1 -1
  38. package/lib/query/fetchQuery.js +7 -6
  39. package/lib/query/fetchQueryInternal.js +1 -1
  40. package/lib/query/fetchQuery_DEPRECATED.js +3 -2
  41. package/lib/store/ClientID.js +8 -2
  42. package/lib/store/DataChecker.js +17 -18
  43. package/lib/store/OperationExecutor.js +14 -14
  44. package/lib/store/RelayConcreteVariables.js +7 -10
  45. package/lib/store/RelayExperimentalGraphResponseHandler.js +153 -0
  46. package/lib/store/RelayExperimentalGraphResponseTransform.js +391 -0
  47. package/lib/store/RelayModernEnvironment.js +67 -43
  48. package/lib/store/RelayModernFragmentSpecResolver.js +9 -9
  49. package/lib/store/RelayModernOperationDescriptor.js +3 -2
  50. package/lib/store/RelayModernRecord.js +13 -12
  51. package/lib/store/RelayModernSelector.js +15 -9
  52. package/lib/store/RelayModernStore.js +15 -16
  53. package/lib/store/RelayOperationTracker.js +1 -1
  54. package/lib/store/RelayOptimisticRecordSource.js +1 -1
  55. package/lib/store/RelayPublishQueue.js +12 -6
  56. package/lib/store/RelayReader.js +131 -40
  57. package/lib/store/RelayRecordSource.js +1 -1
  58. package/lib/store/RelayRecordState.js +1 -1
  59. package/lib/store/RelayReferenceMarker.js +11 -12
  60. package/lib/store/RelayResponseNormalizer.js +26 -23
  61. package/lib/store/RelayStoreReactFlightUtils.js +4 -4
  62. package/lib/store/RelayStoreSubscriptions.js +7 -5
  63. package/lib/store/RelayStoreTypes.js +1 -1
  64. package/lib/store/RelayStoreUtils.js +6 -6
  65. package/lib/store/ResolverCache.js +7 -7
  66. package/lib/store/ResolverFragments.js +12 -8
  67. package/lib/store/StoreInspector.js +1 -1
  68. package/lib/store/TypeID.js +1 -1
  69. package/lib/store/ViewerPattern.js +1 -1
  70. package/lib/store/cloneRelayHandleSourceField.js +6 -5
  71. package/lib/store/cloneRelayScalarHandleSourceField.js +6 -5
  72. package/lib/store/createFragmentSpecResolver.js +1 -1
  73. package/lib/store/createRelayContext.js +4 -2
  74. package/lib/store/defaultGetDataID.js +1 -1
  75. package/lib/store/defaultRequiredFieldLogger.js +1 -1
  76. package/lib/store/hasOverlappingIDs.js +1 -1
  77. package/lib/store/isRelayModernEnvironment.js +1 -1
  78. package/lib/store/normalizeRelayPayload.js +1 -1
  79. package/lib/store/readInlineData.js +7 -3
  80. package/lib/subscription/requestSubscription.js +4 -6
  81. package/lib/util/JSResourceTypes.flow.js +1 -1
  82. package/lib/util/NormalizationNode.js +1 -1
  83. package/lib/util/ReaderNode.js +1 -1
  84. package/lib/util/RelayConcreteNode.js +2 -1
  85. package/lib/util/RelayDefaultHandleKey.js +1 -1
  86. package/lib/util/RelayError.js +1 -1
  87. package/lib/util/RelayFeatureFlags.js +8 -3
  88. package/lib/util/RelayProfiler.js +1 -1
  89. package/lib/util/RelayReplaySubject.js +1 -1
  90. package/lib/util/RelayRuntimeTypes.js +1 -7
  91. package/lib/util/StringInterner.js +71 -0
  92. package/lib/util/createPayloadFor3DField.js +1 -1
  93. package/lib/util/deepFreeze.js +1 -1
  94. package/lib/util/generateID.js +1 -1
  95. package/lib/util/getAllRootVariables.js +29 -0
  96. package/lib/util/getFragmentIdentifier.js +16 -8
  97. package/lib/util/getOperation.js +3 -2
  98. package/lib/util/getPaginationMetadata.js +1 -1
  99. package/lib/util/getPaginationVariables.js +3 -4
  100. package/lib/util/getPendingOperationsForFragment.js +1 -1
  101. package/lib/util/getRefetchMetadata.js +1 -1
  102. package/lib/util/getRelayHandleKey.js +3 -3
  103. package/lib/util/getRequestIdentifier.js +3 -3
  104. package/lib/util/getValueAtPath.js +1 -1
  105. package/lib/util/isEmptyObject.js +1 -1
  106. package/lib/util/isPromise.js +1 -1
  107. package/lib/util/isScalarAndEqual.js +1 -1
  108. package/lib/util/recycleNodesInto.js +1 -1
  109. package/lib/util/registerEnvironmentWithDevTools.js +1 -1
  110. package/lib/util/reportMissingRequiredFields.js +1 -1
  111. package/lib/util/resolveImmediate.js +1 -1
  112. package/lib/util/stableCopy.js +1 -1
  113. package/lib/util/withDuration.js +1 -1
  114. package/multi-actor-environment/ActorIdentifier.js.flow +1 -1
  115. package/multi-actor-environment/ActorSpecificEnvironment.js.flow +28 -20
  116. package/multi-actor-environment/ActorUtils.js.flow +3 -3
  117. package/multi-actor-environment/MultiActorEnvironment.js.flow +46 -25
  118. package/multi-actor-environment/MultiActorEnvironmentTypes.js.flow +28 -12
  119. package/multi-actor-environment/index.js.flow +2 -3
  120. package/mutations/RelayDeclarativeMutationConfig.js.flow +33 -28
  121. package/mutations/RelayRecordProxy.js.flow +5 -6
  122. package/mutations/RelayRecordSourceMutator.js.flow +5 -7
  123. package/mutations/RelayRecordSourceProxy.js.flow +20 -11
  124. package/mutations/RelayRecordSourceSelectorProxy.js.flow +16 -6
  125. package/mutations/applyOptimisticMutation.js.flow +14 -15
  126. package/mutations/commitLocalUpdate.js.flow +2 -2
  127. package/mutations/commitMutation.js.flow +36 -49
  128. package/mutations/readUpdatableQuery_EXPERIMENTAL.js.flow +318 -0
  129. package/mutations/validateMutation.js.flow +20 -18
  130. package/network/ConvertToExecuteFunction.js.flow +3 -3
  131. package/network/RelayNetwork.js.flow +5 -6
  132. package/network/RelayNetworkTypes.js.flow +1 -1
  133. package/network/RelayObservable.js.flow +2 -4
  134. package/network/RelayQueryResponseCache.js.flow +4 -4
  135. package/network/wrapNetworkWithLogObserver.js.flow +9 -9
  136. package/package.json +2 -2
  137. package/query/GraphQLTag.js.flow +11 -11
  138. package/query/PreloadableQueryRegistry.js.flow +5 -3
  139. package/query/fetchQuery.js.flow +19 -19
  140. package/query/fetchQueryInternal.js.flow +7 -10
  141. package/query/fetchQuery_DEPRECATED.js.flow +7 -7
  142. package/relay-runtime.js +2 -2
  143. package/relay-runtime.min.js +3 -3
  144. package/store/ClientID.js.flow +10 -3
  145. package/store/DataChecker.js.flow +21 -30
  146. package/store/OperationExecutor.js.flow +55 -63
  147. package/store/RelayConcreteVariables.js.flow +5 -11
  148. package/store/RelayExperimentalGraphResponseHandler.js.flow +121 -0
  149. package/store/RelayExperimentalGraphResponseTransform.js.flow +470 -0
  150. package/store/RelayModernEnvironment.js.flow +57 -28
  151. package/store/RelayModernFragmentSpecResolver.js.flow +18 -20
  152. package/store/RelayModernOperationDescriptor.js.flow +11 -12
  153. package/store/RelayModernRecord.js.flow +20 -13
  154. package/store/RelayModernSelector.js.flow +25 -15
  155. package/store/RelayModernStore.js.flow +22 -26
  156. package/store/RelayOperationTracker.js.flow +12 -18
  157. package/store/RelayOptimisticRecordSource.js.flow +3 -3
  158. package/store/RelayPublishQueue.js.flow +43 -24
  159. package/store/RelayReader.js.flow +181 -68
  160. package/store/RelayRecordSource.js.flow +3 -3
  161. package/store/RelayRecordState.js.flow +1 -1
  162. package/store/RelayReferenceMarker.js.flow +13 -16
  163. package/store/RelayResponseNormalizer.js.flow +44 -42
  164. package/store/RelayStoreReactFlightUtils.js.flow +4 -5
  165. package/store/RelayStoreSubscriptions.js.flow +10 -9
  166. package/store/RelayStoreTypes.js.flow +73 -30
  167. package/store/RelayStoreUtils.js.flow +9 -10
  168. package/store/ResolverCache.js.flow +17 -15
  169. package/store/ResolverFragments.js.flow +18 -25
  170. package/store/StoreInspector.js.flow +3 -3
  171. package/store/TypeID.js.flow +2 -2
  172. package/store/ViewerPattern.js.flow +3 -3
  173. package/store/cloneRelayHandleSourceField.js.flow +6 -7
  174. package/store/cloneRelayScalarHandleSourceField.js.flow +6 -7
  175. package/store/createFragmentSpecResolver.js.flow +4 -5
  176. package/store/createRelayContext.js.flow +3 -3
  177. package/store/defaultGetDataID.js.flow +1 -1
  178. package/store/defaultRequiredFieldLogger.js.flow +1 -1
  179. package/store/hasOverlappingIDs.js.flow +1 -1
  180. package/store/isRelayModernEnvironment.js.flow +1 -1
  181. package/store/normalizeRelayPayload.js.flow +7 -8
  182. package/store/readInlineData.js.flow +8 -9
  183. package/subscription/requestSubscription.js.flow +16 -25
  184. package/util/JSResourceTypes.flow.js.flow +1 -1
  185. package/util/NormalizationNode.js.flow +1 -1
  186. package/util/ReaderNode.js.flow +10 -1
  187. package/util/RelayConcreteNode.js.flow +4 -1
  188. package/util/RelayDefaultHandleKey.js.flow +1 -1
  189. package/util/RelayError.js.flow +1 -1
  190. package/util/RelayFeatureFlags.js.flow +15 -5
  191. package/util/RelayProfiler.js.flow +1 -1
  192. package/util/RelayReplaySubject.js.flow +3 -4
  193. package/util/RelayRuntimeTypes.js.flow +70 -3
  194. package/util/StringInterner.js.flow +69 -0
  195. package/util/createPayloadFor3DField.js.flow +4 -4
  196. package/util/deepFreeze.js.flow +1 -1
  197. package/util/generateID.js.flow +1 -1
  198. package/util/getAllRootVariables.js.flow +36 -0
  199. package/util/getFragmentIdentifier.js.flow +28 -16
  200. package/util/getOperation.js.flow +3 -3
  201. package/util/getPaginationMetadata.js.flow +6 -11
  202. package/util/getPaginationVariables.js.flow +6 -10
  203. package/util/getPendingOperationsForFragment.js.flow +3 -3
  204. package/util/getRefetchMetadata.js.flow +8 -12
  205. package/util/getRelayHandleKey.js.flow +2 -3
  206. package/util/getRequestIdentifier.js.flow +4 -4
  207. package/util/getValueAtPath.js.flow +1 -1
  208. package/util/isEmptyObject.js.flow +1 -1
  209. package/util/isPromise.js.flow +1 -1
  210. package/util/isScalarAndEqual.js.flow +1 -1
  211. package/util/recycleNodesInto.js.flow +1 -1
  212. package/util/registerEnvironmentWithDevTools.js.flow +1 -1
  213. package/util/reportMissingRequiredFields.js.flow +1 -1
  214. package/util/resolveImmediate.js.flow +2 -2
  215. package/util/stableCopy.js.flow +1 -1
  216. package/util/withDuration.js.flow +1 -1
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -11,16 +11,19 @@
11
11
  // flowlint ambiguous-object-type:error
12
12
  'use strict';
13
13
 
14
- var RelayFeatureFlags = require('./RelayFeatureFlags');
14
+ var _require = require('../store/RelayModernSelector'),
15
+ getDataIDsFromFragment = _require.getDataIDsFromFragment,
16
+ getSelector = _require.getSelector,
17
+ getVariablesFromFragment = _require.getVariablesFromFragment;
15
18
 
16
19
  var isEmptyObject = require('./isEmptyObject');
17
20
 
21
+ var RelayFeatureFlags = require('./RelayFeatureFlags');
22
+
18
23
  var stableCopy = require('./stableCopy');
19
24
 
20
- var _require = require('../store/RelayModernSelector'),
21
- getDataIDsFromFragment = _require.getDataIDsFromFragment,
22
- getVariablesFromFragment = _require.getVariablesFromFragment,
23
- getSelector = _require.getSelector;
25
+ var _require2 = require('./StringInterner'),
26
+ intern = _require2.intern;
24
27
 
25
28
  function getFragmentIdentifier(fragmentNode, fragmentRef) {
26
29
  var selector = getSelector(fragmentNode, fragmentRef);
@@ -31,11 +34,16 @@ function getFragmentIdentifier(fragmentNode, fragmentRef) {
31
34
  var dataIDs = getDataIDsFromFragment(fragmentNode, fragmentRef);
32
35
 
33
36
  if (RelayFeatureFlags.ENABLE_GETFRAGMENTIDENTIFIER_OPTIMIZATION) {
34
- return fragmentOwnerIdentifier + '/' + fragmentNode.name + '/' + (fragmentVariables == null || isEmptyObject(fragmentVariables) ? '{}' : JSON.stringify(stableCopy(fragmentVariables))) + '/' + (typeof dataIDs === 'undefined' ? 'missing' : dataIDs == null ? 'null' : Array.isArray(dataIDs) ? '[' + dataIDs.join(',') + ']' : dataIDs);
37
+ var ids = typeof dataIDs === 'undefined' ? 'missing' : dataIDs == null ? 'null' : Array.isArray(dataIDs) ? '[' + dataIDs.join(',') + ']' : dataIDs;
38
+ ids = RelayFeatureFlags.STRING_INTERN_LEVEL <= 1 ? ids : intern(ids, RelayFeatureFlags.MAX_DATA_ID_LENGTH);
39
+ return fragmentOwnerIdentifier + '/' + fragmentNode.name + '/' + (fragmentVariables == null || isEmptyObject(fragmentVariables) ? '{}' : JSON.stringify(stableCopy(fragmentVariables))) + '/' + ids;
35
40
  } else {
36
41
  var _JSON$stringify;
37
42
 
38
- return fragmentOwnerIdentifier + '/' + fragmentNode.name + '/' + JSON.stringify(stableCopy(fragmentVariables)) + '/' + ((_JSON$stringify = JSON.stringify(dataIDs)) !== null && _JSON$stringify !== void 0 ? _JSON$stringify : 'missing');
43
+ var _ids = (_JSON$stringify = JSON.stringify(dataIDs)) !== null && _JSON$stringify !== void 0 ? _JSON$stringify : 'missing';
44
+
45
+ _ids = RelayFeatureFlags.STRING_INTERN_LEVEL <= 1 ? _ids : intern(_ids, RelayFeatureFlags.MAX_DATA_ID_LENGTH);
46
+ return fragmentOwnerIdentifier + '/' + fragmentNode.name + '/' + JSON.stringify(stableCopy(fragmentVariables)) + '/' + _ids;
39
47
  }
40
48
  }
41
49
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -14,11 +14,12 @@
14
14
  var _require = require('./RelayConcreteNode'),
15
15
  REQUEST = _require.REQUEST,
16
16
  SPLIT_OPERATION = _require.SPLIT_OPERATION;
17
-
18
17
  /**
19
18
  * OperationLoaders can return either a NormalizationSplitOperation or
20
19
  * ConcreteRequest.
21
20
  */
21
+
22
+
22
23
  function getOperation(node) {
23
24
  switch (node.kind) {
24
25
  case REQUEST:
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -32,7 +32,7 @@ function getPaginationVariables(direction, count, cursor, baseVariables, extraVa
32
32
 
33
33
  !(backwardMetadata != null && backwardMetadata.count != null && backwardMetadata.cursor != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected backward pagination metadata to be available. ' + "If you're seeing this, this is likely a bug in Relay.") : invariant(false) : void 0;
34
34
  process.env.NODE_ENV !== "production" ? warning(!extraVariables.hasOwnProperty(backwardMetadata.cursor), 'Relay: `UNSTABLE_extraVariables` provided by caller should not ' + 'contain cursor variable `%s`. This variable is automatically ' + 'determined by Relay.', backwardMetadata.cursor) : void 0;
35
- process.env.NODE_ENV !== "production" ? warning(!extraVariables.hasOwnProperty(backwardMetadata.count), 'Relay: `UNSTABLE_extraVariables` provided by caller should not ' + 'contain count variable `%s`. This variable is automatically ' + 'determined by Relay.', backwardMetadata.count) : void 0; // $FlowFixMe[cannot-spread-interface]
35
+ process.env.NODE_ENV !== "production" ? warning(!extraVariables.hasOwnProperty(backwardMetadata.count), 'Relay: `UNSTABLE_extraVariables` provided by caller should not ' + 'contain count variable `%s`. This variable is automatically ' + 'determined by Relay.', backwardMetadata.count) : void 0;
36
36
 
37
37
  var _paginationVariables = (0, _objectSpread4["default"])((0, _objectSpread4["default"])((0, _objectSpread4["default"])({}, baseVariables), extraVariables), {}, (_objectSpread2 = {}, (0, _defineProperty2["default"])(_objectSpread2, backwardMetadata.cursor, cursor), (0, _defineProperty2["default"])(_objectSpread2, backwardMetadata.count, count), _objectSpread2));
38
38
 
@@ -49,8 +49,7 @@ function getPaginationVariables(direction, count, cursor, baseVariables, extraVa
49
49
 
50
50
  !(forwardMetadata != null && forwardMetadata.count != null && forwardMetadata.cursor != null) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Relay: Expected forward pagination metadata to be available. ' + "If you're seeing this, this is likely a bug in Relay.") : invariant(false) : void 0;
51
51
  process.env.NODE_ENV !== "production" ? warning(!extraVariables.hasOwnProperty(forwardMetadata.cursor), 'Relay: `UNSTABLE_extraVariables` provided by caller should not ' + 'contain cursor variable `%s`. This variable is automatically ' + 'determined by Relay.', forwardMetadata.cursor) : void 0;
52
- process.env.NODE_ENV !== "production" ? warning(!extraVariables.hasOwnProperty(forwardMetadata.count), 'Relay: `UNSTABLE_extraVariables` provided by caller should not ' + 'contain count variable `%s`. This variable is automatically ' + 'determined by Relay.', forwardMetadata.count) : void 0; // $FlowFixMe[cannot-spread-interface]
53
-
52
+ process.env.NODE_ENV !== "production" ? warning(!extraVariables.hasOwnProperty(forwardMetadata.count), 'Relay: `UNSTABLE_extraVariables` provided by caller should not ' + 'contain count variable `%s`. This variable is automatically ' + 'determined by Relay.', forwardMetadata.count) : void 0;
54
53
  var paginationVariables = (0, _objectSpread4["default"])((0, _objectSpread4["default"])((0, _objectSpread4["default"])({}, baseVariables), extraVariables), {}, (_objectSpread3 = {}, (0, _defineProperty2["default"])(_objectSpread3, forwardMetadata.cursor, cursor), (0, _defineProperty2["default"])(_objectSpread3, forwardMetadata.count, count), _objectSpread3));
55
54
 
56
55
  if (backwardMetadata && backwardMetadata.cursor) {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -10,10 +10,10 @@
10
10
  // flowlint ambiguous-object-type:error
11
11
  'use strict';
12
12
 
13
- var invariant = require('invariant');
14
-
15
13
  var _require = require('./RelayDefaultHandleKey'),
16
14
  DEFAULT_HANDLE_KEY = _require.DEFAULT_HANDLE_KEY;
15
+
16
+ var invariant = require('invariant');
17
17
  /**
18
18
  * @internal
19
19
  *
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -10,10 +10,10 @@
10
10
  // flowlint ambiguous-object-type:error
11
11
  'use strict';
12
12
 
13
- var invariant = require('invariant');
14
-
15
13
  var stableCopy = require('./stableCopy');
16
14
 
15
+ var invariant = require('invariant');
16
+
17
17
  /**
18
18
  * Returns a stable identifier for the given pair of `RequestParameters` +
19
19
  * variables.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -11,31 +11,25 @@
11
11
 
12
12
  'use strict';
13
13
 
14
- const RelayOperationTracker = require('../store/RelayOperationTracker');
15
- const RelayPublishQueue = require('../store/RelayPublishQueue');
16
-
17
- const defaultGetDataID = require('../store/defaultGetDataID');
18
- const registerEnvironmentWithDevTools = require('../util/registerEnvironmentWithDevTools');
19
- const wrapNetworkWithLogObserver = require('../network/wrapNetworkWithLogObserver');
20
-
21
14
  import type {HandlerProvider} from '../handlers/RelayDefaultHandlerProvider';
22
15
  import type {GraphQLResponse, PayloadData} from '../network/RelayNetworkTypes';
23
16
  import type {INetwork} from '../network/RelayNetworkTypes';
24
17
  import type RelayObservable from '../network/RelayObservable';
25
18
  import type {
19
+ ExecuteMutationConfig,
20
+ LogFunction,
21
+ MutationParameters,
22
+ OperationAvailability,
23
+ OperationDescriptor,
24
+ OperationTracker,
26
25
  OptimisticResponseConfig,
27
26
  OptimisticUpdateFunction,
28
- OperationDescriptor,
29
- OperationAvailability,
30
- Snapshot,
27
+ RequiredFieldLogger,
31
28
  SelectorStoreUpdater,
32
29
  SingularReaderSelector,
33
- StoreUpdater,
34
- RequiredFieldLogger,
35
- ExecuteMutationConfig,
36
- LogFunction,
30
+ Snapshot,
37
31
  Store,
38
- OperationTracker,
32
+ StoreUpdater,
39
33
  } from '../store/RelayStoreTypes';
40
34
  import type {Disposable, RenderPolicy} from '../util/RelayRuntimeTypes';
41
35
  import type {ActorIdentifier} from './ActorIdentifier';
@@ -44,6 +38,12 @@ import type {
44
38
  IMultiActorEnvironment,
45
39
  } from './MultiActorEnvironmentTypes';
46
40
 
41
+ const wrapNetworkWithLogObserver = require('../network/wrapNetworkWithLogObserver');
42
+ const defaultGetDataID = require('../store/defaultGetDataID');
43
+ const RelayOperationTracker = require('../store/RelayOperationTracker');
44
+ const RelayPublishQueue = require('../store/RelayPublishQueue');
45
+ const registerEnvironmentWithDevTools = require('../util/registerEnvironmentWithDevTools');
46
+
47
47
  export type ActorSpecificEnvironmentConfig = $ReadOnly<{
48
48
  actorIdentifier: ActorIdentifier,
49
49
  configName: ?string,
@@ -113,7 +113,9 @@ class ActorSpecificEnvironment implements IActorEnvironment {
113
113
  return this._defaultRenderPolicy;
114
114
  }
115
115
 
116
- applyMutation(optimisticConfig: OptimisticResponseConfig): Disposable {
116
+ applyMutation<TMutation: MutationParameters>(
117
+ optimisticConfig: OptimisticResponseConfig<TMutation>,
118
+ ): Disposable {
117
119
  return this.multiActorEnvironment.applyMutation(this, optimisticConfig);
118
120
  }
119
121
 
@@ -187,13 +189,19 @@ class ActorSpecificEnvironment implements IActorEnvironment {
187
189
 
188
190
  execute(config: {
189
191
  operation: OperationDescriptor,
190
- updater?: ?SelectorStoreUpdater,
191
192
  }): RelayObservable<GraphQLResponse> {
192
193
  return this.multiActorEnvironment.execute(this, config);
193
194
  }
194
195
 
195
- executeMutation(
196
- options: ExecuteMutationConfig,
196
+ executeSubscription<TMutation: MutationParameters>(config: {
197
+ operation: OperationDescriptor,
198
+ updater?: ?SelectorStoreUpdater<TMutation['response']>,
199
+ }): RelayObservable<GraphQLResponse> {
200
+ return this.multiActorEnvironment.executeSubscription(this, config);
201
+ }
202
+
203
+ executeMutation<TMutation: MutationParameters>(
204
+ options: ExecuteMutationConfig<TMutation>,
197
205
  ): RelayObservable<GraphQLResponse> {
198
206
  return this.multiActorEnvironment.executeMutation(this, options);
199
207
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -13,10 +13,10 @@
13
13
 
14
14
  const ACTOR_IDENTIFIER_FIELD_NAME = 'actor_key';
15
15
 
16
- const {getActorIdentifier} = require('./ActorIdentifier');
17
-
18
16
  import type {ActorIdentifier} from './ActorIdentifier';
19
17
 
18
+ const {getActorIdentifier} = require('./ActorIdentifier');
19
+
20
20
  function getActorIdentifierFromPayload(payload: mixed): ?ActorIdentifier {
21
21
  if (
22
22
  payload != null &&
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -11,16 +11,6 @@
11
11
 
12
12
  'use strict';
13
13
 
14
- const ActorSpecificEnvironment = require('./ActorSpecificEnvironment');
15
- const OperationExecutor = require('../store/OperationExecutor');
16
- const RelayDefaultHandlerProvider = require('../handlers/RelayDefaultHandlerProvider');
17
- const RelayModernStore = require('../store/RelayModernStore');
18
- const RelayObservable = require('../network/RelayObservable');
19
- const RelayRecordSource = require('../store/RelayRecordSource');
20
-
21
- const defaultGetDataID = require('../store/defaultGetDataID');
22
- const defaultRequiredFieldLogger = require('../store/defaultRequiredFieldLogger');
23
-
24
14
  import type {HandlerProvider} from '../handlers/RelayDefaultHandlerProvider';
25
15
  import type {GraphQLResponse, PayloadData} from '../network/RelayNetworkTypes';
26
16
  import type {INetwork} from '../network/RelayNetworkTypes';
@@ -31,6 +21,7 @@ import type {
31
21
  LogFunction,
32
22
  MissingFieldHandler,
33
23
  MutableRecordSource,
24
+ MutationParameters,
34
25
  OperationAvailability,
35
26
  OperationDescriptor,
36
27
  OperationLoader,
@@ -54,6 +45,15 @@ import type {
54
45
  MultiActorStoreUpdater,
55
46
  } from './MultiActorEnvironmentTypes';
56
47
 
48
+ const RelayDefaultHandlerProvider = require('../handlers/RelayDefaultHandlerProvider');
49
+ const RelayObservable = require('../network/RelayObservable');
50
+ const defaultGetDataID = require('../store/defaultGetDataID');
51
+ const defaultRequiredFieldLogger = require('../store/defaultRequiredFieldLogger');
52
+ const OperationExecutor = require('../store/OperationExecutor');
53
+ const RelayModernStore = require('../store/RelayModernStore');
54
+ const RelayRecordSource = require('../store/RelayRecordSource');
55
+ const ActorSpecificEnvironment = require('./ActorSpecificEnvironment');
56
+
57
57
  export type MultiActorEnvironmentConfig = $ReadOnly<{
58
58
  createConfigNameForActor?: ?(actorIdentifier: ActorIdentifier) => string,
59
59
  createNetworkForActor: (actorIdentifier: ActorIdentifier) => INetwork,
@@ -161,9 +161,7 @@ class MultiActorEnvironment implements IMultiActorEnvironment {
161
161
  handlers: [],
162
162
  defaultActorIdentifier: actorEnvironment.actorIdentifier,
163
163
  getSourceForActor: actorIdentifier => {
164
- return this.forActor(actorIdentifier)
165
- .getStore()
166
- .getSource();
164
+ return this.forActor(actorIdentifier).getStore().getSource();
167
165
  },
168
166
  getTargetForActor: () => {
169
167
  return RelayRecordSource.create();
@@ -189,9 +187,7 @@ class MultiActorEnvironment implements IMultiActorEnvironment {
189
187
  handlers,
190
188
  defaultActorIdentifier: actorEnvironment.actorIdentifier,
191
189
  getSourceForActor: actorIdentifier => {
192
- return this.forActor(actorIdentifier)
193
- .getStore()
194
- .getSource();
190
+ return this.forActor(actorIdentifier).getStore().getSource();
195
191
  },
196
192
  getTargetForActor: actorIdentifier => {
197
193
  let target = targets.get(actorIdentifier);
@@ -274,9 +270,9 @@ class MultiActorEnvironment implements IMultiActorEnvironment {
274
270
  });
275
271
  }
276
272
 
277
- applyMutation(
273
+ applyMutation<TMutation: MutationParameters>(
278
274
  actorEnvironment: IActorEnvironment,
279
- optimisticConfig: OptimisticResponseConfig,
275
+ optimisticConfig: OptimisticResponseConfig<TMutation>,
280
276
  ): Disposable {
281
277
  const subscription = this._execute(actorEnvironment, {
282
278
  createSource: () => RelayObservable.create(_sink => {}),
@@ -324,13 +320,38 @@ class MultiActorEnvironment implements IMultiActorEnvironment {
324
320
  }
325
321
 
326
322
  execute(
323
+ actorEnvironment: IActorEnvironment,
324
+ {
325
+ operation,
326
+ }: {
327
+ operation: OperationDescriptor,
328
+ },
329
+ ): RelayObservable<GraphQLResponse> {
330
+ return this._execute(actorEnvironment, {
331
+ createSource: () =>
332
+ actorEnvironment
333
+ .getNetwork()
334
+ .execute(
335
+ operation.request.node.params,
336
+ operation.request.variables,
337
+ operation.request.cacheConfig || {},
338
+ null,
339
+ ),
340
+ isClientPayload: false,
341
+ operation,
342
+ optimisticConfig: null,
343
+ updater: null,
344
+ });
345
+ }
346
+
347
+ executeSubscription<TMutation: MutationParameters>(
327
348
  actorEnvironment: IActorEnvironment,
328
349
  {
329
350
  operation,
330
351
  updater,
331
352
  }: {
332
353
  operation: OperationDescriptor,
333
- updater?: ?SelectorStoreUpdater,
354
+ updater?: ?SelectorStoreUpdater<TMutation['response']>,
334
355
  },
335
356
  ): RelayObservable<GraphQLResponse> {
336
357
  return this._execute(actorEnvironment, {
@@ -350,7 +371,7 @@ class MultiActorEnvironment implements IMultiActorEnvironment {
350
371
  });
351
372
  }
352
373
 
353
- executeMutation(
374
+ executeMutation<TMutation: MutationParameters>(
354
375
  actorEnvironment: IActorEnvironment,
355
376
  {
356
377
  operation,
@@ -358,7 +379,7 @@ class MultiActorEnvironment implements IMultiActorEnvironment {
358
379
  optimisticUpdater,
359
380
  updater,
360
381
  uploadables,
361
- }: ExecuteMutationConfig,
382
+ }: ExecuteMutationConfig<TMutation>,
362
383
  ): RelayObservable<GraphQLResponse> {
363
384
  let optimisticConfig;
364
385
  if (optimisticResponse || optimisticUpdater) {
@@ -414,7 +435,7 @@ class MultiActorEnvironment implements IMultiActorEnvironment {
414
435
  return this._isServer;
415
436
  }
416
437
 
417
- _execute(
438
+ _execute<TMutation: MutationParameters>(
418
439
  actorEnvironment: IActorEnvironment,
419
440
  {
420
441
  createSource,
@@ -426,8 +447,8 @@ class MultiActorEnvironment implements IMultiActorEnvironment {
426
447
  createSource: () => RelayObservable<GraphQLResponse>,
427
448
  isClientPayload: boolean,
428
449
  operation: OperationDescriptor,
429
- optimisticConfig: ?OptimisticResponseConfig,
430
- updater: ?SelectorStoreUpdater,
450
+ optimisticConfig: ?OptimisticResponseConfig<TMutation>,
451
+ updater: ?SelectorStoreUpdater<TMutation['response']>,
431
452
  |},
432
453
  ): RelayObservable<GraphQLResponse> {
433
454
  return RelayObservable.create(sink => {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -11,21 +11,22 @@
11
11
 
12
12
  'use strict';
13
13
 
14
- import type {PayloadData, GraphQLResponse} from '../network/RelayNetworkTypes';
14
+ import type {GraphQLResponse, PayloadData} from '../network/RelayNetworkTypes';
15
15
  import type RelayObservable from '../network/RelayObservable';
16
16
  import type RelayPublishQueue from '../store/RelayPublishQueue';
17
17
  import type {
18
+ ExecuteMutationConfig,
19
+ IEnvironment,
20
+ MutationParameters,
18
21
  OperationAvailability,
19
22
  OperationDescriptor,
20
23
  OptimisticResponseConfig,
21
24
  OptimisticUpdateFunction,
25
+ RecordSourceProxy,
22
26
  SelectorStoreUpdater,
23
27
  SingularReaderSelector,
24
28
  Snapshot,
25
29
  StoreUpdater,
26
- IEnvironment,
27
- ExecuteMutationConfig,
28
- RecordSourceProxy,
29
30
  } from '../store/RelayStoreTypes';
30
31
  import type {Disposable} from '../util/RelayRuntimeTypes';
31
32
  import type {ActorIdentifier} from './ActorIdentifier';
@@ -138,9 +139,9 @@ export interface IMultiActorEnvironment {
138
139
  * Apply an optimistic mutation response and/or updater. The mutation can be
139
140
  * reverted by calling `dispose()` on the returned value.
140
141
  */
141
- applyMutation(
142
+ applyMutation<TMutation: MutationParameters>(
142
143
  actorEnvironment: IActorEnvironment,
143
- optimisticConfig: OptimisticResponseConfig,
144
+ optimisticConfig: OptimisticResponseConfig<TMutation>,
144
145
  ): Disposable;
145
146
 
146
147
  /**
@@ -180,17 +181,32 @@ export interface IMultiActorEnvironment {
180
181
  * responses may be returned (via `next`) over time followed by either
181
182
  * the request completing (`completed`) or an error (`error`).
182
183
  *
184
+ * Note: Observables are lazy, so calling this method will do nothing until
185
+ * the result is subscribed to: environment.execute({...}).subscribe({...}).
186
+ */
187
+ execute(
188
+ actorEnvironment: IActorEnvironment,
189
+ config: {
190
+ operation: OperationDescriptor,
191
+ },
192
+ ): RelayObservable<GraphQLResponse>;
193
+
194
+ /**
195
+ * Send a subscription to the server with Observer semantics: one or more
196
+ * responses may be returned (via `next`) over time followed by either
197
+ * the request completing (`completed`) or an error (`error`).
198
+ *
183
199
  * Networks/servers that support subscriptions may choose to hold the
184
200
  * subscription open indefinitely such that `complete` is not called.
185
201
  *
186
202
  * Note: Observables are lazy, so calling this method will do nothing until
187
- * the result is subscribed to: environment.execute({...}).subscribe({...}).
203
+ * the result is subscribed to: environment.executeSubscription({...}).subscribe({...}).
188
204
  */
189
- execute(
205
+ executeSubscription<TMutation: MutationParameters>(
190
206
  actorEnvironment: IActorEnvironment,
191
207
  config: {
192
208
  operation: OperationDescriptor,
193
- updater?: ?SelectorStoreUpdater,
209
+ updater?: ?SelectorStoreUpdater<TMutation['response']>,
194
210
  },
195
211
  ): RelayObservable<GraphQLResponse>;
196
212
 
@@ -204,9 +220,9 @@ export interface IMultiActorEnvironment {
204
220
  * the result is subscribed to:
205
221
  * environment.executeMutation({...}).subscribe({...}).
206
222
  */
207
- executeMutation(
223
+ executeMutation<TMutation: MutationParameters>(
208
224
  actorEnvironment: IActorEnvironment,
209
- config: ExecuteMutationConfig,
225
+ config: ExecuteMutationConfig<TMutation>,
210
226
  ): RelayObservable<GraphQLResponse>;
211
227
 
212
228
  /**
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -11,9 +11,8 @@
11
11
 
12
12
  'use strict';
13
13
 
14
- const MultiActorEnvironment = require('./MultiActorEnvironment');
15
-
16
14
  const {getActorIdentifier} = require('./ActorIdentifier');
15
+ const MultiActorEnvironment = require('./MultiActorEnvironment');
17
16
 
18
17
  export type {ActorIdentifier} from './ActorIdentifier';
19
18
  export type {