react-relay 16.2.0 → 17.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. package/ReactRelayContext.js +1 -1
  2. package/ReactRelayFragmentContainer.js.flow +8 -6
  3. package/ReactRelayLocalQueryRenderer.js.flow +4 -1
  4. package/ReactRelayPaginationContainer.js.flow +2 -0
  5. package/ReactRelayQueryRenderer.js.flow +1 -1
  6. package/buildReactRelayContainer.js.flow +5 -3
  7. package/getRootVariablesForFragments.js.flow +1 -0
  8. package/hooks.js +1 -1
  9. package/index.js +1 -1
  10. package/legacy.js +1 -1
  11. package/lib/ReactRelayFragmentContainer.js +2 -2
  12. package/lib/buildReactRelayContainer.js +3 -3
  13. package/lib/relay-hooks/legacy/FragmentResource.js +14 -16
  14. package/lib/relay-hooks/{experimental/readFragmentInternal_EXPERIMENTAL.js → readFragmentInternal.js} +7 -5
  15. package/lib/relay-hooks/useFragment.js +3 -13
  16. package/lib/relay-hooks/{experimental/useFragmentInternal_EXPERIMENTAL.js → useFragmentInternal.js} +9 -7
  17. package/lib/relay-hooks/useLazyLoadQueryNode.js +2 -13
  18. package/lib/relay-hooks/usePaginationFragment.js +17 -13
  19. package/lib/relay-hooks/useRefetchableFragment.js +3 -12
  20. package/lib/relay-hooks/{experimental/useRefetchableFragmentInternal_EXPERIMENTAL.js → useRefetchableFragmentInternal.js} +7 -7
  21. package/multi-actor/useRelayActorEnvironment.js.flow +1 -1
  22. package/package.json +2 -2
  23. package/react-relay-hooks.js +2 -2
  24. package/react-relay-hooks.min.js +2 -2
  25. package/react-relay-legacy.js +2 -2
  26. package/react-relay-legacy.min.js +2 -2
  27. package/react-relay.js +2 -2
  28. package/react-relay.min.js +2 -2
  29. package/relay-hooks/EntryPointTypes.flow.js.flow +14 -13
  30. package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +14 -1
  31. package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +21 -0
  32. package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +19 -0
  33. package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +22 -0
  34. package/relay-hooks/legacy/FragmentResource.js.flow +13 -16
  35. package/relay-hooks/legacy/useBlockingPaginationFragment.js.flow +2 -2
  36. package/relay-hooks/legacy/useFragmentNode.js.flow +1 -1
  37. package/relay-hooks/legacy/useRefetchableFragmentNode.js.flow +2 -2
  38. package/relay-hooks/loadQuery.js.flow +9 -8
  39. package/relay-hooks/{experimental/readFragmentInternal_EXPERIMENTAL.js.flow → readFragmentInternal.js.flow} +6 -4
  40. package/relay-hooks/useClientQuery.js.flow +1 -1
  41. package/relay-hooks/useEntryPointLoader.js.flow +1 -1
  42. package/relay-hooks/useFetchTrackingRef.js.flow +1 -1
  43. package/relay-hooks/useFragment.js.flow +8 -20
  44. package/relay-hooks/{experimental/useFragmentInternal_EXPERIMENTAL.js.flow → useFragmentInternal.js.flow} +14 -5
  45. package/relay-hooks/useIsMountedRef.js.flow +1 -1
  46. package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
  47. package/relay-hooks/useIsParentQueryActive.js.flow +5 -2
  48. package/relay-hooks/useLazyLoadQuery.js.flow +3 -2
  49. package/relay-hooks/useLazyLoadQueryNode.js.flow +3 -19
  50. package/relay-hooks/useLoadMoreFunction.js.flow +1 -1
  51. package/relay-hooks/useMemoOperationDescriptor.js.flow +1 -1
  52. package/relay-hooks/useMemoVariables.js.flow +1 -1
  53. package/relay-hooks/useMutation.js.flow +1 -1
  54. package/relay-hooks/usePaginationFragment.js.flow +62 -50
  55. package/relay-hooks/usePreloadedQuery.js.flow +2 -1
  56. package/relay-hooks/useQueryLoader.js.flow +2 -5
  57. package/relay-hooks/useRefetchableFragment.js.flow +7 -37
  58. package/relay-hooks/{experimental/useRefetchableFragmentInternal_EXPERIMENTAL.js.flow → useRefetchableFragmentInternal.js.flow} +11 -11
  59. package/relay-hooks/useRelayEnvironment.js.flow +1 -1
  60. package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -1
  61. package/relay-hooks/useSubscribeToInvalidationState.js.flow +1 -1
  62. package/relay-hooks/useSubscription.js.flow +1 -1
  63. package/relay-hooks/useUnsafeRef_DEPRECATED.js.flow +1 -1
  64. package/lib/relay-hooks/HooksImplementation.js +0 -15
  65. package/lib/relay-hooks/experimental/useFragment_EXPERIMENTAL.js +0 -26
  66. package/lib/relay-hooks/experimental/usePaginationFragment_EXPERIMENTAL.js +0 -127
  67. package/lib/relay-hooks/experimental/useRefetchableFragment_EXPERIMENTAL.js +0 -23
  68. package/relay-hooks/HooksImplementation.js.flow +0 -45
  69. package/relay-hooks/experimental/useFragment_EXPERIMENTAL.js.flow +0 -72
  70. package/relay-hooks/experimental/usePaginationFragment_EXPERIMENTAL.js.flow +0 -161
  71. package/relay-hooks/experimental/useRefetchableFragment_EXPERIMENTAL.js.flow +0 -49
