relay-runtime 11.0.2 → 13.0.0-rc.2

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 (219) hide show
  1. package/README.md +67 -0
  2. package/handlers/RelayDefaultHandlerProvider.js.flow +3 -3
  3. package/handlers/connection/ConnectionHandler.js.flow +9 -18
  4. package/handlers/connection/ConnectionInterface.js.flow +1 -1
  5. package/handlers/connection/MutationHandlers.js.flow +8 -12
  6. package/index.js +1 -1
  7. package/index.js.flow +57 -35
  8. package/lib/handlers/RelayDefaultHandlerProvider.js +1 -1
  9. package/lib/handlers/connection/ConnectionHandler.js +13 -19
  10. package/lib/handlers/connection/ConnectionInterface.js +1 -1
  11. package/lib/handlers/connection/MutationHandlers.js +4 -7
  12. package/lib/index.js +59 -44
  13. package/lib/multi-actor-environment/ActorIdentifier.js +12 -2
  14. package/lib/multi-actor-environment/ActorSpecificEnvironment.js +64 -20
  15. package/lib/multi-actor-environment/ActorUtils.js +27 -0
  16. package/lib/multi-actor-environment/MultiActorEnvironment.js +324 -61
  17. package/lib/multi-actor-environment/MultiActorEnvironmentTypes.js +1 -1
  18. package/lib/multi-actor-environment/index.js +6 -2
  19. package/lib/mutations/RelayDeclarativeMutationConfig.js +5 -2
  20. package/lib/mutations/RelayRecordProxy.js +4 -3
  21. package/lib/mutations/RelayRecordSourceMutator.js +4 -3
  22. package/lib/mutations/RelayRecordSourceProxy.js +13 -5
  23. package/lib/mutations/RelayRecordSourceSelectorProxy.js +19 -6
  24. package/lib/mutations/applyOptimisticMutation.js +7 -7
  25. package/lib/mutations/commitLocalUpdate.js +1 -1
  26. package/lib/mutations/commitMutation.js +15 -11
  27. package/lib/mutations/readUpdatableQuery_EXPERIMENTAL.js +242 -0
  28. package/lib/mutations/validateMutation.js +11 -6
  29. package/lib/network/ConvertToExecuteFunction.js +3 -2
  30. package/lib/network/RelayNetwork.js +4 -3
  31. package/lib/network/RelayNetworkTypes.js +1 -1
  32. package/lib/network/RelayObservable.js +1 -1
  33. package/lib/network/RelayQueryResponseCache.js +22 -6
  34. package/lib/network/wrapNetworkWithLogObserver.js +79 -0
  35. package/lib/query/GraphQLTag.js +3 -2
  36. package/lib/query/PreloadableQueryRegistry.js +1 -1
  37. package/lib/query/fetchQuery.js +7 -6
  38. package/lib/query/fetchQueryInternal.js +1 -1
  39. package/lib/query/fetchQuery_DEPRECATED.js +3 -2
  40. package/lib/store/ClientID.js +8 -2
  41. package/lib/store/DataChecker.js +124 -55
  42. package/lib/store/OperationExecutor.js +489 -215
  43. package/lib/store/RelayConcreteVariables.js +27 -9
  44. package/lib/store/RelayExperimentalGraphResponseHandler.js +153 -0
  45. package/lib/store/RelayExperimentalGraphResponseTransform.js +391 -0
  46. package/lib/store/RelayModernEnvironment.js +100 -120
  47. package/lib/store/RelayModernFragmentSpecResolver.js +53 -27
  48. package/lib/store/RelayModernOperationDescriptor.js +3 -2
  49. package/lib/store/RelayModernRecord.js +48 -13
  50. package/lib/store/RelayModernSelector.js +15 -9
  51. package/lib/store/RelayModernStore.js +56 -23
  52. package/lib/store/RelayOperationTracker.js +34 -24
  53. package/lib/store/RelayOptimisticRecordSource.js +1 -1
  54. package/lib/store/RelayPublishQueue.js +35 -11
  55. package/lib/store/RelayReader.js +257 -72
  56. package/lib/store/RelayRecordSource.js +88 -4
  57. package/lib/store/RelayRecordState.js +1 -1
  58. package/lib/store/RelayReferenceMarker.js +34 -22
  59. package/lib/store/RelayResponseNormalizer.js +172 -96
  60. package/lib/store/RelayStoreReactFlightUtils.js +5 -11
  61. package/lib/store/RelayStoreSubscriptions.js +15 -10
  62. package/lib/store/RelayStoreTypes.js +1 -1
  63. package/lib/store/RelayStoreUtils.js +13 -8
  64. package/lib/store/ResolverCache.js +213 -0
  65. package/lib/store/ResolverFragments.js +10 -6
  66. package/lib/store/StoreInspector.js +1 -1
  67. package/lib/store/TypeID.js +1 -1
  68. package/lib/store/ViewerPattern.js +1 -1
  69. package/lib/store/cloneRelayHandleSourceField.js +6 -5
  70. package/lib/store/cloneRelayScalarHandleSourceField.js +6 -5
  71. package/lib/store/createFragmentSpecResolver.js +1 -1
  72. package/lib/store/createRelayContext.js +5 -3
  73. package/lib/store/defaultGetDataID.js +1 -1
  74. package/lib/store/defaultRequiredFieldLogger.js +1 -1
  75. package/lib/store/hasOverlappingIDs.js +1 -1
  76. package/lib/store/isRelayModernEnvironment.js +1 -1
  77. package/lib/store/normalizeRelayPayload.js +1 -1
  78. package/lib/store/readInlineData.js +7 -3
  79. package/lib/subscription/requestSubscription.js +32 -34
  80. package/lib/util/JSResourceTypes.flow.js +1 -1
  81. package/lib/util/NormalizationNode.js +1 -1
  82. package/lib/util/ReaderNode.js +1 -1
  83. package/lib/util/RelayConcreteNode.js +3 -1
  84. package/lib/util/RelayDefaultHandleKey.js +1 -1
  85. package/lib/util/RelayError.js +1 -1
  86. package/lib/util/RelayFeatureFlags.js +10 -7
  87. package/lib/util/RelayProfiler.js +1 -1
  88. package/lib/util/RelayReplaySubject.js +22 -7
  89. package/lib/util/RelayRuntimeTypes.js +1 -7
  90. package/lib/util/StringInterner.js +71 -0
  91. package/lib/util/createPayloadFor3DField.js +1 -1
  92. package/lib/util/deepFreeze.js +1 -1
  93. package/lib/util/generateID.js +1 -1
  94. package/lib/util/getAllRootVariables.js +29 -0
  95. package/lib/util/getFragmentIdentifier.js +16 -8
  96. package/lib/util/getOperation.js +3 -2
  97. package/lib/util/getPaginationMetadata.js +41 -0
  98. package/lib/util/getPaginationVariables.js +66 -0
  99. package/lib/util/getPendingOperationsForFragment.js +55 -0
  100. package/lib/util/getRefetchMetadata.js +36 -0
  101. package/lib/util/getRelayHandleKey.js +3 -3
  102. package/lib/util/getRequestIdentifier.js +3 -3
  103. package/lib/util/getValueAtPath.js +51 -0
  104. package/lib/util/isEmptyObject.js +2 -2
  105. package/lib/util/isPromise.js +1 -1
  106. package/lib/util/isScalarAndEqual.js +1 -1
  107. package/lib/util/recycleNodesInto.js +1 -1
  108. package/lib/util/registerEnvironmentWithDevTools.js +26 -0
  109. package/lib/util/reportMissingRequiredFields.js +1 -1
  110. package/lib/util/resolveImmediate.js +1 -1
  111. package/lib/util/stableCopy.js +1 -1
  112. package/lib/util/withDuration.js +31 -0
  113. package/multi-actor-environment/ActorIdentifier.js.flow +18 -2
  114. package/multi-actor-environment/ActorSpecificEnvironment.js.flow +94 -58
  115. package/multi-actor-environment/ActorUtils.js.flow +33 -0
  116. package/multi-actor-environment/MultiActorEnvironment.js.flow +366 -93
  117. package/multi-actor-environment/MultiActorEnvironmentTypes.js.flow +88 -23
  118. package/multi-actor-environment/index.js.flow +3 -1
  119. package/mutations/RelayDeclarativeMutationConfig.js.flow +33 -27
  120. package/mutations/RelayRecordProxy.js.flow +5 -6
  121. package/mutations/RelayRecordSourceMutator.js.flow +5 -7
  122. package/mutations/RelayRecordSourceProxy.js.flow +20 -11
  123. package/mutations/RelayRecordSourceSelectorProxy.js.flow +23 -8
  124. package/mutations/applyOptimisticMutation.js.flow +14 -15
  125. package/mutations/commitLocalUpdate.js.flow +2 -2
  126. package/mutations/commitMutation.js.flow +36 -47
  127. package/mutations/readUpdatableQuery_EXPERIMENTAL.js.flow +318 -0
  128. package/mutations/validateMutation.js.flow +27 -17
  129. package/network/ConvertToExecuteFunction.js.flow +3 -3
  130. package/network/RelayNetwork.js.flow +5 -6
  131. package/network/RelayNetworkTypes.js.flow +1 -1
  132. package/network/RelayObservable.js.flow +2 -2
  133. package/network/RelayQueryResponseCache.js.flow +35 -22
  134. package/network/wrapNetworkWithLogObserver.js.flow +99 -0
  135. package/package.json +2 -2
  136. package/query/GraphQLTag.js.flow +11 -11
  137. package/query/PreloadableQueryRegistry.js.flow +5 -3
  138. package/query/fetchQuery.js.flow +19 -19
  139. package/query/fetchQueryInternal.js.flow +7 -10
  140. package/query/fetchQuery_DEPRECATED.js.flow +7 -7
  141. package/relay-runtime.js +2 -2
  142. package/relay-runtime.min.js +2 -2
  143. package/store/ClientID.js.flow +15 -4
  144. package/store/DataChecker.js.flow +142 -60
  145. package/store/OperationExecutor.js.flow +575 -320
  146. package/store/RelayConcreteVariables.js.flow +28 -9
  147. package/store/RelayExperimentalGraphResponseHandler.js.flow +121 -0
  148. package/store/RelayExperimentalGraphResponseTransform.js.flow +470 -0
  149. package/store/RelayModernEnvironment.js.flow +91 -115
  150. package/store/RelayModernFragmentSpecResolver.js.flow +56 -32
  151. package/store/RelayModernOperationDescriptor.js.flow +13 -8
  152. package/store/RelayModernRecord.js.flow +68 -12
  153. package/store/RelayModernSelector.js.flow +25 -15
  154. package/store/RelayModernStore.js.flow +67 -32
  155. package/store/RelayOperationTracker.js.flow +60 -44
  156. package/store/RelayOptimisticRecordSource.js.flow +3 -3
  157. package/store/RelayPublishQueue.js.flow +74 -32
  158. package/store/RelayReader.js.flow +319 -100
  159. package/store/RelayRecordSource.js.flow +73 -7
  160. package/store/RelayRecordState.js.flow +1 -1
  161. package/store/RelayReferenceMarker.js.flow +41 -27
  162. package/store/RelayResponseNormalizer.js.flow +204 -86
  163. package/store/RelayStoreReactFlightUtils.js.flow +5 -12
  164. package/store/RelayStoreSubscriptions.js.flow +20 -12
  165. package/store/RelayStoreTypes.js.flow +200 -41
  166. package/store/RelayStoreUtils.js.flow +25 -12
  167. package/store/ResolverCache.js.flow +249 -0
  168. package/store/ResolverFragments.js.flow +16 -20
  169. package/store/StoreInspector.js.flow +3 -3
  170. package/store/TypeID.js.flow +2 -2
  171. package/store/ViewerPattern.js.flow +3 -3
  172. package/store/cloneRelayHandleSourceField.js.flow +6 -7
  173. package/store/cloneRelayScalarHandleSourceField.js.flow +6 -7
  174. package/store/createFragmentSpecResolver.js.flow +4 -5
  175. package/store/createRelayContext.js.flow +4 -4
  176. package/store/defaultGetDataID.js.flow +1 -1
  177. package/store/defaultRequiredFieldLogger.js.flow +1 -1
  178. package/store/hasOverlappingIDs.js.flow +1 -1
  179. package/store/isRelayModernEnvironment.js.flow +1 -1
  180. package/store/normalizeRelayPayload.js.flow +7 -8
  181. package/store/readInlineData.js.flow +8 -9
  182. package/subscription/requestSubscription.js.flow +55 -51
  183. package/util/JSResourceTypes.flow.js.flow +1 -1
  184. package/util/NormalizationNode.js.flow +11 -4
  185. package/util/ReaderNode.js.flow +25 -2
  186. package/util/RelayConcreteNode.js.flow +5 -1
  187. package/util/RelayDefaultHandleKey.js.flow +1 -1
  188. package/util/RelayError.js.flow +1 -1
  189. package/util/RelayFeatureFlags.js.flow +23 -15
  190. package/util/RelayProfiler.js.flow +1 -1
  191. package/util/RelayReplaySubject.js.flow +10 -10
  192. package/util/RelayRuntimeTypes.js.flow +70 -3
  193. package/util/StringInterner.js.flow +69 -0
  194. package/util/createPayloadFor3DField.js.flow +4 -4
  195. package/util/deepFreeze.js.flow +1 -1
  196. package/util/generateID.js.flow +1 -1
  197. package/util/getAllRootVariables.js.flow +36 -0
  198. package/util/getFragmentIdentifier.js.flow +28 -16
  199. package/util/getOperation.js.flow +3 -3
  200. package/util/getPaginationMetadata.js.flow +69 -0
  201. package/util/getPaginationVariables.js.flow +108 -0
  202. package/util/getPendingOperationsForFragment.js.flow +62 -0
  203. package/util/getRefetchMetadata.js.flow +76 -0
  204. package/util/getRelayHandleKey.js.flow +2 -3
  205. package/util/getRequestIdentifier.js.flow +4 -4
  206. package/util/getValueAtPath.js.flow +46 -0
  207. package/util/isEmptyObject.js.flow +2 -1
  208. package/util/isPromise.js.flow +1 -1
  209. package/util/isScalarAndEqual.js.flow +1 -1
  210. package/util/recycleNodesInto.js.flow +1 -1
  211. package/util/registerEnvironmentWithDevTools.js.flow +33 -0
  212. package/util/reportMissingRequiredFields.js.flow +1 -1
  213. package/util/resolveImmediate.js.flow +2 -2
  214. package/util/stableCopy.js.flow +1 -1
  215. package/util/withDuration.js.flow +32 -0
  216. package/lib/store/RelayRecordSourceMapImpl.js +0 -107
  217. package/lib/store/RelayStoreSubscriptionsUsingMapByID.js +0 -318
  218. package/store/RelayRecordSourceMapImpl.js.flow +0 -91
  219. package/store/RelayStoreSubscriptionsUsingMapByID.js.flow +0 -283
