react-relay 15.0.0 → 16.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (119) hide show
  1. package/ReactRelayContext.js +1 -1
  2. package/ReactRelayQueryFetcher.js.flow +1 -5
  3. package/ReactRelayQueryRenderer.js.flow +9 -36
  4. package/ReactRelayTypes.js.flow +1 -0
  5. package/buildReactRelayContainer.js.flow +3 -1
  6. package/hooks.js +1 -1
  7. package/index.js +1 -1
  8. package/legacy.js +1 -1
  9. package/lib/ReactRelayContainerUtils.js +0 -11
  10. package/lib/ReactRelayContext.js +0 -11
  11. package/lib/ReactRelayFragmentContainer.js +6 -78
  12. package/lib/ReactRelayFragmentMockRenderer.js +0 -11
  13. package/lib/ReactRelayLocalQueryRenderer.js +0 -17
  14. package/lib/ReactRelayPaginationContainer.js +5 -208
  15. package/lib/ReactRelayQueryFetcher.js +2 -51
  16. package/lib/ReactRelayQueryRenderer.js +6 -94
  17. package/lib/ReactRelayQueryRendererContext.js +0 -11
  18. package/lib/ReactRelayRefetchContainer.js +5 -91
  19. package/lib/ReactRelayTestMocker.js +9 -85
  20. package/lib/ReactRelayTypes.js +0 -11
  21. package/lib/RelayContext.js +0 -21
  22. package/lib/assertFragmentMap.js +0 -15
  23. package/lib/buildReactRelayContainer.js +0 -19
  24. package/lib/getRootVariablesForFragments.js +0 -14
  25. package/lib/hooks.js +0 -15
  26. package/lib/index.js +0 -17
  27. package/lib/isRelayEnvironment.js +1 -18
  28. package/lib/jest-react/enqueueTask.js +0 -20
  29. package/lib/jest-react/internalAct.js +0 -38
  30. package/lib/legacy.js +0 -15
  31. package/lib/multi-actor/ActorChange.js +0 -11
  32. package/lib/multi-actor/index.js +0 -11
  33. package/lib/multi-actor/useRelayActorEnvironment.js +0 -11
  34. package/lib/relay-hooks/EntryPointContainer.react.js +0 -11
  35. package/lib/relay-hooks/EntryPointTypes.flow.js +1 -14
  36. package/lib/relay-hooks/FragmentResource.js +76 -132
  37. package/lib/relay-hooks/HooksImplementation.js +0 -11
  38. package/lib/relay-hooks/InternalLogger.js +0 -11
  39. package/lib/relay-hooks/LRUCache.js +0 -22
  40. package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +0 -18
  41. package/lib/relay-hooks/MatchContainer.js +0 -94
  42. package/lib/relay-hooks/NestedRelayEntryPointBuilderUtils.js +9 -0
  43. package/lib/relay-hooks/ProfilerContext.js +0 -15
  44. package/lib/relay-hooks/QueryResource.js +2 -68
  45. package/lib/relay-hooks/RelayEnvironmentProvider.js +0 -11
  46. package/lib/relay-hooks/SuspenseResource.js +0 -34
  47. package/lib/relay-hooks/loadEntryPoint.js +1 -24
  48. package/lib/relay-hooks/loadQuery.js +2 -106
  49. package/lib/relay-hooks/preloadQuery_DEPRECATED.js +2 -27
  50. package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +0 -13
  51. package/lib/relay-hooks/react-cache/RelayReactCache.js +0 -12
  52. package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +1 -36
  53. package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +3 -27
  54. package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +34 -99
  55. package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +0 -15
  56. package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +0 -16
  57. package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +1 -23
  58. package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +0 -29
  59. package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +12 -96
  60. package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +0 -14
  61. package/lib/relay-hooks/useBlockingPaginationFragment.js +0 -42
  62. package/lib/relay-hooks/useClientQuery.js +0 -18
  63. package/lib/relay-hooks/useEntryPointLoader.js +0 -69
  64. package/lib/relay-hooks/useFetchTrackingRef.js +0 -26
  65. package/lib/relay-hooks/useFragment.js +0 -17
  66. package/lib/relay-hooks/useFragmentNode.js +2 -32
  67. package/lib/relay-hooks/useIsMountedRef.js +0 -11
  68. package/lib/relay-hooks/useIsOperationNodeActive.js +0 -11
  69. package/lib/relay-hooks/useIsParentQueryActive.js +0 -11
  70. package/lib/relay-hooks/useLazyLoadQuery.js +0 -18
  71. package/lib/relay-hooks/useLazyLoadQueryNode.js +0 -35
  72. package/lib/relay-hooks/useLoadMoreFunction.js +9 -34
  73. package/lib/relay-hooks/useMemoOperationDescriptor.js +0 -11
  74. package/lib/relay-hooks/useMemoVariables.js +0 -17
  75. package/lib/relay-hooks/useMutation.js +0 -11
  76. package/lib/relay-hooks/usePaginationFragment.js +1 -26
  77. package/lib/relay-hooks/usePreloadedQuery.js +0 -27
  78. package/lib/relay-hooks/useQueryLoader.js +0 -74
  79. package/lib/relay-hooks/useRefetchableFragment.js +0 -16
  80. package/lib/relay-hooks/useRefetchableFragmentNode.js +14 -97
  81. package/lib/relay-hooks/useRelayEnvironment.js +0 -11
  82. package/lib/relay-hooks/useStaticFragmentNodeWarning.js +0 -15
  83. package/lib/relay-hooks/useSubscribeToInvalidationState.js +0 -25
  84. package/lib/relay-hooks/useSubscription.js +0 -15
  85. package/lib/relay-hooks/useUnsafeRef_DEPRECATED.js +0 -17
  86. package/package.json +2 -2
  87. package/react-relay-hooks.js +2 -2
  88. package/react-relay-hooks.min.js +2 -2
  89. package/react-relay-legacy.js +2 -2
  90. package/react-relay-legacy.min.js +2 -2
  91. package/react-relay.js +2 -2
  92. package/react-relay.min.js +2 -2
  93. package/relay-hooks/EntryPointContainer.react.js.flow +5 -0
  94. package/relay-hooks/EntryPointTypes.flow.js.flow +20 -19
  95. package/relay-hooks/FragmentResource.js.flow +114 -26
  96. package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +4 -2
  97. package/relay-hooks/NestedRelayEntryPointBuilderUtils.js.flow +51 -0
  98. package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +7 -5
  99. package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +5 -0
  100. package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +5 -0
  101. package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +2 -0
  102. package/relay-hooks/loadEntryPoint.js.flow +4 -2
  103. package/relay-hooks/loadQuery.js.flow +21 -1
  104. package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +4 -2
  105. package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +2 -1
  106. package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +28 -10
  107. package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +3 -9
  108. package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +28 -57
  109. package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +19 -12
  110. package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +15 -31
  111. package/relay-hooks/useBlockingPaginationFragment.js.flow +2 -4
  112. package/relay-hooks/useClientQuery.js.flow +2 -2
  113. package/relay-hooks/useFragmentNode.js.flow +2 -2
  114. package/relay-hooks/useLoadMoreFunction.js.flow +15 -9
  115. package/relay-hooks/useMutation.js.flow +26 -9
  116. package/relay-hooks/usePaginationFragment.js.flow +2 -8
  117. package/relay-hooks/useQueryLoader.js.flow +2 -8
  118. package/relay-hooks/useRefetchableFragment.js.flow +3 -2
  119. package/relay-hooks/useRefetchableFragmentNode.js.flow +28 -13
