react-relay 14.1.0 → 16.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ReactRelayContainerUtils.js.flow +1 -0
- package/ReactRelayContext.js +1 -1
- package/ReactRelayContext.js.flow +1 -0
- package/ReactRelayFragmentContainer.js.flow +6 -2
- package/ReactRelayFragmentMockRenderer.js.flow +1 -0
- package/ReactRelayLocalQueryRenderer.js.flow +5 -3
- package/ReactRelayPaginationContainer.js.flow +21 -12
- package/ReactRelayQueryFetcher.js.flow +20 -10
- package/ReactRelayQueryRenderer.js.flow +15 -11
- package/ReactRelayQueryRendererContext.js.flow +1 -0
- package/ReactRelayRefetchContainer.js.flow +9 -5
- package/ReactRelayTestMocker.js.flow +3 -1
- package/ReactRelayTypes.js.flow +2 -0
- package/RelayContext.js.flow +1 -0
- package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +2 -1
- package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +1 -0
- package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +1 -0
- package/__flowtests__/RelayModern-flowtest.js.flow +1 -0
- package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +1 -0
- package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +1 -0
- package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +1 -0
- package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +1 -0
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +4 -2
- package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +3 -1
- package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +3 -1
- package/assertFragmentMap.js.flow +1 -0
- package/buildReactRelayContainer.js.flow +10 -6
- package/getRootVariablesForFragments.js.flow +1 -1
- package/hooks.js +1 -1
- package/hooks.js.flow +4 -0
- package/index.js +1 -1
- package/index.js.flow +4 -0
- package/isRelayEnvironment.js.flow +1 -0
- package/jest-react/enqueueTask.js.flow +1 -1
- package/jest-react/index.js.flow +1 -1
- package/jest-react/internalAct.js.flow +1 -1
- package/legacy.js +1 -1
- package/legacy.js.flow +1 -0
- package/lib/ReactRelayContainerUtils.js +0 -11
- package/lib/ReactRelayContext.js +1 -12
- package/lib/ReactRelayFragmentContainer.js +23 -122
- package/lib/ReactRelayFragmentMockRenderer.js +0 -12
- package/lib/ReactRelayLocalQueryRenderer.js +12 -41
- package/lib/ReactRelayPaginationContainer.js +45 -341
- package/lib/ReactRelayQueryFetcher.js +36 -111
- package/lib/ReactRelayQueryRenderer.js +29 -137
- package/lib/ReactRelayQueryRendererContext.js +0 -10
- package/lib/ReactRelayRefetchContainer.js +33 -166
- package/lib/ReactRelayTestMocker.js +18 -128
- package/lib/ReactRelayTypes.js +0 -9
- package/lib/RelayContext.js +0 -23
- package/lib/assertFragmentMap.js +0 -16
- package/lib/buildReactRelayContainer.js +7 -41
- package/lib/getRootVariablesForFragments.js +2 -19
- package/lib/hooks.js +3 -30
- package/lib/index.js +3 -39
- package/lib/isRelayEnvironment.js +1 -16
- package/lib/jest-react/enqueueTask.js +1 -25
- package/lib/jest-react/index.js +0 -1
- package/lib/jest-react/internalAct.js +2 -51
- package/lib/legacy.js +0 -20
- package/lib/multi-actor/ActorChange.js +0 -14
- package/lib/multi-actor/index.js +0 -10
- package/lib/multi-actor/useRelayActorEnvironment.js +2 -16
- package/lib/relay-hooks/EntryPointContainer.react.js +7 -23
- package/lib/relay-hooks/EntryPointTypes.flow.js +0 -10
- package/lib/relay-hooks/FragmentResource.js +130 -280
- package/lib/relay-hooks/HooksImplementation.js +0 -14
- package/lib/relay-hooks/InternalLogger.js +0 -11
- package/lib/relay-hooks/LRUCache.js +0 -39
- package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +27 -65
- package/lib/relay-hooks/MatchContainer.js +9 -111
- package/lib/relay-hooks/NestedRelayEntryPointBuilderUtils.js +9 -0
- package/lib/relay-hooks/ProfilerContext.js +0 -14
- package/lib/relay-hooks/QueryResource.js +14 -149
- package/lib/relay-hooks/RelayEnvironmentProvider.js +3 -17
- package/lib/relay-hooks/SuspenseResource.js +2 -59
- package/lib/relay-hooks/loadEntryPoint.js +10 -45
- package/lib/relay-hooks/loadQuery.js +29 -169
- package/lib/relay-hooks/preloadQuery_DEPRECATED.js +8 -58
- package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +6 -24
- package/lib/relay-hooks/react-cache/RelayReactCache.js +4 -20
- package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +13 -102
- package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +18 -75
- package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +79 -222
- package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +3 -27
- package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +11 -33
- package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +62 -85
- package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +20 -63
- package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +53 -179
- package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +5 -27
- package/lib/relay-hooks/useBlockingPaginationFragment.js +58 -121
- package/lib/relay-hooks/useClientQuery.js +0 -21
- package/lib/relay-hooks/useEntryPointLoader.js +12 -100
- package/lib/relay-hooks/useFetchTrackingRef.js +6 -33
- package/lib/relay-hooks/useFragment.js +5 -32
- package/lib/relay-hooks/useFragmentNode.js +14 -55
- package/lib/relay-hooks/useIsMountedRef.js +2 -14
- package/lib/relay-hooks/useIsOperationNodeActive.js +6 -29
- package/lib/relay-hooks/useIsParentQueryActive.js +1 -15
- package/lib/relay-hooks/useLazyLoadQuery.js +2 -23
- package/lib/relay-hooks/useLazyLoadQueryNode.js +18 -63
- package/lib/relay-hooks/useLoadMoreFunction.js +44 -100
- package/lib/relay-hooks/useMemoOperationDescriptor.js +4 -23
- package/lib/relay-hooks/useMemoVariables.js +8 -43
- package/lib/relay-hooks/useMutation.js +6 -34
- package/lib/relay-hooks/usePaginationFragment.js +49 -89
- package/lib/relay-hooks/usePreloadedQuery.js +10 -54
- package/lib/relay-hooks/useQueryLoader.js +18 -116
- package/lib/relay-hooks/useRefetchableFragment.js +4 -30
- package/lib/relay-hooks/useRefetchableFragmentNode.js +58 -184
- package/lib/relay-hooks/useRelayEnvironment.js +2 -16
- package/lib/relay-hooks/useStaticFragmentNodeWarning.js +2 -20
- package/lib/relay-hooks/useSubscribeToInvalidationState.js +3 -28
- package/lib/relay-hooks/useSubscription.js +3 -22
- package/lib/relay-hooks/useUnsafeRef_DEPRECATED.js +12 -0
- package/multi-actor/ActorChange.js.flow +1 -1
- package/multi-actor/index.js.flow +1 -1
- package/multi-actor/useRelayActorEnvironment.js.flow +2 -2
- 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/EntryPointContainer.react.js.flow +6 -1
- package/relay-hooks/EntryPointTypes.flow.js.flow +23 -20
- package/relay-hooks/FragmentResource.js.flow +148 -34
- package/relay-hooks/HooksImplementation.js.flow +1 -1
- package/relay-hooks/InternalLogger.js.flow +1 -1
- package/relay-hooks/LRUCache.js.flow +1 -1
- package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +19 -10
- package/relay-hooks/MatchContainer.js.flow +1 -1
- package/relay-hooks/NestedRelayEntryPointBuilderUtils.js.flow +51 -0
- package/relay-hooks/ProfilerContext.js.flow +1 -1
- package/relay-hooks/QueryResource.js.flow +25 -5
- package/relay-hooks/RelayEnvironmentProvider.js.flow +2 -2
- package/relay-hooks/SuspenseResource.js.flow +1 -1
- package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +3 -1
- package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +9 -7
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +3 -1
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +3 -1
- package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +40 -33
- package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +1 -1
- package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +38 -32
- package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +20 -18
- package/relay-hooks/__flowtests__/utils.js.flow +13 -2
- package/relay-hooks/loadEntryPoint.js.flow +15 -8
- package/relay-hooks/loadQuery.js.flow +32 -8
- package/relay-hooks/preloadQuery_DEPRECATED.js.flow +5 -6
- package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +17 -10
- package/relay-hooks/react-cache/RelayReactCache.js.flow +1 -1
- package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +4 -4
- package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +5 -4
- package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +32 -14
- package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +4 -10
- package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +1 -1
- package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +39 -49
- package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +1 -2
- package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +29 -16
- package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +17 -33
- package/relay-hooks/useBlockingPaginationFragment.js.flow +85 -58
- package/relay-hooks/useClientQuery.js.flow +3 -3
- package/relay-hooks/useEntryPointLoader.js.flow +10 -6
- package/relay-hooks/useFetchTrackingRef.js.flow +5 -4
- package/relay-hooks/useFragment.js.flow +2 -2
- package/relay-hooks/useFragmentNode.js.flow +7 -6
- package/relay-hooks/useIsMountedRef.js.flow +1 -1
- package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
- package/relay-hooks/useIsParentQueryActive.js.flow +1 -1
- package/relay-hooks/useLazyLoadQuery.js.flow +2 -2
- package/relay-hooks/useLazyLoadQueryNode.js.flow +2 -2
- package/relay-hooks/useLoadMoreFunction.js.flow +27 -16
- package/relay-hooks/useMemoOperationDescriptor.js.flow +3 -3
- package/relay-hooks/useMemoVariables.js.flow +13 -29
- package/relay-hooks/useMutation.js.flow +30 -13
- package/relay-hooks/usePaginationFragment.js.flow +55 -54
- package/relay-hooks/usePreloadedQuery.js.flow +47 -22
- package/relay-hooks/useQueryLoader.js.flow +78 -21
- package/relay-hooks/useRefetchableFragment.js.flow +65 -33
- package/relay-hooks/useRefetchableFragmentNode.js.flow +38 -17
- package/relay-hooks/useRelayEnvironment.js.flow +2 -2
- package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -3
- package/relay-hooks/useSubscribeToInvalidationState.js.flow +2 -2
- package/relay-hooks/useSubscription.js.flow +1 -1
- package/relay-hooks/useUnsafeRef_DEPRECATED.js.flow +25 -0
- package/lib/readContext.js +0 -27
- package/readContext.js.flow +0 -29
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
|
-
* @emails oncall+relay
|
|
8
7
|
* @flow strict-local
|
|
9
8
|
* @format
|
|
9
|
+
* @oncall relay
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import type {LoadMoreFn} from '../useLoadMoreFunction';
|
|
@@ -14,80 +14,84 @@ import type {
|
|
|
14
14
|
FetchFn,
|
|
15
15
|
NonNullableData,
|
|
16
16
|
NullableData,
|
|
17
|
-
QueryOperation,
|
|
18
17
|
QueryVariables,
|
|
19
18
|
QueryVariablesSubset,
|
|
20
19
|
} from './utils';
|
|
21
|
-
import type {IEnvironment,
|
|
20
|
+
import type {IEnvironment, Variables} from 'relay-runtime';
|
|
22
21
|
|
|
23
22
|
import useBlockingPaginationFragment from '../useBlockingPaginationFragment';
|
|
24
23
|
import {
|
|
25
24
|
fragmentData,
|
|
26
|
-
fragmentInput,
|
|
27
25
|
keyAnotherNonNullable,
|
|
28
26
|
keyAnotherNullable,
|
|
29
27
|
keyNonNullable,
|
|
30
28
|
keyNullable,
|
|
29
|
+
refetchableFragmentInput,
|
|
31
30
|
} from './utils';
|
|
32
31
|
|
|
33
32
|
type ExpectedReturnType<
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
TRefetchVariables: Variables,
|
|
34
|
+
TLoadMoreVariables: Variables,
|
|
36
35
|
TFragmentData,
|
|
37
36
|
> = {
|
|
38
37
|
data: TFragmentData,
|
|
39
|
-
loadNext: LoadMoreFn<
|
|
40
|
-
loadPrevious: LoadMoreFn<
|
|
38
|
+
loadNext: LoadMoreFn<TLoadMoreVariables>,
|
|
39
|
+
loadPrevious: LoadMoreFn<TLoadMoreVariables>,
|
|
41
40
|
hasNext: boolean,
|
|
42
41
|
hasPrevious: boolean,
|
|
43
|
-
refetch: FetchFn<
|
|
42
|
+
refetch: FetchFn<TRefetchVariables>,
|
|
44
43
|
};
|
|
45
44
|
|
|
46
45
|
/* eslint-disable react-hooks/rules-of-hooks */
|
|
47
46
|
|
|
48
47
|
// Nullability of returned data type is correct
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
// $FlowFixMe[prop-missing]
|
|
49
|
+
// $FlowFixMe[incompatible-cast]
|
|
50
|
+
(useBlockingPaginationFragment(
|
|
51
|
+
refetchableFragmentInput,
|
|
51
52
|
keyNonNullable,
|
|
52
|
-
): ExpectedReturnType<
|
|
53
|
+
): ExpectedReturnType<QueryVariablesSubset, QueryVariables, NonNullableData>);
|
|
53
54
|
|
|
54
|
-
(useBlockingPaginationFragment
|
|
55
|
-
|
|
55
|
+
(useBlockingPaginationFragment(
|
|
56
|
+
refetchableFragmentInput,
|
|
56
57
|
keyNullable,
|
|
57
|
-
): ExpectedReturnType<
|
|
58
|
+
): ExpectedReturnType<QueryVariables, QueryVariables, NullableData>);
|
|
58
59
|
|
|
59
60
|
// $FlowExpectedError: can't cast nullable to non-nullable
|
|
60
|
-
(useBlockingPaginationFragment
|
|
61
|
-
|
|
61
|
+
(useBlockingPaginationFragment(
|
|
62
|
+
refetchableFragmentInput,
|
|
62
63
|
keyNullable,
|
|
63
|
-
): ExpectedReturnType<
|
|
64
|
+
): ExpectedReturnType<QueryVariables, QueryVariables, NonNullableData>);
|
|
64
65
|
|
|
65
66
|
// $FlowExpectedError: actual type of returned data is correct
|
|
66
|
-
(useBlockingPaginationFragment
|
|
67
|
-
|
|
67
|
+
(useBlockingPaginationFragment(
|
|
68
|
+
refetchableFragmentInput,
|
|
69
|
+
// $FlowExpectedError[incompatible-call]
|
|
68
70
|
keyAnotherNonNullable,
|
|
69
|
-
): ExpectedReturnType<
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
): ExpectedReturnType<QueryVariables, QueryVariablesSubset, NonNullableData>);
|
|
72
|
+
|
|
73
|
+
// $FlowExpectedError[incompatible-call] `Example_user$fragmentType` is incompatible with `FragmentType`
|
|
74
|
+
(useBlockingPaginationFragment(
|
|
75
|
+
refetchableFragmentInput,
|
|
76
|
+
// $FlowExpectedError[incompatible-call]
|
|
73
77
|
keyAnotherNullable,
|
|
74
|
-
): ExpectedReturnType<
|
|
78
|
+
): ExpectedReturnType<QueryVariables, QueryVariables, NullableData>);
|
|
75
79
|
|
|
76
80
|
// $FlowExpectedError: Key should not be a user provided object
|
|
77
|
-
useBlockingPaginationFragment
|
|
81
|
+
useBlockingPaginationFragment(fragmentInput, {abc: 123});
|
|
78
82
|
|
|
79
83
|
// $FlowExpectedError: Key should not be an empty object
|
|
80
|
-
useBlockingPaginationFragment
|
|
84
|
+
useBlockingPaginationFragment(fragmentInput, {});
|
|
81
85
|
|
|
82
86
|
// $FlowExpectedError: Key should be the `<name>$key` type from generated flow
|
|
83
|
-
useBlockingPaginationFragment
|
|
87
|
+
useBlockingPaginationFragment(fragmentInput, fragmentData);
|
|
84
88
|
|
|
85
89
|
// Refetch function options:
|
|
86
90
|
declare var variables: QueryVariables;
|
|
87
91
|
declare var environment: IEnvironment;
|
|
88
92
|
|
|
89
|
-
const {refetch} = useBlockingPaginationFragment
|
|
90
|
-
|
|
93
|
+
const {refetch} = useBlockingPaginationFragment(
|
|
94
|
+
refetchableFragmentInput,
|
|
91
95
|
keyNonNullable,
|
|
92
96
|
);
|
|
93
97
|
// $FlowExpectedError: internal option
|
|
@@ -104,17 +108,20 @@ refetch(variables, {
|
|
|
104
108
|
declare var extraVariables: {nickname: string};
|
|
105
109
|
declare var invalidVariables: {foo: string};
|
|
106
110
|
|
|
107
|
-
const {loadNext} = useBlockingPaginationFragment
|
|
108
|
-
|
|
111
|
+
const {loadNext} = useBlockingPaginationFragment(
|
|
112
|
+
refetchableFragmentInput,
|
|
109
113
|
keyNonNullable,
|
|
110
114
|
);
|
|
111
115
|
// Accepts extraVariables
|
|
112
116
|
loadNext(10, {
|
|
117
|
+
// $FlowFixMe[prop-missing]
|
|
118
|
+
// $FlowFixMe[incompatible-call]
|
|
113
119
|
UNSTABLE_extraVariables: extraVariables,
|
|
114
120
|
});
|
|
115
121
|
|
|
116
|
-
// $
|
|
122
|
+
// $FlowFixMe[prop-missing]
|
|
117
123
|
loadNext(10, {
|
|
124
|
+
// $FlowExpectedError: doesn't accept variables not available in the Flow type
|
|
118
125
|
UNSTABLE_extraVariables: invalidVariables,
|
|
119
126
|
});
|
|
120
127
|
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
|
-
* @emails oncall+relay
|
|
8
7
|
* @flow strict-local
|
|
9
8
|
* @format
|
|
9
|
+
* @oncall relay
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import type {LoadMoreFn} from '../useLoadMoreFunction';
|
|
@@ -14,82 +14,85 @@ import type {
|
|
|
14
14
|
FetchFn,
|
|
15
15
|
NonNullableData,
|
|
16
16
|
NullableData,
|
|
17
|
-
QueryOperation,
|
|
18
17
|
QueryVariables,
|
|
19
18
|
QueryVariablesSubset,
|
|
20
19
|
} from './utils';
|
|
21
|
-
import type {IEnvironment,
|
|
20
|
+
import type {IEnvironment, Variables} from 'relay-runtime';
|
|
22
21
|
|
|
23
22
|
import usePaginationFragment from '../usePaginationFragment';
|
|
24
23
|
import {
|
|
25
24
|
fragmentData,
|
|
26
|
-
fragmentInput,
|
|
27
25
|
keyAnotherNonNullable,
|
|
28
26
|
keyAnotherNullable,
|
|
29
27
|
keyNonNullable,
|
|
30
28
|
keyNullable,
|
|
29
|
+
refetchableFragmentInput,
|
|
31
30
|
} from './utils';
|
|
32
31
|
|
|
33
32
|
type ExpectedReturnType<
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
TRefetchVariables: Variables,
|
|
34
|
+
TLoadMoreVariables: Variables,
|
|
36
35
|
TFragmentData,
|
|
37
36
|
> = {
|
|
38
37
|
data: TFragmentData,
|
|
39
|
-
loadNext: LoadMoreFn<
|
|
40
|
-
loadPrevious: LoadMoreFn<
|
|
38
|
+
loadNext: LoadMoreFn<TLoadMoreVariables>,
|
|
39
|
+
loadPrevious: LoadMoreFn<TLoadMoreVariables>,
|
|
41
40
|
hasNext: boolean,
|
|
42
41
|
hasPrevious: boolean,
|
|
43
42
|
isLoadingNext: boolean,
|
|
44
43
|
isLoadingPrevious: boolean,
|
|
45
|
-
refetch: FetchFn<
|
|
44
|
+
refetch: FetchFn<TRefetchVariables>,
|
|
46
45
|
};
|
|
47
46
|
|
|
48
47
|
/* eslint-disable react-hooks/rules-of-hooks */
|
|
49
48
|
|
|
50
49
|
// Nullability of returned data type is correct
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
// $FlowFixMe[prop-missing]
|
|
51
|
+
// $FlowFixMe[incompatible-cast]
|
|
52
|
+
(usePaginationFragment(
|
|
53
|
+
refetchableFragmentInput,
|
|
53
54
|
keyNonNullable,
|
|
54
|
-
): ExpectedReturnType<
|
|
55
|
+
): ExpectedReturnType<QueryVariablesSubset, QueryVariables, NonNullableData>);
|
|
55
56
|
|
|
56
|
-
(usePaginationFragment
|
|
57
|
-
|
|
57
|
+
(usePaginationFragment(
|
|
58
|
+
refetchableFragmentInput,
|
|
58
59
|
keyNullable,
|
|
59
|
-
): ExpectedReturnType<
|
|
60
|
+
): ExpectedReturnType<QueryVariables, QueryVariables, NullableData>);
|
|
60
61
|
|
|
61
62
|
// $FlowExpectedError: can't cast nullable to non-nullable
|
|
62
|
-
(usePaginationFragment
|
|
63
|
-
|
|
63
|
+
(usePaginationFragment(
|
|
64
|
+
refetchableFragmentInput,
|
|
64
65
|
keyNullable,
|
|
65
|
-
): ExpectedReturnType<
|
|
66
|
+
): ExpectedReturnType<QueryVariables, QueryVariables, NonNullableData>);
|
|
66
67
|
|
|
67
68
|
// $FlowExpectedError: actual type of returned data is correct
|
|
68
|
-
(usePaginationFragment
|
|
69
|
-
|
|
69
|
+
(usePaginationFragment(
|
|
70
|
+
refetchableFragmentInput,
|
|
71
|
+
// $FlowFixMe[incompatible-call]
|
|
70
72
|
keyAnotherNonNullable,
|
|
71
|
-
): ExpectedReturnType<
|
|
73
|
+
): ExpectedReturnType<QueryVariables, QueryVariablesSubset, NonNullableData>);
|
|
72
74
|
// $FlowExpectedError
|
|
73
|
-
(usePaginationFragment
|
|
74
|
-
|
|
75
|
+
(usePaginationFragment(
|
|
76
|
+
refetchableFragmentInput,
|
|
77
|
+
// $FlowFixMe[incompatible-call]
|
|
75
78
|
keyAnotherNullable,
|
|
76
|
-
): ExpectedReturnType<
|
|
79
|
+
): ExpectedReturnType<QueryVariables, QueryVariables, NonNullableData>);
|
|
77
80
|
|
|
78
81
|
// $FlowExpectedError: Key should not be a user provided object
|
|
79
|
-
usePaginationFragment
|
|
82
|
+
usePaginationFragment(refetchableFragmentInput, {abc: 123});
|
|
80
83
|
|
|
81
84
|
// $FlowExpectedError: Key should not be an empty object
|
|
82
|
-
usePaginationFragment
|
|
85
|
+
usePaginationFragment(refetchableFragmentInput, {});
|
|
83
86
|
|
|
84
87
|
// $FlowExpectedError: Key should be the `<name>$key` type from generated flow
|
|
85
|
-
usePaginationFragment
|
|
88
|
+
usePaginationFragment(refetchableFragmentInput, fragmentData);
|
|
86
89
|
|
|
87
90
|
// Refetch function options:
|
|
88
91
|
declare var variables: QueryVariables;
|
|
89
92
|
declare var environment: IEnvironment;
|
|
90
93
|
|
|
91
|
-
const {refetch} = usePaginationFragment
|
|
92
|
-
|
|
94
|
+
const {refetch} = usePaginationFragment(
|
|
95
|
+
refetchableFragmentInput,
|
|
93
96
|
keyNonNullable,
|
|
94
97
|
);
|
|
95
98
|
// $FlowExpectedError: internal option
|
|
@@ -106,17 +109,20 @@ refetch(variables, {
|
|
|
106
109
|
declare var extraVariables: {nickname: string};
|
|
107
110
|
declare var invalidVariables: {foo: string};
|
|
108
111
|
|
|
109
|
-
const {loadNext} = usePaginationFragment
|
|
110
|
-
|
|
112
|
+
const {loadNext} = usePaginationFragment(
|
|
113
|
+
refetchableFragmentInput,
|
|
111
114
|
keyNonNullable,
|
|
112
115
|
);
|
|
113
116
|
// Accepts extraVariables
|
|
114
117
|
loadNext(10, {
|
|
118
|
+
// $FlowFixMe[prop-missing]
|
|
119
|
+
// $FlowFixMe[incompatible-call]
|
|
115
120
|
UNSTABLE_extraVariables: extraVariables,
|
|
116
121
|
});
|
|
117
122
|
|
|
118
|
-
// $
|
|
123
|
+
// $FlowFixMe[prop-missing]
|
|
119
124
|
loadNext(10, {
|
|
125
|
+
// $FlowExpectedError: doesn't accept variables not available in the Flow type
|
|
120
126
|
UNSTABLE_extraVariables: invalidVariables,
|
|
121
127
|
});
|
|
122
128
|
|
|
@@ -4,16 +4,15 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
|
-
* @emails oncall+relay
|
|
8
7
|
* @flow strict-local
|
|
9
8
|
* @format
|
|
9
|
+
* @oncall relay
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import type {
|
|
13
13
|
FetchFn,
|
|
14
14
|
NonNullableData,
|
|
15
15
|
NullableData,
|
|
16
|
-
QueryOperation,
|
|
17
16
|
QueryVariables,
|
|
18
17
|
QueryVariablesSubset,
|
|
19
18
|
} from './utils';
|
|
@@ -22,64 +21,67 @@ import type {IEnvironment} from 'relay-runtime';
|
|
|
22
21
|
import useRefetchableFragment from '../useRefetchableFragment';
|
|
23
22
|
import {
|
|
24
23
|
fragmentData,
|
|
25
|
-
fragmentInput,
|
|
26
24
|
keyAnotherNonNullable,
|
|
27
25
|
keyAnotherNullable,
|
|
28
26
|
keyNonNullable,
|
|
29
27
|
keyNullable,
|
|
28
|
+
refetchableFragmentInput,
|
|
30
29
|
} from './utils';
|
|
31
30
|
|
|
32
31
|
/* eslint-disable react-hooks/rules-of-hooks */
|
|
33
32
|
|
|
34
33
|
// Nullability of returned data type is correct
|
|
35
|
-
|
|
34
|
+
// $FlowFixMe[prop-missing]
|
|
35
|
+
// $FlowFixMe[incompatible-cast]
|
|
36
|
+
(useRefetchableFragment(refetchableFragmentInput, keyNonNullable): [
|
|
36
37
|
NonNullableData,
|
|
37
38
|
FetchFn<QueryVariablesSubset>,
|
|
38
39
|
]);
|
|
39
40
|
|
|
40
|
-
(useRefetchableFragment
|
|
41
|
+
(useRefetchableFragment(refetchableFragmentInput, keyNullable): [
|
|
41
42
|
NullableData,
|
|
42
43
|
FetchFn<QueryVariables>,
|
|
43
44
|
]);
|
|
44
45
|
|
|
45
46
|
// $FlowExpectedError: can't cast nullable to non-nullable
|
|
46
|
-
(useRefetchableFragment
|
|
47
|
+
(useRefetchableFragment(refetchableFragmentInput, keyNullable): [
|
|
47
48
|
NonNullableData,
|
|
48
49
|
FetchFn<QueryVariables>,
|
|
49
50
|
]);
|
|
50
51
|
|
|
51
52
|
// $FlowExpectedError: refetch requires exact type if key is nullable
|
|
52
|
-
(useRefetchableFragment
|
|
53
|
+
(useRefetchableFragment(refetchableFragmentInput, keyNullable): [
|
|
53
54
|
NullableData,
|
|
54
55
|
FetchFn<QueryVariablesSubset>,
|
|
55
56
|
]);
|
|
56
57
|
|
|
57
58
|
// $FlowExpectedError: actual type of returned data is correct
|
|
58
|
-
(useRefetchableFragment
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
59
|
+
(useRefetchableFragment(refetchableFragmentInput, keyAnotherNonNullable): [
|
|
60
|
+
NonNullableData,
|
|
61
|
+
FetchFn<QueryVariablesSubset>,
|
|
62
|
+
]);
|
|
63
|
+
|
|
64
|
+
// $FlowExpectedError - incompatible key types
|
|
65
|
+
(useRefetchableFragment(refetchableFragmentInput, keyAnotherNullable): [
|
|
64
66
|
NullableData,
|
|
65
67
|
FetchFn<QueryVariables>,
|
|
66
68
|
]);
|
|
67
69
|
|
|
68
70
|
// $FlowExpectedError: Key should not be a user provided object
|
|
69
|
-
useRefetchableFragment
|
|
71
|
+
useRefetchableFragment(refetchableFragmentInput, {abc: 123});
|
|
70
72
|
|
|
71
73
|
// $FlowExpectedError: Key should not be an empty object
|
|
72
|
-
useRefetchableFragment
|
|
74
|
+
useRefetchableFragment(refetchableFragmentInput, {});
|
|
73
75
|
|
|
74
76
|
// $FlowExpectedError: Key should be the `<name>$key` type from generated flow
|
|
75
|
-
useRefetchableFragment
|
|
77
|
+
useRefetchableFragment(refetchableFragmentInput, fragmentData);
|
|
76
78
|
|
|
77
79
|
// Refetch function options:
|
|
78
80
|
declare var variables: QueryVariables;
|
|
79
81
|
declare var environment: IEnvironment;
|
|
80
82
|
|
|
81
|
-
const [
|
|
82
|
-
|
|
83
|
+
const [, refetch] = useRefetchableFragment(
|
|
84
|
+
refetchableFragmentInput,
|
|
83
85
|
keyNonNullable,
|
|
84
86
|
);
|
|
85
87
|
// $FlowExpectedError: internal option
|
|
@@ -4,20 +4,31 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
|
-
* @emails oncall+relay
|
|
8
7
|
* @flow strict-local
|
|
9
8
|
* @format
|
|
9
|
+
* @oncall relay
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
'use strict';
|
|
13
13
|
|
|
14
|
-
import type {
|
|
14
|
+
import type {
|
|
15
|
+
Disposable,
|
|
16
|
+
Fragment,
|
|
17
|
+
FragmentType,
|
|
18
|
+
RefetchableFragment,
|
|
19
|
+
} from 'relay-runtime';
|
|
15
20
|
|
|
16
21
|
declare export var fragmentInput: Fragment<
|
|
17
22
|
Example_user$fragmentType,
|
|
18
23
|
Example_user$data,
|
|
19
24
|
>;
|
|
20
25
|
|
|
26
|
+
declare export var refetchableFragmentInput: RefetchableFragment<
|
|
27
|
+
Example_user$fragmentType,
|
|
28
|
+
Example_user$data,
|
|
29
|
+
QueryVariables,
|
|
30
|
+
>;
|
|
31
|
+
|
|
21
32
|
declare export opaque type Example_user$fragmentType: FragmentType;
|
|
22
33
|
export type Example_user$data = NonNullableData;
|
|
23
34
|
export type Example_user$key = {
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @flow strict-local
|
|
8
8
|
* @format
|
|
9
|
-
* @
|
|
9
|
+
* @oncall relay
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
'use strict';
|
|
@@ -46,8 +46,10 @@ function loadEntryPoint<
|
|
|
46
46
|
}
|
|
47
47
|
const preloadProps = entryPoint.getPreloadProps(entryPointParams);
|
|
48
48
|
const {queries, entryPoints, extraProps} = preloadProps;
|
|
49
|
-
|
|
50
|
-
const
|
|
49
|
+
// $FlowFixMe[incompatible-type]
|
|
50
|
+
const preloadedQueries: Partial<TPreloadedQueries> = {};
|
|
51
|
+
// $FlowFixMe[incompatible-type]
|
|
52
|
+
const preloadedEntryPoints: Partial<TPreloadedEntryPoints> = {};
|
|
51
53
|
if (queries != null) {
|
|
52
54
|
const queriesPropNames = Object.keys(queries);
|
|
53
55
|
queriesPropNames.forEach(queryPropName => {
|
|
@@ -58,6 +60,7 @@ function loadEntryPoint<
|
|
|
58
60
|
environmentProviderOptions,
|
|
59
61
|
);
|
|
60
62
|
|
|
63
|
+
// $FlowFixMe[underconstrained-implicit-instantiation]
|
|
61
64
|
preloadedQueries[queryPropName] = loadQuery(
|
|
62
65
|
environment,
|
|
63
66
|
parameters,
|
|
@@ -81,11 +84,15 @@ function loadEntryPoint<
|
|
|
81
84
|
}
|
|
82
85
|
const {entryPoint: nestedEntryPoint, entryPointParams: nestedParams} =
|
|
83
86
|
entryPointDescription;
|
|
84
|
-
preloadedEntryPoints[entryPointPropName] = loadEntryPoint
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
87
|
+
preloadedEntryPoints[entryPointPropName] = loadEntryPoint<
|
|
88
|
+
_,
|
|
89
|
+
{...},
|
|
90
|
+
{...},
|
|
91
|
+
{...},
|
|
92
|
+
mixed,
|
|
93
|
+
EntryPointComponent<{...}, {...}, {...}, mixed>,
|
|
94
|
+
_,
|
|
95
|
+
>(environmentProvider, nestedEntryPoint, nestedParams);
|
|
89
96
|
});
|
|
90
97
|
}
|
|
91
98
|
|
|
@@ -6,12 +6,13 @@
|
|
|
6
6
|
*
|
|
7
7
|
* @flow strict-local
|
|
8
8
|
* @format
|
|
9
|
-
* @
|
|
9
|
+
* @oncall relay
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
'use strict';
|
|
13
13
|
|
|
14
14
|
import type {
|
|
15
|
+
EnvironmentProviderOptions,
|
|
15
16
|
LoadQueryOptions,
|
|
16
17
|
PreloadableConcreteRequest,
|
|
17
18
|
PreloadedQueryInner,
|
|
@@ -23,6 +24,7 @@ import type {
|
|
|
23
24
|
IEnvironment,
|
|
24
25
|
OperationDescriptor,
|
|
25
26
|
OperationType,
|
|
27
|
+
Query,
|
|
26
28
|
RequestIdentifier,
|
|
27
29
|
RequestParameters,
|
|
28
30
|
} from 'relay-runtime';
|
|
@@ -30,11 +32,11 @@ import type {
|
|
|
30
32
|
const invariant = require('invariant');
|
|
31
33
|
const React = require('react');
|
|
32
34
|
const {
|
|
35
|
+
__internal: {fetchQueryDeduped},
|
|
33
36
|
Observable,
|
|
34
37
|
PreloadableQueryRegistry,
|
|
35
38
|
RelayFeatureFlags,
|
|
36
39
|
ReplaySubject,
|
|
37
|
-
__internal: {fetchQueryDeduped},
|
|
38
40
|
createOperationDescriptor,
|
|
39
41
|
getRequest,
|
|
40
42
|
getRequestIdentifier,
|
|
@@ -55,9 +57,31 @@ function useTrackLoadQueryInRender() {
|
|
|
55
57
|
}
|
|
56
58
|
}
|
|
57
59
|
|
|
58
|
-
|
|
60
|
+
type QueryType<T> = T extends Query<infer V, infer D, infer RR>
|
|
61
|
+
? {
|
|
62
|
+
variables: V,
|
|
63
|
+
response: D,
|
|
64
|
+
rawResponse?: $NonMaybeType<RR>,
|
|
65
|
+
}
|
|
66
|
+
: $Call<<T>(PreloadableConcreteRequest<T>) => T, T>;
|
|
67
|
+
|
|
68
|
+
declare function loadQuery<
|
|
69
|
+
T,
|
|
70
|
+
TEnvironmentProviderOptions = EnvironmentProviderOptions,
|
|
71
|
+
>(
|
|
72
|
+
environment: IEnvironment,
|
|
73
|
+
preloadableRequest: T,
|
|
74
|
+
variables: QueryType<T>['variables'],
|
|
75
|
+
options?: ?LoadQueryOptions,
|
|
76
|
+
environmentProviderOptions?: ?TEnvironmentProviderOptions,
|
|
77
|
+
): PreloadedQueryInner<QueryType<T>, TEnvironmentProviderOptions>;
|
|
78
|
+
|
|
79
|
+
function loadQuery<
|
|
80
|
+
TQuery: OperationType,
|
|
81
|
+
TEnvironmentProviderOptions = EnvironmentProviderOptions,
|
|
82
|
+
>(
|
|
59
83
|
environment: IEnvironment,
|
|
60
|
-
preloadableRequest:
|
|
84
|
+
preloadableRequest: PreloadableConcreteRequest<TQuery>,
|
|
61
85
|
variables: TQuery['variables'],
|
|
62
86
|
options?: ?LoadQueryOptions,
|
|
63
87
|
environmentProviderOptions?: ?TEnvironmentProviderOptions,
|
|
@@ -115,8 +139,8 @@ function loadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
|
|
|
115
139
|
// allows us to capture the events that occur during the eager execution
|
|
116
140
|
// of the operation, and then replay them to the Observable we
|
|
117
141
|
// ultimately return.
|
|
118
|
-
const executionSubject = new ReplaySubject();
|
|
119
|
-
const returnedObservable = Observable.create(sink =>
|
|
142
|
+
const executionSubject = new ReplaySubject<GraphQLResponse>();
|
|
143
|
+
const returnedObservable = Observable.create<GraphQLResponse>(sink =>
|
|
120
144
|
executionSubject.subscribe(sink),
|
|
121
145
|
);
|
|
122
146
|
|
|
@@ -139,7 +163,7 @@ function loadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
|
|
|
139
163
|
didMakeNetworkRequest = true;
|
|
140
164
|
|
|
141
165
|
let observable;
|
|
142
|
-
const subject = new ReplaySubject();
|
|
166
|
+
const subject = new ReplaySubject<GraphQLResponse>();
|
|
143
167
|
if (RelayFeatureFlags.ENABLE_LOAD_QUERY_REQUEST_DEDUPING === true) {
|
|
144
168
|
// Here, we are calling fetchQueryDeduped at the network layer level,
|
|
145
169
|
// which ensures that only a single network request is active for a given
|
|
@@ -270,7 +294,7 @@ function loadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
|
|
|
270
294
|
};
|
|
271
295
|
|
|
272
296
|
let params;
|
|
273
|
-
let cancelOnLoadCallback;
|
|
297
|
+
let cancelOnLoadCallback: () => void;
|
|
274
298
|
let queryId;
|
|
275
299
|
if (preloadableRequest.kind === 'PreloadableConcreteRequest') {
|
|
276
300
|
const preloadableConcreteRequest: PreloadableConcreteRequest<TQuery> =
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
|
-
* @emails oncall+relay
|
|
8
7
|
* @flow strict-local
|
|
9
8
|
* @format
|
|
9
|
+
* @oncall relay
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
'use strict';
|
|
@@ -31,7 +31,6 @@ import type {
|
|
|
31
31
|
const {
|
|
32
32
|
Observable,
|
|
33
33
|
PreloadableQueryRegistry,
|
|
34
|
-
RelayFeatureFlags,
|
|
35
34
|
ReplaySubject,
|
|
36
35
|
createOperationDescriptor,
|
|
37
36
|
getRequest,
|
|
@@ -45,8 +44,8 @@ const WEAKMAP_SUPPORTED = typeof WeakMap === 'function';
|
|
|
45
44
|
const STORE_OR_NETWORK_DEFAULT: PreloadFetchPolicy = 'store-or-network';
|
|
46
45
|
|
|
47
46
|
const pendingQueriesByEnvironment = WEAKMAP_SUPPORTED
|
|
48
|
-
? new WeakMap()
|
|
49
|
-
: new Map();
|
|
47
|
+
? new WeakMap<IEnvironment, Map<string, PendingQueryEntry>>()
|
|
48
|
+
: new Map<IEnvironment, Map<string, PendingQueryEntry>>();
|
|
50
49
|
|
|
51
50
|
type PendingQueryEntry =
|
|
52
51
|
| $ReadOnly<{
|
|
@@ -92,7 +91,7 @@ function preloadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
|
|
|
92
91
|
);
|
|
93
92
|
const source =
|
|
94
93
|
queryEntry.kind === 'network'
|
|
95
|
-
? Observable.create(sink => {
|
|
94
|
+
? Observable.create<GraphQLResponse>(sink => {
|
|
96
95
|
let subscription;
|
|
97
96
|
if (pendingQueries.get(queryEntry.cacheKey) == null) {
|
|
98
97
|
const newQueryEntry = preloadQueryDeduped(
|
|
@@ -205,7 +204,7 @@ function preloadQueryDeduped<TQuery: OperationType>(
|
|
|
205
204
|
} else if (prevQueryEntry == null || prevQueryEntry.kind !== 'network') {
|
|
206
205
|
// Should fetch but we're not already fetching: fetch!
|
|
207
206
|
const source = network.execute(params, variables, networkCacheConfig, null);
|
|
208
|
-
const subject = new ReplaySubject();
|
|
207
|
+
const subject = new ReplaySubject<GraphQLResponse>();
|
|
209
208
|
nextQueryEntry = {
|
|
210
209
|
cacheKey,
|
|
211
210
|
fetchKey,
|