react-relay 13.1.1 → 14.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (178) hide show
  1. package/ReactRelayContainerUtils.js.flow +0 -2
  2. package/ReactRelayContext.js +1 -1
  3. package/ReactRelayContext.js.flow +0 -2
  4. package/ReactRelayFragmentContainer.js.flow +7 -6
  5. package/ReactRelayFragmentMockRenderer.js.flow +0 -2
  6. package/ReactRelayLocalQueryRenderer.js.flow +1 -3
  7. package/ReactRelayPaginationContainer.js.flow +13 -10
  8. package/ReactRelayQueryFetcher.js.flow +10 -11
  9. package/ReactRelayQueryRenderer.js.flow +15 -16
  10. package/ReactRelayQueryRendererContext.js.flow +1 -3
  11. package/ReactRelayRefetchContainer.js.flow +10 -7
  12. package/ReactRelayTestMocker.js.flow +0 -2
  13. package/ReactRelayTypes.js.flow +6 -8
  14. package/RelayContext.js.flow +0 -2
  15. package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +2 -4
  16. package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +3 -5
  17. package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +3 -5
  18. package/__flowtests__/RelayModern-flowtest.js.flow +2 -4
  19. package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +2 -4
  20. package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +2 -4
  21. package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +2 -4
  22. package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +2 -4
  23. package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +2 -2
  24. package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +2 -2
  25. package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +3 -3
  26. package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +3 -3
  27. package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +3 -3
  28. package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +3 -3
  29. package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +2 -2
  30. package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +2 -2
  31. package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +2 -2
  32. package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +2 -2
  33. package/assertFragmentMap.js.flow +0 -2
  34. package/buildReactRelayContainer.js.flow +2 -4
  35. package/getRootVariablesForFragments.js.flow +0 -2
  36. package/hooks.js +1 -1
  37. package/hooks.js.flow +0 -2
  38. package/index.js +1 -1
  39. package/index.js.flow +2 -2
  40. package/isRelayEnvironment.js.flow +0 -2
  41. package/jest-react/internalAct.js.flow +25 -9
  42. package/legacy.js +1 -1
  43. package/legacy.js.flow +0 -2
  44. package/lib/ReactRelayContainerUtils.js +0 -1
  45. package/lib/ReactRelayContext.js +0 -1
  46. package/lib/ReactRelayFragmentContainer.js +10 -9
  47. package/lib/ReactRelayFragmentMockRenderer.js +0 -1
  48. package/lib/ReactRelayLocalQueryRenderer.js +0 -1
  49. package/lib/ReactRelayPaginationContainer.js +14 -11
  50. package/lib/ReactRelayQueryFetcher.js +2 -2
  51. package/lib/ReactRelayQueryRenderer.js +2 -4
  52. package/lib/ReactRelayQueryRendererContext.js +0 -1
  53. package/lib/ReactRelayRefetchContainer.js +11 -14
  54. package/lib/ReactRelayTestMocker.js +1 -2
  55. package/lib/ReactRelayTypes.js +0 -1
  56. package/lib/RelayContext.js +0 -1
  57. package/lib/assertFragmentMap.js +0 -1
  58. package/lib/buildReactRelayContainer.js +1 -2
  59. package/lib/getRootVariablesForFragments.js +1 -2
  60. package/lib/hooks.js +0 -1
  61. package/lib/index.js +3 -1
  62. package/lib/isRelayEnvironment.js +0 -1
  63. package/lib/jest-react/internalAct.js +24 -4
  64. package/lib/legacy.js +0 -1
  65. package/lib/multi-actor/useRelayActorEnvironment.js +0 -1
  66. package/lib/readContext.js +2 -2
  67. package/lib/relay-hooks/EntryPointContainer.react.js +0 -1
  68. package/lib/relay-hooks/EntryPointTypes.flow.js +0 -1
  69. package/lib/relay-hooks/FragmentResource.js +68 -29
  70. package/lib/relay-hooks/HooksImplementation.js +29 -0
  71. package/lib/relay-hooks/InternalLogger.js +0 -1
  72. package/lib/relay-hooks/LRUCache.js +0 -1
  73. package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +0 -1
  74. package/lib/relay-hooks/MatchContainer.js +2 -2
  75. package/lib/relay-hooks/ProfilerContext.js +0 -1
  76. package/lib/relay-hooks/QueryResource.js +5 -168
  77. package/lib/relay-hooks/RelayEnvironmentProvider.js +0 -1
  78. package/lib/relay-hooks/SuspenseResource.js +1 -2
  79. package/lib/relay-hooks/loadQuery.js +1 -1
  80. package/lib/relay-hooks/preloadQuery_DEPRECATED.js +8 -13
  81. package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +0 -1
  82. package/lib/relay-hooks/react-cache/RelayReactCache.js +36 -0
  83. package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +344 -0
  84. package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +239 -0
  85. package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +598 -0
  86. package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +50 -0
  87. package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +55 -0
  88. package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +150 -0
  89. package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +124 -0
  90. package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +367 -0
  91. package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +45 -0
  92. package/lib/relay-hooks/useBlockingPaginationFragment.js +4 -3
  93. package/lib/relay-hooks/useClientQuery.js +33 -0
  94. package/lib/relay-hooks/useEntryPointLoader.js +1 -2
  95. package/lib/relay-hooks/useFetchTrackingRef.js +0 -1
  96. package/lib/relay-hooks/useFragment.js +15 -2
  97. package/lib/relay-hooks/useFragmentNode.js +0 -1
  98. package/lib/relay-hooks/useIsMountedRef.js +0 -1
  99. package/lib/relay-hooks/useLazyLoadQuery.js +4 -2
  100. package/lib/relay-hooks/useLazyLoadQueryNode.js +0 -1
  101. package/lib/relay-hooks/useLoadMoreFunction.js +1 -2
  102. package/lib/relay-hooks/useMemoOperationDescriptor.js +0 -1
  103. package/lib/relay-hooks/useMemoVariables.js +0 -1
  104. package/lib/relay-hooks/useMutation.js +5 -7
  105. package/lib/relay-hooks/usePaginationFragment.js +15 -3
  106. package/lib/relay-hooks/usePreloadedQuery.js +4 -2
  107. package/lib/relay-hooks/useQueryLoader.js +1 -2
  108. package/lib/relay-hooks/useRefetchableFragment.js +14 -2
  109. package/lib/relay-hooks/useRefetchableFragmentNode.js +1 -2
  110. package/lib/relay-hooks/useRelayEnvironment.js +0 -1
  111. package/lib/relay-hooks/useStaticFragmentNodeWarning.js +0 -1
  112. package/lib/relay-hooks/useSubscribeToInvalidationState.js +0 -1
  113. package/lib/relay-hooks/useSubscription.js +0 -1
  114. package/multi-actor/useRelayActorEnvironment.js.flow +0 -2
  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 -2
  123. package/relay-hooks/EntryPointContainer.react.js.flow +2 -4
  124. package/relay-hooks/EntryPointTypes.flow.js.flow +30 -32
  125. package/relay-hooks/FragmentResource.js.flow +80 -37
  126. package/relay-hooks/HooksImplementation.js.flow +43 -0
  127. package/relay-hooks/InternalLogger.js.flow +0 -2
  128. package/relay-hooks/LRUCache.js.flow +0 -2
  129. package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +4 -6
  130. package/relay-hooks/MatchContainer.js.flow +11 -6
  131. package/relay-hooks/ProfilerContext.js.flow +0 -2
  132. package/relay-hooks/QueryResource.js.flow +12 -209
  133. package/relay-hooks/RelayEnvironmentProvider.js.flow +2 -4
  134. package/relay-hooks/SuspenseResource.js.flow +0 -2
  135. package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +3 -3
  136. package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +2 -2
  137. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +2 -2
  138. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +2 -2
  139. package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +4 -6
  140. package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +0 -2
  141. package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +4 -6
  142. package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +0 -2
  143. package/relay-hooks/__flowtests__/utils.js.flow +8 -10
  144. package/relay-hooks/loadQuery.js.flow +2 -1
  145. package/relay-hooks/preloadQuery_DEPRECATED.js.flow +11 -20
  146. package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +0 -2
  147. package/relay-hooks/react-cache/RelayReactCache.js.flow +40 -0
  148. package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +430 -0
  149. package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +297 -0
  150. package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +599 -0
  151. package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +72 -0
  152. package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +70 -0
  153. package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +171 -0
  154. package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +151 -0
  155. package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +595 -0
  156. package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +65 -0
  157. package/relay-hooks/useBlockingPaginationFragment.js.flow +4 -6
  158. package/relay-hooks/useClientQuery.js.flow +39 -0
  159. package/relay-hooks/useEntryPointLoader.js.flow +6 -8
  160. package/relay-hooks/useFetchTrackingRef.js.flow +2 -4
  161. package/relay-hooks/useFragment.js.flow +17 -12
  162. package/relay-hooks/useFragmentNode.js.flow +2 -4
  163. package/relay-hooks/useIsMountedRef.js.flow +1 -3
  164. package/relay-hooks/useLazyLoadQuery.js.flow +17 -5
  165. package/relay-hooks/useLazyLoadQueryNode.js.flow +2 -4
  166. package/relay-hooks/useLoadMoreFunction.js.flow +6 -8
  167. package/relay-hooks/useMemoOperationDescriptor.js.flow +0 -2
  168. package/relay-hooks/useMemoVariables.js.flow +0 -2
  169. package/relay-hooks/useMutation.js.flow +5 -7
  170. package/relay-hooks/usePaginationFragment.js.flow +44 -19
  171. package/relay-hooks/usePreloadedQuery.js.flow +14 -5
  172. package/relay-hooks/useQueryLoader.js.flow +4 -6
  173. package/relay-hooks/useRefetchableFragment.js.flow +32 -3
  174. package/relay-hooks/useRefetchableFragmentNode.js.flow +38 -25
  175. package/relay-hooks/useRelayEnvironment.js.flow +0 -2
  176. package/relay-hooks/useStaticFragmentNodeWarning.js.flow +0 -2
  177. package/relay-hooks/useSubscribeToInvalidationState.js.flow +0 -2
  178. package/relay-hooks/useSubscription.js.flow +14 -10
