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
@@ -1,72 +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 type {Fragment, FragmentType, GraphQLTaggedNode} from 'relay-runtime';
15
-
16
- const {useTrackLoadQueryInRender} = require('../loadQuery');
17
- const useStaticFragmentNodeWarning = require('../useStaticFragmentNodeWarning');
18
- const useFragmentInternal = require('./useFragmentInternal_EXPERIMENTAL');
19
- const {useDebugValue} = require('react');
20
- const {getFragment} = require('relay-runtime');
21
-
22
- type HasSpread<TFragmentType> = {
23
- +$fragmentSpreads: TFragmentType,
24
- ...
25
- };
26
-
27
- // if the key is non-nullable, return non-nullable value
28
- declare function useFragment<TFragmentType: FragmentType, TData>(
29
- fragment: Fragment<TFragmentType, TData>,
30
- key: HasSpread<TFragmentType>,
31
- ): TData;
32
-
33
- // if the key is nullable, return nullable value
34
- declare function useFragment<TFragmentType: FragmentType, TData>(
35
- fragment: Fragment<TFragmentType, TData>,
36
- key: ?HasSpread<TFragmentType>,
37
- ): ?TData;
38
-
39
- // if the key is a non-nullable array of keys, return non-nullable array
40
- declare function useFragment<TFragmentType: FragmentType, TData>(
41
- fragment: Fragment<TFragmentType, TData>,
42
- key: $ReadOnlyArray<HasSpread<TFragmentType>>,
43
- ): TData;
44
-
45
- // if the key is a nullable array of keys, return nullable array
46
- declare function useFragment<TFragmentType: FragmentType, TData>(
47
- fragment: Fragment<TFragmentType, TData>,
48
- key: ?$ReadOnlyArray<HasSpread<TFragmentType>>,
49
- ): ?TData;
50
-
51
- function useFragment(fragment: GraphQLTaggedNode, key: mixed): mixed {
52
- // We need to use this hook in order to be able to track if
53
- // loadQuery was called during render
54
- useTrackLoadQueryInRender();
55
-
56
- const fragmentNode = getFragment(fragment);
57
- if (__DEV__) {
58
- // eslint-disable-next-line react-hooks/rules-of-hooks
59
- useStaticFragmentNodeWarning(
60
- fragmentNode,
61
- 'first argument of useFragment()',
62
- );
63
- }
64
- const data = useFragmentInternal(fragmentNode, key, 'useFragment()');
65
- if (__DEV__) {
66
- // eslint-disable-next-line react-hooks/rules-of-hooks
67
- useDebugValue({fragment: fragmentNode.name, data});
68
- }
69
- return data;
70
- }
71
-
72
- module.exports = useFragment;
@@ -1,161 +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 type {LoadMoreFn, UseLoadMoreFunctionArgs} from '../useLoadMoreFunction';
15
- import type {ReturnType} from '../usePaginationFragment';
16
- import type {Options} from './useRefetchableFragmentInternal_EXPERIMENTAL';
17
- import type {
18
- FragmentType,
19
- GraphQLResponse,
20
- Observer,
21
- RefetchableFragment,
22
- Variables,
23
- } from 'relay-runtime';
24
-
25
- const useLoadMoreFunction = require('../useLoadMoreFunction');
26
- const useRelayEnvironment = require('../useRelayEnvironment');
27
- const useStaticFragmentNodeWarning = require('../useStaticFragmentNodeWarning');
28
- const useRefetchableFragmentInternal = require('./useRefetchableFragmentInternal_EXPERIMENTAL');
29
- const {useCallback, useDebugValue, useState} = require('react');
30
- const {
31
- getFragment,
32
- getFragmentIdentifier,
33
- getPaginationMetadata,
34
- } = require('relay-runtime');
35
-
36
- function usePaginationFragment<
37
- TFragmentType: FragmentType,
38
- TVariables: Variables,
39
- TData,
40
- TKey: ?{+$fragmentSpreads: TFragmentType, ...},
41
- >(
42
- fragmentInput: RefetchableFragment<TFragmentType, TData, TVariables>,
43
- parentFragmentRef: TKey,
44
- ): ReturnType<TVariables, TData, TKey> {
45
- const fragmentNode = getFragment(fragmentInput);
46
- useStaticFragmentNodeWarning(
47
- fragmentNode,
48
- 'first argument of usePaginationFragment()',
49
- );
50
- const componentDisplayName = 'usePaginationFragment()';
51
-
52
- const {connectionPathInFragmentData, paginationRequest, paginationMetadata} =
53
- getPaginationMetadata(fragmentNode, componentDisplayName);
54
-
55
- const {fragmentData, fragmentRef, refetch} = useRefetchableFragmentInternal<
56
- {variables: TVariables, response: TData},
57
- {data?: TData},
58
- >(fragmentNode, parentFragmentRef, componentDisplayName);
59
- const fragmentIdentifier = getFragmentIdentifier(fragmentNode, fragmentRef);
60
-
61
- // Backward pagination
62
- const [loadPrevious, hasPrevious, isLoadingPrevious, disposeFetchPrevious] =
63
- useLoadMore<TVariables>({
64
- componentDisplayName,
65
- connectionPathInFragmentData,
66
- direction: 'backward',
67
- fragmentData,
68
- fragmentIdentifier,
69
- fragmentNode,
70
- fragmentRef,
71
- paginationMetadata,
72
- paginationRequest,
73
- });
74
-
75
- // Forward pagination
76
- const [loadNext, hasNext, isLoadingNext, disposeFetchNext] =
77
- useLoadMore<TVariables>({
78
- componentDisplayName,
79
- connectionPathInFragmentData,
80
- direction: 'forward',
81
- fragmentData,
82
- fragmentIdentifier,
83
- fragmentNode,
84
- fragmentRef,
85
- paginationMetadata,
86
- paginationRequest,
87
- });
88
-
89
- const refetchPagination = useCallback(
90
- (variables: TVariables, options: void | Options) => {
91
- disposeFetchNext();
92
- disposeFetchPrevious();
93
- return refetch(variables, {...options, __environment: undefined});
94
- },
95
- [disposeFetchNext, disposeFetchPrevious, refetch],
96
- );
97
-
98
- if (__DEV__) {
99
- // eslint-disable-next-line react-hooks/rules-of-hooks
100
- useDebugValue({
101
- fragment: fragmentNode.name,
102
- data: fragmentData,
103
- hasNext,
104
- isLoadingNext,
105
- hasPrevious,
106
- isLoadingPrevious,
107
- });
108
- }
109
- return {
110
- // $FlowFixMe[incompatible-return]
111
- data: fragmentData,
112
- loadNext,
113
- loadPrevious,
114
- hasNext,
115
- hasPrevious,
116
- isLoadingNext,
117
- isLoadingPrevious,
118
- refetch: refetchPagination,
119
- };
120
- }
121
-
122
- function useLoadMore<TVariables: Variables>(
123
- args: $Diff<
124
- UseLoadMoreFunctionArgs,
125
- {
126
- observer: Observer<GraphQLResponse>,
127
- onReset: () => void,
128
- ...
129
- },
130
- >,
131
- ): [LoadMoreFn<TVariables>, boolean, boolean, () => void] {
132
- const environment = useRelayEnvironment();
133
- const [isLoadingMore, reallySetIsLoadingMore] = useState(false);
134
- // Schedule this update since it must be observed by components at the same
135
- // batch as when hasNext changes. hasNext is read from the store and store
136
- // updates are scheduled, so this must be scheduled too.
137
- const setIsLoadingMore = (value: boolean) => {
138
- const schedule = environment.getScheduler()?.schedule;
139
- if (schedule) {
140
- schedule(() => {
141
- reallySetIsLoadingMore(value);
142
- });
143
- } else {
144
- reallySetIsLoadingMore(value);
145
- }
146
- };
147
- const observer = {
148
- start: () => setIsLoadingMore(true),
149
- complete: () => setIsLoadingMore(false),
150
- error: () => setIsLoadingMore(false),
151
- };
152
- const handleReset = () => setIsLoadingMore(false);
153
- const [loadMore, hasMore, disposeFetch] = useLoadMoreFunction<TVariables>({
154
- ...args,
155
- observer,
156
- onReset: handleReset,
157
- });
158
- return [loadMore, hasMore, isLoadingMore, disposeFetch];
159
- }
160
-
161
- module.exports = usePaginationFragment;
@@ -1,49 +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 type {ReturnType} from '../useRefetchableFragment';
15
- import type {FragmentType, RefetchableFragment, Variables} from 'relay-runtime';
16
-
17
- const useStaticFragmentNodeWarning = require('../useStaticFragmentNodeWarning');
18
- const useRefetchableFragmentInternal = require('./useRefetchableFragmentInternal_EXPERIMENTAL');
19
- const {useDebugValue} = require('react');
20
- const {getFragment} = require('relay-runtime');
21
-
22
- function useRefetchableFragment<
23
- TFragmentType: FragmentType,
24
- TVariables: Variables,
25
- TData,
26
- TKey: ?{+$fragmentSpreads: TFragmentType, ...},
27
- >(
28
- fragmentInput: RefetchableFragment<TFragmentType, TData, TVariables>,
29
- fragmentRef: TKey,
30
- ): ReturnType<TVariables, TData, TKey> {
31
- const fragmentNode = getFragment(fragmentInput);
32
- useStaticFragmentNodeWarning(
33
- fragmentNode,
34
- 'first argument of useRefetchableFragment()',
35
- );
36
- const {fragmentData, refetch} = useRefetchableFragmentInternal<
37
- {variables: TVariables, response: TData},
38
- {data?: TData},
39
- >(fragmentNode, fragmentRef, 'useRefetchableFragment()');
40
- if (__DEV__) {
41
- // eslint-disable-next-line react-hooks/rules-of-hooks
42
- useDebugValue({fragment: fragmentNode.name, data: fragmentData});
43
- }
44
- // $FlowFixMe[incompatible-return]
45
- // $FlowFixMe[prop-missing]
46
- return [fragmentData, refetch];
47
- }
48
-
49
- module.exports = useRefetchableFragment;