react-relay 14.1.0 → 15.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (194) hide show
  1. package/ReactRelayContainerUtils.js.flow +1 -0
  2. package/ReactRelayContext.js +1 -1
  3. package/ReactRelayContext.js.flow +1 -0
  4. package/ReactRelayFragmentContainer.js.flow +6 -2
  5. package/ReactRelayFragmentMockRenderer.js.flow +1 -0
  6. package/ReactRelayLocalQueryRenderer.js.flow +5 -3
  7. package/ReactRelayPaginationContainer.js.flow +21 -12
  8. package/ReactRelayQueryFetcher.js.flow +19 -5
  9. package/ReactRelayQueryRenderer.js.flow +32 -1
  10. package/ReactRelayQueryRendererContext.js.flow +1 -0
  11. package/ReactRelayRefetchContainer.js.flow +9 -5
  12. package/ReactRelayTestMocker.js.flow +3 -1
  13. package/ReactRelayTypes.js.flow +1 -0
  14. package/RelayContext.js.flow +1 -0
  15. package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +2 -1
  16. package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +1 -0
  17. package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +1 -0
  18. package/__flowtests__/RelayModern-flowtest.js.flow +1 -0
  19. package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +1 -0
  20. package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +1 -0
  21. package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +1 -0
  22. package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +1 -0
  23. package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +3 -1
  24. package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +3 -1
  25. package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +4 -2
  26. package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +3 -1
  27. package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +4 -2
  28. package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +3 -1
  29. package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +4 -2
  30. package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +4 -2
  31. package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +3 -1
  32. package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +3 -1
  33. package/assertFragmentMap.js.flow +1 -0
  34. package/buildReactRelayContainer.js.flow +7 -5
  35. package/getRootVariablesForFragments.js.flow +1 -1
  36. package/hooks.js +1 -1
  37. package/hooks.js.flow +4 -0
  38. package/index.js +1 -1
  39. package/index.js.flow +4 -0
  40. package/isRelayEnvironment.js.flow +1 -0
  41. package/jest-react/enqueueTask.js.flow +1 -1
  42. package/jest-react/index.js.flow +1 -1
  43. package/jest-react/internalAct.js.flow +1 -1
  44. package/legacy.js +1 -1
  45. package/legacy.js.flow +1 -0
  46. package/lib/ReactRelayContainerUtils.js +2 -2
  47. package/lib/ReactRelayContext.js +3 -3
  48. package/lib/ReactRelayFragmentContainer.js +39 -66
  49. package/lib/ReactRelayFragmentMockRenderer.js +2 -3
  50. package/lib/ReactRelayLocalQueryRenderer.js +18 -30
  51. package/lib/ReactRelayPaginationContainer.js +66 -159
  52. package/lib/ReactRelayQueryFetcher.js +48 -74
  53. package/lib/ReactRelayQueryRenderer.js +62 -82
  54. package/lib/ReactRelayQueryRendererContext.js +2 -1
  55. package/lib/ReactRelayRefetchContainer.js +52 -99
  56. package/lib/ReactRelayTestMocker.js +32 -66
  57. package/lib/ReactRelayTypes.js +2 -0
  58. package/lib/RelayContext.js +4 -6
  59. package/lib/assertFragmentMap.js +3 -4
  60. package/lib/buildReactRelayContainer.js +10 -25
  61. package/lib/getRootVariablesForFragments.js +5 -8
  62. package/lib/hooks.js +5 -17
  63. package/lib/index.js +5 -24
  64. package/lib/isRelayEnvironment.js +5 -3
  65. package/lib/jest-react/enqueueTask.js +5 -9
  66. package/lib/jest-react/index.js +0 -1
  67. package/lib/jest-react/internalAct.js +9 -20
  68. package/lib/legacy.js +2 -7
  69. package/lib/multi-actor/ActorChange.js +2 -5
  70. package/lib/multi-actor/index.js +2 -1
  71. package/lib/multi-actor/useRelayActorEnvironment.js +4 -7
  72. package/lib/relay-hooks/EntryPointContainer.react.js +9 -14
  73. package/lib/relay-hooks/EntryPointTypes.flow.js +5 -2
  74. package/lib/relay-hooks/FragmentResource.js +102 -196
  75. package/lib/relay-hooks/HooksImplementation.js +2 -5
  76. package/lib/relay-hooks/InternalLogger.js +2 -2
  77. package/lib/relay-hooks/LRUCache.js +2 -19
  78. package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +33 -53
  79. package/lib/relay-hooks/MatchContainer.js +14 -22
  80. package/lib/relay-hooks/ProfilerContext.js +3 -2
  81. package/lib/relay-hooks/QueryResource.js +30 -99
  82. package/lib/relay-hooks/RelayEnvironmentProvider.js +5 -8
  83. package/lib/relay-hooks/SuspenseResource.js +8 -31
  84. package/lib/relay-hooks/loadEntryPoint.js +19 -31
  85. package/lib/relay-hooks/loadQuery.js +41 -77
  86. package/lib/relay-hooks/preloadQuery_DEPRECATED.js +10 -35
  87. package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +9 -14
  88. package/lib/relay-hooks/react-cache/RelayReactCache.js +7 -11
  89. package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +24 -78
  90. package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +23 -56
  91. package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +65 -143
  92. package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +5 -14
  93. package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +17 -23
  94. package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +73 -74
  95. package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +24 -38
  96. package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +60 -102
  97. package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +7 -15
  98. package/lib/relay-hooks/useBlockingPaginationFragment.js +71 -92
  99. package/lib/relay-hooks/useClientQuery.js +3 -6
  100. package/lib/relay-hooks/useEntryPointLoader.js +17 -36
  101. package/lib/relay-hooks/useFetchTrackingRef.js +10 -11
  102. package/lib/relay-hooks/useFragment.js +8 -18
  103. package/lib/relay-hooks/useFragmentNode.js +20 -31
  104. package/lib/relay-hooks/useIsMountedRef.js +4 -5
  105. package/lib/relay-hooks/useIsOperationNodeActive.js +8 -20
  106. package/lib/relay-hooks/useIsParentQueryActive.js +3 -6
  107. package/lib/relay-hooks/useLazyLoadQuery.js +6 -9
  108. package/lib/relay-hooks/useLazyLoadQueryNode.js +23 -33
  109. package/lib/relay-hooks/useLoadMoreFunction.js +45 -76
  110. package/lib/relay-hooks/useMemoOperationDescriptor.js +6 -14
  111. package/lib/relay-hooks/useMemoVariables.js +15 -33
  112. package/lib/relay-hooks/useMutation.js +8 -25
  113. package/lib/relay-hooks/usePaginationFragment.js +61 -76
  114. package/lib/relay-hooks/usePreloadedQuery.js +12 -29
  115. package/lib/relay-hooks/useQueryLoader.js +23 -47
  116. package/lib/relay-hooks/useRefetchableFragment.js +8 -18
  117. package/lib/relay-hooks/useRefetchableFragmentNode.js +64 -107
  118. package/lib/relay-hooks/useRelayEnvironment.js +4 -7
  119. package/lib/relay-hooks/useStaticFragmentNodeWarning.js +4 -7
  120. package/lib/relay-hooks/useSubscribeToInvalidationState.js +8 -8
  121. package/lib/relay-hooks/useSubscription.js +5 -9
  122. package/lib/relay-hooks/useUnsafeRef_DEPRECATED.js +29 -0
  123. package/multi-actor/ActorChange.js.flow +1 -1
  124. package/multi-actor/index.js.flow +1 -1
  125. package/multi-actor/useRelayActorEnvironment.js.flow +2 -2
  126. package/package.json +2 -2
  127. package/react-relay-hooks.js +2 -2
  128. package/react-relay-hooks.min.js +2 -2
  129. package/react-relay-legacy.js +2 -2
  130. package/react-relay-legacy.min.js +2 -2
  131. package/react-relay.js +2 -2
  132. package/react-relay.min.js +2 -2
  133. package/relay-hooks/EntryPointContainer.react.js.flow +1 -1
  134. package/relay-hooks/EntryPointTypes.flow.js.flow +7 -5
  135. package/relay-hooks/FragmentResource.js.flow +34 -8
  136. package/relay-hooks/HooksImplementation.js.flow +1 -1
  137. package/relay-hooks/InternalLogger.js.flow +1 -1
  138. package/relay-hooks/LRUCache.js.flow +1 -1
  139. package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +15 -8
  140. package/relay-hooks/MatchContainer.js.flow +1 -1
  141. package/relay-hooks/ProfilerContext.js.flow +1 -1
  142. package/relay-hooks/QueryResource.js.flow +25 -5
  143. package/relay-hooks/RelayEnvironmentProvider.js.flow +2 -2
  144. package/relay-hooks/SuspenseResource.js.flow +1 -1
  145. package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +3 -1
  146. package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +2 -2
  147. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +3 -1
  148. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +3 -1
  149. package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +35 -33
  150. package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +1 -1
  151. package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +33 -32
  152. package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +18 -18
  153. package/relay-hooks/__flowtests__/utils.js.flow +13 -2
  154. package/relay-hooks/loadEntryPoint.js.flow +11 -6
  155. package/relay-hooks/loadQuery.js.flow +11 -7
  156. package/relay-hooks/preloadQuery_DEPRECATED.js.flow +5 -6
  157. package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +13 -8
  158. package/relay-hooks/react-cache/RelayReactCache.js.flow +1 -1
  159. package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +4 -4
  160. package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +3 -3
  161. package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +4 -4
  162. package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +1 -1
  163. package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +1 -1
  164. package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +41 -22
  165. package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +1 -2
  166. package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +11 -5
  167. package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +2 -2
  168. package/relay-hooks/useBlockingPaginationFragment.js.flow +85 -56
  169. package/relay-hooks/useClientQuery.js.flow +1 -1
  170. package/relay-hooks/useEntryPointLoader.js.flow +10 -6
  171. package/relay-hooks/useFetchTrackingRef.js.flow +5 -4
  172. package/relay-hooks/useFragment.js.flow +2 -2
  173. package/relay-hooks/useFragmentNode.js.flow +5 -4
  174. package/relay-hooks/useIsMountedRef.js.flow +1 -1
  175. package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
  176. package/relay-hooks/useIsParentQueryActive.js.flow +1 -1
  177. package/relay-hooks/useLazyLoadQuery.js.flow +2 -2
  178. package/relay-hooks/useLazyLoadQueryNode.js.flow +2 -2
  179. package/relay-hooks/useLoadMoreFunction.js.flow +14 -9
  180. package/relay-hooks/useMemoOperationDescriptor.js.flow +3 -3
  181. package/relay-hooks/useMemoVariables.js.flow +13 -29
  182. package/relay-hooks/useMutation.js.flow +4 -4
  183. package/relay-hooks/usePaginationFragment.js.flow +53 -46
  184. package/relay-hooks/usePreloadedQuery.js.flow +47 -22
  185. package/relay-hooks/useQueryLoader.js.flow +85 -22
  186. package/relay-hooks/useRefetchableFragment.js.flow +64 -33
  187. package/relay-hooks/useRefetchableFragmentNode.js.flow +10 -4
  188. package/relay-hooks/useRelayEnvironment.js.flow +2 -2
  189. package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -3
  190. package/relay-hooks/useSubscribeToInvalidationState.js.flow +2 -2
  191. package/relay-hooks/useSubscription.js.flow +1 -1
  192. package/relay-hooks/useUnsafeRef_DEPRECATED.js.flow +25 -0
  193. package/lib/readContext.js +0 -27
  194. package/readContext.js.flow +0 -29