@@ -9,12 +9,11 @@
9
9
  * @format
10
10
  */
11
11
 
12
- // flowlint ambiguous-object-type:error
13
-
14
12
  'use strict';
15
13
 
16
14
  import type {LoaderFn} from './useQueryLoader';
17
15
  import type {
16
+ ConcreteRequest,
18
17
  Disposable,
19
18
  FetchPolicy,
20
19
  IEnvironment,
@@ -70,24 +69,24 @@ export type ReturnType<
70
69
  TQuery: OperationType,
71
70
  TKey: ?{+$data?: mixed, ...},
72
71
  TOptions = Options,
73
- > = {|
72
+ > = {
74
73
  fragmentData: mixed,
75
74
  fragmentRef: mixed,
76
75
  refetch: RefetchFnDynamic<TQuery, TKey, TOptions>,
77
76
  disableStoreUpdates: () => void,
78
77
  enableStoreUpdates: () => void,
79
- |};
78
+ };
80
79
 
81
- export type Options = {|
80
+ export type Options = {
82
81
  fetchPolicy?: FetchPolicy,
83
82
  onComplete?: (Error | null) => void,
84
83
  UNSTABLE_renderPolicy?: RenderPolicy,
85
- |};
84
+ };
86
85
 
87
- type InternalOptions = {|
86
+ type InternalOptions = {
88
87
  ...Options,
89
88
  __environment?: IEnvironment,
90
- |};
89
+ };
91
90
 
92
91
  type RefetchFnBase<TVars, TOptions> = (
93
92
  vars: TVars,
@@ -104,21 +103,21 @@ type RefetchFnInexact<
104
103
  > = RefetchFnBase<$Shape<VariablesOf<TQuery>>, TOptions>;
105
104
 
106
105
  type Action =
107
- | {|
106
+ | {
108
107
  type: 'reset',
109
108
  environment: IEnvironment,
110
109
  fragmentIdentifier: string,
111
- |}
112
- | {|
110
+ }
111
+ | {
113
112
  type: 'refetch',
114
113
  refetchQuery: OperationDescriptor,
115
114
  fetchPolicy?: FetchPolicy,
116
115
  renderPolicy?: RenderPolicy,
117
116
  onComplete?: (Error | null) => void,
118
117
  refetchEnvironment: ?IEnvironment,
119
- |};
118
+ };
120
119
 
121
- type RefetchState = {|
120
+ type RefetchState = {
122
121
  fetchPolicy: FetchPolicy | void,
123
122
  mirroredEnvironment: IEnvironment,
124
123
  mirroredFragmentIdentifier: string,
@@ -126,7 +125,7 @@ type RefetchState = {|
126
125
  refetchEnvironment?: ?IEnvironment,
127
126
  refetchQuery: OperationDescriptor | null,
128
127
  renderPolicy: RenderPolicy | void,
129
- |};
128
+ };
130
129
 
131
130
  type DebugIDandTypename = {
132
131
  id: string,
@@ -241,7 +240,7 @@ function useRefetchableFragmentNode<
241
240
  );
242
241
  }
243
242
 
244
- const handleQueryCompleted = maybeError => {
243
+ const handleQueryCompleted = (maybeError: void | Error) => {
245
244
  onComplete && onComplete(maybeError ?? null);
246
245
  };
247
246
 
@@ -358,17 +357,31 @@ function useRefetchableFragmentNode<
358
357
  }
359
358
 
360
359
  function useRefetchFunction<TQuery: OperationType>(
361
- componentDisplayName,
362
- dispatch,
363
- disposeQuery,
364
- fragmentData,
365
- fragmentIdentifier,
366
- fragmentNode,
367
- fragmentRefPathInResponse,
368
- identifierField,
360
+ componentDisplayName: string,
361
+ dispatch: (
362
+ | {
363
+ environment: IEnvironment,
364
+ fragmentIdentifier: string,
365
+ type: 'reset',
366
+ }
367
+ | {
368
+ fetchPolicy?: FetchPolicy,
369
+ onComplete?: (Error | null) => void,
370
+ refetchEnvironment: ?IEnvironment,
371
+ refetchQuery: OperationDescriptor,
372
+ renderPolicy?: RenderPolicy,
373
+ type: 'refetch',
374
+ },
375
+ ) => void,
376
+ disposeQuery: () => void,
377
+ fragmentData: mixed,
378
+ fragmentIdentifier: string,
379
+ fragmentNode: ReaderFragment,
380
+ fragmentRefPathInResponse: $ReadOnlyArray<string | number>,
381
+ identifierField: ?string,
369
382
  loadQuery: LoaderFn<TQuery>,
370
- parentFragmentRef,
371
- refetchableRequest,
383
+ parentFragmentRef: mixed,
384
+ refetchableRequest: ConcreteRequest,
372
385
  ): RefetchFn<TQuery, InternalOptions> {
373
386
  const isMountedRef = useIsMountedRef();
374
387
  const identifierValue =
@@ -9,8 +9,6 @@
9
9
  * @format
10
10
  */
11
11
 
12
- // flowlint ambiguous-object-type:error
13
-
14
12
  'use strict';
15
13
 
16
14
  import type {IEnvironment} from 'relay-runtime';
@@ -9,8 +9,6 @@
9
9
  * @format
10
10
  */
11
11
 
12
- // flowlint ambiguous-object-type:error
13
-
14
12
  'use strict';
15
13
 
16
14
  import type {ReaderFragment} from 'relay-runtime';
@@ -9,8 +9,6 @@
9
9
  * @format
10
10
  */
11
11
 
12
- // flowlint ambiguous-object-type:error
13
-
14
12
  'use strict';
15
13
 
16
14
  import type {DataID, Disposable} from 'relay-runtime';
@@ -8,35 +8,39 @@
8
8
  * @format
9
9
  */
10
10
 
11
- // flowlint ambiguous-object-type:error
12
-
13
11
  'use strict';
14
12
 
15
13
  import type {
16
14
  Disposable,
17
15
  GraphQLSubscriptionConfig,
18
16
  IEnvironment,
19
- SubscriptionParameters,
20
17
  } from 'relay-runtime';
21
18
 
22
19
  const useRelayEnvironment = require('./useRelayEnvironment');
23
20
  const {useEffect} = require('react');
24
21
  const {requestSubscription} = require('relay-runtime');
25
22
 
26
- type RequestSubscriptionFn<TSubscriptionParameters: SubscriptionParameters> = (
23
+ type RequestSubscriptionFn<TVariables, TData, TRawResponse> = (
27
24
  environment: IEnvironment,
28
- config: GraphQLSubscriptionConfig<TSubscriptionParameters>,
25
+ config: GraphQLSubscriptionConfig<TVariables, TData, TRawResponse>,
29
26
  ) => Disposable;
30
27
 
31
- function useSubscription<TSubscriptionParameters: SubscriptionParameters>(
32
- config: GraphQLSubscriptionConfig<TSubscriptionParameters>,
33
- requestSubscriptionFn?: RequestSubscriptionFn<TSubscriptionParameters>,
28
+ function useSubscription<TVariables, TData, TRawResponse>(
29
+ config: GraphQLSubscriptionConfig<TVariables, TData, TRawResponse>,
30
+ requestSubscriptionFn?: RequestSubscriptionFn<
31
+ TVariables,
32
+ TData,
33
+ TRawResponse,
34
+ >,
34
35
  ): void {
35
36
  // N.B. this will re-subscribe every render if config or requestSubscriptionFn
36
37
  // are not memoized.
37
38
  // Please do not pass an object defined in-line.
38
- const actualRequestSubscription: RequestSubscriptionFn<TSubscriptionParameters> =
39
- requestSubscriptionFn ?? (requestSubscription: $FlowFixMe);
39
+ const actualRequestSubscription: RequestSubscriptionFn<
40
+ TVariables,
41
+ TData,
42
+ TRawResponse,
43
+ > = requestSubscriptionFn ?? (requestSubscription: $FlowFixMe);
40
44
  const environment = useRelayEnvironment();
41
45
  useEffect(() => {
42
46
  // $FlowFixMe[method-unbinding] added when improving typing for this parameters