react-relay 14.1.0 → 16.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (196) 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 +20 -10
  9. package/ReactRelayQueryRenderer.js.flow +15 -11
  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 +2 -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 +10 -6
  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 +0 -11
  47. package/lib/ReactRelayContext.js +1 -12
  48. package/lib/ReactRelayFragmentContainer.js +23 -122
  49. package/lib/ReactRelayFragmentMockRenderer.js +0 -12
  50. package/lib/ReactRelayLocalQueryRenderer.js +12 -41
  51. package/lib/ReactRelayPaginationContainer.js +45 -341
  52. package/lib/ReactRelayQueryFetcher.js +36 -111
  53. package/lib/ReactRelayQueryRenderer.js +29 -137
  54. package/lib/ReactRelayQueryRendererContext.js +0 -10
  55. package/lib/ReactRelayRefetchContainer.js +33 -166
  56. package/lib/ReactRelayTestMocker.js +18 -128
  57. package/lib/ReactRelayTypes.js +0 -9
  58. package/lib/RelayContext.js +0 -23
  59. package/lib/assertFragmentMap.js +0 -16
  60. package/lib/buildReactRelayContainer.js +7 -41
  61. package/lib/getRootVariablesForFragments.js +2 -19
  62. package/lib/hooks.js +3 -30
  63. package/lib/index.js +3 -39
  64. package/lib/isRelayEnvironment.js +1 -16
  65. package/lib/jest-react/enqueueTask.js +1 -25
  66. package/lib/jest-react/index.js +0 -1
  67. package/lib/jest-react/internalAct.js +2 -51
  68. package/lib/legacy.js +0 -20
  69. package/lib/multi-actor/ActorChange.js +0 -14
  70. package/lib/multi-actor/index.js +0 -10
  71. package/lib/multi-actor/useRelayActorEnvironment.js +2 -16
  72. package/lib/relay-hooks/EntryPointContainer.react.js +7 -23
  73. package/lib/relay-hooks/EntryPointTypes.flow.js +0 -10
  74. package/lib/relay-hooks/FragmentResource.js +130 -280
  75. package/lib/relay-hooks/HooksImplementation.js +0 -14
  76. package/lib/relay-hooks/InternalLogger.js +0 -11
  77. package/lib/relay-hooks/LRUCache.js +0 -39
  78. package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +27 -65
  79. package/lib/relay-hooks/MatchContainer.js +9 -111
  80. package/lib/relay-hooks/NestedRelayEntryPointBuilderUtils.js +9 -0
  81. package/lib/relay-hooks/ProfilerContext.js +0 -14
  82. package/lib/relay-hooks/QueryResource.js +14 -149
  83. package/lib/relay-hooks/RelayEnvironmentProvider.js +3 -17
  84. package/lib/relay-hooks/SuspenseResource.js +2 -59
  85. package/lib/relay-hooks/loadEntryPoint.js +10 -45
  86. package/lib/relay-hooks/loadQuery.js +29 -169
  87. package/lib/relay-hooks/preloadQuery_DEPRECATED.js +8 -58
  88. package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +6 -24
  89. package/lib/relay-hooks/react-cache/RelayReactCache.js +4 -20
  90. package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +13 -102
  91. package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +18 -75
  92. package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +79 -222
  93. package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +3 -27
  94. package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +11 -33
  95. package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +62 -85
  96. package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +20 -63
  97. package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +53 -179
  98. package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +5 -27
  99. package/lib/relay-hooks/useBlockingPaginationFragment.js +58 -121
  100. package/lib/relay-hooks/useClientQuery.js +0 -21
  101. package/lib/relay-hooks/useEntryPointLoader.js +12 -100
  102. package/lib/relay-hooks/useFetchTrackingRef.js +6 -33
  103. package/lib/relay-hooks/useFragment.js +5 -32
  104. package/lib/relay-hooks/useFragmentNode.js +14 -55
  105. package/lib/relay-hooks/useIsMountedRef.js +2 -14
  106. package/lib/relay-hooks/useIsOperationNodeActive.js +6 -29
  107. package/lib/relay-hooks/useIsParentQueryActive.js +1 -15
  108. package/lib/relay-hooks/useLazyLoadQuery.js +2 -23
  109. package/lib/relay-hooks/useLazyLoadQueryNode.js +18 -63
  110. package/lib/relay-hooks/useLoadMoreFunction.js +44 -100
  111. package/lib/relay-hooks/useMemoOperationDescriptor.js +4 -23
  112. package/lib/relay-hooks/useMemoVariables.js +8 -43
  113. package/lib/relay-hooks/useMutation.js +6 -34
  114. package/lib/relay-hooks/usePaginationFragment.js +49 -89
  115. package/lib/relay-hooks/usePreloadedQuery.js +10 -54
  116. package/lib/relay-hooks/useQueryLoader.js +18 -116
  117. package/lib/relay-hooks/useRefetchableFragment.js +4 -30
  118. package/lib/relay-hooks/useRefetchableFragmentNode.js +58 -184
  119. package/lib/relay-hooks/useRelayEnvironment.js +2 -16
  120. package/lib/relay-hooks/useStaticFragmentNodeWarning.js +2 -20
  121. package/lib/relay-hooks/useSubscribeToInvalidationState.js +3 -28
  122. package/lib/relay-hooks/useSubscription.js +3 -22
  123. package/lib/relay-hooks/useUnsafeRef_DEPRECATED.js +12 -0
  124. package/multi-actor/ActorChange.js.flow +1 -1
  125. package/multi-actor/index.js.flow +1 -1
  126. package/multi-actor/useRelayActorEnvironment.js.flow +2 -2
  127. package/package.json +2 -2
  128. package/react-relay-hooks.js +2 -2
  129. package/react-relay-hooks.min.js +2 -2
  130. package/react-relay-legacy.js +2 -2
  131. package/react-relay-legacy.min.js +2 -2
  132. package/react-relay.js +2 -2
  133. package/react-relay.min.js +2 -2
  134. package/relay-hooks/EntryPointContainer.react.js.flow +6 -1
  135. package/relay-hooks/EntryPointTypes.flow.js.flow +23 -20
  136. package/relay-hooks/FragmentResource.js.flow +148 -34
  137. package/relay-hooks/HooksImplementation.js.flow +1 -1
  138. package/relay-hooks/InternalLogger.js.flow +1 -1
  139. package/relay-hooks/LRUCache.js.flow +1 -1
  140. package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +19 -10
  141. package/relay-hooks/MatchContainer.js.flow +1 -1
  142. package/relay-hooks/NestedRelayEntryPointBuilderUtils.js.flow +51 -0
  143. package/relay-hooks/ProfilerContext.js.flow +1 -1
  144. package/relay-hooks/QueryResource.js.flow +25 -5
  145. package/relay-hooks/RelayEnvironmentProvider.js.flow +2 -2
  146. package/relay-hooks/SuspenseResource.js.flow +1 -1
  147. package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +3 -1
  148. package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +9 -7
  149. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +3 -1
  150. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +3 -1
  151. package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +40 -33
  152. package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +1 -1
  153. package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +38 -32
  154. package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +20 -18
  155. package/relay-hooks/__flowtests__/utils.js.flow +13 -2
  156. package/relay-hooks/loadEntryPoint.js.flow +15 -8
  157. package/relay-hooks/loadQuery.js.flow +32 -8
  158. package/relay-hooks/preloadQuery_DEPRECATED.js.flow +5 -6
  159. package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +17 -10
  160. package/relay-hooks/react-cache/RelayReactCache.js.flow +1 -1
  161. package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +4 -4
  162. package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +5 -4
  163. package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +32 -14
  164. package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +4 -10
  165. package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +1 -1
  166. package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +39 -49
  167. package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +1 -2
  168. package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +29 -16
  169. package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +17 -33
  170. package/relay-hooks/useBlockingPaginationFragment.js.flow +85 -58
  171. package/relay-hooks/useClientQuery.js.flow +3 -3
  172. package/relay-hooks/useEntryPointLoader.js.flow +10 -6
  173. package/relay-hooks/useFetchTrackingRef.js.flow +5 -4
  174. package/relay-hooks/useFragment.js.flow +2 -2
  175. package/relay-hooks/useFragmentNode.js.flow +7 -6
  176. package/relay-hooks/useIsMountedRef.js.flow +1 -1
  177. package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
  178. package/relay-hooks/useIsParentQueryActive.js.flow +1 -1
  179. package/relay-hooks/useLazyLoadQuery.js.flow +2 -2
  180. package/relay-hooks/useLazyLoadQueryNode.js.flow +2 -2
  181. package/relay-hooks/useLoadMoreFunction.js.flow +27 -16
  182. package/relay-hooks/useMemoOperationDescriptor.js.flow +3 -3
  183. package/relay-hooks/useMemoVariables.js.flow +13 -29
  184. package/relay-hooks/useMutation.js.flow +30 -13
  185. package/relay-hooks/usePaginationFragment.js.flow +55 -54
  186. package/relay-hooks/usePreloadedQuery.js.flow +47 -22
  187. package/relay-hooks/useQueryLoader.js.flow +78 -21
  188. package/relay-hooks/useRefetchableFragment.js.flow +65 -33
  189. package/relay-hooks/useRefetchableFragmentNode.js.flow +38 -17
  190. package/relay-hooks/useRelayEnvironment.js.flow +2 -2
  191. package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -3
  192. package/relay-hooks/useSubscribeToInvalidationState.js.flow +2 -2
  193. package/relay-hooks/useSubscription.js.flow +1 -1
  194. package/relay-hooks/useUnsafeRef_DEPRECATED.js.flow +25 -0
  195. package/lib/readContext.js +0 -27
  196. package/readContext.js.flow +0 -29