@@ -6,54 +6,38 @@
6
6
  *
7
7
  *
8
8
  * @format
9
+ * @oncall relay
9
10
  */
11
+
10
12
  'use strict';
11
13
 
12
14
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
13
-
14
15
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
15
-
16
16
  var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
17
-
18
17
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
19
-
20
18
  var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
21
-
22
19
  var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
23
-
24
20
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
25
-
26
21
  var _excluded = ["componentRef", "__relayContext", "__rootIsQueryRenderer"];
27
-
28
22
  var buildReactRelayContainer = require('./buildReactRelayContainer');
29
-
30
23
  var getRootVariablesForFragments = require('./getRootVariablesForFragments');
31
-
32
24
  var _require = require('./ReactRelayContainerUtils'),
33
- getContainerName = _require.getContainerName;
34
-
25
+ getContainerName = _require.getContainerName;
35
26
  var ReactRelayContext = require('./ReactRelayContext');
36
-
37
27
  var ReactRelayQueryFetcher = require('./ReactRelayQueryFetcher');
38
-
39
28
  var _require2 = require('./RelayContext'),
40
- assertRelayContext = _require2.assertRelayContext;
41
-
29
+ assertRelayContext = _require2.assertRelayContext;
42
30
  var areEqual = require("fbjs/lib/areEqual");
