react-relay 14.0.0 → 15.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/ReactRelayContainerUtils.js.flow +1 -2
- package/ReactRelayContext.js +1 -1
- package/ReactRelayContext.js.flow +1 -2
- package/ReactRelayFragmentContainer.js.flow +6 -4
- package/ReactRelayFragmentMockRenderer.js.flow +1 -2
- package/ReactRelayLocalQueryRenderer.js.flow +5 -5
- package/ReactRelayPaginationContainer.js.flow +21 -14
- package/ReactRelayQueryFetcher.js.flow +28 -16
- package/ReactRelayQueryRenderer.js.flow +42 -13
- package/ReactRelayQueryRendererContext.js.flow +2 -3
- package/ReactRelayRefetchContainer.js.flow +9 -9
- package/ReactRelayTestMocker.js.flow +3 -3
- package/ReactRelayTypes.js.flow +7 -8
- package/RelayContext.js.flow +1 -2
- package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +4 -5
- package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +4 -5
- package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +4 -5
- package/__flowtests__/RelayModern-flowtest.js.flow +3 -4
- package/__flowtests__/RelayModernFlowtest_badref.graphql.js.flow +3 -4
- package/__flowtests__/RelayModernFlowtest_notref.graphql.js.flow +3 -4
- package/__flowtests__/RelayModernFlowtest_user.graphql.js.flow +3 -4
- package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +3 -4
- 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 -2
- package/buildReactRelayContainer.js.flow +7 -7
- package/getRootVariablesForFragments.js.flow +1 -3
- package/hooks.js +1 -1
- package/hooks.js.flow +4 -2
- package/index.js +1 -1
- package/index.js.flow +6 -2
- package/isRelayEnvironment.js.flow +1 -2
- 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 -2
- package/lib/ReactRelayContainerUtils.js +2 -3
- package/lib/ReactRelayContext.js +3 -4
- package/lib/ReactRelayFragmentContainer.js +47 -73
- package/lib/ReactRelayFragmentMockRenderer.js +2 -4
- package/lib/ReactRelayLocalQueryRenderer.js +18 -31
- package/lib/ReactRelayPaginationContainer.js +74 -164
- package/lib/ReactRelayQueryFetcher.js +49 -76
- package/lib/ReactRelayQueryRenderer.js +63 -84
- package/lib/ReactRelayQueryRendererContext.js +2 -2
- package/lib/ReactRelayRefetchContainer.js +58 -108
- package/lib/ReactRelayTestMocker.js +33 -68
- package/lib/ReactRelayTypes.js +2 -1
- package/lib/RelayContext.js +4 -7
- package/lib/assertFragmentMap.js +3 -5
- package/lib/buildReactRelayContainer.js +11 -27
- package/lib/getRootVariablesForFragments.js +6 -10
- package/lib/hooks.js +5 -18
- package/lib/index.js +7 -24
- package/lib/isRelayEnvironment.js +5 -4
- package/lib/jest-react/enqueueTask.js +5 -9
- package/lib/jest-react/index.js +0 -1
- package/lib/jest-react/internalAct.js +9 -20
- package/lib/legacy.js +2 -8
- package/lib/multi-actor/ActorChange.js +2 -5
- package/lib/multi-actor/index.js +2 -1
- package/lib/multi-actor/useRelayActorEnvironment.js +4 -8
- package/lib/relay-hooks/EntryPointContainer.react.js +9 -15
- package/lib/relay-hooks/EntryPointTypes.flow.js +5 -3
- package/lib/relay-hooks/FragmentResource.js +109 -203
- package/lib/relay-hooks/HooksImplementation.js +3 -6
- package/lib/relay-hooks/InternalLogger.js +2 -3
- package/lib/relay-hooks/LRUCache.js +2 -20
- package/lib/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js +33 -54
- package/lib/relay-hooks/MatchContainer.js +15 -24
- package/lib/relay-hooks/ProfilerContext.js +3 -3
- package/lib/relay-hooks/QueryResource.js +31 -101
- package/lib/relay-hooks/RelayEnvironmentProvider.js +5 -9
- package/lib/relay-hooks/SuspenseResource.js +9 -33
- package/lib/relay-hooks/loadEntryPoint.js +19 -31
- package/lib/relay-hooks/loadQuery.js +42 -78
- package/lib/relay-hooks/preloadQuery_DEPRECATED.js +11 -37
- package/lib/relay-hooks/prepareEntryPoint_DEPRECATED.js +9 -15
- package/lib/relay-hooks/react-cache/RelayReactCache.js +7 -12
- package/lib/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js +27 -81
- package/lib/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js +206 -0
- package/lib/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js +195 -215
- package/lib/relay-hooks/react-cache/useFragment_REACT_CACHE.js +5 -15
- package/lib/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js +17 -24
- package/lib/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js +149 -0
- package/lib/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js +24 -39
- package/lib/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js +325 -0
- package/lib/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js +37 -0
- package/lib/relay-hooks/useBlockingPaginationFragment.js +73 -93
- package/lib/relay-hooks/useClientQuery.js +30 -0
- package/lib/relay-hooks/useEntryPointLoader.js +18 -38
- package/lib/relay-hooks/useFetchTrackingRef.js +10 -12
- package/lib/relay-hooks/useFragment.js +8 -19
- package/lib/relay-hooks/useFragmentNode.js +20 -32
- package/lib/relay-hooks/useIsMountedRef.js +4 -6
- package/lib/relay-hooks/useIsOperationNodeActive.js +8 -20
- package/lib/relay-hooks/useIsParentQueryActive.js +3 -6
- package/lib/relay-hooks/useLazyLoadQuery.js +7 -24
- package/lib/relay-hooks/useLazyLoadQueryNode.js +23 -34
- package/lib/relay-hooks/useLoadMoreFunction.js +46 -78
- package/lib/relay-hooks/useMemoOperationDescriptor.js +6 -15
- package/lib/relay-hooks/useMemoVariables.js +15 -34
- package/lib/relay-hooks/useMutation.js +9 -27
- package/lib/relay-hooks/usePaginationFragment.js +73 -76
- package/lib/relay-hooks/usePreloadedQuery.js +13 -44
- package/lib/relay-hooks/useQueryLoader.js +24 -49
- package/lib/relay-hooks/useRefetchableFragment.js +19 -17
- package/lib/relay-hooks/useRefetchableFragmentNode.js +65 -109
- package/lib/relay-hooks/useRelayEnvironment.js +4 -8
- package/lib/relay-hooks/useStaticFragmentNodeWarning.js +4 -8
- package/lib/relay-hooks/useSubscribeToInvalidationState.js +8 -9
- package/lib/relay-hooks/useSubscription.js +5 -10
- package/lib/relay-hooks/useUnsafeRef_DEPRECATED.js +29 -0
- package/multi-actor/ActorChange.js.flow +1 -1
- package/multi-actor/index.js.flow +1 -1
- package/multi-actor/useRelayActorEnvironment.js.flow +2 -4
- 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 +3 -5
- package/relay-hooks/EntryPointTypes.flow.js.flow +37 -37
- package/relay-hooks/FragmentResource.js.flow +43 -19
- package/relay-hooks/HooksImplementation.js.flow +7 -9
- package/relay-hooks/InternalLogger.js.flow +1 -3
- package/relay-hooks/LRUCache.js.flow +1 -3
- package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +19 -14
- package/relay-hooks/MatchContainer.js.flow +6 -8
- package/relay-hooks/ProfilerContext.js.flow +1 -3
- package/relay-hooks/QueryResource.js.flow +29 -11
- package/relay-hooks/RelayEnvironmentProvider.js.flow +4 -6
- package/relay-hooks/SuspenseResource.js.flow +1 -3
- package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +6 -4
- package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +4 -4
- 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 +39 -39
- package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +1 -3
- package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +37 -38
- package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +18 -20
- package/relay-hooks/__flowtests__/utils.js.flow +21 -12
- package/relay-hooks/loadEntryPoint.js.flow +11 -6
- package/relay-hooks/loadQuery.js.flow +11 -7
- package/relay-hooks/preloadQuery_DEPRECATED.js.flow +9 -12
- package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +13 -10
- package/relay-hooks/react-cache/RelayReactCache.js.flow +1 -3
- package/relay-hooks/react-cache/getQueryResultOrFetchQuery_REACT_CACHE.js.flow +26 -20
- package/relay-hooks/react-cache/readFragmentInternal_REACT_CACHE.js.flow +297 -0
- package/relay-hooks/react-cache/useFragmentInternal_REACT_CACHE.js.flow +136 -96
- package/relay-hooks/react-cache/useFragment_REACT_CACHE.js.flow +1 -3
- package/relay-hooks/react-cache/useLazyLoadQuery_REACT_CACHE.js.flow +3 -5
- package/relay-hooks/react-cache/usePaginationFragment_REACT_CACHE.js.flow +190 -0
- package/relay-hooks/react-cache/usePreloadedQuery_REACT_CACHE.js.flow +3 -6
- package/relay-hooks/react-cache/useRefetchableFragmentInternal_REACT_CACHE.js.flow +601 -0
- package/relay-hooks/react-cache/useRefetchableFragment_REACT_CACHE.js.flow +65 -0
- package/relay-hooks/useBlockingPaginationFragment.js.flow +86 -59
- package/relay-hooks/useClientQuery.js.flow +39 -0
- package/relay-hooks/useEntryPointLoader.js.flow +16 -14
- package/relay-hooks/useFetchTrackingRef.js.flow +7 -8
- package/relay-hooks/useFragment.js.flow +2 -4
- package/relay-hooks/useFragmentNode.js.flow +7 -8
- package/relay-hooks/useIsMountedRef.js.flow +2 -4
- package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
- package/relay-hooks/useIsParentQueryActive.js.flow +1 -1
- package/relay-hooks/useLazyLoadQuery.js.flow +9 -32
- package/relay-hooks/useLazyLoadQueryNode.js.flow +4 -6
- package/relay-hooks/useLoadMoreFunction.js.flow +20 -17
- package/relay-hooks/useMemoOperationDescriptor.js.flow +3 -5
- package/relay-hooks/useMemoVariables.js.flow +13 -31
- package/relay-hooks/useMutation.js.flow +6 -8
- package/relay-hooks/usePaginationFragment.js.flow +75 -43
- package/relay-hooks/usePreloadedQuery.js.flow +49 -43
- package/relay-hooks/useQueryLoader.js.flow +89 -28
- package/relay-hooks/useRefetchableFragment.js.flow +83 -23
- package/relay-hooks/useRefetchableFragmentNode.js.flow +26 -22
- package/relay-hooks/useRelayEnvironment.js.flow +2 -4
- package/relay-hooks/useStaticFragmentNodeWarning.js.flow +3 -5
- package/relay-hooks/useSubscribeToInvalidationState.js.flow +2 -4
- package/relay-hooks/useSubscription.js.flow +1 -3
- package/relay-hooks/useUnsafeRef_DEPRECATED.js.flow +25 -0
- package/lib/readContext.js +0 -28
- package/readContext.js.flow +0 -31
@@ -4,92 +4,92 @@
|
|
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
|
-
// flowlint ambiguous-object-type:error
|
13
|
-
|
14
12
|
import type {LoadMoreFn} from '../useLoadMoreFunction';
|
15
13
|
import type {
|
16
14
|
FetchFn,
|
17
15
|
NonNullableData,
|
18
16
|
NullableData,
|
19
|
-
QueryOperation,
|
20
17
|
QueryVariables,
|
21
18
|
QueryVariablesSubset,
|
22
19
|
} from './utils';
|
23
|
-
import type {IEnvironment,
|
20
|
+
import type {IEnvironment, Variables} from 'relay-runtime';
|
24
21
|
|
25
22
|
import useBlockingPaginationFragment from '../useBlockingPaginationFragment';
|
26
23
|
import {
|
27
24
|
fragmentData,
|
28
|
-
fragmentInput,
|
29
25
|
keyAnotherNonNullable,
|
30
26
|
keyAnotherNullable,
|
31
27
|
keyNonNullable,
|
32
28
|
keyNullable,
|
29
|
+
refetchableFragmentInput,
|
33
30
|
} from './utils';
|
34
31
|
|
35
32
|
type ExpectedReturnType<
|
36
|
-
|
37
|
-
|
33
|
+
TRefetchVariables: Variables,
|
34
|
+
TLoadMoreVariables: Variables,
|
38
35
|
TFragmentData,
|
39
|
-
> = {
|
36
|
+
> = {
|
40
37
|
data: TFragmentData,
|
41
|
-
loadNext: LoadMoreFn<
|
42
|
-
loadPrevious: LoadMoreFn<
|
38
|
+
loadNext: LoadMoreFn<TLoadMoreVariables>,
|
39
|
+
loadPrevious: LoadMoreFn<TLoadMoreVariables>,
|
43
40
|
hasNext: boolean,
|
44
41
|
hasPrevious: boolean,
|
45
|
-
refetch: FetchFn<
|
46
|
-
|
42
|
+
refetch: FetchFn<TRefetchVariables>,
|
43
|
+
};
|
47
44
|
|
48
45
|
/* eslint-disable react-hooks/rules-of-hooks */
|
49
46
|
|
50
47
|
// Nullability of returned data type is correct
|
51
|
-
(useBlockingPaginationFragment
|
52
|
-
|
48
|
+
(useBlockingPaginationFragment(
|
49
|
+
refetchableFragmentInput,
|
53
50
|
keyNonNullable,
|
54
|
-
): ExpectedReturnType<
|
51
|
+
): ExpectedReturnType<QueryVariablesSubset, QueryVariables, NonNullableData>);
|
55
52
|
|
56
|
-
(useBlockingPaginationFragment
|
57
|
-
|
53
|
+
(useBlockingPaginationFragment(
|
54
|
+
refetchableFragmentInput,
|
58
55
|
keyNullable,
|
59
|
-
): ExpectedReturnType<
|
56
|
+
): ExpectedReturnType<QueryVariables, QueryVariables, NullableData>);
|
60
57
|
|
61
58
|
// $FlowExpectedError: can't cast nullable to non-nullable
|
62
|
-
(useBlockingPaginationFragment
|
63
|
-
|
59
|
+
(useBlockingPaginationFragment(
|
60
|
+
refetchableFragmentInput,
|
64
61
|
keyNullable,
|
65
|
-
): ExpectedReturnType<
|
62
|
+
): ExpectedReturnType<QueryVariables, QueryVariables, NonNullableData>);
|
66
63
|
|
67
64
|
// $FlowExpectedError: actual type of returned data is correct
|
68
|
-
(useBlockingPaginationFragment
|
69
|
-
|
65
|
+
(useBlockingPaginationFragment(
|
66
|
+
refetchableFragmentInput,
|
67
|
+
// $FlowExpectedError[incompatible-call]
|
70
68
|
keyAnotherNonNullable,
|
71
|
-
): ExpectedReturnType<
|
72
|
-
|
73
|
-
|
74
|
-
|
69
|
+
): ExpectedReturnType<QueryVariables, QueryVariablesSubset, NonNullableData>);
|
70
|
+
|
71
|
+
// $FlowExpectedError[incompatible-call] `Example_user$fragmentType` is incompatible with `FragmentType`
|
72
|
+
(useBlockingPaginationFragment(
|
73
|
+
refetchableFragmentInput,
|
74
|
+
// $FlowExpectedError[incompatible-call]
|
75
75
|
keyAnotherNullable,
|
76
|
-
): ExpectedReturnType<
|
76
|
+
): ExpectedReturnType<QueryVariables, QueryVariables, NullableData>);
|
77
77
|
|
78
78
|
// $FlowExpectedError: Key should not be a user provided object
|
79
|
-
useBlockingPaginationFragment
|
79
|
+
useBlockingPaginationFragment(fragmentInput, {abc: 123});
|
80
80
|
|
81
81
|
// $FlowExpectedError: Key should not be an empty object
|
82
|
-
useBlockingPaginationFragment
|
82
|
+
useBlockingPaginationFragment(fragmentInput, {});
|
83
83
|
|
84
84
|
// $FlowExpectedError: Key should be the `<name>$key` type from generated flow
|
85
|
-
useBlockingPaginationFragment
|
85
|
+
useBlockingPaginationFragment(fragmentInput, fragmentData);
|
86
86
|
|
87
87
|
// Refetch function options:
|
88
88
|
declare var variables: QueryVariables;
|
89
89
|
declare var environment: IEnvironment;
|
90
90
|
|
91
|
-
const {refetch} = useBlockingPaginationFragment
|
92
|
-
|
91
|
+
const {refetch} = useBlockingPaginationFragment(
|
92
|
+
refetchableFragmentInput,
|
93
93
|
keyNonNullable,
|
94
94
|
);
|
95
95
|
// $FlowExpectedError: internal option
|
@@ -103,11 +103,11 @@ refetch(variables, {
|
|
103
103
|
});
|
104
104
|
|
105
105
|
// LoadMore options
|
106
|
-
declare var extraVariables: {
|
107
|
-
declare var invalidVariables: {
|
106
|
+
declare var extraVariables: {nickname: string};
|
107
|
+
declare var invalidVariables: {foo: string};
|
108
108
|
|
109
|
-
const {loadNext} = useBlockingPaginationFragment
|
110
|
-
|
109
|
+
const {loadNext} = useBlockingPaginationFragment(
|
110
|
+
refetchableFragmentInput,
|
111
111
|
keyNonNullable,
|
112
112
|
);
|
113
113
|
// Accepts extraVariables
|
@@ -115,8 +115,8 @@ loadNext(10, {
|
|
115
115
|
UNSTABLE_extraVariables: extraVariables,
|
116
116
|
});
|
117
117
|
|
118
|
-
// $FlowExpectedError: doesn't accept variables not available in the Flow type
|
119
118
|
loadNext(10, {
|
119
|
+
// $FlowExpectedError: doesn't accept variables not available in the Flow type
|
120
120
|
UNSTABLE_extraVariables: invalidVariables,
|
121
121
|
});
|
122
122
|
|
@@ -4,13 +4,11 @@
|
|
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
|
-
// flowlint ambiguous-object-type:error
|
13
|
-
|
14
12
|
import type {
|
15
13
|
useFragmentFlowtest_user$data,
|
16
14
|
useFragmentFlowtest_user$key,
|
@@ -4,94 +4,93 @@
|
|
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
|
-
// flowlint ambiguous-object-type:error
|
13
|
-
|
14
12
|
import type {LoadMoreFn} from '../useLoadMoreFunction';
|
15
13
|
import type {
|
16
14
|
FetchFn,
|
17
15
|
NonNullableData,
|
18
16
|
NullableData,
|
19
|
-
QueryOperation,
|
20
17
|
QueryVariables,
|
21
18
|
QueryVariablesSubset,
|
22
19
|
} from './utils';
|
23
|
-
import type {IEnvironment,
|
20
|
+
import type {IEnvironment, Variables} from 'relay-runtime';
|
24
21
|
|
25
22
|
import usePaginationFragment from '../usePaginationFragment';
|
26
23
|
import {
|
27
24
|
fragmentData,
|
28
|
-
fragmentInput,
|
29
25
|
keyAnotherNonNullable,
|
30
26
|
keyAnotherNullable,
|
31
27
|
keyNonNullable,
|
32
28
|
keyNullable,
|
29
|
+
refetchableFragmentInput,
|
33
30
|
} from './utils';
|
34
31
|
|
35
32
|
type ExpectedReturnType<
|
36
|
-
|
37
|
-
|
33
|
+
TRefetchVariables: Variables,
|
34
|
+
TLoadMoreVariables: Variables,
|
38
35
|
TFragmentData,
|
39
|
-
> = {
|
36
|
+
> = {
|
40
37
|
data: TFragmentData,
|
41
|
-
loadNext: LoadMoreFn<
|
42
|
-
loadPrevious: LoadMoreFn<
|
38
|
+
loadNext: LoadMoreFn<TLoadMoreVariables>,
|
39
|
+
loadPrevious: LoadMoreFn<TLoadMoreVariables>,
|
43
40
|
hasNext: boolean,
|
44
41
|
hasPrevious: boolean,
|
45
42
|
isLoadingNext: boolean,
|
46
43
|
isLoadingPrevious: boolean,
|
47
|
-
refetch: FetchFn<
|
48
|
-
|
44
|
+
refetch: FetchFn<TRefetchVariables>,
|
45
|
+
};
|
49
46
|
|
50
47
|
/* eslint-disable react-hooks/rules-of-hooks */
|
51
48
|
|
52
49
|
// Nullability of returned data type is correct
|
53
|
-
(usePaginationFragment
|
54
|
-
|
50
|
+
(usePaginationFragment(
|
51
|
+
refetchableFragmentInput,
|
55
52
|
keyNonNullable,
|
56
|
-
): ExpectedReturnType<
|
53
|
+
): ExpectedReturnType<QueryVariablesSubset, QueryVariables, NonNullableData>);
|
57
54
|
|
58
|
-
(usePaginationFragment
|
59
|
-
|
55
|
+
(usePaginationFragment(
|
56
|
+
refetchableFragmentInput,
|
60
57
|
keyNullable,
|
61
|
-
): ExpectedReturnType<
|
58
|
+
): ExpectedReturnType<QueryVariables, QueryVariables, NullableData>);
|
62
59
|
|
63
60
|
// $FlowExpectedError: can't cast nullable to non-nullable
|
64
|
-
(usePaginationFragment
|
65
|
-
|
61
|
+
(usePaginationFragment(
|
62
|
+
refetchableFragmentInput,
|
66
63
|
keyNullable,
|
67
|
-
): ExpectedReturnType<
|
64
|
+
): ExpectedReturnType<QueryVariables, QueryVariables, NonNullableData>);
|
68
65
|
|
69
66
|
// $FlowExpectedError: actual type of returned data is correct
|
70
|
-
(usePaginationFragment
|
71
|
-
|
67
|
+
(usePaginationFragment(
|
68
|
+
refetchableFragmentInput,
|
69
|
+
// $FlowFixMe[incompatible-call]
|
72
70
|
keyAnotherNonNullable,
|
73
|
-
): ExpectedReturnType<
|
71
|
+
): ExpectedReturnType<QueryVariables, QueryVariablesSubset, NonNullableData>);
|
74
72
|
// $FlowExpectedError
|
75
|
-
(usePaginationFragment
|
76
|
-
|
73
|
+
(usePaginationFragment(
|
74
|
+
refetchableFragmentInput,
|
75
|
+
// $FlowFixMe[incompatible-call]
|
77
76
|
keyAnotherNullable,
|
78
|
-
): ExpectedReturnType<
|
77
|
+
): ExpectedReturnType<QueryVariables, QueryVariables, NonNullableData>);
|
79
78
|
|
80
79
|
// $FlowExpectedError: Key should not be a user provided object
|
81
|
-
usePaginationFragment
|
80
|
+
usePaginationFragment(refetchableFragmentInput, {abc: 123});
|
82
81
|
|
83
82
|
// $FlowExpectedError: Key should not be an empty object
|
84
|
-
usePaginationFragment
|
83
|
+
usePaginationFragment(refetchableFragmentInput, {});
|
85
84
|
|
86
85
|
// $FlowExpectedError: Key should be the `<name>$key` type from generated flow
|
87
|
-
usePaginationFragment
|
86
|
+
usePaginationFragment(refetchableFragmentInput, fragmentData);
|
88
87
|
|
89
88
|
// Refetch function options:
|
90
89
|
declare var variables: QueryVariables;
|
91
90
|
declare var environment: IEnvironment;
|
92
91
|
|
93
|
-
const {refetch} = usePaginationFragment
|
94
|
-
|
92
|
+
const {refetch} = usePaginationFragment(
|
93
|
+
refetchableFragmentInput,
|
95
94
|
keyNonNullable,
|
96
95
|
);
|
97
96
|
// $FlowExpectedError: internal option
|
@@ -105,11 +104,11 @@ refetch(variables, {
|
|
105
104
|
});
|
106
105
|
|
107
106
|
// LoadMore options
|
108
|
-
declare var extraVariables: {
|
109
|
-
declare var invalidVariables: {
|
107
|
+
declare var extraVariables: {nickname: string};
|
108
|
+
declare var invalidVariables: {foo: string};
|
110
109
|
|
111
|
-
const {loadNext} = usePaginationFragment
|
112
|
-
|
110
|
+
const {loadNext} = usePaginationFragment(
|
111
|
+
refetchableFragmentInput,
|
113
112
|
keyNonNullable,
|
114
113
|
);
|
115
114
|
// Accepts extraVariables
|
@@ -117,8 +116,8 @@ loadNext(10, {
|
|
117
116
|
UNSTABLE_extraVariables: extraVariables,
|
118
117
|
});
|
119
118
|
|
120
|
-
// $FlowExpectedError: doesn't accept variables not available in the Flow type
|
121
119
|
loadNext(10, {
|
120
|
+
// $FlowExpectedError: doesn't accept variables not available in the Flow type
|
122
121
|
UNSTABLE_extraVariables: invalidVariables,
|
123
122
|
});
|
124
123
|
|
@@ -4,18 +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
|
-
// flowlint ambiguous-object-type:error
|
13
|
-
|
14
12
|
import type {
|
15
13
|
FetchFn,
|
16
14
|
NonNullableData,
|
17
15
|
NullableData,
|
18
|
-
QueryOperation,
|
19
16
|
QueryVariables,
|
20
17
|
QueryVariablesSubset,
|
21
18
|
} from './utils';
|
@@ -24,64 +21,65 @@ import type {IEnvironment} from 'relay-runtime';
|
|
24
21
|
import useRefetchableFragment from '../useRefetchableFragment';
|
25
22
|
import {
|
26
23
|
fragmentData,
|
27
|
-
fragmentInput,
|
28
24
|
keyAnotherNonNullable,
|
29
25
|
keyAnotherNullable,
|
30
26
|
keyNonNullable,
|
31
27
|
keyNullable,
|
28
|
+
refetchableFragmentInput,
|
32
29
|
} from './utils';
|
33
30
|
|
34
31
|
/* eslint-disable react-hooks/rules-of-hooks */
|
35
32
|
|
36
33
|
// Nullability of returned data type is correct
|
37
|
-
(useRefetchableFragment
|
34
|
+
(useRefetchableFragment(refetchableFragmentInput, keyNonNullable): [
|
38
35
|
NonNullableData,
|
39
36
|
FetchFn<QueryVariablesSubset>,
|
40
37
|
]);
|
41
38
|
|
42
|
-
(useRefetchableFragment
|
39
|
+
(useRefetchableFragment(refetchableFragmentInput, keyNullable): [
|
43
40
|
NullableData,
|
44
41
|
FetchFn<QueryVariables>,
|
45
42
|
]);
|
46
43
|
|
47
44
|
// $FlowExpectedError: can't cast nullable to non-nullable
|
48
|
-
(useRefetchableFragment
|
45
|
+
(useRefetchableFragment(refetchableFragmentInput, keyNullable): [
|
49
46
|
NonNullableData,
|
50
47
|
FetchFn<QueryVariables>,
|
51
48
|
]);
|
52
49
|
|
53
50
|
// $FlowExpectedError: refetch requires exact type if key is nullable
|
54
|
-
(useRefetchableFragment
|
51
|
+
(useRefetchableFragment(refetchableFragmentInput, keyNullable): [
|
55
52
|
NullableData,
|
56
53
|
FetchFn<QueryVariablesSubset>,
|
57
54
|
]);
|
58
55
|
|
59
56
|
// $FlowExpectedError: actual type of returned data is correct
|
60
|
-
(useRefetchableFragment
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
57
|
+
(useRefetchableFragment(refetchableFragmentInput, keyAnotherNonNullable): [
|
58
|
+
NonNullableData,
|
59
|
+
FetchFn<QueryVariablesSubset>,
|
60
|
+
]);
|
61
|
+
|
62
|
+
// $FlowExpectedError - incompatible key types
|
63
|
+
(useRefetchableFragment(refetchableFragmentInput, keyAnotherNullable): [
|
66
64
|
NullableData,
|
67
65
|
FetchFn<QueryVariables>,
|
68
66
|
]);
|
69
67
|
|
70
68
|
// $FlowExpectedError: Key should not be a user provided object
|
71
|
-
useRefetchableFragment
|
69
|
+
useRefetchableFragment(refetchableFragmentInput, {abc: 123});
|
72
70
|
|
73
71
|
// $FlowExpectedError: Key should not be an empty object
|
74
|
-
useRefetchableFragment
|
72
|
+
useRefetchableFragment(refetchableFragmentInput, {});
|
75
73
|
|
76
74
|
// $FlowExpectedError: Key should be the `<name>$key` type from generated flow
|
77
|
-
useRefetchableFragment
|
75
|
+
useRefetchableFragment(refetchableFragmentInput, fragmentData);
|
78
76
|
|
79
77
|
// Refetch function options:
|
80
78
|
declare var variables: QueryVariables;
|
81
79
|
declare var environment: IEnvironment;
|
82
80
|
|
83
|
-
const [
|
84
|
-
|
81
|
+
const [, refetch] = useRefetchableFragment(
|
82
|
+
refetchableFragmentInput,
|
85
83
|
keyNonNullable,
|
86
84
|
);
|
87
85
|
// $FlowExpectedError: internal option
|
@@ -4,22 +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
|
-
// flowlint ambiguous-object-type:error
|
13
|
-
|
14
12
|
'use strict';
|
15
13
|
|
16
|
-
import type {
|
14
|
+
import type {
|
15
|
+
Disposable,
|
16
|
+
Fragment,
|
17
|
+
FragmentType,
|
18
|
+
RefetchableFragment,
|
19
|
+
} from 'relay-runtime';
|
17
20
|
|
18
21
|
declare export var fragmentInput: Fragment<
|
19
22
|
Example_user$fragmentType,
|
20
23
|
Example_user$data,
|
21
24
|
>;
|
22
25
|
|
26
|
+
declare export var refetchableFragmentInput: RefetchableFragment<
|
27
|
+
Example_user$fragmentType,
|
28
|
+
Example_user$data,
|
29
|
+
QueryVariables,
|
30
|
+
>;
|
31
|
+
|
23
32
|
declare export opaque type Example_user$fragmentType: FragmentType;
|
24
33
|
export type Example_user$data = NonNullableData;
|
25
34
|
export type Example_user$key = {
|
@@ -28,18 +37,18 @@ export type Example_user$key = {
|
|
28
37
|
...
|
29
38
|
};
|
30
39
|
|
31
|
-
export type NonNullableData = {
|
40
|
+
export type NonNullableData = {
|
32
41
|
+id: string,
|
33
42
|
+count: number,
|
34
|
-
|
43
|
+
};
|
35
44
|
export type NullableData = ?NonNullableData;
|
36
45
|
export type NonNullablePluralData = $ReadOnlyArray<NonNullableData>;
|
37
46
|
export type NullablePluralData = ?$ReadOnlyArray<NonNullableData>;
|
38
47
|
|
39
|
-
export type AnotherNonNullableData = {
|
48
|
+
export type AnotherNonNullableData = {
|
40
49
|
+name: ?string,
|
41
50
|
+friends: ?number,
|
42
|
-
|
51
|
+
};
|
43
52
|
|
44
53
|
declare export var keyNonNullable: Example_user$key;
|
45
54
|
|
@@ -66,16 +75,16 @@ declare export var fragmentData: {
|
|
66
75
|
...
|
67
76
|
};
|
68
77
|
|
69
|
-
export type QueryOperation = {
|
78
|
+
export type QueryOperation = {
|
70
79
|
+variables: QueryVariables,
|
71
80
|
+response: {...},
|
72
|
-
|
81
|
+
};
|
73
82
|
|
74
|
-
export type QueryVariables = {
|
83
|
+
export type QueryVariables = {
|
75
84
|
id: string,
|
76
85
|
nickname: ?string,
|
77
86
|
name: string,
|
78
|
-
|
87
|
+
};
|
79
88
|
|
80
89
|
export type QueryVariablesSubset = {
|
81
90
|
id: string,
|
@@ -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';
|
@@ -58,6 +58,7 @@ function loadEntryPoint<
|
|
58
58
|
environmentProviderOptions,
|
59
59
|
);
|
60
60
|
|
61
|
+
// $FlowFixMe[underconstrained-implicit-instantiation]
|
61
62
|
preloadedQueries[queryPropName] = loadQuery(
|
62
63
|
environment,
|
63
64
|
parameters,
|
@@ -81,11 +82,15 @@ function loadEntryPoint<
|
|
81
82
|
}
|
82
83
|
const {entryPoint: nestedEntryPoint, entryPointParams: nestedParams} =
|
83
84
|
entryPointDescription;
|
84
|
-
preloadedEntryPoints[entryPointPropName] = loadEntryPoint
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
85
|
+
preloadedEntryPoints[entryPointPropName] = loadEntryPoint<
|
86
|
+
_,
|
87
|
+
{...},
|
88
|
+
{...},
|
89
|
+
{...},
|
90
|
+
mixed,
|
91
|
+
EntryPointComponent<{...}, {...}, {...}, mixed>,
|
92
|
+
_,
|
93
|
+
>(environmentProvider, nestedEntryPoint, nestedParams);
|
89
94
|
});
|
90
95
|
}
|
91
96
|
|
@@ -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,
|
@@ -30,11 +31,11 @@ import type {
|
|
30
31
|
const invariant = require('invariant');
|
31
32
|
const React = require('react');
|
32
33
|
const {
|
34
|
+
__internal: {fetchQueryDeduped},
|
33
35
|
Observable,
|
34
36
|
PreloadableQueryRegistry,
|
35
37
|
RelayFeatureFlags,
|
36
38
|
ReplaySubject,
|
37
|
-
__internal: {fetchQueryDeduped},
|
38
39
|
createOperationDescriptor,
|
39
40
|
getRequest,
|
40
41
|
getRequestIdentifier,
|
@@ -55,7 +56,10 @@ function useTrackLoadQueryInRender() {
|
|
55
56
|
}
|
56
57
|
}
|
57
58
|
|
58
|
-
function loadQuery<
|
59
|
+
function loadQuery<
|
60
|
+
TQuery: OperationType,
|
61
|
+
TEnvironmentProviderOptions = EnvironmentProviderOptions,
|
62
|
+
>(
|
59
63
|
environment: IEnvironment,
|
60
64
|
preloadableRequest: GraphQLTaggedNode | PreloadableConcreteRequest<TQuery>,
|
61
65
|
variables: TQuery['variables'],
|
@@ -115,8 +119,8 @@ function loadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
|
|
115
119
|
// allows us to capture the events that occur during the eager execution
|
116
120
|
// of the operation, and then replay them to the Observable we
|
117
121
|
// ultimately return.
|
118
|
-
const executionSubject = new ReplaySubject();
|
119
|
-
const returnedObservable = Observable.create(sink =>
|
122
|
+
const executionSubject = new ReplaySubject<GraphQLResponse>();
|
123
|
+
const returnedObservable = Observable.create<GraphQLResponse>(sink =>
|
120
124
|
executionSubject.subscribe(sink),
|
121
125
|
);
|
122
126
|
|
@@ -139,7 +143,7 @@ function loadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
|
|
139
143
|
didMakeNetworkRequest = true;
|
140
144
|
|
141
145
|
let observable;
|
142
|
-
const subject = new ReplaySubject();
|
146
|
+
const subject = new ReplaySubject<GraphQLResponse>();
|
143
147
|
if (RelayFeatureFlags.ENABLE_LOAD_QUERY_REQUEST_DEDUPING === true) {
|
144
148
|
// Here, we are calling fetchQueryDeduped at the network layer level,
|
145
149
|
// which ensures that only a single network request is active for a given
|
@@ -270,7 +274,7 @@ function loadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
|
|
270
274
|
};
|
271
275
|
|
272
276
|
let params;
|
273
|
-
let cancelOnLoadCallback;
|
277
|
+
let cancelOnLoadCallback: () => void;
|
274
278
|
let queryId;
|
275
279
|
if (preloadableRequest.kind === 'PreloadableConcreteRequest') {
|
276
280
|
const preloadableConcreteRequest: PreloadableConcreteRequest<TQuery> =
|
@@ -4,13 +4,11 @@
|
|
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
|
-
// flowlint ambiguous-object-type:error
|
13
|
-
|
14
12
|
'use strict';
|
15
13
|
|
16
14
|
import type {
|
@@ -33,7 +31,6 @@ import type {
|
|
33
31
|
const {
|
34
32
|
Observable,
|
35
33
|
PreloadableQueryRegistry,
|
36
|
-
RelayFeatureFlags,
|
37
34
|
ReplaySubject,
|
38
35
|
createOperationDescriptor,
|
39
36
|
getRequest,
|
@@ -47,11 +44,11 @@ const WEAKMAP_SUPPORTED = typeof WeakMap === 'function';
|
|
47
44
|
const STORE_OR_NETWORK_DEFAULT: PreloadFetchPolicy = 'store-or-network';
|
48
45
|
|
49
46
|
const pendingQueriesByEnvironment = WEAKMAP_SUPPORTED
|
50
|
-
? new WeakMap()
|
51
|
-
: new Map();
|
47
|
+
? new WeakMap<IEnvironment, Map<string, PendingQueryEntry>>()
|
48
|
+
: new Map<IEnvironment, Map<string, PendingQueryEntry>>();
|
52
49
|
|
53
50
|
type PendingQueryEntry =
|
54
|
-
| $ReadOnly<{
|
51
|
+
| $ReadOnly<{
|
55
52
|
cacheKey: string,
|
56
53
|
fetchKey: ?string | ?number,
|
57
54
|
fetchPolicy: PreloadFetchPolicy,
|
@@ -61,8 +58,8 @@ type PendingQueryEntry =
|
|
61
58
|
status: PreloadQueryStatus,
|
62
59
|
subject: ReplaySubject<GraphQLResponse>,
|
63
60
|
subscription: Subscription,
|
64
|
-
|
65
|
-
| $ReadOnly<{
|
61
|
+
}>
|
62
|
+
| $ReadOnly<{
|
66
63
|
cacheKey: string,
|
67
64
|
fetchKey: ?string | ?number,
|
68
65
|
fetchPolicy: PreloadFetchPolicy,
|
@@ -70,7 +67,7 @@ type PendingQueryEntry =
|
|
70
67
|
id: ?string,
|
71
68
|
name: string,
|
72
69
|
status: PreloadQueryStatus,
|
73
|
-
|
70
|
+
}>;
|
74
71
|
|
75
72
|
function preloadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
|
76
73
|
environment: IEnvironment,
|
@@ -94,7 +91,7 @@ function preloadQuery<TQuery: OperationType, TEnvironmentProviderOptions>(
|
|
94
91
|
);
|
95
92
|
const source =
|
96
93
|
queryEntry.kind === 'network'
|
97
|
-
? Observable.create(sink => {
|
94
|
+
? Observable.create<GraphQLResponse>(sink => {
|
98
95
|
let subscription;
|
99
96
|
if (pendingQueries.get(queryEntry.cacheKey) == null) {
|
100
97
|
const newQueryEntry = preloadQueryDeduped(
|
@@ -207,7 +204,7 @@ function preloadQueryDeduped<TQuery: OperationType>(
|
|
207
204
|
} else if (prevQueryEntry == null || prevQueryEntry.kind !== 'network') {
|
208
205
|
// Should fetch but we're not already fetching: fetch!
|
209
206
|
const source = network.execute(params, variables, networkCacheConfig, null);
|
210
|
-
const subject = new ReplaySubject();
|
207
|
+
const subject = new ReplaySubject<GraphQLResponse>();
|
211
208
|
nextQueryEntry = {
|
212
209
|
cacheKey,
|
213
210
|
fetchKey,
|