@@ -1,86 +1,38 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- *
8
- * @format
9
- */
10
1
  'use strict';
11
2
 
12
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
13
-
14
4
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
15
-
16
5
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
17
-
18
6
  var areEqual = require("fbjs/lib/areEqual");
19
-
20
7
  var invariant = require('invariant');
21
-
22
8
  var _require = require('relay-runtime'),
23
- Network = _require.Network,
24
- createOperationDescriptor = _require.createOperationDescriptor,
25
- isRelayModernEnvironment = _require.isRelayModernEnvironment;
26
-
9
+ Network = _require.Network,
10
+ createOperationDescriptor = _require.createOperationDescriptor,
11
+ isRelayModernEnvironment = _require.isRelayModernEnvironment;
27
12
  var warning = require("fbjs/lib/warning");
28
-
29
- /**
30
- * The next id to return from `generateId()`.
31
- */
32
13
  var nextId = 0;
33
-
34
14
  var ReactRelayTestMocker = /*#__PURE__*/function () {
35
15
  function ReactRelayTestMocker(env) {
36
16
  (0, _defineProperty2["default"])(this, "_defaults", {});
37
17
  (0, _defineProperty2["default"])(this, "_pendingFetches", []);
38
-
39
18
  if (isRelayModernEnvironment(env)) {
40
19
  this._mockNetworkLayer(env);
41
20
  } else {
42
21
  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
22
  }
44
-
45
23
  this._environment = env;
46
24
  }
47
-
48
25
  ReactRelayTestMocker.mockOutEnvironment = function mockOutEnvironment(env) {
49
26
  return new ReactRelayTestMocker(env);
50
- }
51
- /**
52
- * Get a unique id number (as a string). Note: will wrap around after 2^32
53
- * calls, if your test needs that many IDs.
54
- *
55
- * @returns a unique id string
56
- */
57
- ;
58
-
27
+ };
59
28
  ReactRelayTestMocker.generateId = function generateId() {
60
29
  var toRet = nextId.toString();
61
30
  nextId++;
62
31
  return toRet;
63
- }
64
- /**
65
- * Create a unique identifier for a (query, variables) pair.
66
- * @param request: the request associated with the query
67
- * @param variables: the variables associated with this invocation of the
68
- * query
69
- *
70
- * @returns a string which can later be used to uniquely identify this query
71
- * in the list of pending queries
72
- */
73
- ;
74
-
32
+ };
75
33
  ReactRelayTestMocker.getIdentifier = function getIdentifier(request) {
76
34
  return request.name;
77
- }
78
- /**
79
- * Remove variables that we don't need from the query that will make it more
80
- * annoying to test (e.g. client_mutation_id, actor_id)
81
- */
82
- ;
83
-
35
+ };
84
36
  ReactRelayTestMocker.stripUnused = function stripUnused(variables) {
85
37
  if (variables.input) {
86
38
  var toRemove = ['client_mutation_id', 'actor_id', 'clientMutationId', 'actorId'];
@@ -92,23 +44,11 @@ var ReactRelayTestMocker = /*#__PURE__*/function () {
92
44
  });
93
45
  return strippedVariables;
94
46
  }