@@ -11,10 +11,10 @@
11
11
 
12
12
  'use strict';
13
13
 
14
- import type {Options} from './legacy/useRefetchableFragmentNode';
15
14
  import type {LoadMoreFn, UseLoadMoreFunctionArgs} from './useLoadMoreFunction';
16
- import type {RefetchFn} from './useRefetchableFragment';
15
+ import type {Options} from './useRefetchableFragmentInternal';
17
16
  import type {
17
+ Disposable,
18
18
  FragmentType,
19
19
  GraphQLResponse,
20
20
  Observer,
@@ -22,9 +22,9 @@ import type {
22
22
  Variables,
23
23
  } from 'relay-runtime';
24
24
 
25
- const HooksImplementation = require('./HooksImplementation');
26
- const useRefetchableFragmentNode = require('./legacy/useRefetchableFragmentNode');
27
25
  const useLoadMoreFunction = require('./useLoadMoreFunction');
26
+ const useRefetchableFragmentInternal = require('./useRefetchableFragmentInternal');
27
+ const useRelayEnvironment = require('./useRelayEnvironment');
28
28
  const useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
29
29
  const {useCallback, useDebugValue, useState} = require('react');
30
30
  const {
@@ -33,6 +33,40 @@ const {
33
33
  getPaginationMetadata,
34
34
  } = require('relay-runtime');
35
35
 
36
+ type RefetchVariables<TVariables, TKey: ?{+$fragmentSpreads: mixed, ...}> =
37
+ // NOTE: This type ensures that the type of the returned variables is either:
38
+ // - nullable if the provided ref type is nullable
39
+ // - non-nullable if the provided ref type is non-nullable
40
+ [+key: TKey] extends [+key: {+$fragmentSpreads: mixed, ...}]
41
+ ? Partial<TVariables>
42
+ : TVariables;
43
+
44
+ type RefetchFnBase<TVars, TOptions> = (
45
+ vars: TVars,
46
+ options?: TOptions,
47
+ ) => Disposable;
48
+
49
+ type RefetchFn<TVariables, TKey, TOptions = Options> = RefetchFnBase<
50
+ RefetchVariables<TVariables, TKey>,
51
+ TOptions,
52
+ >;
53
+
54
+ export type ReturnType<TVariables, TData, TKey> = {
55
+ // NOTE: This type ensures that the type of the returned data is either:
56
+ // - nullable if the provided ref type is nullable
57
+ // - non-nullable if the provided ref type is non-nullable
58
+ data: [+key: TKey] extends [+key: {+$fragmentSpreads: mixed, ...}]
59
+ ? TData
60
+ : ?TData,
61
+ loadNext: LoadMoreFn<TVariables>,
62
+ loadPrevious: LoadMoreFn<TVariables>,
63
+ hasNext: boolean,
64
+ hasPrevious: boolean,
65
+ isLoadingNext: boolean,
66
+ isLoadingPrevious: boolean,
67
+ refetch: RefetchFn<TVariables, TKey>,
68
+ };
69
+
36
70
  // This separate type export is only needed as long as we are injecting
37
71
  // a separate hooks implementation in ./HooksImplementation -- it can
38
72
  // be removed after we stop doing that.
@@ -46,7 +80,7 @@ export type UsePaginationFragmentType = <
46
80
  parentFragmentRef: TKey,
47
81
  ) => ReturnType<TVariables, TData, TKey>;
48
82
 
49
- function usePaginationFragment_LEGACY<
83
+ hook usePaginationFragment<
50
84
  TFragmentType: FragmentType,
51
85
  TVariables: Variables,
52
86
  TData,
@@ -65,9 +99,9 @@ function usePaginationFragment_LEGACY<
65
99
  const {connectionPathInFragmentData, paginationRequest, paginationMetadata} =
66
100
  getPaginationMetadata(fragmentNode, componentDisplayName);
67
101
 
68
- const {fragmentData, fragmentRef, refetch} = useRefetchableFragmentNode<
69
- $FlowFixMe,
70
- $FlowFixMe,
102
+ const {fragmentData, fragmentRef, refetch} = useRefetchableFragmentInternal<
103
+ {variables: TVariables, response: TData},
104
+ {data?: TData},
71
105
  >(fragmentNode, parentFragmentRef, componentDisplayName);
72
106
  const fragmentIdentifier = getFragmentIdentifier(fragmentNode, fragmentRef);
73
107
 
@@ -99,7 +133,7 @@ function usePaginationFragment_LEGACY<
99
133
  paginationRequest,
100
134
  });