43
-
44
31
  var React = require('react');
45
-
46
32
  var _require3 = require('relay-runtime'),
47
- Observable = _require3.Observable,
48
- createFragmentSpecResolver = _require3.createFragmentSpecResolver,
49
- createOperationDescriptor = _require3.createOperationDescriptor,
50
- getDataIDsFromObject = _require3.getDataIDsFromObject,
51
- getRequest = _require3.getRequest,
52
- getVariablesFromObject = _require3.getVariablesFromObject,
53
- isScalarAndEqual = _require3.isScalarAndEqual;
54
-
33
+ Observable = _require3.Observable,
34
+ createFragmentSpecResolver = _require3.createFragmentSpecResolver,
35
+ createOperationDescriptor = _require3.createOperationDescriptor,
36
+ getDataIDsFromObject = _require3.getDataIDsFromObject,
37
+ getRequest = _require3.getRequest,
38
+ getVariablesFromObject = _require3.getVariablesFromObject,
39
+ isScalarAndEqual = _require3.isScalarAndEqual;
55
40
  var warning = require("fbjs/lib/warning");
56
-
57
41
  /**
58
42
  * Composes a React component class, returning a new class that intercepts
59
43
  * props, resolving them with the provided fragments and subscribing for
@@ -61,20 +45,19 @@ var warning = require("fbjs/lib/warning");
61
45
  */
