react-relay 11.0.2 → 13.0.0-rc.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (177) hide show
  1. package/README.md +47 -0
  2. package/ReactRelayContainerUtils.js.flow +1 -1
  3. package/ReactRelayContext.js +1 -1
  4. package/ReactRelayContext.js.flow +3 -4
  5. package/ReactRelayFragmentContainer.js.flow +25 -25
  6. package/ReactRelayFragmentMockRenderer.js.flow +2 -2
  7. package/ReactRelayLocalQueryRenderer.js.flow +7 -8
  8. package/ReactRelayPaginationContainer.js.flow +112 -59
  9. package/ReactRelayQueryFetcher.js.flow +10 -11
  10. package/ReactRelayQueryRenderer.js.flow +116 -82
  11. package/ReactRelayQueryRendererContext.js.flow +1 -1
  12. package/ReactRelayRefetchContainer.js.flow +42 -39
  13. package/ReactRelayTestMocker.js.flow +17 -15
  14. package/ReactRelayTypes.js.flow +11 -11
  15. package/RelayContext.js.flow +4 -4
  16. package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +2 -3
  17. package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +12 -8
  18. package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +11 -7
  19. package/__flowtests__/RelayModern-flowtest.js.flow +79 -47
  20. package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +6 -5
  21. package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +6 -5
  22. package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +5 -4
  23. package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +5 -4
  24. package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +72 -0
  25. package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +72 -0
  26. package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +227 -0
  27. package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +164 -0
  28. package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +227 -0
  29. package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +164 -0
  30. package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +66 -0
  31. package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +66 -0
  32. package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +59 -0
  33. package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +61 -0
  34. package/assertFragmentMap.js.flow +3 -3
  35. package/buildReactRelayContainer.js.flow +12 -11
  36. package/getRootVariablesForFragments.js.flow +3 -5
  37. package/hooks.js +1 -1
  38. package/hooks.js.flow +6 -7
  39. package/index.js +1 -1
  40. package/index.js.flow +7 -8
  41. package/isRelayEnvironment.js.flow +1 -1
  42. package/jest-react/enqueueTask.js.flow +56 -0
  43. package/jest-react/index.js.flow +12 -0
  44. package/jest-react/internalAct.js.flow +138 -0
  45. package/legacy.js +1 -1
  46. package/legacy.js.flow +1 -1
  47. package/lib/ReactRelayContainerUtils.js +1 -1
  48. package/lib/ReactRelayContext.js +1 -1
  49. package/lib/ReactRelayFragmentContainer.js +22 -16
  50. package/lib/ReactRelayFragmentMockRenderer.js +3 -3
  51. package/lib/ReactRelayLocalQueryRenderer.js +8 -9
  52. package/lib/ReactRelayPaginationContainer.js +97 -39
  53. package/lib/ReactRelayQueryFetcher.js +3 -3
  54. package/lib/ReactRelayQueryRenderer.js +87 -54
  55. package/lib/ReactRelayQueryRendererContext.js +1 -1
  56. package/lib/ReactRelayRefetchContainer.js +39 -26
  57. package/lib/ReactRelayTestMocker.js +8 -9
  58. package/lib/ReactRelayTypes.js +1 -1
  59. package/lib/RelayContext.js +4 -3
  60. package/lib/assertFragmentMap.js +3 -2
  61. package/lib/buildReactRelayContainer.js +8 -8
  62. package/lib/getRootVariablesForFragments.js +2 -3
  63. package/lib/hooks.js +6 -6
  64. package/lib/index.js +8 -8
  65. package/lib/isRelayEnvironment.js +1 -1
  66. package/lib/jest-react/enqueueTask.js +53 -0
  67. package/lib/jest-react/index.js +13 -0
  68. package/lib/jest-react/internalAct.js +115 -0
  69. package/lib/legacy.js +1 -1
  70. package/lib/multi-actor/ActorChange.js +30 -0
  71. package/lib/multi-actor/index.js +11 -0
  72. package/lib/multi-actor/useRelayActorEnvironment.js +29 -0
  73. package/lib/readContext.js +1 -1
  74. package/lib/relay-hooks/EntryPointContainer.react.js +4 -4
  75. package/lib/relay-hooks/EntryPointTypes.flow.js +1 -1
  76. package/lib/relay-hooks/FragmentResource.js +342 -89
  77. package/lib/relay-hooks/InternalLogger.js +1 -1
  78. package/lib/relay-hooks/LRUCache.js +1 -1
  79. package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +5 -5
  80. package/lib/relay-hooks/MatchContainer.js +2 -2
  81. package/lib/relay-hooks/ProfilerContext.js +1 -1
  82. package/lib/relay-hooks/QueryResource.js +172 -29
  83. package/lib/relay-hooks/RelayEnvironmentProvider.js +6 -4
  84. package/lib/relay-hooks/SuspenseResource.js +130 -0
  85. package/lib/relay-hooks/loadEntryPoint.js +1 -1
  86. package/lib/relay-hooks/loadQuery.js +42 -20
  87. package/lib/relay-hooks/preloadQuery_DEPRECATED.js +25 -16
  88. package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +1 -1
  89. package/lib/relay-hooks/useBlockingPaginationFragment.js +5 -6
  90. package/lib/relay-hooks/useEntryPointLoader.js +3 -3
  91. package/lib/relay-hooks/useFetchTrackingRef.js +3 -2
  92. package/lib/relay-hooks/useFragment.js +7 -7
  93. package/lib/relay-hooks/useFragmentNode.js +5 -5
  94. package/lib/relay-hooks/useIsMountedRef.js +1 -1
  95. package/lib/relay-hooks/useIsOperationNodeActive.js +3 -3
  96. package/lib/relay-hooks/useIsParentQueryActive.js +1 -1
  97. package/lib/relay-hooks/useLazyLoadQuery.js +4 -4
  98. package/lib/relay-hooks/useLazyLoadQueryNode.js +11 -5
  99. package/lib/relay-hooks/useLoadMoreFunction.js +9 -13
  100. package/lib/relay-hooks/useMemoOperationDescriptor.js +3 -3
  101. package/lib/relay-hooks/useMemoVariables.js +3 -3
  102. package/lib/relay-hooks/useMutation.js +18 -7
  103. package/lib/relay-hooks/usePaginationFragment.js +3 -4
  104. package/lib/relay-hooks/usePreloadedQuery.js +6 -6
  105. package/lib/relay-hooks/useQueryLoader.js +31 -11
  106. package/lib/relay-hooks/useRefetchableFragment.js +1 -1
  107. package/lib/relay-hooks/useRefetchableFragmentNode.js +14 -18
  108. package/lib/relay-hooks/useRelayEnvironment.js +3 -3
  109. package/lib/relay-hooks/useStaticFragmentNodeWarning.js +3 -3
  110. package/lib/relay-hooks/useSubscribeToInvalidationState.js +3 -2
  111. package/lib/relay-hooks/useSubscription.js +11 -8
  112. package/multi-actor/ActorChange.js.flow +58 -0
  113. package/multi-actor/index.js.flow +14 -0
  114. package/multi-actor/useRelayActorEnvironment.js.flow +49 -0
  115. package/package.json +3 -3
  116. package/react-relay-hooks.js +2 -2
  117. package/react-relay-hooks.min.js +2 -2
  118. package/react-relay-legacy.js +2 -2
  119. package/react-relay-legacy.min.js +2 -2
  120. package/react-relay.js +2 -2
  121. package/react-relay.min.js +2 -2
  122. package/readContext.js.flow +1 -1
  123. package/relay-hooks/EntryPointContainer.react.js.flow +9 -16
  124. package/relay-hooks/EntryPointTypes.flow.js.flow +25 -26
  125. package/relay-hooks/FragmentResource.js.flow +359 -93
  126. package/relay-hooks/InternalLogger.js.flow +1 -1
  127. package/relay-hooks/LRUCache.js.flow +1 -1
  128. package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +33 -47
  129. package/relay-hooks/MatchContainer.js.flow +4 -3
  130. package/relay-hooks/ProfilerContext.js.flow +1 -1
  131. package/relay-hooks/QueryResource.js.flow +217 -26
  132. package/relay-hooks/RelayEnvironmentProvider.js.flow +15 -5
  133. package/relay-hooks/SuspenseResource.js.flow +115 -0
  134. package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +5 -4
  135. package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +2 -2
  136. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +59 -0
  137. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +61 -0
  138. package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +11 -10
  139. package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +55 -32
  140. package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +11 -10
  141. package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +11 -10
  142. package/relay-hooks/__flowtests__/utils.js.flow +21 -32
  143. package/relay-hooks/loadEntryPoint.js.flow +7 -13
  144. package/relay-hooks/loadQuery.js.flow +50 -32
  145. package/relay-hooks/preloadQuery_DEPRECATED.js.flow +31 -22
  146. package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +7 -13
  147. package/relay-hooks/useBlockingPaginationFragment.js.flow +14 -12
  148. package/relay-hooks/useEntryPointLoader.js.flow +8 -11
  149. package/relay-hooks/useFetchTrackingRef.js.flow +3 -3
  150. package/relay-hooks/useFragment.js.flow +31 -62
  151. package/relay-hooks/useFragmentNode.js.flow +6 -8
  152. package/relay-hooks/useIsMountedRef.js.flow +1 -1
  153. package/relay-hooks/useIsOperationNodeActive.js.flow +4 -6
  154. package/relay-hooks/useIsParentQueryActive.js.flow +4 -5
  155. package/relay-hooks/useLazyLoadQuery.js.flow +14 -16
  156. package/relay-hooks/useLazyLoadQueryNode.js.flow +20 -14
  157. package/relay-hooks/useLoadMoreFunction.js.flow +21 -30
  158. package/relay-hooks/useMemoOperationDescriptor.js.flow +6 -8
  159. package/relay-hooks/useMemoVariables.js.flow +7 -7
  160. package/relay-hooks/useMutation.js.flow +27 -27
  161. package/relay-hooks/usePaginationFragment.js.flow +39 -45
  162. package/relay-hooks/usePreloadedQuery.js.flow +14 -20
  163. package/relay-hooks/useQueryLoader.js.flow +42 -23
  164. package/relay-hooks/useRefetchableFragment.js.flow +8 -9
  165. package/relay-hooks/useRefetchableFragmentNode.js.flow +25 -33
  166. package/relay-hooks/useRelayEnvironment.js.flow +3 -5
  167. package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -4
  168. package/relay-hooks/useSubscribeToInvalidationState.js.flow +4 -7
  169. package/relay-hooks/useSubscription.js.flow +21 -11
  170. package/lib/relay-hooks/getPaginationMetadata.js +0 -41
  171. package/lib/relay-hooks/getPaginationVariables.js +0 -67
  172. package/lib/relay-hooks/getRefetchMetadata.js +0 -36
  173. package/lib/relay-hooks/getValueAtPath.js +0 -51
  174. package/relay-hooks/getPaginationMetadata.js.flow +0 -74
  175. package/relay-hooks/getPaginationVariables.js.flow +0 -110
  176. package/relay-hooks/getRefetchMetadata.js.flow +0 -80
  177. package/relay-hooks/getValueAtPath.js.flow +0 -46
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -11,37 +11,35 @@
11
11
 