101
135
 
102
- const refetchPagination: RefetchFn<TVariables, TKey> = useCallback(
136
+ const refetchPagination = useCallback(
103
137
  (variables: TVariables, options: void | Options) => {
104
138
  disposeFetchNext();
105
139
  disposeFetchPrevious();
@@ -110,6 +144,7 @@ function usePaginationFragment_LEGACY<
110
144
 
111
145
  if (__DEV__) {
112
146
  // eslint-disable-next-line react-hooks/rules-of-hooks
147
+ // $FlowFixMe[react-rule-hook]
113
148
  useDebugValue({
114
149
  fragment: fragmentNode.name,
115
150
  data: fragmentData,
@@ -120,7 +155,8 @@ function usePaginationFragment_LEGACY<
120
155
  });
121
156
  }
122
157
  return {
123
- data: (fragmentData: $FlowFixMe),
158
+ // $FlowFixMe[incompatible-return]
159
+ data: fragmentData,
124
160
  loadNext,
125
161
  loadPrevious,
126
162
  hasNext,
@@ -131,7 +167,7 @@ function usePaginationFragment_LEGACY<
131
167
  };
132
168
  }
133
169
 
134
- function useLoadMore<TVariables: Variables>(
170
+ hook useLoadMore<TVariables: Variables>(
135
171
  args: $Diff<
136
172
  UseLoadMoreFunctionArgs,
137
173
  {
@@ -141,7 +177,21 @@ function useLoadMore<TVariables: Variables>(
141
177
  },
142
178
  >,
143
179
  ): [LoadMoreFn<TVariables>, boolean, boolean, () => void] {
144
- const [isLoadingMore, setIsLoadingMore] = useState(false);
180
+ const environment = useRelayEnvironment();
181
+ const [isLoadingMore, reallySetIsLoadingMore] = useState(false);
182
+ // Schedule this update since it must be observed by components at the same
183
+ // batch as when hasNext changes. hasNext is read from the store and store
184
+ // updates are scheduled, so this must be scheduled too.
185
+ const setIsLoadingMore = (value: boolean) => {
186
+ const schedule = environment.getScheduler()?.schedule;
187
+ if (schedule) {
188
+ schedule(() => {
189
+ reallySetIsLoadingMore(value);
190
+ });
191
+ } else {
192
+ reallySetIsLoadingMore(value);
193
+ }
194
+ };
145
195
  const observer = {
146
196
  start: () => setIsLoadingMore(true),
147
197
  complete: () => setIsLoadingMore(false),
@@ -156,42 +206,4 @@ function useLoadMore<TVariables: Variables>(
156
206
  return [loadMore, hasMore, isLoadingMore, disposeFetch];
157
207
  }
158
208
 
159
- export type ReturnType<TVariables, TData, TKey> = {
160
- // NOTE: This type ensures that the type of the returned data is either:
161
- // - nullable if the provided ref type is nullable
162
- // - non-nullable if the provided ref type is non-nullable
163
- data: [+key: TKey] extends [+key: {+$fragmentSpreads: mixed, ...}]
164
- ? TData
165
- : ?TData,
166
- loadNext: LoadMoreFn<TVariables>,
167
- loadPrevious: LoadMoreFn<TVariables>,
168
- hasNext: boolean,
169
- hasPrevious: boolean,
170
- isLoadingNext: boolean,
171
- isLoadingPrevious: boolean,
172
- refetch: RefetchFn<TVariables, TKey>,
173
- };
174
-
175
- function usePaginationFragment<
176
- TFragmentType: FragmentType,
177
- TVariables: Variables,
178
- TData,
179
- TKey: ?{+$fragmentSpreads: TFragmentType, ...},
180
- >(
181
- fragmentInput: RefetchableFragment<TFragmentType, TData, TVariables>,
182
- parentFragmentRef: TKey,
183
- ): ReturnType<TVariables, TData, TKey> {
184
- const impl = HooksImplementation.get();
185
- if (impl) {
186
- // $FlowExpectedError[incompatible-return] Flow cannot prove that two conditional type satisfy each other
187
- return impl.usePaginationFragment<TFragmentType, TVariables, TData, TKey>(
188
- fragmentInput,
189
- parentFragmentRef,
190
- );
191
- } else {
192
- // eslint-disable-next-line react-hooks/rules-of-hooks
193
- return usePaginationFragment_LEGACY(fragmentInput, parentFragmentRef);
194
- }
195
- }
196
-
197
209
  module.exports = usePaginationFragment;
@@ -52,7 +52,7 @@ type PreloadedQuery<
52
52
  TEnvironmentProviderOptions,
53
53
  >;
54
54
 
55
- function usePreloadedQuery<
55
+ hook usePreloadedQuery<
56
56
  TVariables: Variables,
57
57
  TData,
58
58
  TRawResponse: ?{...} = void,
@@ -164,6 +164,7 @@ function usePreloadedQuery<
164
164
 
165
165
  if (__DEV__) {
166
166
  // eslint-disable-next-line react-hooks/rules-of-hooks
167
+ // $FlowFixMe[react-rule-hook]
167
168
  useDebugValue({
168
169
  query: preloadedQuery.name,
169
170
  variables: preloadedQuery.variables,
@@ -108,11 +108,7 @@ declare function useQueryLoader<TQuery: OperationType>(
108
108
  initialQueryReference?: ?PreloadedQuery<TQuery>,
109
109
  ): UseQueryLoaderHookReturnType<TQuery['variables'], TQuery['response']>;
110
110
 
111
- function useQueryLoader<
112
- TVariables: Variables,
113
- TData,
114
- TRawResponse: ?{...} = void,
115
- >(
111
+ hook useQueryLoader<TVariables: Variables, TData, TRawResponse: ?{...} = void>(
116
112
  preloadableRequest: Query<TVariables, TData, TRawResponse>,
117
113
  initialQueryReference?: ?PreloadedQuery<{
118
114
  response: TData,
@@ -172,6 +168,7 @@ function useQueryLoader<
172
168
  // necessary here
173
169
  // TODO(T78446637): Handle disposal of managed query references in
174
170
  // components that were never mounted after rendering
171
+ // $FlowFixMe[react-rule-unsafe-ref]
175
172
  undisposedQueryReferencesRef.current.add(initialQueryReferenceInternal);
176
173
  setPreviousInitialQueryReference(initialQueryReferenceInternal);
177
174
  setQueryReference(initialQueryReferenceInternal);
@@ -11,7 +11,7 @@
11
11
 
12
12
  'use strict';
13
13
 
14
- import type {Options} from './legacy/useRefetchableFragmentNode';
14
+ import type {Options} from './useRefetchableFragmentInternal';
15
15
  import type {
16
16
  Disposable,
17
17
  FragmentType,
@@ -19,8 +19,7 @@ import type {
19
19
  Variables,
20
20
  } from 'relay-runtime';
21
21
 
22
- const HooksImplementation = require('./HooksImplementation');
23
- const useRefetchableFragmentNode = require('./legacy/useRefetchableFragmentNode');
22
+ const useRefetchableFragmentInternal = require('./useRefetchableFragmentInternal');
24
23
  const useStaticFragmentNodeWarning = require('./useStaticFragmentNodeWarning');
25
24
  const {useDebugValue} = require('react');
26
25
  const {getFragment} = require('relay-runtime');
@@ -65,7 +64,7 @@ export type UseRefetchableFragmentType = <
65
64
  key: TKey,
66
65
  ) => ReturnType<TVariables, TData, TKey>;
67
66
 
68
- function useRefetchableFragment_LEGACY<
67
+ hook useRefetchableFragment<
69
68
  TFragmentType: FragmentType,
70
69
  TVariables: Variables,
71
70
  TData,
@@ -79,47 +78,18 @@ function useRefetchableFragment_LEGACY<
79
78
  fragmentNode,
80
79
  'first argument of useRefetchableFragment()',
81
80
  );
82
- const {fragmentData, refetch} = useRefetchableFragmentNode<
83
- {
84
- response: TData,
85
- variables: TVariables,
86
- },
87
- {
88
- +$data: mixed,
89
- ...
90
- },
81
+ const {fragmentData, refetch} = useRefetchableFragmentInternal<
82
+ {variables: TVariables, response: TData},
83
+ {data?: TData},
91
84
  >(fragmentNode, fragmentRef, 'useRefetchableFragment()');
92
85
  if (__DEV__) {
93
86
  // eslint-disable-next-line react-hooks/rules-of-hooks
87
+ // $FlowFixMe[react-rule-hook]
94
88
  useDebugValue({fragment: fragmentNode.name, data: fragmentData});
95
89
  }
96
-
97
90
  // $FlowFixMe[incompatible-return]
98
91
  // $FlowFixMe[prop-missing]
99
- // $FlowFixMe[incompatible-variance]
100
92
  return [fragmentData, refetch];
101
93
  }
102
94
 
103
- function useRefetchableFragment<
104
- TFragmentType: FragmentType,
105
- TVariables: Variables,
106
- TData,
107
- TKey: ?{+$fragmentSpreads: TFragmentType, ...},
108
- >(
109
- fragmentInput: RefetchableFragment<TFragmentType, TData, TVariables>,
110
- parentFragmentRef: TKey,
111
- ): ReturnType<TVariables, TData, TKey> {
112
- const impl = HooksImplementation.get();
113
- if (impl) {
114
- // $FlowExpectedError[incompatible-return] Flow cannot prove that two conditional type satisfy each other
115
- return impl.useRefetchableFragment<TFragmentType, TVariables, TData, TKey>(
116
- fragmentInput,
117
- parentFragmentRef,
118
- );
119
- } else {
120
- // eslint-disable-next-line react-hooks/rules-of-hooks
121
- return useRefetchableFragment_LEGACY(fragmentInput, parentFragmentRef);
122
- }
123
- }
124
-
125
95
  module.exports = useRefetchableFragment;
@@ -11,8 +11,7 @@
11
11
 
12
12
  'use strict';
13
13
 
14
- import type {RefetchableIdentifierInfo} from '../../../relay-runtime/util/ReaderNode';
15
- import type {LoaderFn} from '../useQueryLoader';
14
+ import type {LoaderFn} from './useQueryLoader';
16
15
  import type {
17
16
  ConcreteRequest,
18
17
  Disposable,
@@ -21,18 +20,19 @@ import type {
21
20
  OperationDescriptor,
22
21
  OperationType,
23
22
  ReaderFragment,
23
+ RefetchableIdentifierInfo,
24
24
  RenderPolicy,
25
25
  Variables,
26
26
  VariablesOf,
27
27
  } from 'relay-runtime';
28
28
 
29
- const ProfilerContext = require('../ProfilerContext');
30
- const {getQueryResourceForEnvironment} = require('../QueryResource');
31
- const useIsMountedRef = require('../useIsMountedRef');
32
- const useQueryLoader = require('../useQueryLoader');
33
- const useRelayEnvironment = require('../useRelayEnvironment');
34
- const readFragmentInternal = require('./readFragmentInternal_EXPERIMENTAL');
35
- const useFragmentInternal = require('./useFragmentInternal_EXPERIMENTAL');
29
+ const ProfilerContext = require('./ProfilerContext');
30
+ const {getQueryResourceForEnvironment} = require('./QueryResource');
31
+ const readFragmentInternal = require('./readFragmentInternal');
32
+ const useFragmentInternal = require('./useFragmentInternal');
33
+ const useIsMountedRef = require('./useIsMountedRef');
34
+ const useQueryLoader = require('./useQueryLoader');
35
+ const useRelayEnvironment = require('./useRelayEnvironment');
36
36
  const invariant = require('invariant');
37
37
  const {useCallback, useContext, useReducer} = require('react');
38
38
  const {
@@ -160,7 +160,7 @@ function reducer(state: RefetchState, action: Action): RefetchState {
160
160
  }
161
161
  }
162
162
 
163
- function useRefetchableFragmentNode<
163
+ hook useRefetchableFragmentNode<
164
164
  TQuery: OperationType,
165
165
  TKey: ?{+$data?: mixed, ...},
166
166
  >(
@@ -355,7 +355,7 @@ function useRefetchableFragmentNode<
355
355
  };
356
356
  }
357
357
 
358
- function useRefetchFunction<TQuery: OperationType>(
358
+ hook useRefetchFunction<TQuery: OperationType>(
359
359
  componentDisplayName: string,
360
360
  dispatch: (
361
361
  | {
@@ -17,7 +17,7 @@ const ReactRelayContext = require('./../ReactRelayContext');
17
17
  const invariant = require('invariant');
18
18
  const {useContext} = require('react');
19
19
 
20
- function useRelayEnvironment(): IEnvironment {
20
+ hook useRelayEnvironment(): IEnvironment {
21
21
  const context = useContext(ReactRelayContext);
22
22
  invariant(
23
23
  context != null,
@@ -16,7 +16,7 @@ import type {ReaderFragment} from 'relay-runtime';
16
16
  const useUnsafeRef_DEPRECATED = require('./useUnsafeRef_DEPRECATED');
17
17
  const warning = require('warning');
18
18
 
19
- function useStaticFragmentNodeWarning(
19
+ hook useStaticFragmentNodeWarning(
20
20
  fragmentNode: ReaderFragment,
21
21
  warningContext: string,
22
22
  ): void {
@@ -25,8 +25,10 @@ function useStaticFragmentNodeWarning(
25
25
  // __DEV__ setting which shouldn't change. This allows us to only pay the
26
26
  // cost of `useRef` in development mode to produce the warning.
27
27
  // eslint-disable-next-line react-hooks/rules-of-hooks
28
+ // $FlowFixMe[react-rule-hook]
28
29
  const initialPropRef = useUnsafeRef_DEPRECATED(fragmentNode.name);
29
30
  warning(
31
+ // $FlowFixMe[react-rule-unsafe-ref]
30
32
  initialPropRef.current === fragmentNode.name,
31
33
  'Relay: The %s has to remain the same over the lifetime of a component. ' +
32
34
  'Changing it is not supported and will result in unexpected behavior.',
@@ -25,7 +25,7 @@ const {useEffect, useRef} = require('react');
25
25
  * re-established and the previous one will be disposed.
26
26
  * The subscription will automatically be disposed on unmount
27
27
  */
28
- function useSubscribeToInvalidationState(
28
+ hook useSubscribeToInvalidationState(
29
29
  dataIDs: $ReadOnlyArray<DataID>,
30
30
  callback: () => void,
31
31
  ): Disposable {
@@ -26,7 +26,7 @@ type RequestSubscriptionFn<TVariables, TData, TRawResponse> = (
26
26
  config: GraphQLSubscriptionConfig<TVariables, TData, TRawResponse>,
27
27
  ) => Disposable;
28
28
 
29
- function useSubscription<TVariables, TData, TRawResponse>(
29
+ hook useSubscription<TVariables, TData, TRawResponse>(
30
30
  config: GraphQLSubscriptionConfig<TVariables, TData, TRawResponse>,
31
31
  requestSubscriptionFn?: RequestSubscriptionFn<
32
32
  TVariables,
@@ -18,7 +18,7 @@ const {useMemo} = require('react');
18
18
  * pattern to read or write from a ref during render as it does not trigger
19
19
  * a rerender and might result in bugs.
20
20
  */
21
- function useUnsafeRef_DEPRECATED<T>(init: T): {current: T} {
21
+ hook useUnsafeRef_DEPRECATED<T>(init: T): {current: T} {
22
22
  return useMemo<{current: T}>(() => ({current: init}), []);
23
23
  }
24
24
 
@@ -1,15 +0,0 @@
1
- 'use strict';
2
-
3
- var warning = require("fbjs/lib/warning");
4
- var implementation = null;
5
- function inject(impl) {
6
- process.env.NODE_ENV !== "production" ? warning(implementation === null, 'Relay HooksImplementation was injected twice.') : void 0;
7
- implementation = impl;
8
- }
9
- function get() {
10
- return implementation;
11
- }
12
- module.exports = {
13
- inject: inject,
14
- get: get
15
- };
@@ -1,26 +0,0 @@
1
- 'use strict';
2
-
3
- var _require = require('../loadQuery'),
4
- useTrackLoadQueryInRender = _require.useTrackLoadQueryInRender;
5
- var useStaticFragmentNodeWarning = require('../useStaticFragmentNodeWarning');
6
- var useFragmentInternal = require('./useFragmentInternal_EXPERIMENTAL');
7
- var _require2 = require('react'),
8
- useDebugValue = _require2.useDebugValue;
9
- var _require3 = require('relay-runtime'),
10
- getFragment = _require3.getFragment;
11
- function useFragment(fragment, key) {
12
- useTrackLoadQueryInRender();
13
- var fragmentNode = getFragment(fragment);
14
- if (process.env.NODE_ENV !== "production") {
15
- useStaticFragmentNodeWarning(fragmentNode, 'first argument of useFragment()');
16
- }
17
- var data = useFragmentInternal(fragmentNode, key, 'useFragment()');
18
- if (process.env.NODE_ENV !== "production") {
19
- useDebugValue({
20
- fragment: fragmentNode.name,
21
- data: data
22
- });
23
- }
24
- return data;
25
- }
26
- module.exports = useFragment;
@@ -1,127 +0,0 @@
1
- 'use strict';
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault")["default"];
4
- var _objectSpread2 = _interopRequireDefault(require("@babel/runtime/helpers/objectSpread2"));
5
- var useLoadMoreFunction = require('../useLoadMoreFunction');
6
- var useRelayEnvironment = require('../useRelayEnvironment');
7
- var useStaticFragmentNodeWarning = require('../useStaticFragmentNodeWarning');
8
- var useRefetchableFragmentInternal = require('./useRefetchableFragmentInternal_EXPERIMENTAL');
9
- var _require = require('react'),
10
- useCallback = _require.useCallback,
11
- useDebugValue = _require.useDebugValue,
12
- useState = _require.useState;
13
- var _require2 = require('relay-runtime'),
14
- getFragment = _require2.getFragment,
15
- getFragmentIdentifier = _require2.getFragmentIdentifier,
16
- getPaginationMetadata = _require2.getPaginationMetadata;
17
- function usePaginationFragment(fragmentInput, parentFragmentRef) {
18
- var fragmentNode = getFragment(fragmentInput);
19
- useStaticFragmentNodeWarning(fragmentNode, 'first argument of usePaginationFragment()');
20
- var componentDisplayName = 'usePaginationFragment()';
21
- var _getPaginationMetadat = getPaginationMetadata(fragmentNode, componentDisplayName),
22
- connectionPathInFragmentData = _getPaginationMetadat.connectionPathInFragmentData,
23
- paginationRequest = _getPaginationMetadat.paginationRequest,
24
- paginationMetadata = _getPaginationMetadat.paginationMetadata;
25
- var _useRefetchableFragme = useRefetchableFragmentInternal(fragmentNode, parentFragmentRef, componentDisplayName),
26
- fragmentData = _useRefetchableFragme.fragmentData,
27
- fragmentRef = _useRefetchableFragme.fragmentRef,
28
- refetch = _useRefetchableFragme.refetch;
29
- var fragmentIdentifier = getFragmentIdentifier(fragmentNode, fragmentRef);
30
- var _useLoadMore = useLoadMore({
31
- componentDisplayName: componentDisplayName,
32
- connectionPathInFragmentData: connectionPathInFragmentData,
33
- direction: 'backward',
34
- fragmentData: fragmentData,
35
- fragmentIdentifier: fragmentIdentifier,
36
- fragmentNode: fragmentNode,
37
- fragmentRef: fragmentRef,
38
- paginationMetadata: paginationMetadata,
39
- paginationRequest: paginationRequest
40
- }),
41
- loadPrevious = _useLoadMore[0],
42
- hasPrevious = _useLoadMore[1],
43
- isLoadingPrevious = _useLoadMore[2],
44
- disposeFetchPrevious = _useLoadMore[3];
45
- var _useLoadMore2 = useLoadMore({
46
- componentDisplayName: componentDisplayName,
47
- connectionPathInFragmentData: connectionPathInFragmentData,
48
- direction: 'forward',
49
- fragmentData: fragmentData,
50
- fragmentIdentifier: fragmentIdentifier,
51
- fragmentNode: fragmentNode,
52
- fragmentRef: fragmentRef,
53
- paginationMetadata: paginationMetadata,
54
- paginationRequest: paginationRequest
55
- }),
56
- loadNext = _useLoadMore2[0],
57
- hasNext = _useLoadMore2[1],
58
- isLoadingNext = _useLoadMore2[2],
59
- disposeFetchNext = _useLoadMore2[3];
60
- var refetchPagination = useCallback(function (variables, options) {
61
- disposeFetchNext();
62
- disposeFetchPrevious();
63
- return refetch(variables, (0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, options), {}, {
64
- __environment: undefined
65
- }));
66
- }, [disposeFetchNext, disposeFetchPrevious, refetch]);
67
- if (process.env.NODE_ENV !== "production") {
68
- useDebugValue({
69
- fragment: fragmentNode.name,
70
- data: fragmentData,
71
- hasNext: hasNext,
72
- isLoadingNext: isLoadingNext,
73
- hasPrevious: hasPrevious,
74
- isLoadingPrevious: isLoadingPrevious
75
- });
76
- }
77
- return {
78
- data: fragmentData,
79
- loadNext: loadNext,
80
- loadPrevious: loadPrevious,
81
- hasNext: hasNext,
82
- hasPrevious: hasPrevious,
83
- isLoadingNext: isLoadingNext,
84
- isLoadingPrevious: isLoadingPrevious,
85
- refetch: refetchPagination
86
- };
87
- }
88
- function useLoadMore(args) {
89
- var environment = useRelayEnvironment();
90
- var _useState = useState(false),
91
- isLoadingMore = _useState[0],
92
- reallySetIsLoadingMore = _useState[1];
93
- var setIsLoadingMore = function setIsLoadingMore(value) {
94
- var _environment$getSched;
95
- var schedule = (_environment$getSched = environment.getScheduler()) === null || _environment$getSched === void 0 ? void 0 : _environment$getSched.schedule;
96
- if (schedule) {
97
- schedule(function () {
98
- reallySetIsLoadingMore(value);
99
- });
100
- } else {
101
- reallySetIsLoadingMore(value);
102
- }
103
- };
104
- var observer = {
105
- start: function start() {
106
- return setIsLoadingMore(true);
107
- },
108
- complete: function complete() {
109
- return setIsLoadingMore(false);
110
- },
111
- error: function error() {
112
- return setIsLoadingMore(false);
113
- }
114
- };
115
- var handleReset = function handleReset() {
116
- return setIsLoadingMore(false);
117
- };
118
- var _useLoadMoreFunction = useLoadMoreFunction((0, _objectSpread2["default"])((0, _objectSpread2["default"])({}, args), {}, {
119
- observer: observer,
120
- onReset: handleReset
121
- })),
122
- loadMore = _useLoadMoreFunction[0],
123
- hasMore = _useLoadMoreFunction[1],
124
- disposeFetch = _useLoadMoreFunction[2];
125
- return [loadMore, hasMore, isLoadingMore, disposeFetch];
126
- }
127
- module.exports = usePaginationFragment;
@@ -1,23 +0,0 @@
1
- 'use strict';
2
-
3
- var useStaticFragmentNodeWarning = require('../useStaticFragmentNodeWarning');
4
- var useRefetchableFragmentInternal = require('./useRefetchableFragmentInternal_EXPERIMENTAL');
5
- var _require = require('react'),
6
- useDebugValue = _require.useDebugValue;
7
- var _require2 = require('relay-runtime'),
8
- getFragment = _require2.getFragment;
9
- function useRefetchableFragment(fragmentInput, fragmentRef) {
10
- var fragmentNode = getFragment(fragmentInput);
11
- useStaticFragmentNodeWarning(fragmentNode, 'first argument of useRefetchableFragment()');
12
- var _useRefetchableFragme = useRefetchableFragmentInternal(fragmentNode, fragmentRef, 'useRefetchableFragment()'),
13
- fragmentData = _useRefetchableFragme.fragmentData,
14
- refetch = _useRefetchableFragme.refetch;
15
- if (process.env.NODE_ENV !== "production") {
16
- useDebugValue({
17
- fragment: fragmentNode.name,
18
- data: fragmentData
19
- });
20
- }
21
- return [fragmentData, refetch];
22
- }
23
- module.exports = useRefetchableFragment;
@@ -1,45 +0,0 @@
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
- * @flow strict-local
8
- * @format
9
- * @oncall relay
10
- */
11
-
12
- 'use strict';
13
-
14
- import typeof useFragmentInternal from './experimental/useFragmentInternal_EXPERIMENTAL';
15
- import typeof useFragment from './useFragment';
16
- import type {UsePaginationFragmentType} from './usePaginationFragment';
17
- import type {UseRefetchableFragmentType} from './useRefetchableFragment';
18
-
19
- const warning = require('warning');
20
-
21
- type HooksImplementation = {
22
- useFragment: useFragment,
23
- usePaginationFragment: UsePaginationFragmentType,
24
- useRefetchableFragment: UseRefetchableFragmentType,
25
- useFragment__internal?: useFragmentInternal,
26
- };
27
-
28
- let implementation: HooksImplementation | null = null;
29
-
30
- function inject(impl: HooksImplementation): void {
31
- warning(
32
- implementation === null,
33
- 'Relay HooksImplementation was injected twice.',
34
- );
35
- implementation = impl;
36
- }
37
-
38
- function get(): HooksImplementation | null {
39
- return implementation;
40
- }
41
-
42
- module.exports = {
43
- inject,
44
- get,
45
- };