react-relay 16.1.0 → 17.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/ReactRelayContext.js +1 -1
- package/ReactRelayFragmentContainer.js.flow +8 -6
- package/ReactRelayLocalQueryRenderer.js.flow +4 -1
- package/ReactRelayPaginationContainer.js.flow +2 -0
- package/ReactRelayQueryRenderer.js.flow +1 -1
- package/ReactRelayTypes.js.flow +1 -0
- package/buildReactRelayContainer.js.flow +5 -3
- package/getRootVariablesForFragments.js.flow +1 -0
- package/hooks.js +1 -1
- package/hooks.js.flow +1 -1
- package/index.js +1 -1
- package/index.js.flow +1 -1
- package/legacy.js +1 -1
- package/lib/ReactRelayFragmentContainer.js +2 -2
- package/lib/buildReactRelayContainer.js +3 -3
- package/lib/relay-hooks/SuspenseResource.js +7 -4
- package/lib/relay-hooks/{FragmentResource.js → legacy/FragmentResource.js} +19 -20
- package/lib/relay-hooks/{useBlockingPaginationFragment.js → legacy/useBlockingPaginationFragment.js} +2 -2
- package/lib/relay-hooks/{useFragmentNode.js → legacy/useFragmentNode.js} +2 -2
- package/lib/relay-hooks/{useRefetchableFragmentNode.js → legacy/useRefetchableFragmentNode.js} +8 -8
- package/lib/relay-hooks/{experimental/readFragmentInternal_EXPERIMENTAL.js → readFragmentInternal.js} +7 -5
- package/lib/relay-hooks/useFragment.js +3 -13
- package/lib/relay-hooks/{experimental/useFragmentInternal_EXPERIMENTAL.js → useFragmentInternal.js} +67 -31
- package/lib/relay-hooks/useLazyLoadQueryNode.js +2 -13
- package/lib/relay-hooks/usePaginationFragment.js +17 -13
- package/lib/relay-hooks/useRefetchableFragment.js +3 -12
- package/lib/relay-hooks/{experimental/useRefetchableFragmentInternal_EXPERIMENTAL.js → useRefetchableFragmentInternal.js} +7 -7
- package/multi-actor/useRelayActorEnvironment.js.flow +1 -1
- package/package.json +2 -2
- package/react-relay-hooks.js +2 -2
- package/react-relay-hooks.min.js +2 -2
- package/react-relay-legacy.js +2 -2
- package/react-relay-legacy.min.js +2 -2
- package/react-relay.js +2 -2
- package/react-relay.min.js +2 -2
- package/relay-hooks/EntryPointTypes.flow.js.flow +22 -27
- package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +14 -1
- package/relay-hooks/NestedRelayEntryPointBuilderUtils.js.flow +5 -11
- package/relay-hooks/SuspenseResource.js.flow +11 -8
- package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +22 -1
- package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +19 -0
- package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +22 -0
- package/relay-hooks/{FragmentResource.js.flow → legacy/FragmentResource.js.flow} +21 -21
- package/relay-hooks/{useBlockingPaginationFragment.js.flow → legacy/useBlockingPaginationFragment.js.flow} +6 -6
- package/relay-hooks/{useFragmentNode.js.flow → legacy/useFragmentNode.js.flow} +3 -3
- package/relay-hooks/{useRefetchableFragmentNode.js.flow → legacy/useRefetchableFragmentNode.js.flow} +9 -9
- package/relay-hooks/loadQuery.js.flow +9 -8
- package/relay-hooks/{experimental/readFragmentInternal_EXPERIMENTAL.js.flow → readFragmentInternal.js.flow} +8 -4
- package/relay-hooks/useClientQuery.js.flow +1 -1
- package/relay-hooks/useEntryPointLoader.js.flow +1 -1
- package/relay-hooks/useFetchTrackingRef.js.flow +1 -1
- package/relay-hooks/useFragment.js.flow +16 -22
- package/relay-hooks/{experimental/useFragmentInternal_EXPERIMENTAL.js.flow → useFragmentInternal.js.flow} +71 -19
- package/relay-hooks/useIsMountedRef.js.flow +1 -1
- package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
- package/relay-hooks/useIsParentQueryActive.js.flow +5 -2
- package/relay-hooks/useLazyLoadQuery.js.flow +3 -2
- package/relay-hooks/useLazyLoadQueryNode.js.flow +3 -19
- package/relay-hooks/useLoadMoreFunction.js.flow +1 -1
- package/relay-hooks/useMemoOperationDescriptor.js.flow +1 -1
- package/relay-hooks/useMemoVariables.js.flow +1 -1
- package/relay-hooks/useMutation.js.flow +1 -1
- package/relay-hooks/usePaginationFragment.js.flow +62 -50
- package/relay-hooks/usePreloadedQuery.js.flow +2 -1
- package/relay-hooks/useQueryLoader.js.flow +2 -5
- package/relay-hooks/useRefetchableFragment.js.flow +7 -37
- package/relay-hooks/{experimental/useRefetchableFragmentInternal_EXPERIMENTAL.js.flow → useRefetchableFragmentInternal.js.flow} +11 -11
- package/relay-hooks/useRelayEnvironment.js.flow +1 -1
- package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -1
- package/relay-hooks/useSubscribeToInvalidationState.js.flow +1 -1
- package/relay-hooks/useSubscription.js.flow +1 -1
- package/relay-hooks/useUnsafeRef_DEPRECATED.js.flow +1 -1
- package/lib/relay-hooks/HooksImplementation.js +0 -15
- package/lib/relay-hooks/experimental/useFragment_EXPERIMENTAL.js +0 -26
- package/lib/relay-hooks/experimental/usePaginationFragment_EXPERIMENTAL.js +0 -127
- package/lib/relay-hooks/experimental/useRefetchableFragment_EXPERIMENTAL.js +0 -23
- package/relay-hooks/HooksImplementation.js.flow +0 -45
- package/relay-hooks/experimental/useFragment_EXPERIMENTAL.js.flow +0 -66
- package/relay-hooks/experimental/usePaginationFragment_EXPERIMENTAL.js.flow +0 -161
- package/relay-hooks/experimental/useRefetchableFragment_EXPERIMENTAL.js.flow +0 -49
@@ -11,7 +11,7 @@
|
|
11
11
|
|
12
12
|
'use strict';
|
13
13
|
|
14
|
-
import type {Options} from './
|
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
|
23
|
-
const useRefetchableFragmentNode = require('./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
|
-
|
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} =
|
83
|
-
{
|
84
|
-
|
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 {
|
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('
|
30
|
-
const {getQueryResourceForEnvironment} = require('
|
31
|
-
const
|
32
|
-
const
|
33
|
-
const
|
34
|
-
const
|
35
|
-
const
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
-
};
|
@@ -1,66 +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 a non-nullable array of keys, return non-nullable array
|
34
|
-
declare function useFragment<TFragmentType: FragmentType, TData>(
|
35
|
-
fragment: Fragment<TFragmentType, TData>,
|
36
|
-
key: $ReadOnlyArray<HasSpread<TFragmentType>>,
|
37
|
-
): TData;
|
38
|
-
|
39
|
-
// if the key is null/void, return null/void value
|
40
|
-
declare function useFragment<TFragmentType: FragmentType, TData>(
|
41
|
-
fragment: Fragment<TFragmentType, TData>,
|
42
|
-
key: null | void,
|
43
|
-
): null | void;
|
44
|
-
|
45
|
-
function useFragment(fragment: GraphQLTaggedNode, key: mixed): mixed {
|
46
|
-
// We need to use this hook in order to be able to track if
|
47
|
-
// loadQuery was called during render
|
48
|
-
useTrackLoadQueryInRender();
|
49
|
-
|
50
|
-
const fragmentNode = getFragment(fragment);
|
51
|
-
if (__DEV__) {
|
52
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
53
|
-
useStaticFragmentNodeWarning(
|
54
|
-
fragmentNode,
|
55
|
-
'first argument of useFragment()',
|
56
|
-
);
|
57
|
-
}
|
58
|
-
const data = useFragmentInternal(fragmentNode, key, 'useFragment()');
|
59
|
-
if (__DEV__) {
|
60
|
-
// eslint-disable-next-line react-hooks/rules-of-hooks
|
61
|
-
useDebugValue({fragment: fragmentNode.name, data});
|
62
|
-
}
|
63
|
-
return data;
|
64
|
-
}
|
65
|
-
|
66
|
-
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;
|