12
12
  'use strict';
13
13
 
14
- const React = require('react');
15
-
16
- const invariant = require('invariant');
17
- const warning = require('warning');
18
-
19
- const {
20
- PreloadableQueryRegistry,
21
- ReplaySubject,
22
- createOperationDescriptor,
23
- getRequest,
24
- getRequestIdentifier,
25
- Observable,
26
- RelayFeatureFlags,
27
- __internal: {fetchQueryDeduped},
28
- } = require('relay-runtime');
29
-
30
14
  import type {
15
+ LoadQueryOptions,
31
16
  PreloadableConcreteRequest,
32
17
  PreloadedQueryInner,
33
- LoadQueryOptions,
34
18
  } from './EntryPointTypes.flow';
35
19
  import type {
20
+ GraphQLResponse,
21
+ GraphQLTaggedNode,
36
22
  IEnvironment,
37
23
  OperationDescriptor,
38
24
  OperationType,
39
- GraphQLTaggedNode,
40
- GraphQLResponse,
41
25
  RequestIdentifier,
42
26
  RequestParameters,
43
27
  } from 'relay-runtime';
44
28
 
29
+ const invariant = require('invariant');
30
+ const React = require('react');
31
+ const {
32
+ Observable,
33
+ PreloadableQueryRegistry,
34
+ RelayFeatureFlags,
35
+ ReplaySubject,
36
+ __internal: {fetchQueryDeduped},
37
+ createOperationDescriptor,
38
+ getRequest,
39
+ getRequestIdentifier,
40
+ } = require('relay-runtime');
41
+ const warning = require('warning');
42
+
45
43
  let RenderDispatcher = null;