95
-
96
47
  return variables;
97
- }
98
- /**
99
- * Replace the environment's network layer with a mocked out one to allow for
100
- * better testing. Mocking the network allows testing without using a mocked
101
- * out QueryRenderer, and will allow for easier testing of components wrapped
102
- * in refetch containers, for example. It also allows test writers to see how
103
- * their components behave under error conditions.
104
- */
105
- ;
106
-
48
+ };
107
49
  var _proto = ReactRelayTestMocker.prototype;
108
-
109
50
  _proto._mockNetworkLayer = function _mockNetworkLayer(env) {
110
51
  var _this = this;
111
-
112
52
  var fetch = function fetch(request, variables, cacheConfig) {
113
53
  var resolve;
114
54
  var reject;
@@ -117,13 +57,11 @@ var ReactRelayTestMocker = /*#__PURE__*/function () {
117
57
  reject = rej;
118
58
  });
119
59
  var strippedVars = ReactRelayTestMocker.stripUnused(variables);
120
- var ident = ReactRelayTestMocker.getIdentifier(request); // there's a default value for this query, use it
121
-
60
+ var ident = ReactRelayTestMocker.getIdentifier(request);
122
61
  if (_this._defaults[ident]) {
123
62
  var payload = _this._defaults[ident];
124
63
  return typeof payload === 'function' ? payload(strippedVars) : payload;
125
64
  }
126
-
127
65
  _this._pendingFetches.push({
128
66
  ident: ident,
129
67
  cacheConfig: cacheConfig,
@@ -134,16 +72,13 @@ var ReactRelayTestMocker = /*#__PURE__*/function () {
134
72
  request: request,
135
73
  variables: strippedVars
136
74
  });
137
-
138
75
  return promise;
139
76
  };
140
-
141
77
  var isLoading = function isLoading(ident) {
142
78
  return _this._pendingFetches.some(function (pending) {
143
79
  return pending.ident === ident;
144
80
  });
145
81
  };
146
-
147
82
  var resolveRawQuery = function resolveRawQuery(toResolve, payload) {
148
83
  _this._pendingFetches = _this._pendingFetches.filter(function (pending) {
149
84
  return pending !== toResolve;
@@ -151,7 +86,6 @@ var ReactRelayTestMocker = /*#__PURE__*/function () {
151
86
  var deferred = toResolve.deferred;
152
87
  deferred.resolve(payload);
153
88
  };
154
-
155
89
  var rejectQuery = function rejectQuery(toResolve, payload) {
156
90
  _this._pendingFetches = _this._pendingFetches.filter(function (pending) {
157
91
  return pending !== toResolve;
@@ -159,7 +93,6 @@ var ReactRelayTestMocker = /*#__PURE__*/function () {
159
93
  var deferred = toResolve.deferred;
160
94
  deferred.reject(payload.error);
161
95
  };
162
-
163
96
  env.mock = {
164
97
  isLoading: isLoading,
165
98
  rejectQuery: rejectQuery,
@@ -167,82 +100,44 @@ var ReactRelayTestMocker = /*#__PURE__*/function () {
167
100
  fetch: fetch
168
101
  };
169
102
  env.hasMockedNetwork = true;
170
-
171
103
  env.__setNet(Network.create(fetch));
172
-
173
104
  return env;
174
- }
175
- /**
176
- * set a default payload for a given query
177
- */
178
- ;
179
-
105
+ };
180
106
  _proto.setDefault = function setDefault(toSet) {
181
107
  var query = toSet.query,
182
- payload = toSet.payload;
108
+ payload = toSet.payload;
183
109
  var ident = ReactRelayTestMocker.getIdentifier(query.params);
184
110
  this._defaults[ident] = payload;
185
- }
186
- /**
187
- * remove a default payload for a given query
188
- */
189
- ;
190
-
111
+ };
191
112
  _proto.unsetDefault = function unsetDefault(toUnset) {
192
113
  var query = toUnset.query;
193
114
  var ident = ReactRelayTestMocker.getIdentifier(query.params);
194
115
  delete this._defaults[ident];
195
- }
196
- /**
197
- * Write directly to the Relay store instead of trying to resolve a query that
198
- * was sent via the network.
199
- *
200
- * Use this method when testing a component wrapped in a fragment container
201
- * (via `createFragmentContainer`). The component under test should also be
202
- * wrapped in a `RelayTestRenderer`.
203
- */
204
- ;
205
-
116
+ };
206
117
  _proto.dataWrite = function dataWrite(config) {
207
118
  var query = config.query,
208
- variables = config.variables,
209
- payload = config.payload;
119
+ variables = config.variables,
120
+ payload = config.payload;
210
121
  var operationDescriptor = createOperationDescriptor(query, variables);
211
122
  !(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
123
  this._environment.commitPayload(operationDescriptor, payload.data);
214
- }
215
- /**
216
- * Write the data specified in config's payload to the instance's environment.
217
- * NOTE: callers may need to invoke `jest.runOnlyPendingTimers()` after
218
- * calling this function.
219
- *
220
- * @param config: an object containing the data to write and the query and
221
- * variables that the payload is simulating a response to
222
- */
223
- ;
224
-
124
+ };
225
125
  _proto.networkWrite = function networkWrite(config) {
226
126
  !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
127
  var query = config.query,
228
- variables = config.variables,
229
- payload = config.payload;
128
+ variables = config.variables,
129
+ payload = config.payload;
230
130
  var ident = ReactRelayTestMocker.getIdentifier(query.params);
231
131
  var usedVars;
232
-
233
132
  if (variables) {
234
133
  var operationDescriptor = createOperationDescriptor(query, variables);
235
134
  usedVars = ReactRelayTestMocker.stripUnused(operationDescriptor.request.variables);
236
135
  }
237
-
238
136
  var toResolve;
239
-
240
137
  this._pendingFetches.forEach(function (pending) {
241
138
  var pendingVars = pending.variables;
242
-
243
139
  if (pending.ident === ident) {
244
140
  !(!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
141
  if (variables) {
247
142
  if (areEqual(pendingVars, usedVars)) {
248
143
  toResolve = pending;
@@ -252,12 +147,9 @@ var ReactRelayTestMocker = /*#__PURE__*/function () {
252
147
  }
253
148
  }
254
149
  });
255
-
256
150
  var varMessage = usedVars ? ' - variables: ' + JSON.stringify(usedVars) : '';
257
151
  !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
260
-
152
+ var realPayload = typeof payload === 'function' ? payload(toResolve.variables) : payload;
261
153
  if (realPayload.errors != null && realPayload.errors.length > 0) {
262
154
  this._environment.mock.rejectQuery(toResolve, {
263
155
  error: realPayload.errors[0]
@@ -266,8 +158,6 @@ var ReactRelayTestMocker = /*#__PURE__*/function () {
266
158
  this._environment.mock.resolveRawQuery(toResolve, realPayload);
267
159
  }
268
160
  };
269
-
270
161
  return ReactRelayTestMocker;
271
162
  }();
272
-
273
163
  module.exports = ReactRelayTestMocker;
@@ -1,10 +1 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- *
8
- * @format
9
- */
10
1
  'use strict';
@@ -1,37 +1,14 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- *
8
- * @format
9
- */
10
1
  'use strict';
11
2
 
12
3
  var isRelayEnvironment = require('./isRelayEnvironment');
13
-
14
4
  var invariant = require('invariant');
15
- /**
16
- * Asserts that the input is a matches the `RelayContext` type defined in
17
- * `RelayEnvironmentTypes` and returns it as that type.
18
- */
19
-
20
-
21
5
  function assertRelayContext(relay) {
22
6
  !isRelayContext(relay) ? process.env.NODE_ENV !== "production" ? invariant(false, 'RelayContext: Expected `context.relay` to be an object conforming to ' + 'the `RelayContext` interface, got `%s`.', relay) : invariant(false) : void 0;
23
7
  return relay;
24
8
  }
25
- /**
26
- * Determine if the input is a plain object that matches the `RelayContext`
27
- * type defined in `RelayEnvironmentTypes`.
28
- */
29
-
30
-
31
9
  function isRelayContext(context) {
32
10
  return typeof context === 'object' && context !== null && !Array.isArray(context) && isRelayEnvironment(context.environment);
33
11
  }
34
-
35
12
  module.exports = {
36
13
  assertRelayContext: assertRelayContext,
37
14
  isRelayContext: isRelayContext
@@ -1,23 +1,8 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- *
8
- * @format
9
- */
10
1
  'use strict';
11
2
 
12
3
  var invariant = require('invariant');
13
- /**
14
- * Fail fast if the user supplies invalid fragments as input.
15
- */
16
-
17
-
18
4
  function assertFragmentMap(componentName, fragmentSpec) {
19
5
  !(fragmentSpec && typeof fragmentSpec === 'object') ? process.env.NODE_ENV !== "production" ? invariant(false, 'Could not create Relay Container for `%s`. ' + 'Expected a set of GraphQL fragments, got `%s` instead.', componentName, fragmentSpec) : invariant(false) : void 0;
20
-
21
6
  for (var key in fragmentSpec) {
22
7
  if (fragmentSpec.hasOwnProperty(key)) {
23
8
  var fragment = fragmentSpec[key];
@@ -25,5 +10,4 @@ function assertFragmentMap(componentName, fragmentSpec) {
25
10
  }
26
11
  }
27
12
  }
28
-
29
13
  module.exports = assertFragmentMap;
@@ -1,78 +1,44 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- *
8
- * @format
9
- */
10
1
  'use strict';
11
2
 
12
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
13
-
14
4
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
15
-
16
5
  var assertFragmentMap = require('./assertFragmentMap');
17
-
18
6
  var _require = require('./ReactRelayContainerUtils'),
19
- getComponentName = _require.getComponentName,
20
- getContainerName = _require.getContainerName;
21
-
7
+ getComponentName = _require.getComponentName,
8
+ getContainerName = _require.getContainerName;
22
9
  var ReactRelayContext = require('./ReactRelayContext');
23
-
24
10
  var ReactRelayQueryRendererContext = require('./ReactRelayQueryRendererContext');
25
-
26
- var readContext = require('./readContext');
27
-
28
11
  var invariant = require('invariant');
29
-
30
12
  var React = require('react');
31
-
32
13
  var _require2 = require('relay-runtime'),
33
- getFragment = _require2.getFragment;
34
-
35
- /**
36
- * Helper to create the Relay HOCs with ref forwarding, setting the displayName
37
- * and reading the React context.
38
- */
14
+ getFragment = _require2.getFragment;
15
+ var useContext = React.useContext;
39
16
  function buildReactRelayContainer(ComponentClass, fragmentSpec, createContainerWithFragments) {
40
- // Sanity-check user-defined fragment input
41
17
  var containerName = getContainerName(ComponentClass);
42
18
  assertFragmentMap(getComponentName(ComponentClass), fragmentSpec);
43
19
  var fragments = {};
44
-
45
20
  for (var key in fragmentSpec) {
46
21
  fragments[key] = getFragment(fragmentSpec[key]);
47
22
  }
48
-
49
23
  var Container = createContainerWithFragments(ComponentClass, fragments);
50
24
  Container.displayName = containerName;
51
-
52
25
  function forwardRef(props, ref) {
53
26
  var _queryRendererContext;
54
-
55
- var context = readContext(ReactRelayContext);
27
+ var context = useContext(ReactRelayContext);
56
28
  !(context != null) ? process.env.NODE_ENV !== "production" ? invariant(false, '`%s` tried to render a context that was not valid this means that ' + '`%s` was rendered outside of a query renderer.', containerName, containerName) : invariant(false) : void 0;
57
- var queryRendererContext = readContext(ReactRelayQueryRendererContext);
29
+ var queryRendererContext = useContext(ReactRelayQueryRendererContext);
58
30
  return /*#__PURE__*/React.createElement(Container, (0, _extends2["default"])({}, props, {
59
31
  __relayContext: context,
60
32
  __rootIsQueryRenderer: (_queryRendererContext = queryRendererContext === null || queryRendererContext === void 0 ? void 0 : queryRendererContext.rootIsQueryRenderer) !== null && _queryRendererContext !== void 0 ? _queryRendererContext : false,
61
33
  componentRef: props.componentRef || ref
62
34
  }));
63
35
  }
64
-
65
36
  forwardRef.displayName = containerName;
66
37
  var ForwardContainer = React.forwardRef(forwardRef);
67
-
68
38
  if (process.env.NODE_ENV !== "production") {
69
- // Used by RelayModernTestUtils
70
39
  ForwardContainer.__ComponentClass = ComponentClass;
71
40
  ForwardContainer.displayName = containerName;
72
- } // $FlowFixMe[incompatible-return]
73
-
74
-
41
+ }
75
42
  return ForwardContainer;
76
43
  }
77
-
78
44
  module.exports = buildReactRelayContainer;
@@ -1,29 +1,13 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- *
8
- * @format
9
- */
10
1
  'use strict';
11
2
 
12
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
13
-
14
4
  var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
15
-
16
5
  var _require = require('relay-runtime'),
17
- getSelector = _require.getSelector;
18
-
6
+ getSelector = _require.getSelector;
19
7
  function getRootVariablesForFragments(fragments, props) {
20
- var rootVariables = {}; // NOTE: For extra safety, we make sure the rootVariables include the
21
- // variables from all owners in this fragmentSpec, even though they
22
- // should all point to the same owner
23
-
8
+ var rootVariables = {};
24
9
  Object.keys(fragments).forEach(function (key) {
25
10
  var _selector$selectors$, _selector$selectors$2, _selector$owner$varia;
26
-
27
11
  var fragmentNode = fragments[key];
28
12
  var fragmentRef = props[key];
29
13
  var selector = getSelector(fragmentNode, fragmentRef);
@@ -32,5 +16,4 @@ function getRootVariablesForFragments(fragments, props) {
32
16
  });
33
17
  return rootVariables;
34
18
  }
35
-
36
19
  module.exports = getRootVariablesForFragments;
package/lib/hooks.js CHANGED
@@ -1,51 +1,23 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- *
8
- * @format
9
- */
10
1
  'use strict';
11
2
 
12
3
  var EntryPointContainer = require('./relay-hooks/EntryPointContainer.react');
13
-
14
4
  var loadEntryPoint = require('./relay-hooks/loadEntryPoint');
15
-
16
5
  var _require = require('./relay-hooks/loadQuery'),
17
- loadQuery = _require.loadQuery;
18
-
6
+ loadQuery = _require.loadQuery;
7
+ var ProfilerContext = require('./relay-hooks/ProfilerContext');
19
8
  var RelayEnvironmentProvider = require('./relay-hooks/RelayEnvironmentProvider');
20
-
21
9
  var useEntryPointLoader = require('./relay-hooks/useEntryPointLoader');
22
-
23
10
  var useFragment = require('./relay-hooks/useFragment');
24
-
25
11
  var useLazyLoadQuery = require('./relay-hooks/useLazyLoadQuery');
26
-
27
12
  var useMutation = require('./relay-hooks/useMutation');
28
-
29
13
  var usePaginationFragment = require('./relay-hooks/usePaginationFragment');
30
-
31
14
  var usePreloadedQuery = require('./relay-hooks/usePreloadedQuery');
32
-
33
15
  var useQueryLoader = require('./relay-hooks/useQueryLoader');
34
-
35
16
  var useRefetchableFragment = require('./relay-hooks/useRefetchableFragment');
36
-
37
17
  var useRelayEnvironment = require('./relay-hooks/useRelayEnvironment');
38
-
39
18
  var useSubscribeToInvalidationState = require('./relay-hooks/useSubscribeToInvalidationState');
40
-
41
19
  var useSubscription = require('./relay-hooks/useSubscription');
42
-
43
20
  var RelayRuntime = require('relay-runtime');
44
-
45
- /**
46
- * The public interface for Relay Hooks.
47
- * This will eventually become the main public interface for react-relay.
48
- */
49
21
  module.exports = {
50
22
  ConnectionHandler: RelayRuntime.ConnectionHandler,
51
23
  applyOptimisticMutation: RelayRuntime.applyOptimisticMutation,
@@ -56,6 +28,7 @@ module.exports = {
56
28
  requestSubscription: RelayRuntime.requestSubscription,
57
29
  EntryPointContainer: EntryPointContainer,
58
30
  RelayEnvironmentProvider: RelayEnvironmentProvider,
31
+ ProfilerContext: ProfilerContext,
59
32
  fetchQuery: RelayRuntime.fetchQuery,
60
33
  loadQuery: loadQuery,
61
34
  loadEntryPoint: loadEntryPoint,
package/lib/index.js CHANGED
@@ -1,66 +1,30 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- *
8
- * @format
9
- */
10
1
  'use strict';
11
2
 
12
3
  var ReactRelayContext = require('./ReactRelayContext');
13
-
14
4
  var ReactRelayFragmentContainer = require('./ReactRelayFragmentContainer');
15
-
16
5
  var ReactRelayLocalQueryRenderer = require('./ReactRelayLocalQueryRenderer');
17
-
18
6
  var ReactRelayPaginationContainer = require('./ReactRelayPaginationContainer');
19
-
20
7
  var ReactRelayQueryRenderer = require('./ReactRelayQueryRenderer');
21
-
22
8
  var ReactRelayRefetchContainer = require('./ReactRelayRefetchContainer');
23
-
24
9
  var EntryPointContainer = require('./relay-hooks/EntryPointContainer.react');
25
-
26
10
  var loadEntryPoint = require('./relay-hooks/loadEntryPoint');
27
-
28
11
  var _require = require('./relay-hooks/loadQuery'),
29
- loadQuery = _require.loadQuery;
30
-
12
+ loadQuery = _require.loadQuery;
13
+ var ProfilerContext = require('./relay-hooks/ProfilerContext');
31
14
  var RelayEnvironmentProvider = require('./relay-hooks/RelayEnvironmentProvider');
32
-
33
15
  var useClientQuery = require('./relay-hooks/useClientQuery');
34
-
35
16
  var useEntryPointLoader = require('./relay-hooks/useEntryPointLoader');
36
-
37
17
  var useFragment = require('./relay-hooks/useFragment');
38
-
39
18
  var useLazyLoadQuery = require('./relay-hooks/useLazyLoadQuery');
40
-
41
19
  var useMutation = require('./relay-hooks/useMutation');
42
-
43
20
  var usePaginationFragment = require('./relay-hooks/usePaginationFragment');
44
-
45
21
  var usePreloadedQuery = require('./relay-hooks/usePreloadedQuery');
46
-
47
22
  var useQueryLoader = require('./relay-hooks/useQueryLoader');
48
-
49
23
  var useRefetchableFragment = require('./relay-hooks/useRefetchableFragment');
50
-
51
24
  var useRelayEnvironment = require('./relay-hooks/useRelayEnvironment');
52
-
53
25
  var useSubscribeToInvalidationState = require('./relay-hooks/useSubscribeToInvalidationState');
54
-
55
26
  var useSubscription = require('./relay-hooks/useSubscription');
56
-
57
27
  var RelayRuntime = require('relay-runtime');
58
-
59
- /**
60
- * The public interface to react-relay.
61
- * Currently contains both Relay Hooks and legacy Container APIs.
62
- * Will eventually only export the interface from ./hooks.js.
63
- */
64
28
  module.exports = {
65
29
  ConnectionHandler: RelayRuntime.ConnectionHandler,
66
30
  QueryRenderer: ReactRelayQueryRenderer,
@@ -78,9 +42,9 @@ module.exports = {
78
42
  graphql: RelayRuntime.graphql,
79
43
  readInlineData: RelayRuntime.readInlineData,
80
44
  requestSubscription: RelayRuntime.requestSubscription,
81
- // Relay Hooks
82
45
  EntryPointContainer: EntryPointContainer,
83
46
  RelayEnvironmentProvider: RelayEnvironmentProvider,
47
+ ProfilerContext: ProfilerContext,
84
48
  fetchQuery: RelayRuntime.fetchQuery,
85
49
  loadQuery: loadQuery,
86
50
  loadEntryPoint: loadEntryPoint,
@@ -1,21 +1,6 @@
1
- /**
2
- * Copyright (c) Meta Platforms, Inc. and affiliates.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file in the root directory of this source tree.
6
- *
7
- *
8
- * @format
9
- */
10
1
  'use strict';
11
- /**
12
- * Determine if a given value is an object that implements the `Environment`
13
- * interface defined in `RelayEnvironmentTypes`.
14
- */
15
2
 
16
3
  function isRelayEnvironment(environment) {
17
- return typeof environment === 'object' && environment !== null && // TODO: add applyMutation/sendMutation once ready in both cores
18
- typeof environment.check === 'function' && typeof environment.lookup === 'function' && typeof environment.retain === 'function' && typeof environment.execute === 'function' && typeof environment.subscribe === 'function';
4
+ return typeof environment === 'object' && environment !== null && typeof environment.check === 'function' && typeof environment.lookup === 'function' && typeof environment.retain === 'function' && typeof environment.execute === 'function' && typeof environment.subscribe === 'function';
19
5
  }
20
-
21
6
  module.exports = isRelayEnvironment;