62
46
  function createContainerWithFragments(Component, fragments, taggedNode) {
63
47
  var _class;
64
-
65
48
  var containerName = getContainerName(Component);
66
49
  return _class = /*#__PURE__*/function (_React$Component) {
67
50
  (0, _inheritsLoose2["default"])(_class, _React$Component);
51
+ // $FlowFixMe[missing-local-annot]
68
52
 
69
53
  function _class(props) {
70
54
  var _props$__rootIsQueryR, _this;
71
-
72
55
  _this = _React$Component.call(this, props) || this;
73
56
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "_handleFragmentDataUpdate", function () {
74
57
  var resolverFromThisUpdate = _this.state.resolver;
75
-
76
58
  _this.setState(function (updatedState) {
77
- return (// If this event belongs to the current data source, update.
59
+ return (
60
+ // If this event belongs to the current data source, update.
78
61
  // Otherwise we should ignore it.
79
62
  resolverFromThisUpdate === updatedState.resolver ? {
80
63
  data: updatedState.resolver.resolve()
@@ -89,10 +72,8 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
89
72
  dispose: function dispose() {}
90
73
  };
91
74
  }
92
-
93
75
  var _assertRelayContext = assertRelayContext(_this.props.__relayContext),
94
- environment = _assertRelayContext.environment;
95
-
76
+ environment = _assertRelayContext.environment;
96
77
  var rootVariables = getRootVariablesForFragments(fragments, _this.props);
97
78
  var fetchVariables = typeof refetchVariables === 'function' ? refetchVariables(_this._getFragmentVariables()) : refetchVariables;
98
79
  fetchVariables = (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, rootVariables), fetchVariables);
@@ -100,11 +81,9 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
100
81
  var cacheConfig = options ? {
101
82
  force: !!options.force
102
83
  } : undefined;
103
-
104
84
  if (cacheConfig != null && (options === null || options === void 0 ? void 0 : options.metadata) != null) {
105
85
  cacheConfig.metadata = options === null || options === void 0 ? void 0 : options.metadata;
106
86
  }
107
-
108
87
  var observer = typeof observerOrCallback === 'function' ? {
109
88
  // callback is not exectued on complete or unsubscribe
110
89
  // for backward compatibility
@@ -112,20 +91,20 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
112
91
  error: observerOrCallback
113
92
  } : observerOrCallback || {};
114
93
  var query = getRequest(taggedNode);
115
- var operation = createOperationDescriptor(query, fetchVariables, cacheConfig); // TODO: T26288752 find a better way
94
+ var operation = createOperationDescriptor(query, fetchVariables, cacheConfig);
116
95
 
117
- _this.state.localVariables = fetchVariables; // Cancel any previously running refetch.
96
+ // TODO: T26288752 find a better way
97
+ _this.state.localVariables = fetchVariables;
118
98
 
119
- _this._refetchSubscription && _this._refetchSubscription.unsubscribe(); // Declare refetchSubscription before assigning it in .start(), since
120
- // synchronous completion may call callbacks .subscribe() returns.
99
+ // Cancel any previously running refetch.
100
+ _this._refetchSubscription && _this._refetchSubscription.unsubscribe();
121
101
 
102
+ // Declare refetchSubscription before assigning it in .start(), since
103
+ // synchronous completion may call callbacks .subscribe() returns.
122
104
  var refetchSubscription;
123
-
124
105
  var storeSnapshot = _this._getQueryFetcher().lookupInStore(environment, operation, options === null || options === void 0 ? void 0 : options.fetchPolicy);
125
-
126
106
  if (storeSnapshot != null) {
127
107
  _this.state.resolver.setVariables(fragmentVariables, operation.request.node);
128
-
129
108
  _this.setState(function (latestState) {
130
109
  return {
131
110
  data: latestState.resolver.resolve(),
@@ -137,12 +116,10 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
137
116
  observer.next && observer.next();
138
117
  observer.complete && observer.complete();
139
118
  });
140
-
141
119
  return {
142
120
  dispose: function dispose() {}
143
121
  };
144
122
  }
145
-
146
123
  _this._getQueryFetcher().execute({
147
124
  environment: environment,
148
125
  operation: operation,
@@ -150,7 +127,6 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
150
127
  preservePreviousReferences: true
151
128
  }).mergeMap(function (response) {
152
129
  _this.state.resolver.setVariables(fragmentVariables, operation.request.node);
153
-
154
130
  return Observable.create(function (sink) {
155
131
  return _this.setState(function (latestState) {
156
132
  return {
@@ -176,7 +152,6 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
176
152
  observer.start && observer.start(subscription);
177
153
  }
178
154
  }));
179
-
180
155
  return {
181
156
  dispose: function dispose() {
182
157
  refetchSubscription && refetchSubscription.unsubscribe();
@@ -185,11 +160,11 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
185
160
  });
186
161
  var relayContext = assertRelayContext(props.__relayContext);
187
162
  var rootIsQueryRenderer = (_props$__rootIsQueryR = props.__rootIsQueryRenderer) !== null && _props$__rootIsQueryR !== void 0 ? _props$__rootIsQueryR : false;
188
- _this._refetchSubscription = null; // Do not provide a subscription/callback here.
163
+ _this._refetchSubscription = null;
164
+ // Do not provide a subscription/callback here.
189
165
  // It is possible for this render to be interrupted or aborted,
190
166
  // In which case the subscription would cause a leak.
191
167
  // We will add the subscription in componentDidMount().
192
-
193
168
  var resolver = createFragmentSpecResolver(relayContext, containerName, fragments, props, rootIsQueryRenderer);
194
169
  _this.state = {
195
170
  data: resolver.resolve(),
@@ -203,15 +178,11 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
203
178
  _this._isUnmounted = false;
204
179
  return _this;
205
180
  }
206
-
207
181
  var _proto = _class.prototype;
208
-
209
182
  _proto.componentDidMount = function componentDidMount() {
210
183
  this._isUnmounted = false;
211
-
212
184
  this._subscribeToNewResolverAndRerenderIfStoreHasChanged();
213
185
  };
214
-
215
186
  _proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
216
187
  // If the environment has changed or props point to new records then
217
188
  // previously fetched data and any pending fetches no longer apply:
@@ -222,21 +193,18 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
222
193
  prevState.resolver.dispose();
223
194
  this._queryFetcher && this._queryFetcher.dispose();
224
195
  this._refetchSubscription && this._refetchSubscription.unsubscribe();
225
-
226
196
  this._subscribeToNewResolverAndRerenderIfStoreHasChanged();
227
197
  } else {
228
198
  this._rerenderIfStoreHasChanged();
229
199
  }
230
200
  }
201
+
231
202
  /**
232
203
  * When new props are received, read data for the new props and add it to
233
204
  * state. Props may be the same in which case previous data can be reused.
234
- */
235
- ;
236
-
205
+ */;
237
206
  _class.getDerivedStateFromProps = function getDerivedStateFromProps(nextProps, prevState) {
238
207
  var _nextProps$__rootIsQu;
239
-
240
208
  // Any props change could impact the query, so we mirror props in state.
241
209
  // This is an unusual pattern, but necessary for this container usecase.
242
210
  var prevProps = prevState.prevProps;
@@ -246,12 +214,13 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
246
214
  var nextIDs = getDataIDsFromObject(fragments, nextProps);
247
215
  var prevRootVariables = getRootVariablesForFragments(fragments, prevProps);
248
216
  var nextRootVariables = getRootVariablesForFragments(fragments, nextProps);
249
- var resolver = prevState.resolver; // If the environment has changed or props point to new records then
217
+ var resolver = prevState.resolver;
218
+
219
+ // If the environment has changed or props point to new records then
250
220
  // previously fetched data and any pending fetches no longer apply:
251
221
  // - Existing references are on the old environment.
252
222
  // - Existing references are based on old variables.
253
223
  // - Pending fetches are for the previous records.
254
-
255
224
  if (prevState.prevPropsContext.environment !== relayContext.environment || !areEqual(prevRootVariables, nextRootVariables) || !areEqual(prevIDs, nextIDs)) {
256
225
  // Do not provide a subscription/callback here.
257
226
  // It is possible for this render to be interrupted or aborted,
@@ -270,39 +239,31 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
270
239
  } else if (!prevState.localVariables) {
271
240
  resolver.setProps(nextProps);
272
241
  }
273
-
274
242
  var data = resolver.resolve();
275
-
276
243
  if (data !== prevState.data) {
277
244
  return {
278
245
  data: data,
279
246
  prevProps: nextProps
280
247
  };
281
248
  }
282
-
283
249
  return null;
284
250
  };
285
-
286
251
  _proto.componentWillUnmount = function componentWillUnmount() {
287
252
  this._isUnmounted = true;
288
253
  this.state.resolver.dispose();
289
254
  this._queryFetcher && this._queryFetcher.dispose();
290
255
  this._refetchSubscription && this._refetchSubscription.unsubscribe();
291
256
  };
292
-
293
257
  _proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps, nextState) {
294
258
  // Short-circuit if any Relay-related data has changed
295
259
  if (nextState.data !== this.state.data || nextState.relayProp !== this.state.relayProp) {
296
260
  return true;
297
- } // Otherwise, for convenience short-circuit if all non-Relay props
261
+ }
262
+ // Otherwise, for convenience short-circuit if all non-Relay props
298
263
  // are scalar and equal
299
-
300
-
301
264
  var keys = Object.keys(nextProps);
302
-
303
265
  for (var ii = 0; ii < keys.length; ii++) {
304
266
  var key = keys[ii];
305
-
306
267
  if (key === '__relayContext') {
307
268
  if (this.state.prevPropsContext.environment !== nextState.prevPropsContext.environment) {
308
269
  return true;
@@ -313,67 +274,63 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
313
274
  }
314
275
  }
315
276
  }
316
-
317
277
  return false;
318
278
  };
319
-
320
279
  _proto._rerenderIfStoreHasChanged = function _rerenderIfStoreHasChanged() {
321
280
  var _this$state = this.state,
322
- data = _this$state.data,
323
- resolver = _this$state.resolver; // External values could change between render and commit.
281
+ data = _this$state.data,
282
+ resolver = _this$state.resolver;
283
+ // External values could change between render and commit.
324
284
  // Check for this case, even though it requires an extra store read.
325
-
326
285
  var maybeNewData = resolver.resolve();
327
-
328
286
  if (data !== maybeNewData) {
329
287
  this.setState({
330
288
  data: maybeNewData
331
289
  });
332
290
  }
333
291
  };
334
-
335
292
  _proto._subscribeToNewResolverAndRerenderIfStoreHasChanged = function _subscribeToNewResolverAndRerenderIfStoreHasChanged() {
336
293
  var _this$state2 = this.state,
337
- data = _this$state2.data,
338
- resolver = _this$state2.resolver;
339
- var maybeNewData = resolver.resolve(); // Event listeners are only safe to add during the commit phase,
294
+ data = _this$state2.data,
295
+ resolver = _this$state2.resolver;
296
+ var maybeNewData = resolver.resolve();
297
+
298
+ // Event listeners are only safe to add during the commit phase,
340
299
  // So they won't leak if render is interrupted or errors.
300
+ resolver.setCallback(this.props, this._handleFragmentDataUpdate);
341
301
 
342
- resolver.setCallback(this.props, this._handleFragmentDataUpdate); // External values could change between render and commit.
302
+ // External values could change between render and commit.
343
303
  // Check for this case, even though it requires an extra store read.
344
-
345
304
  if (data !== maybeNewData) {
346
305
  this.setState({
347
306
  data: maybeNewData
348
307
  });
349
308
  }
350
309
  }
310
+
351
311
  /**
352
312
  * Render new data for the existing props/context.
353
- */
354
- ;
355
-
313
+ */;
356
314
  _proto._getFragmentVariables = function _getFragmentVariables() {
357
315
  return getVariablesFromObject(fragments, this.props);
358
316
  };
359
-
360
317
  _proto._getQueryFetcher = function _getQueryFetcher() {
361
318
  if (!this._queryFetcher) {
362
319
  this._queryFetcher = new ReactRelayQueryFetcher();
363
320
  }
364
-
365
321
  return this._queryFetcher;
366
322
  };
367
-
323
+ // $FlowFixMe[missing-local-annot]
368
324
  _proto.render = function render() {
325
+ // eslint-disable-next-line no-unused-vars
369
326
  var _this$props = this.props,
370
- componentRef = _this$props.componentRef,
371
- __relayContext = _this$props.__relayContext,
372
- __rootIsQueryRenderer = _this$props.__rootIsQueryRenderer,
373
- props = (0, _objectWithoutPropertiesLoose2["default"])(_this$props, _excluded);
327
+ componentRef = _this$props.componentRef,
328
+ __relayContext = _this$props.__relayContext,
329
+ __rootIsQueryRenderer = _this$props.__rootIsQueryRenderer,
330
+ props = (0, _objectWithoutPropertiesLoose2["default"])(_this$props, _excluded);
374
331
  var _this$state3 = this.state,
375
- relayProp = _this$state3.relayProp,
376
- contextForChildren = _this$state3.contextForChildren;
332
+ relayProp = _this$state3.relayProp,
333
+ contextForChildren = _this$state3.contextForChildren;
377
334
  return /*#__PURE__*/React.createElement(ReactRelayContext.Provider, {
378
335
  value: contextForChildren
379
336
  }, /*#__PURE__*/React.createElement(Component, (0, _extends2["default"])({}, props, this.state.data, {
@@ -381,17 +338,16 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
381
338
  relay: relayProp
382
339
  })));
383
340
  };
384
-
385
341
  return _class;
386
342
  }(React.Component), (0, _defineProperty2["default"])(_class, "displayName", containerName), _class;
387
343
  }
388
-
389
344
  function getRelayProp(environment, refetch) {
390
345
  return {
391
346
  environment: environment,
392
347
  refetch: refetch
393
348
  };
394
349
  }
350
+
395
351
  /**
396
352
  * Wrap the basic `createContainer()` function with logic to adapt to the
397
353
  * `context.relay.environment` in which it is rendered. Specifically, the
@@ -399,15 +355,12 @@ function getRelayProp(environment, refetch) {
399
355
  * `fragmentSpec` is memoized once per environment, rather than once per
400
356
  * instance of the container constructed/rendered.
401
357
  */
402
-
403
-
404
358
  function createContainer(Component, fragmentSpec, taggedNode) {
405
359
  // $FlowFixMe[incompatible-return]
406
360
  return buildReactRelayContainer(Component, fragmentSpec, function (ComponentClass, fragments) {
407
361
  return createContainerWithFragments(ComponentClass, fragments, taggedNode);
408
362
  });
409
363
  }
410
-
411
364
  module.exports = {
412
365
  createContainer: createContainer
413
366
  };
@@ -6,61 +6,52 @@
6
6
  *
7
7
  *
8
8
  * @format
9
+ * @oncall relay
9
10
  */
11
+
10
12
  'use strict';
11
13
 
12
14
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
13
-
14
15
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
15
-
16
16
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
17
-
18
17
  var areEqual = require("fbjs/lib/areEqual");
19
-
20
18
  var invariant = require('invariant');
21
-
22
19
  var _require = require('relay-runtime'),
23
- Network = _require.Network,
24
- createOperationDescriptor = _require.createOperationDescriptor,
25
- isRelayModernEnvironment = _require.isRelayModernEnvironment;
26
-
20
+ Network = _require.Network,
21
+ createOperationDescriptor = _require.createOperationDescriptor,
22
+ isRelayModernEnvironment = _require.isRelayModernEnvironment;
27
23
  var warning = require("fbjs/lib/warning");
28
-
29
24
  /**
30
25
  * The next id to return from `generateId()`.
31
26
  */
32
27
  var nextId = 0;
33
-
34
28
  var ReactRelayTestMocker = /*#__PURE__*/function () {
35
29
  function ReactRelayTestMocker(env) {
36
30
  (0, _defineProperty2["default"])(this, "_defaults", {});
37
31
  (0, _defineProperty2["default"])(this, "_pendingFetches", []);
38
-
39
32
  if (isRelayModernEnvironment(env)) {
40
33
  this._mockNetworkLayer(env);
41
34
  } else {
42
35
  process.env.NODE_ENV !== "production" ? warning(false, 'Network mocking is currently only supported in Relay Modern. ' + 'You will not be able to resolve requests made with Relay ' + 'Classic environments.') : void 0;
43
36
  }
44
-
45
37
  this._environment = env;
46
38
  }
47
-
48
39
  ReactRelayTestMocker.mockOutEnvironment = function mockOutEnvironment(env) {
49
40
  return new ReactRelayTestMocker(env);
50
41
  }
42
+
51
43
  /**
52
44
  * Get a unique id number (as a string). Note: will wrap around after 2^32
53
45
  * calls, if your test needs that many IDs.
54
46
  *
55
47
  * @returns a unique id string
56
- */
57
- ;
58
-
48
+ */;
59
49
  ReactRelayTestMocker.generateId = function generateId() {
60
50
  var toRet = nextId.toString();
61
51
  nextId++;
62
52
  return toRet;
63
53
  }
54
+
64
55
  /**
65
56
  * Create a unique identifier for a (query, variables) pair.
66
57
  * @param request: the request associated with the query
@@ -69,18 +60,15 @@ var ReactRelayTestMocker = /*#__PURE__*/function () {
69
60
  *
70
61
  * @returns a string which can later be used to uniquely identify this query
71
62
  * in the list of pending queries
72
- */
73
- ;
74
-
63
+ */;
75
64
  ReactRelayTestMocker.getIdentifier = function getIdentifier(request) {
76
65
  return request.name;
77
66
  }
67
+
78
68
  /**
79
69
  * Remove variables that we don't need from the query that will make it more
80
70
  * annoying to test (e.g. client_mutation_id, actor_id)
81
- */
82
- ;
83
-
71
+ */;
84
72
  ReactRelayTestMocker.stripUnused = function stripUnused(variables) {
85
73
  if (variables.input) {
86
74
  var toRemove = ['client_mutation_id', 'actor_id', 'clientMutationId', 'actorId'];
@@ -92,23 +80,19 @@ var ReactRelayTestMocker = /*#__PURE__*/function () {
92
80
  });
93
81
  return strippedVariables;
94
82
  }
95
-
96
83
  return variables;
97
84
  }
85
+
98
86
  /**
99
87
  * Replace the environment's network layer with a mocked out one to allow for
100
88
  * better testing. Mocking the network allows testing without using a mocked
101
89
  * out QueryRenderer, and will allow for easier testing of components wrapped
102
90
  * in refetch containers, for example. It also allows test writers to see how
103
91
  * their components behave under error conditions.
104
- */
105
- ;
106
-
92
+ */;
107
93
  var _proto = ReactRelayTestMocker.prototype;
108
-
109
94
  _proto._mockNetworkLayer = function _mockNetworkLayer(env) {
110
95
  var _this = this;
111
-
112
96
  var fetch = function fetch(request, variables, cacheConfig) {
113
97
  var resolve;
114
98
  var reject;
@@ -117,13 +101,13 @@ var ReactRelayTestMocker = /*#__PURE__*/function () {
117
101
  reject = rej;
118
102
  });
119
103
  var strippedVars = ReactRelayTestMocker.stripUnused(variables);
120
- var ident = ReactRelayTestMocker.getIdentifier(request); // there's a default value for this query, use it
104
+ var ident = ReactRelayTestMocker.getIdentifier(request);
121
105
 
106
+ // there's a default value for this query, use it
122
107
  if (_this._defaults[ident]) {
123
108
  var payload = _this._defaults[ident];
124
109
  return typeof payload === 'function' ? payload(strippedVars) : payload;
125
110
  }
126
-
127
111
  _this._pendingFetches.push({
128
112
  ident: ident,
129
113
  cacheConfig: cacheConfig,
@@ -134,16 +118,13 @@ var ReactRelayTestMocker = /*#__PURE__*/function () {
134
118
  request: request,
135
119
  variables: strippedVars
136
120
  });
137
-
138
121
  return promise;
139
122
  };
140
-
141
123
  var isLoading = function isLoading(ident) {
142
124
  return _this._pendingFetches.some(function (pending) {
143
125
  return pending.ident === ident;
144
126
  });
145
127
  };
146
-
147
128
  var resolveRawQuery = function resolveRawQuery(toResolve, payload) {
148
129
  _this._pendingFetches = _this._pendingFetches.filter(function (pending) {
149
130
  return pending !== toResolve;
@@ -151,7 +132,6 @@ var ReactRelayTestMocker = /*#__PURE__*/function () {
151
132
  var deferred = toResolve.deferred;
152
133
  deferred.resolve(payload);
153
134
  };
154
-
155
135
  var rejectQuery = function rejectQuery(toResolve, payload) {
156
136
  _this._pendingFetches = _this._pendingFetches.filter(function (pending) {
157
137
  return pending !== toResolve;
@@ -159,7 +139,6 @@ var ReactRelayTestMocker = /*#__PURE__*/function () {
159
139
  var deferred = toResolve.deferred;
160
140
  deferred.reject(payload.error);
161
141
  };
162
-
163
142
  env.mock = {
164
143
  isLoading: isLoading,
165
144
  rejectQuery: rejectQuery,
@@ -167,32 +146,29 @@ var ReactRelayTestMocker = /*#__PURE__*/function () {
167
146
  fetch: fetch
168
147
  };
169
148
  env.hasMockedNetwork = true;
170
-
171
149
  env.__setNet(Network.create(fetch));
172
-
173
150
  return env;
174
151
  }
152
+
175
153
  /**
176
154
  * set a default payload for a given query
177
- */
178
- ;
179
-
155
+ */;
180
156
  _proto.setDefault = function setDefault(toSet) {
181
157
  var query = toSet.query,
182
- payload = toSet.payload;
158
+ payload = toSet.payload;
183
159
  var ident = ReactRelayTestMocker.getIdentifier(query.params);
184
160
  this._defaults[ident] = payload;
185
161
  }
162
+
186
163
  /**
187
164
  * remove a default payload for a given query
188
- */
189
- ;
190
-
165
+ */;
191
166
  _proto.unsetDefault = function unsetDefault(toUnset) {
192
167
  var query = toUnset.query;
193
168
  var ident = ReactRelayTestMocker.getIdentifier(query.params);
194
169
  delete this._defaults[ident];
195
170
  }
171
+
196
172
  /**
197
173
  * Write directly to the Relay store instead of trying to resolve a query that
198
174
  * was sent via the network.
@@ -200,18 +176,16 @@ var ReactRelayTestMocker = /*#__PURE__*/function () {
200
176
  * Use this method when testing a component wrapped in a fragment container
201
177
  * (via `createFragmentContainer`). The component under test should also be
202
178
  * wrapped in a `RelayTestRenderer`.
203
- */
204
- ;
205
-
179
+ */;
206
180
  _proto.dataWrite = function dataWrite(config) {
207
181
  var query = config.query,
208
- variables = config.variables,
209
- payload = config.payload;
182
+ variables = config.variables,
183
+ payload = config.payload;
210
184
  var operationDescriptor = createOperationDescriptor(query, variables);
211
185
  !(payload.data != null && payload.errors === undefined) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Only `data` can be written when using `writeDirect`. You may need to ' + 'wrap your payload in an object like `{data: payload}`.') : invariant(false) : void 0;
212
-
213
186
  this._environment.commitPayload(operationDescriptor, payload.data);
214
187
  }
188
+
215
189
  /**
216
190
  * Write the data specified in config's payload to the instance's environment.
217
191
  * NOTE: callers may need to invoke `jest.runOnlyPendingTimers()` after
@@ -219,30 +193,23 @@ var ReactRelayTestMocker = /*#__PURE__*/function () {
219
193
  *
220
194
  * @param config: an object containing the data to write and the query and
221
195
  * variables that the payload is simulating a response to
222
- */
223
- ;
224
-
196
+ */;
225
197
  _proto.networkWrite = function networkWrite(config) {
226
198
  !this._environment.hasMockedNetwork ? process.env.NODE_ENV !== "production" ? invariant(false, 'You cannot resolve queries without a mocked environment. Did you mean ' + 'to use `writeDirect` instead?') : invariant(false) : void 0;
227
199
  var query = config.query,
228
- variables = config.variables,
229
- payload = config.payload;
200
+ variables = config.variables,
201
+ payload = config.payload;
230
202
  var ident = ReactRelayTestMocker.getIdentifier(query.params);
231
203
  var usedVars;
232
-
233
204
  if (variables) {
234
205
  var operationDescriptor = createOperationDescriptor(query, variables);
235
206
  usedVars = ReactRelayTestMocker.stripUnused(operationDescriptor.request.variables);
236
207
  }
237
-
238
208
  var toResolve;
239
-
240
209
  this._pendingFetches.forEach(function (pending) {
241
210
  var pendingVars = pending.variables;
242
-
243
211
  if (pending.ident === ident) {
244
212
  !(!toResolve || variables) ? process.env.NODE_ENV !== "production" ? invariant(false, 'Multiple queries with the same name are currently pending. You ' + 'should pass variables to `write` so that it can determine which ' + 'to resolve') : invariant(false) : void 0;
245
-
246
213
  if (variables) {
247
214
  if (areEqual(pendingVars, usedVars)) {
248
215
  toResolve = pending;
@@ -252,12 +219,13 @@ var ReactRelayTestMocker = /*#__PURE__*/function () {
252
219
  }
253
220
  }
254
221
  });
255
-
256
222
  var varMessage = usedVars ? ' - variables: ' + JSON.stringify(usedVars) : '';
257
223
  !toResolve ? process.env.NODE_ENV !== "production" ? invariant(false, 'You are attempting to resolve a query that has not been fetched ' + '(%s%s).\n\tPlease ensure you passed the correct variables, or use ' + '`writeDirect` instead.', ident, varMessage) : invariant(false) : void 0;
258
- var realPayload = // $FlowFixMe[incompatible-call]
259
- typeof payload === 'function' ? payload(toResolve.variables) : payload; // if there are errors, reject the query
224
+ var realPayload =
225
+ // $FlowFixMe[incompatible-call]
226
+ typeof payload === 'function' ? payload(toResolve.variables) : payload;
260
227
 
228
+ // if there are errors, reject the query
261
229
  if (realPayload.errors != null && realPayload.errors.length > 0) {
262
230
  this._environment.mock.rejectQuery(toResolve, {
263
231
  error: realPayload.errors[0]
@@ -266,8 +234,6 @@ var ReactRelayTestMocker = /*#__PURE__*/function () {
266
234
  this._environment.mock.resolveRawQuery(toResolve, realPayload);
267
235
  }
268
236
  };
269
-
270
237
  return ReactRelayTestMocker;
271
238
  }();
272
-
273
239
  module.exports = ReactRelayTestMocker;