46
44
  let fetchKey = 100001;
47
45
 
@@ -59,7 +57,7 @@ function useTrackLoadQueryInRender() {
59
57
  function loadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
60
58
  environment: IEnvironment,
61
59
  preloadableRequest: GraphQLTaggedNode | PreloadableConcreteRequest<TQuery>,
62
- variables: $ElementType<TQuery, 'variables'>,
60
+ variables: TQuery['variables'],
63
61
  options?: ?LoadQueryOptions,
64
62
  environmentProviderOptions?: ?TEnvironmentProviderOptions,
65
63
  ): PreloadedQueryInner<TQuery, TEnvironmentProviderOptions> {
@@ -274,7 +272,8 @@ function loadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
274
272
  let cancelOnLoadCallback;
275
273
  let queryId;
276
274
  if (preloadableRequest.kind === 'PreloadableConcreteRequest') {
277
- const preloadableConcreteRequest: PreloadableConcreteRequest<TQuery> = (preloadableRequest: $FlowFixMe);
275
+ const preloadableConcreteRequest: PreloadableConcreteRequest<TQuery> =
276
+ (preloadableRequest: $FlowFixMe);
278
277
  ({params} = preloadableConcreteRequest);
279
278
 
280
279
  ({id: queryId} = params);
@@ -298,8 +297,8 @@ function loadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
298
297
  // store in the first place, so it couldn't have been cached.
299
298
  const networkObservable =
300
299
  fetchPolicy === 'store-only' ? null : makeNetworkRequest(params);
300
+ // $FlowFixMe[method-unbinding] added when improving typing for this parameters
301
301
  ({dispose: cancelOnLoadCallback} = PreloadableQueryRegistry.onLoad(
302
- // $FlowFixMe[incompatible-call]
303
302
  queryId,
304
303
  preloadedModule => {
305
304
  cancelOnLoadCallback();
@@ -318,7 +317,8 @@ function loadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
318
317
  ));
319
318
  }
320
319
  } else {
321
- const graphQlTaggedNode: GraphQLTaggedNode = (preloadableRequest: $FlowFixMe);
320
+ const graphQlTaggedNode: GraphQLTaggedNode =
321
+ (preloadableRequest: $FlowFixMe);
322
322
  const request = getRequest(graphQlTaggedNode);
323
323
  params = request.params;
324
324
  queryId = params.cacheID != null ? params.cacheID : params.id;
@@ -326,6 +326,27 @@ function loadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
326
326
  }
327
327
 
328
328
  let isDisposed = false;
329
+ let isReleased = false;
330
+ let isNetworkRequestCancelled = false;
331
+ const releaseQuery = () => {
332
+ if (isReleased) {
333
+ return;
334
+ }
335
+ retainReference && retainReference.dispose();
336
+ isReleased = true;
337
+ };
338
+ const cancelNetworkRequest = () => {
339
+ if (isNetworkRequestCancelled) {
340
+ return;
341
+ }
342
+ if (didExecuteNetworkSource) {
343
+ unsubscribeFromExecution && unsubscribeFromExecution();
344
+ } else {
345
+ unsubscribeFromNetworkRequest && unsubscribeFromNetworkRequest();
346
+ }
347
+ cancelOnLoadCallback && cancelOnLoadCallback();
348
+ isNetworkRequestCancelled = true;
349
+ };
329
350
  return {
330
351
  kind: 'PreloadedQuery',
331
352
  environment,
@@ -334,20 +355,17 @@ function loadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
334
355
  if (isDisposed) {
335
356
  return;
336
357
  }
337
- if (didExecuteNetworkSource) {
338
- unsubscribeFromExecution && unsubscribeFromExecution();
339
- } else {
340
- unsubscribeFromNetworkRequest && unsubscribeFromNetworkRequest();
341
- }
342
- retainReference && retainReference.dispose();
343
- cancelOnLoadCallback && cancelOnLoadCallback();
358
+ releaseQuery();
359
+ cancelNetworkRequest();
344
360
  isDisposed = true;
345
361
  },
362
+ releaseQuery,
363
+ cancelNetworkRequest,
346
364
  fetchKey,
347
365
  id: queryId,
348
366
  // $FlowFixMe[unsafe-getters-setters] - this has no side effects
349
367
  get isDisposed() {
350
- return isDisposed;
368
+ return isDisposed || isReleased;
351
369
  },
352
370
  // $FlowFixMe[unsafe-getters-setters] - this has no side effects
353
371
  get networkError() {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -13,18 +13,6 @@
13
13
 
14
14
  'use strict';
15
15
 
16
- const invariant = require('invariant');
17
-
18
- const {
19
- createOperationDescriptor,
20
- Environment,
21
- getRequest,
22
- getRequestIdentifier,
23
- Observable,
24
- PreloadableQueryRegistry,
25
- ReplaySubject,
26
- } = require('relay-runtime');
27
-
28
16
  import type {
29
17
  PreloadableConcreteRequest,
30
18
  PreloadedQueryInner_DEPRECATED,
@@ -42,6 +30,16 @@ import type {
42
30
  Subscription,
43
31
  } from 'relay-runtime';
44
32
 
33
+ const {
34
+ Observable,
35
+ PreloadableQueryRegistry,
36
+ RelayFeatureFlags,
37
+ ReplaySubject,
38
+ createOperationDescriptor,
39
+ getRequest,
40
+ getRequestIdentifier,
41
+ } = require('relay-runtime');
42
+
45
43
  // Expire results by this delay after they resolve.
46
44
  const DEFAULT_PREFETCH_TIMEOUT = 30 * 1000; // 30 seconds
47
45
 
@@ -81,10 +79,6 @@ function preloadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
81
79
  options?: ?PreloadOptions,
82
80
  environmentProviderOptions?: ?TEnvironmentProviderOptions,
83
81
  ): PreloadedQueryInner_DEPRECATED<TQuery, TEnvironmentProviderOptions> {
84
- invariant(
85
- environment instanceof Environment,
86
- 'preloadQuery(): Expected a RelayModernEnvironment',
87
- );
88
82
  let _pendingQueries = pendingQueriesByEnvironment.get(environment);
89
83
  if (_pendingQueries == null) {
90
84
  _pendingQueries = new Map();
@@ -118,7 +112,23 @@ function preloadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
118
112
  }
119
113
  return () => {
120
114
  subscription?.unsubscribe();
121
- cleanup(pendingQueries, queryEntry);
115
+ if (environment.isServer()) {
116
+ return;
117
+ }
118
+ if (
119
+ RelayFeatureFlags.DELAY_CLEANUP_OF_PENDING_PRELOAD_QUERIES ===
120
+ true
121
+ ) {
122
+ setTimeout(() => {
123
+ // Clear the cache entry after the default timeout
124
+ // null-check for Flow
125
+ if (queryEntry != null) {
126
+ cleanup(pendingQueries, queryEntry);
127
+ }
128
+ }, DEFAULT_PREFETCH_TIMEOUT);
129
+ } else {
130
+ cleanup(pendingQueries, queryEntry);
131
+ }
122
132
  };
123
133
  })
124
134
  : null;
@@ -138,7 +148,7 @@ function preloadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
138
148
  }