@@ -1,14 +1,3 @@
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
- * @oncall relay
10
- */
11
-
12
1
  'use strict';
13
2
 
14
3
  var React = require('react');
@@ -1,14 +1,3 @@
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
- * @oncall relay
10
- */
11
-
12
1
  'use strict';
13
2
 
14
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
@@ -38,31 +27,20 @@ var _require3 = require('relay-runtime'),
38
27
  getVariablesFromObject = _require3.getVariablesFromObject,
39
28
  isScalarAndEqual = _require3.isScalarAndEqual;
40
29
  var warning = require("fbjs/lib/warning");
41
- /**
42
- * Composes a React component class, returning a new class that intercepts
43
- * props, resolving them with the provided fragments and subscribing for
44
- * updates.
45
- */
46
30
  function createContainerWithFragments(Component, fragments, taggedNode) {
47
31
  var _class;
48
32
  var containerName = getContainerName(Component);
49
33
  return _class = /*#__PURE__*/function (_React$Component) {
50
34
  (0, _inheritsLoose2["default"])(_class, _React$Component);
51
- // $FlowFixMe[missing-local-annot]
52
-
53
35
  function _class(props) {
54
36
  var _props$__rootIsQueryR, _this;
55
37
  _this = _React$Component.call(this, props) || this;
56
38
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "_handleFragmentDataUpdate", function () {
57
39
  var resolverFromThisUpdate = _this.state.resolver;
58
40
  _this.setState(function (updatedState) {
59
- return (
60
- // If this event belongs to the current data source, update.
61
- // Otherwise we should ignore it.
62
- resolverFromThisUpdate === updatedState.resolver ? {
63
- data: updatedState.resolver.resolve()
64
- } : null
65
- );
41
+ return resolverFromThisUpdate === updatedState.resolver ? {
42
+ data: updatedState.resolver.resolve()
43
+ } : null;
66
44
  });
67
45
  });
68
46
  (0, _defineProperty2["default"])((0, _assertThisInitialized2["default"])(_this), "_refetch", function (refetchVariables, renderVariables, observerOrCallback, options) {
@@ -85,22 +63,13 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
85
63
  cacheConfig.metadata = options === null || options === void 0 ? void 0 : options.metadata;
86
64
  }
87
65
  var observer = typeof observerOrCallback === 'function' ? {
88
- // callback is not exectued on complete or unsubscribe
89
- // for backward compatibility
90
66
  next: observerOrCallback,
91
67
  error: observerOrCallback
92
68
  } : observerOrCallback || {};
93
69
  var query = getRequest(taggedNode);
94
70
  var operation = createOperationDescriptor(query, fetchVariables, cacheConfig);
95
-
96
- // TODO: T26288752 find a better way
97
71
  _this.state.localVariables = fetchVariables;
98
-
99
- // Cancel any previously running refetch.
100
72
  _this._refetchSubscription && _this._refetchSubscription.unsubscribe();
101
-
102
- // Declare refetchSubscription before assigning it in .start(), since
103
- // synchronous completion may call callbacks .subscribe() returns.
104
73
  var refetchSubscription;
105
74
  var storeSnapshot = _this._getQueryFetcher().lookupInStore(environment, operation, options === null || options === void 0 ? void 0 : options.fetchPolicy);
106
75
  if (storeSnapshot != null) {
@@ -123,7 +92,6 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
123
92
  _this._getQueryFetcher().execute({
124
93
  environment: environment,
125
94
  operation: operation,
126
- // TODO (T26430099): Cleanup old references
127
95
  preservePreviousReferences: true
128
96
  }).mergeMap(function (response) {
129
97
  _this.state.resolver.setVariables(fragmentVariables, operation.request.node);
@@ -141,8 +109,6 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
141
109
  });
142
110
  });
143
111
  })["finally"](function () {
144
- // Finalizing a refetch should only clear this._refetchSubscription
145
- // if the finizing subscription is the most recent call.
146
112
  if (_this._refetchSubscription === refetchSubscription) {
147
113
  _this._refetchSubscription = null;
148
114
  }
@@ -161,10 +127,6 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
161
127
  var relayContext = assertRelayContext(props.__relayContext);
162
128
  var rootIsQueryRenderer = (_props$__rootIsQueryR = props.__rootIsQueryRenderer) !== null && _props$__rootIsQueryR !== void 0 ? _props$__rootIsQueryR : false;
163
129
  _this._refetchSubscription = null;
164
- // Do not provide a subscription/callback here.
165
- // It is possible for this render to be interrupted or aborted,
166
- // In which case the subscription would cause a leak.
167
- // We will add the subscription in componentDidMount().
168
130
  var resolver = createFragmentSpecResolver(relayContext, containerName, fragments, props, rootIsQueryRenderer);
169
131
  _this.state = {
170
132
  data: resolver.resolve(),
@@ -184,11 +146,6 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
184
146
  this._subscribeToNewResolverAndRerenderIfStoreHasChanged();
185
147
  };
186
148
  _proto.componentDidUpdate = function componentDidUpdate(prevProps, prevState) {
187
- // If the environment has changed or props point to new records then
188
- // previously fetched data and any pending fetches no longer apply:
189
- // - Existing references are on the old environment.
190
- // - Existing references are based on old variables.
191
- // - Pending fetches are for the previous records.
192
149
  if (this.state.resolver !== prevState.resolver) {
193
150
  prevState.resolver.dispose();
194
151
  this._queryFetcher && this._queryFetcher.dispose();
@@ -197,16 +154,9 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
197
154
  } else {
198
155
  this._rerenderIfStoreHasChanged();
199
156
  }
200
- }
201
-
202
- /**
203
- * When new props are received, read data for the new props and add it to
204
- * state. Props may be the same in which case previous data can be reused.
205
- */;
157
+ };
206
158
  _class.getDerivedStateFromProps = function getDerivedStateFromProps(nextProps, prevState) {
207
159
  var _nextProps$__rootIsQu;
208
- // Any props change could impact the query, so we mirror props in state.
209
- // This is an unusual pattern, but necessary for this container usecase.
210
160
  var prevProps = prevState.prevProps;
211
161
  var relayContext = assertRelayContext(nextProps.__relayContext);
212
162
  var rootIsQueryRenderer = (_nextProps$__rootIsQu = nextProps.__rootIsQueryRenderer) !== null && _nextProps$__rootIsQu !== void 0 ? _nextProps$__rootIsQu : false;
@@ -215,17 +165,7 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
215
165
  var prevRootVariables = getRootVariablesForFragments(fragments, prevProps);
216
166
  var nextRootVariables = getRootVariablesForFragments(fragments, nextProps);
217
167
  var resolver = prevState.resolver;
218
-
219
- // If the environment has changed or props point to new records then
220
- // previously fetched data and any pending fetches no longer apply:
221
- // - Existing references are on the old environment.
222
- // - Existing references are based on old variables.
223
- // - Pending fetches are for the previous records.
224
168
  if (prevState.prevPropsContext.environment !== relayContext.environment || !areEqual(prevRootVariables, nextRootVariables) || !areEqual(prevIDs, nextIDs)) {
225
- // Do not provide a subscription/callback here.
226
- // It is possible for this render to be interrupted or aborted,
227
- // In which case the subscription would cause a leak.
228
- // We will add the subscription in componentDidUpdate().
229
169
  resolver = createFragmentSpecResolver(relayContext, containerName, fragments, nextProps, rootIsQueryRenderer);
230
170
  return {
231
171
  data: resolver.resolve(),
@@ -255,12 +195,9 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
255
195
  this._refetchSubscription && this._refetchSubscription.unsubscribe();
256
196
  };
257
197
  _proto.shouldComponentUpdate = function shouldComponentUpdate(nextProps, nextState) {
258
- // Short-circuit if any Relay-related data has changed
259
198
  if (nextState.data !== this.state.data || nextState.relayProp !== this.state.relayProp) {
260
199
  return true;
261
200
  }
262
- // Otherwise, for convenience short-circuit if all non-Relay props
263
- // are scalar and equal
264
201
  var keys = Object.keys(nextProps);
265
202
  for (var ii = 0; ii < keys.length; ii++) {
266
203
  var key = keys[ii];
@@ -280,8 +217,6 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
280
217
  var _this$state = this.state,
281
218
  data = _this$state.data,
282
219
  resolver = _this$state.resolver;
283
- // External values could change between render and commit.
284
- // Check for this case, even though it requires an extra store read.
285
220
  var maybeNewData = resolver.resolve();
286
221
  if (data !== maybeNewData) {
287
222
  this.setState({
@@ -294,23 +229,13 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
294
229
  data = _this$state2.data,
295
230
  resolver = _this$state2.resolver;
296
231
  var maybeNewData = resolver.resolve();
297
-
298
- // Event listeners are only safe to add during the commit phase,
299
- // So they won't leak if render is interrupted or errors.
300
232
  resolver.setCallback(this.props, this._handleFragmentDataUpdate);
301
-
302
- // External values could change between render and commit.
303
- // Check for this case, even though it requires an extra store read.
304
233
  if (data !== maybeNewData) {
305
234
  this.setState({
306
235
  data: maybeNewData
307
236
  });
308
237
  }
309
- }
310
-
311
- /**
312
- * Render new data for the existing props/context.
313
- */;
238
+ };
314
239
  _proto._getFragmentVariables = function _getFragmentVariables() {
315
240
  return getVariablesFromObject(fragments, this.props);
316
241
  };
@@ -320,9 +245,7 @@ function createContainerWithFragments(Component, fragments, taggedNode) {
320
245
  }
321
246
  return this._queryFetcher;
322
247
  };
323
- // $FlowFixMe[missing-local-annot]
324
248
  _proto.render = function render() {
325
- // eslint-disable-next-line no-unused-vars
326
249
  var _this$props = this.props,
327
250
  componentRef = _this$props.componentRef,
328
251
  __relayContext = _this$props.__relayContext,
@@ -347,16 +270,7 @@ function getRelayProp(environment, refetch) {
347
270
  refetch: refetch
348
271
  };
349
272
  }
350
-
351
- /**
352
- * Wrap the basic `createContainer()` function with logic to adapt to the
353
- * `context.relay.environment` in which it is rendered. Specifically, the
354
- * extraction of the environment-specific version of fragments in the
355
- * `fragmentSpec` is memoized once per environment, rather than once per
356
- * instance of the container constructed/rendered.
357
- */
358
273
  function createContainer(Component, fragmentSpec, taggedNode) {
359
- // $FlowFixMe[incompatible-return]
360
274
  return buildReactRelayContainer(Component, fragmentSpec, function (ComponentClass, fragments) {
361
275
  return createContainerWithFragments(ComponentClass, fragments, taggedNode);
362
276
  });
@@ -1,14 +1,3 @@
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
- * @oncall relay
10
- */
11
-
12
1
  'use strict';
13
2
 
14
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
@@ -21,9 +10,6 @@ var _require = require('relay-runtime'),
21
10
  createOperationDescriptor = _require.createOperationDescriptor,
22
11
  isRelayModernEnvironment = _require.isRelayModernEnvironment;
23
12
  var warning = require("fbjs/lib/warning");
24
- /**
25
- * The next id to return from `generateId()`.
26
- */
27
13
  var nextId = 0;
28
14
  var ReactRelayTestMocker = /*#__PURE__*/function () {
29
15
  function ReactRelayTestMocker(env) {
@@ -38,37 +24,15 @@ var ReactRelayTestMocker = /*#__PURE__*/function () {
38
24
  }
39
25
  ReactRelayTestMocker.mockOutEnvironment = function mockOutEnvironment(env) {
40
26
  return new ReactRelayTestMocker(env);
41
- }
42
-
43
- /**
44
- * Get a unique id number (as a string). Note: will wrap around after 2^32
45
- * calls, if your test needs that many IDs.
46
- *
47
- * @returns a unique id string
48
- */;
27
+ };
49
28
  ReactRelayTestMocker.generateId = function generateId() {
50
29
  var toRet = nextId.toString();
51
30
  nextId++;
52
31
  return toRet;
53
- }
54
-
55
- /**
56
- * Create a unique identifier for a (query, variables) pair.
57
- * @param request: the request associated with the query
58
- * @param variables: the variables associated with this invocation of the
59
- * query
60
- *
61
- * @returns a string which can later be used to uniquely identify this query
62
- * in the list of pending queries
63
- */;
32
+ };
64
33
  ReactRelayTestMocker.getIdentifier = function getIdentifier(request) {
65
34
  return request.name;
66
- }
67
-
68
- /**
69
- * Remove variables that we don't need from the query that will make it more
70
- * annoying to test (e.g. client_mutation_id, actor_id)
71
- */;
35
+ };
72
36
  ReactRelayTestMocker.stripUnused = function stripUnused(variables) {
73
37
  if (variables.input) {
74
38
  var toRemove = ['client_mutation_id', 'actor_id', 'clientMutationId', 'actorId'];
@@ -81,15 +45,7 @@ var ReactRelayTestMocker = /*#__PURE__*/function () {
81
45
  return strippedVariables;
82
46
  }
83
47
  return variables;
84
- }
85
-
86
- /**
87
- * Replace the environment's network layer with a mocked out one to allow for
88
- * better testing. Mocking the network allows testing without using a mocked
89
- * out QueryRenderer, and will allow for easier testing of components wrapped
90
- * in refetch containers, for example. It also allows test writers to see how
91
- * their components behave under error conditions.
92
- */;
48
+ };
93
49
  var _proto = ReactRelayTestMocker.prototype;
94
50
  _proto._mockNetworkLayer = function _mockNetworkLayer(env) {
95
51
  var _this = this;
@@ -102,8 +58,6 @@ var ReactRelayTestMocker = /*#__PURE__*/function () {
102
58
  });
103
59
  var strippedVars = ReactRelayTestMocker.stripUnused(variables);
104
60
  var ident = ReactRelayTestMocker.getIdentifier(request);
105
-
106
- // there's a default value for this query, use it
107
61
  if (_this._defaults[ident]) {
108
62
  var payload = _this._defaults[ident];
109
63
  return typeof payload === 'function' ? payload(strippedVars) : payload;
@@ -148,35 +102,18 @@ var ReactRelayTestMocker = /*#__PURE__*/function () {
148
102
  env.hasMockedNetwork = true;
149
103
  env.__setNet(Network.create(fetch));
150
104
  return env;
151
- }
152
-
153
- /**
154
- * set a default payload for a given query
155
- */;
105
+ };
156
106
  _proto.setDefault = function setDefault(toSet) {
157
107
  var query = toSet.query,
158
108
  payload = toSet.payload;
159
109
  var ident = ReactRelayTestMocker.getIdentifier(query.params);
160
110
  this._defaults[ident] = payload;
161
- }
162
-
163
- /**
164
- * remove a default payload for a given query
165
- */;
111
+ };
166
112
  _proto.unsetDefault = function unsetDefault(toUnset) {
167
113
  var query = toUnset.query;
168
114
  var ident = ReactRelayTestMocker.getIdentifier(query.params);
169
115
  delete this._defaults[ident];
170
- }
171
-
172
- /**
173
- * Write directly to the Relay store instead of trying to resolve a query that
174
- * was sent via the network.
175
- *
176
- * Use this method when testing a component wrapped in a fragment container
177
- * (via `createFragmentContainer`). The component under test should also be
178
- * wrapped in a `RelayTestRenderer`.
179
- */;
116
+ };
180
117
  _proto.dataWrite = function dataWrite(config) {
181
118
  var query = config.query,
182
119
  variables = config.variables,
@@ -184,16 +121,7 @@ var ReactRelayTestMocker = /*#__PURE__*/function () {
184
121
  var operationDescriptor = createOperationDescriptor(query, variables);
185
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;
186
123
  this._environment.commitPayload(operationDescriptor, payload.data);
187
- }
188
-
189
- /**
190
- * Write the data specified in config's payload to the instance's environment.
191
- * NOTE: callers may need to invoke `jest.runOnlyPendingTimers()` after
192
- * calling this function.
193
- *
194
- * @param config: an object containing the data to write and the query and
195
- * variables that the payload is simulating a response to
196
- */;
124
+ };
197
125
  _proto.networkWrite = function networkWrite(config) {
198
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;
199
127
  var query = config.query,
@@ -221,11 +149,7 @@ var ReactRelayTestMocker = /*#__PURE__*/function () {
221
149
  });
222
150
  var varMessage = usedVars ? ' - variables: ' + JSON.stringify(usedVars) : '';
223
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;
224
- var realPayload =
225
- // $FlowFixMe[incompatible-call]
226
- typeof payload === 'function' ? payload(toResolve.variables) : payload;
227
-
228
- // if there are errors, reject the query
152
+ var realPayload = typeof payload === 'function' ? payload(toResolve.variables) : payload;
229
153
  if (realPayload.errors != null && realPayload.errors.length > 0) {
230
154
  this._environment.mock.rejectQuery(toResolve, {
231
155
  error: realPayload.errors[0]
@@ -1,12 +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
- * @oncall relay
10
- */
11
-
12
1
  'use strict';
@@ -1,32 +1,11 @@
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
- * @oncall relay
10
- */
11
-
12
1
  'use strict';
13
2
 
14
3
  var isRelayEnvironment = require('./isRelayEnvironment');
15
4
  var invariant = require('invariant');
16
-
17
- /**
18
- * Asserts that the input is a matches the `RelayContext` type defined in
19
- * `RelayEnvironmentTypes` and returns it as that type.
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
- /**
27
- * Determine if the input is a plain object that matches the `RelayContext`
28
- * type defined in `RelayEnvironmentTypes`.
29
- */
30
9
  function isRelayContext(context) {
31
10
  return typeof context === 'object' && context !== null && !Array.isArray(context) && isRelayEnvironment(context.environment);
32
11
  }
@@ -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
- * @oncall relay
10
- */
11
-
12
1
  'use strict';
13
2
 
14
3
  var invariant = require('invariant');
15
-
16
- /**
17
- * Fail fast if the user supplies invalid fragments as input.
18
- */
19
4
  function assertFragmentMap(componentName, fragmentSpec) {
20
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;
21
6
  for (var key in fragmentSpec) {
@@ -1,14 +1,3 @@
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
- * @oncall relay
10
- */
11
-
12
1
  'use strict';
13
2
 
14
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
@@ -24,12 +13,7 @@ var React = require('react');
24
13
  var _require2 = require('relay-runtime'),
25
14
  getFragment = _require2.getFragment;
26
15
  var useContext = React.useContext;
27
- /**
28
- * Helper to create the Relay HOCs with ref forwarding, setting the displayName
29
- * and reading the React context.
30
- */
31
16
  function buildReactRelayContainer(ComponentClass, fragmentSpec, createContainerWithFragments) {
32
- // Sanity-check user-defined fragment input
33
17
  var containerName = getContainerName(ComponentClass);
34
18
  assertFragmentMap(getComponentName(ComponentClass), fragmentSpec);
35
19
  var fragments = {};
@@ -52,12 +36,9 @@ function buildReactRelayContainer(ComponentClass, fragmentSpec, createContainerW
52
36
  forwardRef.displayName = containerName;
53
37
  var ForwardContainer = React.forwardRef(forwardRef);
54
38
  if (process.env.NODE_ENV !== "production") {
55
- // Used by RelayModernTestUtils
56
39
  ForwardContainer.__ComponentClass = ComponentClass;
57
40
  ForwardContainer.displayName = containerName;
58
41
  }
59
-
60
- // $FlowFixMe[incompatible-return]
61
42
  return ForwardContainer;
62
43
  }
63
44
  module.exports = buildReactRelayContainer;
@@ -1,14 +1,3 @@
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
- * @oncall relay
10
- */
11
-
12
1
  'use strict';
13
2
 
14
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
@@ -17,9 +6,6 @@ var _require = require('relay-runtime'),
17
6
  getSelector = _require.getSelector;
18
7
  function getRootVariablesForFragments(fragments, props) {
19
8
  var rootVariables = {};
20
- // 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
9
  Object.keys(fragments).forEach(function (key) {
24
10
  var _selector$selectors$, _selector$selectors$2, _selector$owner$varia;
25
11
  var fragmentNode = fragments[key];
package/lib/hooks.js CHANGED
@@ -1,14 +1,3 @@
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
- * @oncall relay
10
- */
11
-
12
1
  'use strict';
13
2
 
14
3
  var EntryPointContainer = require('./relay-hooks/EntryPointContainer.react');
@@ -29,10 +18,6 @@ var useRelayEnvironment = require('./relay-hooks/useRelayEnvironment');
29
18
  var useSubscribeToInvalidationState = require('./relay-hooks/useSubscribeToInvalidationState');
30
19
  var useSubscription = require('./relay-hooks/useSubscription');
31
20
  var RelayRuntime = require('relay-runtime');
32
- /**
33
- * The public interface for Relay Hooks.
34
- * This will eventually become the main public interface for react-relay.
35
- */
36
21
  module.exports = {
37
22
  ConnectionHandler: RelayRuntime.ConnectionHandler,
38
23
  applyOptimisticMutation: RelayRuntime.applyOptimisticMutation,
package/lib/index.js CHANGED
@@ -1,14 +1,3 @@
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
- * @oncall relay
10
- */
11
-
12
1
  'use strict';
13
2
 
14
3
  var ReactRelayContext = require('./ReactRelayContext');
@@ -36,11 +25,6 @@ var useRelayEnvironment = require('./relay-hooks/useRelayEnvironment');
36
25
  var useSubscribeToInvalidationState = require('./relay-hooks/useSubscribeToInvalidationState');
37
26
  var useSubscription = require('./relay-hooks/useSubscription');
38
27
  var RelayRuntime = require('relay-runtime');
39
- /**
40
- * The public interface to react-relay.
41
- * Currently contains both Relay Hooks and legacy Container APIs.
42
- * Will eventually only export the interface from ./hooks.js.
43
- */
44
28
  module.exports = {
45
29
  ConnectionHandler: RelayRuntime.ConnectionHandler,
46
30
  QueryRenderer: ReactRelayQueryRenderer,
@@ -58,7 +42,6 @@ module.exports = {
58
42
  graphql: RelayRuntime.graphql,
59
43
  readInlineData: RelayRuntime.readInlineData,
60
44
  requestSubscription: RelayRuntime.requestSubscription,
61
- // Relay Hooks
62
45
  EntryPointContainer: EntryPointContainer,
63
46
  RelayEnvironmentProvider: RelayEnvironmentProvider,
64
47
  ProfilerContext: ProfilerContext,
@@ -1,23 +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
- * @oncall relay
10
- */
11
-
12
1
  'use strict';
13
2
 
14
- /**
15
- * Determine if a given value is an object that implements the `Environment`
16
- * interface defined in `RelayEnvironmentTypes`.
17
- */
18
3
  function isRelayEnvironment(environment) {
19
- return typeof environment === 'object' && environment !== null &&
20
- // TODO: add applyMutation/sendMutation once ready in both cores
21
- 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';
22
5
  }
23
6
  module.exports = isRelayEnvironment;
@@ -1,15 +1,3 @@
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
- * @format
8
- * @oncall relay
9
- */
10
-
11
- // This file is sync'd from https://github.com/facebook/react/tree/main/packages/jest-react
12
-
13
1
  'use strict';
14
2
 
15
3
  var didWarnAboutMessageChannel = false;
@@ -17,17 +5,10 @@ var enqueueTaskImpl = null;
17
5
  function enqueueTask(task) {
18
6
  if (enqueueTaskImpl === null) {
19
7
  try {
20
- // read require off the module object to get around the bundlers.
21
- // we don't want them to detect a require and bundle a Node polyfill.
22
8
  var requireString = ('require' + Math.random()).slice(0, 7);
23
9
  var nodeRequire = module && module[requireString];
24
- // assuming we're in node, let's try to get node's
25
- // version of setImmediate, bypassing fake timers if any.
26
10
  enqueueTaskImpl = nodeRequire.call(module, 'timers').setImmediate;
27
11
  } catch (_unused) {
28
- // we're in a browser
29
- // we can't use regular timers because they may still be faked
30
- // so we try MessageChannel+postMessage instead
31
12
  enqueueTaskImpl = function enqueueTaskImpl(callback) {
32
13
  if (process.env.NODE_ENV !== "production") {
33
14
  if (didWarnAboutMessageChannel === false) {
@@ -37,7 +18,6 @@ function enqueueTask(task) {
37
18
  }
38
19
  }
39
20
  }
40
- /*global MessageChannel*/
41
21
  var channel = new MessageChannel();
42
22
  channel.port1.onmessage = callback;
43
23
  channel.port2.postMessage(undefined);