@@ -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.
@@ -12,23 +12,11 @@
12
12
 
13
13
  'use strict';
14
14
 
15
- const RelayDeclarativeMutationConfig = require('./RelayDeclarativeMutationConfig');
16
-
17
- const invariant = require('invariant');
18
- const isRelayModernEnvironment = require('../store/isRelayModernEnvironment');
19
- const validateMutation = require('./validateMutation');
20
- const warning = require('warning');
21
-
22
- const {getRequest} = require('../query/GraphQLTag');
23
- const {generateUniqueClientID} = require('../store/ClientID');
24
- const {
25
- createOperationDescriptor,
26
- } = require('../store/RelayModernOperationDescriptor');
27
-
28
15
  import type {PayloadError, UploadableMap} from '../network/RelayNetworkTypes';
29
16
  import type {GraphQLTaggedNode} from '../query/GraphQLTag';
30
17
  import type {
31
18
  IEnvironment,
19
+ MutationParameters,
32
20
  SelectorStoreUpdater,
33
21
  } from '../store/RelayStoreTypes';
34
22
  import type {
@@ -38,57 +26,63 @@ import type {
38
26
  } from '../util/RelayRuntimeTypes';
39
27
  import type {DeclarativeMutationConfig} from './RelayDeclarativeMutationConfig';
40
28
 
41
- export type DEPRECATED_MutationConfig<T> = {|
29
+ const {getRequest} = require('../query/GraphQLTag');
30
+ const {generateUniqueClientID} = require('../store/ClientID');
31
+ const isRelayModernEnvironment = require('../store/isRelayModernEnvironment');
32
+ const {
33
+ createOperationDescriptor,
34
+ } = require('../store/RelayModernOperationDescriptor');
35
+ const RelayDeclarativeMutationConfig = require('./RelayDeclarativeMutationConfig');
36
+ const validateMutation = require('./validateMutation');
37
+ const invariant = require('invariant');
38
+ const warning = require('warning');
39
+
40
+ export type DEPRECATED_MutationConfig<TMutationResponse> = {|
42
41
  configs?: Array<DeclarativeMutationConfig>,
43
42
  cacheConfig?: CacheConfig,
44
43
  mutation: GraphQLTaggedNode,
45
44
  variables: Variables,
46
45
  uploadables?: UploadableMap,
47
- onCompleted?: ?(response: T, errors: ?Array<PayloadError>) => void,
46
+ onCompleted?: ?(
47
+ response: TMutationResponse,
48
+ errors: ?Array<PayloadError>,
49
+ ) => void,
48
50
  onError?: ?(error: Error) => void,
49
51
  onUnsubscribe?: ?() => void,
50
- optimisticUpdater?: ?SelectorStoreUpdater,
52
+ optimisticUpdater?: ?SelectorStoreUpdater<TMutationResponse>,
51
53
  optimisticResponse?: Object,
52
- updater?: ?SelectorStoreUpdater,
54
+ updater?: ?SelectorStoreUpdater<TMutationResponse>,
53
55
  |};
54
56
 
55
- export type MutationParameters = {|
56
- +response: {...},
57
- +variables: interface {},
58
- +rawResponse?: {...},
59
- |};
60
-
61
- export type MutationConfig<T: MutationParameters> = {|
57
+ export type MutationConfig<TMutation: MutationParameters> = {|
62
58
  configs?: Array<DeclarativeMutationConfig>,
63
59
  cacheConfig?: CacheConfig,
64
60
  mutation: GraphQLTaggedNode,
65
61
  onError?: ?(error: Error) => void,
66
62
  onCompleted?: ?(
67
- response: $ElementType<T, 'response'>,
63
+ response: TMutation['response'],
68
64
  errors: ?Array<PayloadError>,
69
65
  ) => void,
66
+ onNext?: ?() => void,
70
67
  onUnsubscribe?: ?() => void,
71
- optimisticResponse?: $ElementType<
72
- {
73
- +rawResponse?: {...},
74
- ...T,
75
- ...
76
- },
77
- 'rawResponse',
78
- >,
79
- optimisticUpdater?: ?SelectorStoreUpdater,
80
- updater?: ?SelectorStoreUpdater,
68
+ optimisticResponse?: {
69
+ +rawResponse?: {...},
70
+ ...TMutation,
71
+ ...
72
+ }['rawResponse'],
73
+ optimisticUpdater?: ?SelectorStoreUpdater<TMutation['response']>,
74
+ updater?: ?SelectorStoreUpdater<TMutation['response']>,
81
75
  uploadables?: UploadableMap,
82
- variables: $ElementType<T, 'variables'>,
76
+ variables: TMutation['variables'],
83
77
  |};
84
78
 
85
79
  /**
86
80
  * Higher-level helper function to execute a mutation against a specific
87
81
  * environment.
88
82
  */
89
- function commitMutation<T: MutationParameters>(
83
+ function commitMutation<TMutation: MutationParameters>(
90
84
  environment: IEnvironment,
91
- config: MutationConfig<T>,
85
+ config: MutationConfig<TMutation>,
92
86
  ): Disposable {
93
87
  invariant(
94
88
  isRelayModernEnvironment(environment),
@@ -103,14 +97,8 @@ function commitMutation<T: MutationParameters>(
103
97
  throw new Error('commitMutation: Expected mutation to be of type request');
104
98
  }
105
99
  let {optimisticResponse, optimisticUpdater, updater} = config;
106
- const {
107
- configs,
108
- cacheConfig,
109
- onError,
110
- onUnsubscribe,
111
- variables,
112
- uploadables,
113
- } = config;
100
+ const {configs, cacheConfig, onError, onUnsubscribe, variables, uploadables} =
101
+ config;
114
102
  const operation = createOperationDescriptor(
115
103
  mutation,
116
104
  variables,
@@ -161,6 +149,7 @@ function commitMutation<T: MutationParameters>(
161
149
  errors.push(...payload.errors);
162
150
  }
163
151
  }
152
+ config.onNext?.();
164
153
  },
165
154
  complete: () => {
166
155
  const {onCompleted} = config;
@@ -0,0 +1,318 @@
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
+ * @emails oncall+relay
9
+ * @format
10
+ */
11
+
12
+ // flowlint ambiguous-object-type:error
13
+
14
+ 'use strict';
15
+
16
+ import type {GraphQLTaggedNode} from '../query/GraphQLTag';
17
+ import type {RecordProxy, RecordSourceProxy} from '../store/RelayStoreTypes';
18
+ import type {ReaderLinkedField, ReaderSelection} from '../util/ReaderNode';
19
+ import type {OperationType} from '../util/RelayRuntimeTypes';
20
+
21
+ const {getRequest} = require('../query/GraphQLTag');
22
+ const {getArgumentValues} = require('../store/RelayStoreUtils');
23
+
24
+ const nonUpdatableKeys = ['id', '__id', '__typename'];
25
+
26
+ function readUpdatableQuery_EXPERIMENTAL<TQuery: OperationType>(
27
+ query: GraphQLTaggedNode,
28
+ variables: TQuery['variables'],
29
+ proxy: RecordSourceProxy,
30
+ ): TQuery['response'] {
31
+ // TODO assert that the concrete request is an updatable query
32
+ const request = getRequest(query);
33
+
34
+ const updatableProxy = {};
35
+ updateProxyFromSelections(
36
+ updatableProxy,
37
+ proxy.getRoot(),
38
+ variables,
39
+ request.fragment.selections,
40
+ proxy,
41
+ );
42
+ if (__DEV__) {
43
+ Object.freeze(updatableProxy);
44
+ }
45
+ return updatableProxy;
46
+ }
47
+
48
+ function updateProxyFromSelections<TQuery: OperationType>(
49
+ mutableUpdatableProxy: TQuery['response'],
50
+ recordProxy: RecordProxy,
51
+ queryVariables: TQuery['variables'],
52
+ selections: $ReadOnlyArray<ReaderSelection>,
53
+ root: RecordSourceProxy,
54
+ ) {
55
+ for (const selection of selections) {
56
+ switch (selection.kind) {
57
+ case 'LinkedField':
58
+ // Linked fields are assignable if they contain fragment spreads or
59
+ // read-only otherwise.
60
+ const isAssignable = selection.selections.some(
61
+ item => item.kind === 'FragmentSpread',
62
+ );
63
+
64
+ const set = !isAssignable
65
+ ? undefined
66
+ : selection.plural
67
+ ? createSetterForPluralLinkedField(
68
+ selection,
69
+ queryVariables,
70
+ recordProxy,
71
+ root,
72
+ )
73
+ : createSetterForSingularLinkedField(
74
+ selection,
75
+ queryVariables,
76
+ recordProxy,
77
+ root,
78
+ );
79
+
80
+ const get = selection.plural
81
+ ? createGetterForPluralLinkedField(
82
+ selection,
83
+ queryVariables,
84
+ recordProxy,
85
+ root,
86
+ )
87
+ : createGetterForSingularLinkedField(
88
+ selection,
89
+ queryVariables,
90
+ recordProxy,
91
+ root,
92
+ );
93
+
94
+ Object.defineProperty(
95
+ mutableUpdatableProxy,
96
+ selection.alias ?? selection.name,
97
+ {
98
+ get,
99
+ set,
100
+ },
101
+ );
102
+ break;
103
+ case 'ScalarField':
104
+ const scalarFieldName = selection.alias ?? selection.name;
105
+ Object.defineProperty(mutableUpdatableProxy, scalarFieldName, {
106
+ get: function () {
107
+ const variables = getArgumentValues(
108
+ selection.args ?? [],
109
+ queryVariables,
110
+ );
111
+ // Flow incorrect assumes that the return value for the get method must match
112
+ // the set parameter.
113
+ return (recordProxy.getValue(
114
+ selection.name,
115
+ // $FlowFixMe[unclear-type] No good way to type these variables
116
+ (variables: any),
117
+ // $FlowFixMe[unclear-type] Typed by the generated updatable query flow type
118
+ ): any);
119
+ },
120
+ set: nonUpdatableKeys.includes(selection.name)
121
+ ? undefined
122
+ : // $FlowFixMe[unclear-type] Typed by the generated updatable query flow type
123
+ function (newValue: ?any) {
124
+ const variables = getArgumentValues(
125
+ selection.args ?? [],
126
+ queryVariables,
127
+ );
128
+ recordProxy.setValue(
129
+ newValue,
130
+ selection.name,
131
+ // $FlowFixMe[unclear-type] No good way to type these variables
132
+ (variables: any),
133
+ );
134
+ },
135
+ });
136
+ break;
137
+ case 'InlineFragment':
138
+ if (recordProxy.getType() === selection.type) {
139
+ updateProxyFromSelections(
140
+ mutableUpdatableProxy,
141
+ recordProxy,
142
+ queryVariables,
143
+ selection.selections,
144
+ root,
145
+ );
146
+ }
147
+ break;
148
+ case 'ClientExtension':
149
+ updateProxyFromSelections(
150
+ mutableUpdatableProxy,
151
+ recordProxy,
152
+ queryVariables,
153
+ selection.selections,
154
+ root,
155
+ );
156
+ break;
157
+ case 'FragmentSpread':
158
+ // Explicitly ignore
159
+ break;
160
+ default:
161
+ throw new Error(
162
+ 'Encountered an unexpected ReaderSelection variant in RelayRecordSourceProxy. This indicates a bug in Relay.',
163
+ );
164
+ }
165
+ }
166
+ }
167
+
168
+ function createSetterForPluralLinkedField<TQuery: OperationType>(
169
+ selection: ReaderLinkedField,
170
+ queryVariables: TQuery['variables'],
171
+ recordProxy: RecordProxy,
172
+ root: RecordSourceProxy,
173
+ ) {
174
+ return function set(newValue: ?$ReadOnlyArray<{__id: string, ...}>) {
175
+ const variables = getArgumentValues(selection.args ?? [], queryVariables);
176
+ if (newValue == null) {
177
+ // $FlowFixMe[unclear-type] No good way to type these variables
178
+ recordProxy.setValue(null, selection.name, (variables: any));
179
+ } else {
180
+ const recordProxies = newValue.map(item => {
181
+ if (item == null) {
182
+ throw new Error(
183
+ 'When assigning an array of items, none of the items should be null or undefined.',
184
+ );
185
+ }
186
+ const {__id} = item;
187
+ if (__id == null) {
188
+ throw new Error(
189
+ 'The __id field must be present on each item passed to the setter. This indicates a bug in Relay.',
190
+ );
191
+ }
192
+ const newValueRecord = root.get(__id);
193
+ if (newValueRecord == null) {
194
+ throw new Error(
195
+ `Did not find item with data id ${__id} in the store.`,
196
+ );
197
+ }
198
+ return newValueRecord;
199
+ });
200
+ recordProxy.setLinkedRecords(
201
+ recordProxies,
202
+ selection.name,
203
+ // $FlowFixMe[unclear-type] No good way to type these variables
204
+ (variables: any),
205
+ );
206
+ }
207
+ };
208
+ }
209
+ function createSetterForSingularLinkedField<TQuery: OperationType>(
210
+ selection: ReaderLinkedField,
211
+ queryVariables: TQuery['variables'],
212
+ recordProxy: RecordProxy,
213
+ root: RecordSourceProxy,
214
+ ) {
215
+ return function set(newValue: ?{__id: string, ...}) {
216
+ const variables = getArgumentValues(selection.args ?? [], queryVariables);
217
+ if (newValue == null) {
218
+ // $FlowFixMe[unclear-type] No good way to type these variables
219
+ recordProxy.setValue(null, selection.name, (variables: any));
220
+ } else {
221
+ const {__id} = newValue;
222
+ if (__id == null) {
223
+ throw new Error(
224
+ 'The __id field must be present on the argument. This indicates a bug in Relay.',
225
+ );
226
+ }
227
+ const newValueRecord = root.get(__id);
228
+ if (newValueRecord == null) {
229
+ throw new Error(`Did not find item with data id ${__id} in the store.`);
230
+ }
231
+ recordProxy.setLinkedRecord(
232
+ newValueRecord,
233
+ selection.name,
234
+ // $FlowFixMe[unclear-type] No good way to type these variables
235
+ (variables: any),
236
+ );
237
+ }
238
+ };
239
+ }
240
+
241
+ function createGetterForPluralLinkedField<TQuery: OperationType>(
242
+ selection: ReaderLinkedField,
243
+ queryVariables: TQuery['variables'],
244
+ recordProxy: RecordProxy,
245
+ root: RecordSourceProxy,
246
+ ) {
247
+ return function () {
248
+ const variables = getArgumentValues(selection.args ?? [], queryVariables);
249
+ const linkedRecords = recordProxy.getLinkedRecords(
250
+ selection.name,
251
+ // $FlowFixMe[unclear-type] No good way to type these variables
252
+ (variables: any),
253
+ );
254
+ if (linkedRecords != null) {
255
+ return (linkedRecords.map(linkedRecord => {
256
+ if (linkedRecord != null) {
257
+ const updatableProxy = {};
258
+ updateProxyFromSelections(
259
+ updatableProxy,
260
+ linkedRecord,
261
+ queryVariables,
262
+ selection.selections,
263
+ root,
264
+ );
265
+ if (__DEV__) {
266
+ Object.freeze(updatableProxy);
267
+ }
268
+ // Flow incorrect assumes that the return value for the get method must match
269
+ // the set parameter.
270
+ // $FlowFixMe[unclear-type] Typed by the generated updatable query flow type
271
+ return (updatableProxy: any);
272
+ } else {
273
+ return linkedRecord;
274
+ }
275
+ // $FlowFixMe[unclear-type] Typed by the generated updatable query flow type
276
+ }): any);
277
+ } else {
278
+ return linkedRecords;
279
+ }
280
+ };
281
+ }
282
+
283
+ function createGetterForSingularLinkedField<TQuery: OperationType>(
284
+ selection: ReaderLinkedField,
285
+ queryVariables: TQuery['variables'],
286
+ recordProxy: RecordProxy,
287
+ root: RecordSourceProxy,
288
+ ) {
289
+ return function () {
290
+ const variables = getArgumentValues(selection.args ?? [], queryVariables);
291
+ const linkedRecord = recordProxy.getLinkedRecord(
292
+ selection.name,
293
+ // $FlowFixMe[unclear-type] No good way to type these variables
294
+ (variables: any),
295
+ );
296
+ if (linkedRecord != null) {
297
+ const updatableProxy = {};
298
+ updateProxyFromSelections(
299
+ updatableProxy,
300
+ linkedRecord,
301
+ queryVariables,
302
+ selection.selections,
303
+ root,
304
+ );
305
+ if (__DEV__) {
306
+ Object.freeze(updatableProxy);
307
+ }
308
+ // Flow incorrect assumes that the return value for the get method must match
309
+ // the set parameter.
310
+ // $FlowFixMe[unclear-type] Typed by the generated updatable query flow type
311
+ return (updatableProxy: any);
312
+ } else {
313
+ return linkedRecord;
314
+ }
315
+ };
316
+ }
317
+
318
+ module.exports = {readUpdatableQuery_EXPERIMENTAL};
@@ -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,29 +13,17 @@
13
13
  'use strict';
14
14
 
15
15
  import type {
16
- NormalizationSelection,
17
16
  NormalizationField,
17
+ NormalizationSelection,
18
18
  } from '../util/NormalizationNode';
19
19
  import type {ConcreteRequest} from '../util/RelayConcreteNode';
20
20
  import type {Variables} from '../util/RelayRuntimeTypes';
21
21
 
22
- type ValidationContext = {|
23
- visitedPaths: Set<string>,
24
- path: string,
25
- variables: Variables,
26
- missingDiff: Object,
27
- extraDiff: Object,
28
- moduleImportPaths: Set<string>,
29
- |};
30
-
31
- const warning = require('warning');
32
-
33
- const hasOwnProperty = Object.prototype.hasOwnProperty;
34
-
35
22
  const {
36
- CONDITION,
23
+ ACTOR_CHANGE,
37
24
  CLIENT_COMPONENT,
38
25
  CLIENT_EXTENSION,
26
+ CONDITION,
39
27
  DEFER,
40
28
  FLIGHT_FIELD,
41
29
  FRAGMENT_SPREAD,
@@ -48,10 +36,26 @@ const {
48
36
  STREAM,
49
37
  TYPE_DISCRIMINATOR,
50
38
  } = require('../util/RelayConcreteNode');
39
+ const warning = require('warning');
40
+
41
+ type ValidationContext = {|
42
+ visitedPaths: Set<string>,
43
+ path: string,
44
+ variables: Variables,
45
+ missingDiff: Object,
46
+ extraDiff: Object,
47
+ moduleImportPaths: Set<string>,
48
+ |};
49
+ // $FlowFixMe[method-unbinding] added when improving typing for this parameters
50
+ const hasOwnProperty = Object.prototype.hasOwnProperty;
51
51
 
52
52
  let validateMutation = () => {};
53
53
  if (__DEV__) {
54
- const addFieldToDiff = (path: string, diff: Object, isScalar) => {
54
+ const addFieldToDiff = (
55
+ path: string,
56
+ diff: Object,
57
+ isScalar: void | boolean,
58
+ ) => {
55
59
  let deepLoc = diff;
56
60
  path.split('.').forEach((key, index, arr) => {
57
61
  if (deepLoc[key] == null) {
@@ -128,6 +132,12 @@ if (__DEV__) {
128
132
  case LINKED_FIELD:
129
133
  case FLIGHT_FIELD:
130
134
  return validateField(optimisticResponse, selection, context);
135
+ case ACTOR_CHANGE:
136
+ return validateField(
137
+ optimisticResponse,
138
+ selection.linkedField,
139
+ context,
140
+ );
131
141
  case INLINE_FRAGMENT:
132
142
  const type = selection.type;
133
143
  const isConcreteType = selection.abstractKey == 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.
@@ -12,10 +12,10 @@
12
12
 
13
13
  'use strict';
14
14
 
15
- const RelayObservable = require('./RelayObservable');
16
-
17
15
  import type {ExecuteFunction, FetchFunction} from './RelayNetworkTypes';
18
16
 
17
+ const RelayObservable = require('./RelayObservable');
18
+
19
19
  /**
20
20
  * Converts a FetchFunction into an ExecuteFunction for use by RelayNetwork.
21
21
  */
@@ -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.
@@ -12,22 +12,21 @@
12
12
 
13
13
  'use strict';
14
14
 
15
- const invariant = require('invariant');
16
-
17
- const {convertFetch} = require('./ConvertToExecuteFunction');
18
-
19
15
  import type {RequestParameters} from '../util/RelayConcreteNode';
20
16
  import type {CacheConfig, Variables} from '../util/RelayRuntimeTypes';
21
17
  import type {
22
18
  FetchFunction,
23
19
  GraphQLResponse,
24
- LogRequestInfoFunction,
25
20
  INetwork,
21
+ LogRequestInfoFunction,
26
22
  SubscribeFunction,
27
23
  UploadableMap,
28
24
  } from './RelayNetworkTypes';
29
25
  import type RelayObservable from './RelayObservable';
30
26
 
27
+ const {convertFetch} = require('./ConvertToExecuteFunction');
28
+ const invariant = require('invariant');
29
+
31
30
  /**
32
31
  * Creates an implementation of the `Network` interface defined in
33
32
  * `RelayNetworkTypes` given `fetch` and `subscribe` functions.
@@ -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.
@@ -223,7 +223,7 @@ class RelayObservable<+T> implements Subscribable<T> {
223
223
  do(observer: Observer<T>): RelayObservable<T> {
224
224
  return RelayObservable.create(sink => {
225
225
  const both = (action: any) =>
226
- function() {
226
+ function () {
227
227
  try {
228
228
  observer[action] && observer[action].apply(observer, arguments);
229
229
  } catch (error) {