139
149
 
140
150
  function preloadQueryDeduped<TQuery: OperationType>(
141
- environment: Environment,
151
+ environment: IEnvironment,
142
152
  pendingQueries: Map<string, PendingQueryEntry>,
143
153
  preloadableRequest: GraphQLTaggedNode | PreloadableConcreteRequest<TQuery>,
144
154
  variables: VariablesOf<TQuery>,
@@ -147,7 +157,8 @@ function preloadQueryDeduped<TQuery: OperationType>(
147
157
  let params;
148
158
  let query: ?ConcreteRequest;
149
159
  if (preloadableRequest.kind === 'PreloadableConcreteRequest') {
150
- const preloadableConcreteRequest: PreloadableConcreteRequest<TQuery> = (preloadableRequest: $FlowFixMe);
160
+ const preloadableConcreteRequest: PreloadableConcreteRequest<TQuery> =
161
+ (preloadableRequest: $FlowFixMe);
151
162
  params = preloadableConcreteRequest.params;
152
163
  query = params.id != null ? PreloadableQueryRegistry.get(params.id) : null;
153
164
  } else {
@@ -245,9 +256,7 @@ function preloadQueryDeduped<TQuery: OperationType>(
245
256
  } else {
246
257
  nextQueryEntry = prevQueryEntry;
247
258
  }
248
- // $FlowFixMe[incompatible-call]
249
259
  pendingQueries.set(cacheKey, nextQueryEntry);
250
- // $FlowFixMe[incompatible-return]
251
260
  return nextQueryEntry;
252
261
  }
253
262
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -13,8 +13,6 @@
13
13
 
14
14
  'use strict';
15
15
 
16
- const preloadQuery = require('./preloadQuery_DEPRECATED');
17
-
18
16
  import type {
19
17
  EntryPoint,
20
18
  EntryPointComponent,
@@ -22,6 +20,8 @@ import type {
22
20
  IEnvironmentProvider,
23
21
  } from './EntryPointTypes.flow';
24
22
 
23
+ const preloadQuery = require('./preloadQuery_DEPRECATED');
24
+
25
25
  function prepareEntryPoint<
26
26
  TEntryPointParams: {...},
27
27
  TPreloadedQueries: {...},
@@ -51,12 +51,8 @@ function prepareEntryPoint<
51
51
  if (queries != null) {
52
52
  const queriesPropNames = Object.keys(queries);
53
53
  queriesPropNames.forEach(queryPropName => {
54
- const {
55
- environmentProviderOptions,
56
- options,
57
- parameters,
58
- variables,
59
- } = queries[queryPropName];
54
+ const {environmentProviderOptions, options, parameters, variables} =
55
+ queries[queryPropName];
60
56
 
61
57
  const environment = environmentProvider.getEnvironment(
62
58
  environmentProviderOptions,
@@ -79,10 +75,8 @@ function prepareEntryPoint<
79
75
  if (entryPointDescription == null) {
80
76
  return;
81
77
  }
82
- const {
83
- entryPoint: nestedEntryPoint,
84
- entryPointParams: nestedParams,
85
- } = entryPointDescription;
78
+ const {entryPoint: nestedEntryPoint, entryPointParams: nestedParams} =
79
+ entryPointDescription;
86
80
  preloadedEntryPoints[entryPointPropName] = prepareEntryPoint(
87
81
  environmentProvider,
88
82
  nestedEntryPoint,
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -13,25 +13,27 @@
13
13
 
14
14
  'use strict';
15
15
 
16
- const getPaginationMetadata = require('./getPaginationMetadata');
17
- const invariant = require('invariant');
18
- const useLoadMoreFunction = require('./useLoadMoreFunction');
19
- const useRefetchableFragmentNode = require('./useRefetchableFragmentNode');
20
- const useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
21
-
22
- const {useCallback, useEffect, useRef, useState} = require('react');
23
- const {getFragment, getFragmentIdentifier} = require('relay-runtime');
24
-
25
16
  import type {LoadMoreFn, UseLoadMoreFunctionArgs} from './useLoadMoreFunction';
26
17
  import type {RefetchFnDynamic} from './useRefetchableFragmentNode';
27
18
  import type {
28
- FragmentReference,
19
+ FragmentType,
29
20
  GraphQLResponse,
30
21
  GraphQLTaggedNode,
31
22
  Observer,
32
23
  OperationType,
33
24
  } from 'relay-runtime';
34
25
 
26
+ const useLoadMoreFunction = require('./useLoadMoreFunction');
27
+ const useRefetchableFragmentNode = require('./useRefetchableFragmentNode');
28
+ const useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
29
+ const invariant = require('invariant');
30
+ const {useCallback, useEffect, useRef, useState} = require('react');
31
+ const {
32
+ getFragment,
33
+ getFragmentIdentifier,
34
+ getPaginationMetadata,
35
+ } = require('relay-runtime');
36
+
35
37
  export type ReturnType<TQuery: OperationType, TKey, TFragmentData> = {|
36
38
  data: TFragmentData,
37
39
  loadNext: LoadMoreFn<TQuery>,
@@ -43,7 +45,7 @@ export type ReturnType<TQuery: OperationType, TKey, TFragmentData> = {|
43
45
 
44
46
  function useBlockingPaginationFragment<
45
47
  TQuery: OperationType,
46
- TKey: ?{+$data?: mixed, +$fragmentRefs: FragmentReference, ...},
48
+ TKey: ?{+$data?: mixed, +$fragmentSpreads: FragmentType, ...},
47
49
  >(
48
50
  fragmentInput: GraphQLTaggedNode,
49
51
  parentFragmentRef: TKey,
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -13,12 +13,6 @@
13
13
 
14
14
  'use strict';
15
15
 
16
- const loadEntryPoint = require('./loadEntryPoint');
17
- const useIsMountedRef = require('./useIsMountedRef');
18
-
19
- const {useTrackLoadQueryInRender} = require('./loadQuery');
20
- const {useCallback, useEffect, useRef, useState} = require('react');
21
-
22
16
  import type {
23
17
  EntryPoint,
24
18
  EntryPointComponent,
@@ -27,6 +21,11 @@ import type {
27
21
  PreloadedEntryPoint,
28
22
  } from './EntryPointTypes.flow';
29
23
 
24
+ const loadEntryPoint = require('./loadEntryPoint');
25
+ const {useTrackLoadQueryInRender} = require('./loadQuery');
26
+ const useIsMountedRef = require('./useIsMountedRef');
27
+ const {useCallback, useEffect, useRef, useState} = require('react');
28
+
30
29
  type UseEntryPointLoaderHookReturnType<
31
30
  TEntryPointParams: {...},
32
31
  TPreloadedQueries: {...},
@@ -121,10 +120,8 @@ function useLoadEntryPoint<
121
120
  const [entryPointReference, setEntryPointReference] = useState<
122
121
  PreloadedEntryPoint<TEntryPointComponent> | NullEntryPointReference,
123
122
  >(initialEntryPointReferenceInternal);
124
- const [
125
- entryPointParams,
126
- setEntryPointParams,
127
- ] = useState<TEntryPointParams | null>(initialEntryPointParamsInternal);
123
+ const [entryPointParams, setEntryPointParams] =
124
+ useState<TEntryPointParams | null>(initialEntryPointParamsInternal);
128
125
 
129
126
  const disposeEntryPoint = useCallback(() => {
130
127
  if (isMountedRef.current) {
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -13,10 +13,10 @@
13
13
 
14
14
  'use strict';
15
15
 
16
- const {useCallback, useEffect, useRef} = require('react');
17
-
18
16
  import type {Subscription} from 'relay-runtime';
19
17
 
18
+ const {useCallback, useEffect, useRef} = require('react');
19
+
20
20
  /**
21
21
  * This hook returns a mutable React ref that holds the value of whether a
22
22
  * fetch request is in flight. The reason this is a mutable ref instead of
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -13,82 +13,51 @@
13
13
 
14
14
  'use strict';
15
15
 
16
- const useFragmentNode = require('./useFragmentNode');
17
- const useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
16
+ import type {Fragment, FragmentType, GraphQLTaggedNode} from 'relay-runtime';
18
17
 
19
18
  const {useTrackLoadQueryInRender} = require('./loadQuery');
19
+ const useFragmentNode = require('./useFragmentNode');
20
+ const useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
20
21
  const {useDebugValue} = require('react');
21
22
  const {getFragment} = require('relay-runtime');
22
23
 
23
- import type {GraphQLTaggedNode, FragmentReference} from 'relay-runtime';
24
-
25
- // NOTE: These declares ensure that the type of the returned data is:
26
- // - non-nullable if the provided ref type is non-nullable
27
- // - nullable if the provided ref type is nullable
28
- // - array of non-nullable if the privoided ref type is an array of
29
- // non-nullable refs
30
- // - array of nullable if the privoided ref type is an array of nullable refs
24
+ type HasSpread<TFragmentType> = {
25
+ +$fragmentSpreads: TFragmentType,
26
+ ...
27
+ };
31
28
 
32
- declare function useFragment<
33
- TKey: {+$data?: mixed, +$fragmentRefs: FragmentReference, ...},
34
- >(
35
- fragmentInput: GraphQLTaggedNode,
36
- fragmentRef: TKey,
37
- ): $Call<<TFragmentData>({+$data?: TFragmentData, ...}) => TFragmentData, TKey>;
29
+ // if the key is non-nullable, return non-nullable value
30
+ declare function useFragment<TFragmentType: FragmentType, TData>(
31
+ fragment: Fragment<TFragmentType, TData>,
32
+ key: HasSpread<TFragmentType>,
33
+ ): TData;
38
34
 
39
- declare function useFragment<
40
- TKey: ?{+$data?: mixed, +$fragmentRefs: FragmentReference, ...},
41
- >(
42
- fragmentInput: GraphQLTaggedNode,
43
- fragmentRef: TKey,
44
- ): $Call<
45
- <TFragmentData>(?{+$data?: TFragmentData, ...}) => ?TFragmentData,
46
- TKey,
47
- >;
35
+ // if the key is nullable, return nullable value
36
+ declare function useFragment<TFragmentType: FragmentType, TData>(
37
+ fragment: Fragment<TFragmentType, TData>,
38
+ key: ?HasSpread<TFragmentType>,
39
+ ): ?TData;
48
40
 
49
- declare function useFragment<
50
- TKey: $ReadOnlyArray<{
51
- +$data?: mixed,
52
- +$fragmentRefs: FragmentReference,
53
- ...
54
- }>,
55
- >(
56
- fragmentInput: GraphQLTaggedNode,
57
- fragmentRef: TKey,
58
- ): $Call<
59
- <TFragmentData>(
60
- $ReadOnlyArray<{+$data?: TFragmentData, ...}>,
61
- ) => TFragmentData,
62
- TKey,
63
- >;
41
+ // if the key is a non-nullable array of keys, return non-nullable array
42
+ declare function useFragment<TFragmentType: FragmentType, TData>(
43
+ fragment: Fragment<TFragmentType, TData>,
44
+ key: $ReadOnlyArray<HasSpread<TFragmentType>>,
45
+ ): TData;
64
46
 
65
- declare function useFragment<
66
- TKey: ?$ReadOnlyArray<{
67
- +$data?: mixed,
68
- +$fragmentRefs: FragmentReference,
69
- ...
70
- }>,
71
- >(
72
- fragmentInput: GraphQLTaggedNode,
73
- fragmentRef: TKey,
74
- ): $Call<
75
- <TFragmentData>(
76
- ?$ReadOnlyArray<{+$data?: TFragmentData, ...}>,
77
- ) => ?TFragmentData,
78
- TKey,
79
- >;
47
+ // if the key is a nullable array of keys, return nullable array
48
+ declare function useFragment<TFragmentType: FragmentType, TData>(
49
+ fragment: Fragment<TFragmentType, TData>,
50
+ key: ?$ReadOnlyArray<HasSpread<TFragmentType>>,
51
+ ): ?TData;
80
52
 
81
- function useFragment(
82
- fragmentInput: GraphQLTaggedNode,
83
- fragmentRef: mixed,
84
- ): mixed {
53
+ function useFragment(fragment: GraphQLTaggedNode, key: mixed): mixed {
85
54
  // We need to use this hook in order to be able to track if
86
55
  // loadQuery was called during render
87
56
  useTrackLoadQueryInRender();
88
57
 
89
- const fragmentNode = getFragment(fragmentInput);
58
+ const fragmentNode = getFragment(fragment);
90
59
  useStaticFragmentNodeWarning(fragmentNode, 'first argument of useFragment()');
91
- const {data} = useFragmentNode<_>(fragmentNode, fragmentRef, 'useFragment()');
60
+ const {data} = useFragmentNode<_>(fragmentNode, key, 'useFragment()');
92
61
  if (__DEV__) {
93
62
  // eslint-disable-next-line react-hooks/rules-of-hooks
94
63
  useDebugValue({fragment: fragmentNode.name, data});
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -13,14 +13,13 @@
13
13
 
14
14
  'use strict';
15
15
 
16
- const useRelayEnvironment = require('./useRelayEnvironment');
17
- const warning = require('warning');
16
+ import type {ReaderFragment} from 'relay-runtime';
18
17
 
19
18
  const {getFragmentResourceForEnvironment} = require('./FragmentResource');
19
+ const useRelayEnvironment = require('./useRelayEnvironment');
20
20
  const {useEffect, useRef, useState} = require('react');
21
21
  const {getFragmentIdentifier} = require('relay-runtime');
22
-
23
- import type {ReaderFragment} from 'relay-runtime';
22
+ const warning = require('warning');
24
23
 
25
24
  type ReturnType<TFragmentData: mixed> = {|
26
25
  data: TFragmentData,
@@ -51,9 +50,8 @@ function useFragmentNode<TFragmentData: mixed>(
51
50
  const isListeningForUpdatesRef = useRef(true);
52
51
  function enableStoreUpdates() {
53
52
  isListeningForUpdatesRef.current = true;
54
- const didMissUpdates = FragmentResource.checkMissedUpdates(
55
- fragmentResult,
56
- )[0];
53
+ const didMissUpdates =
54
+ FragmentResource.checkMissedUpdates(fragmentResult)[0];
57
55
  if (didMissUpdates) {
58
56
  handleDataUpdate();
59
57
  }
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -11,18 +11,16 @@
11
11
 
12
12
  'use strict';
13
13
 
14
- const React = require('react');
14
+ import type {ReaderFragment} from 'relay-runtime';
15
15
 
16
- const invariant = require('invariant');
17
16
  const useRelayEnvironment = require('./useRelayEnvironment');
18
-
17
+ const invariant = require('invariant');
18
+ const React = require('react');
19
19
  const {
20
20
  __internal: {getObservableForActiveRequest},
21
21
  getSelector,
22
22
  } = require('relay-runtime');
23
23
 
24
- import type {ReaderFragment} from 'relay-runtime';
25
-
26
24
  const {useEffect, useState, useMemo} = React;
27
25
 
28
26
  function useIsOperationNodeActive(
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Copyright (c) Facebook, Inc. and its affiliates.
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
3
  *
4
4
  * This source code is licensed under the MIT license found in the
5
5
  * LICENSE file in the root directory of this source tree.
@@ -11,15 +11,14 @@
11
11
 
12
12
  'use strict';
13
13
 
14
+ import type {FragmentType, GraphQLTaggedNode} from 'relay-runtime';
15
+
14
16
  const useIsOperationNodeActive = require('./useIsOperationNodeActive');
15
17
  const useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
16
-
17
18
  const {getFragment} = require('relay-runtime');
18
19
 
19
- import type {GraphQLTaggedNode, FragmentReference} from 'relay-runtime';
20
-
21
20
  function useIsParentQueryActive<
22
- TKey: ?{+$data?: mixed, +$fragmentRefs: FragmentReference, ...},
21
+ TKey: ?{+$data?: mixed, +$fragmentSpreads: FragmentType, ...},
23
22
  >(fragmentInput: GraphQLTaggedNode, fragmentRef: TKey): boolean {
24
23
  const fragmentNode = getFragment(fragmentInput);
25
24
  useStaticFragmentNodeWarning(