react-relay 20.1.1 → 21.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/ReactRelayContext.js +1 -1
- package/ReactRelayContext.js.flow +2 -2
- package/ReactRelayFragmentContainer.js.flow +8 -9
- package/ReactRelayLocalQueryRenderer.js.flow +11 -3
- package/ReactRelayLoggingContext.js.flow +3 -3
- package/ReactRelayPaginationContainer.js.flow +31 -24
- package/ReactRelayQueryFetcher.js.flow +1 -1
- package/ReactRelayQueryRenderer.js.flow +2 -2
- package/ReactRelayQueryRendererContext.js.flow +2 -2
- package/ReactRelayRefetchContainer.js.flow +17 -14
- package/ReactRelayTestMocker.js.flow +10 -10
- package/ReactRelayTypes.js.flow +18 -20
- package/RelayContext.js.flow +3 -3
- package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +11 -11
- package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +5 -5
- package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +5 -5
- package/__flowtests__/RelayModern-flowtest.js.flow +24 -27
- package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +1 -1
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +3 -4
- package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +3 -4
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +9 -10
- package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +4 -5
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +9 -10
- package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +4 -5
- package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +3 -4
- package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +3 -4
- package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +3 -4
- package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +5 -6
- package/buildReactRelayContainer.js.flow +4 -4
- package/getRootVariablesForFragments.js.flow +1 -1
- package/hooks.js +1 -1
- package/hooks.js.flow +23 -8
- package/index.js +1 -1
- package/index.js.flow +40 -14
- package/isRelayEnvironment.js.flow +1 -1
- package/jest-react/internalAct.js.flow +1 -1
- package/legacy.js +1 -1
- package/legacy.js.flow +32 -13
- package/lib/ReactRelayFragmentContainer.js +1 -1
- package/lib/ReactRelayPaginationContainer.js +8 -8
- package/lib/ReactRelayRefetchContainer.js +8 -8
- package/lib/ReactRelayTestMocker.js +5 -5
- package/lib/hooks.js +18 -8
- package/lib/index.js +30 -14
- package/lib/legacy.js +26 -13
- package/lib/relay-hooks/legacy/useBlockingPaginationFragment.js +5 -5
- package/lib/relay-hooks/legacy/useRefetchableFragmentNode.js +34 -34
- package/lib/relay-hooks/loadEntryPoint.js +2 -2
- package/lib/relay-hooks/loadQuery.js +14 -14
- package/lib/relay-hooks/preloadQuery_DEPRECATED.js +10 -10
- package/lib/relay-hooks/readFragmentInternal.js +6 -6
- package/lib/relay-hooks/rsc/serverFetchQuery.js +20 -0
- package/lib/relay-hooks/rsc/serverPreloadQuery.js +31 -0
- package/lib/relay-hooks/rsc/serverReadFragment.js +15 -0
- package/lib/relay-hooks/rsc/useQueryFromServer.js +62 -0
- package/lib/relay-hooks/useFragmentInternal_CURRENT.js +49 -25
- package/lib/relay-hooks/useFragmentInternal_EXPERIMENTAL.js +81 -44
- package/lib/relay-hooks/useLazyLoadQueryNode.js +32 -19
- package/lib/relay-hooks/useMutation.js +6 -14
- package/lib/relay-hooks/useMutationAction_EXPERIMENTAL.js +26 -0
- package/lib/relay-hooks/usePreloadedQuery.js +52 -47
- package/lib/relay-hooks/useQueryLoader.js +2 -2
- package/lib/relay-hooks/useQueryLoader_EXPERIMENTAL.js +2 -2
- package/lib/relay-hooks/useRefetchableFragmentInternal.js +31 -31
- package/lib/rsc-client_EXPERIMENTAL.js +7 -0
- package/lib/rsc_EXPERIMENTAL.js +43 -0
- package/multi-actor/ActorChange.js.flow +1 -1
- package/package.json +3 -2
- package/relay-hooks/EntryPointContainer.react.js.flow +6 -6
- package/relay-hooks/EntryPointTypes.flow.js.flow +61 -67
- package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +23 -21
- package/relay-hooks/MatchContainer.js.flow +12 -6
- package/relay-hooks/NestedRelayEntryPointBuilderUtils.js.flow +3 -9
- package/relay-hooks/QueryResource.js.flow +6 -6
- package/relay-hooks/RelayEnvironmentProvider.js.flow +2 -2
- package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +6 -6
- package/relay-hooks/__flowtests__/EntryPointTypes/ExtractQueryTypes-flowtest.js.flow +48 -1
- package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +9 -9
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +3 -4
- package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +5 -6
- package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +27 -32
- package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +25 -25
- package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +26 -32
- package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +23 -30
- package/relay-hooks/__flowtests__/utils.js.flow +4 -4
- package/relay-hooks/getConnectionState.js.flow +2 -2
- package/relay-hooks/legacy/FragmentResource.js.flow +13 -13
- package/relay-hooks/legacy/useBlockingPaginationFragment.js.flow +24 -25
- package/relay-hooks/legacy/useFragmentNode.js.flow +4 -4
- package/relay-hooks/legacy/useRefetchableFragmentNode.js.flow +79 -81
- package/relay-hooks/loadEntryPoint.js.flow +15 -13
- package/relay-hooks/loadQuery.js.flow +18 -18
- package/relay-hooks/preloadQuery_DEPRECATED.js.flow +16 -13
- package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +7 -7
- package/relay-hooks/readFragmentInternal.js.flow +9 -9
- package/relay-hooks/rsc/serverFetchQuery.js.flow +31 -0
- package/relay-hooks/rsc/serverPreloadQuery.js.flow +69 -0
- package/relay-hooks/rsc/serverReadFragment.js.flow +33 -0
- package/relay-hooks/rsc/useQueryFromServer.js.flow +135 -0
- package/relay-hooks/useClientQuery.js.flow +2 -2
- package/relay-hooks/useEntryPointLoader.js.flow +11 -11
- package/relay-hooks/useFragment.js.flow +7 -7
- package/relay-hooks/useFragmentInternal.js.flow +1 -1
- package/relay-hooks/useFragmentInternal_CURRENT.js.flow +54 -22
- package/relay-hooks/useFragmentInternal_EXPERIMENTAL.js.flow +95 -46
- package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
- package/relay-hooks/useIsParentQueryActive.js.flow +1 -1
- package/relay-hooks/useLazyLoadQuery.js.flow +10 -3
- package/relay-hooks/useLazyLoadQueryNode.js.flow +67 -28
- package/relay-hooks/useLoadMoreFunction.js.flow +7 -6
- package/relay-hooks/useLoadMoreFunction_EXPERIMENTAL.js.flow +5 -5
- package/relay-hooks/useMemoVariables.js.flow +1 -1
- package/relay-hooks/useMutation.js.flow +8 -16
- package/relay-hooks/useMutationAction_EXPERIMENTAL.js.flow +68 -0
- package/relay-hooks/usePaginationFragment.js.flow +15 -11
- package/relay-hooks/usePrefetchableForwardPaginationFragment.js.flow +19 -18
- package/relay-hooks/usePrefetchableForwardPaginationFragment_EXPERIMENTAL.js.flow +19 -18
- package/relay-hooks/usePreloadedQuery.js.flow +119 -85
- package/relay-hooks/useQueryLoader.js.flow +27 -23
- package/relay-hooks/useQueryLoader_EXPERIMENTAL.js.flow +10 -10
- package/relay-hooks/useRefetchableFragment.js.flow +16 -11
- package/relay-hooks/useRefetchableFragmentInternal.js.flow +77 -79
- package/relay-hooks/useRelayLoggingContext.js.flow +1 -1
- package/relay-hooks/useSubscribeToInvalidationState.js.flow +1 -1
- package/relay-hooks/useSubscription.js.flow +1 -1
- package/rsc-client_EXPERIMENTAL.js +10 -0
- package/rsc-client_EXPERIMENTAL.js.flow +23 -0
- package/rsc_EXPERIMENTAL.js +10 -0
- package/rsc_EXPERIMENTAL.js.flow +90 -0
|
@@ -40,44 +40,44 @@ const usersFragment: useFragmentFlowtest_users$fragment = graphql`
|
|
|
40
40
|
/* eslint-disable react-hooks/rules-of-hooks */
|
|
41
41
|
|
|
42
42
|
// Nullability of returned data type is correct
|
|
43
|
-
|
|
43
|
+
useFragment(
|
|
44
44
|
userFragment,
|
|
45
|
-
|
|
46
|
-
)
|
|
47
|
-
|
|
45
|
+
Any as useFragmentFlowtest_user$key,
|
|
46
|
+
) as useFragmentFlowtest_user$data;
|
|
47
|
+
useFragment(
|
|
48
48
|
userFragment,
|
|
49
|
-
|
|
50
|
-
)
|
|
51
|
-
|
|
49
|
+
Any as ?useFragmentFlowtest_user$key,
|
|
50
|
+
) as ?useFragmentFlowtest_user$data;
|
|
51
|
+
useFragment(
|
|
52
52
|
usersFragment,
|
|
53
|
-
|
|
54
|
-
)
|
|
55
|
-
|
|
53
|
+
Any as useFragmentFlowtest_users$key,
|
|
54
|
+
) as useFragmentFlowtest_users$data;
|
|
55
|
+
useFragment(
|
|
56
56
|
usersFragment,
|
|
57
|
-
|
|
58
|
-
)
|
|
57
|
+
Any as ?useFragmentFlowtest_users$key,
|
|
58
|
+
) as ?useFragmentFlowtest_users$data;
|
|
59
59
|
|
|
60
|
-
// $FlowExpectedError: can't cast nullable to non-nullable
|
|
61
|
-
|
|
60
|
+
// $FlowExpectedError[incompatible-type] : can't cast nullable to non-nullable
|
|
61
|
+
useFragment(
|
|
62
62
|
userFragment,
|
|
63
|
-
|
|
64
|
-
)
|
|
65
|
-
// $FlowExpectedError: can't cast nullable plural to non-nullable plural
|
|
66
|
-
|
|
63
|
+
Any as ?useFragmentFlowtest_user$key,
|
|
64
|
+
) as useFragmentFlowtest_user$data;
|
|
65
|
+
// $FlowExpectedError[incompatible-type] : can't cast nullable plural to non-nullable plural
|
|
66
|
+
useFragment(
|
|
67
67
|
usersFragment,
|
|
68
|
-
|
|
69
|
-
)
|
|
68
|
+
Any as ?useFragmentFlowtest_users$key,
|
|
69
|
+
) as useFragmentFlowtest_users$data;
|
|
70
70
|
|
|
71
|
-
// $FlowExpectedError: Key should be one of the generated types
|
|
71
|
+
// $FlowExpectedError[incompatible-type] : Key should be one of the generated types
|
|
72
72
|
useFragment(userFragment, 'INVALID_KEY');
|
|
73
73
|
|
|
74
|
-
// $FlowExpectedError: Key should not be a user provided object
|
|
74
|
+
// $FlowExpectedError[incompatible-type] : Key should not be a user provided object
|
|
75
75
|
useFragment(userFragment, {a: 123});
|
|
76
76
|
|
|
77
|
-
// $FlowExpectedError: Key should not be an empty object
|
|
77
|
+
// $FlowExpectedError[incompatible-type] : Key should not be an empty object
|
|
78
78
|
useFragment(userFragment, {});
|
|
79
79
|
|
|
80
|
-
// $FlowExpectedError: Key should be the `<name>$key` type from generated flow
|
|
81
|
-
useFragment(userFragment,
|
|
80
|
+
// $FlowExpectedError[incompatible-type] : Key should be the `<name>$key` type from generated flow
|
|
81
|
+
useFragment(userFragment, Any as useFragmentFlowtest_user$data);
|
|
82
82
|
|
|
83
83
|
/* eslint-enable react-hooks/rules-of-hooks */
|
|
@@ -30,8 +30,8 @@ import {
|
|
|
30
30
|
} from './utils';
|
|
31
31
|
|
|
32
32
|
type ExpectedReturnType<
|
|
33
|
-
TRefetchVariables
|
|
34
|
-
TLoadMoreVariables
|
|
33
|
+
TRefetchVariables extends Variables,
|
|
34
|
+
TLoadMoreVariables extends Variables,
|
|
35
35
|
TFragmentData,
|
|
36
36
|
> = {
|
|
37
37
|
data: TFragmentData,
|
|
@@ -48,60 +48,54 @@ type ExpectedReturnType<
|
|
|
48
48
|
|
|
49
49
|
// Nullability of returned data type is correct
|
|
50
50
|
// $FlowFixMe[prop-missing]
|
|
51
|
-
// $FlowFixMe[incompatible-
|
|
51
|
+
// $FlowFixMe[incompatible-type]
|
|
52
52
|
// $FlowFixMe[incompatible-exact]
|
|
53
53
|
// $FlowFixMe[react-rule-hook]
|
|
54
|
-
|
|
54
|
+
usePaginationFragment(
|
|
55
55
|
refetchableFragmentInput,
|
|
56
56
|
keyNonNullable,
|
|
57
|
-
)
|
|
57
|
+
) as ExpectedReturnType<QueryVariablesSubset, QueryVariables, NonNullableData>;
|
|
58
58
|
|
|
59
59
|
// $FlowFixMe[react-rule-hook]
|
|
60
|
-
|
|
60
|
+
usePaginationFragment(
|
|
61
61
|
refetchableFragmentInput,
|
|
62
62
|
keyNullable,
|
|
63
|
-
)
|
|
63
|
+
) as ExpectedReturnType<QueryVariables, QueryVariables, NullableData>;
|
|
64
64
|
|
|
65
|
-
// $FlowExpectedError: can't cast nullable to non-nullable
|
|
66
65
|
// $FlowFixMe[react-rule-hook]
|
|
67
|
-
// $FlowFixMe[incompatible-cast
|
|
68
|
-
|
|
66
|
+
// $FlowFixMe[incompatible-type] can't cast nullable to non-nullable
|
|
67
|
+
usePaginationFragment(
|
|
69
68
|
refetchableFragmentInput,
|
|
70
69
|
keyNullable,
|
|
71
|
-
)
|
|
70
|
+
) as ExpectedReturnType<QueryVariables, QueryVariables, NonNullableData>;
|
|
72
71
|
|
|
73
|
-
// $FlowExpectedError: actual type of returned data is correct
|
|
74
72
|
// $FlowFixMe[react-rule-hook]
|
|
75
73
|
// $FlowFixMe[incompatible-exact]
|
|
76
74
|
// $FlowFixMe[prop-missing]
|
|
77
|
-
// $FlowFixMe[incompatible-
|
|
78
|
-
|
|
75
|
+
// $FlowFixMe[incompatible-type] actual type of returned data is correct
|
|
76
|
+
usePaginationFragment(
|
|
79
77
|
refetchableFragmentInput,
|
|
80
|
-
// $FlowFixMe[incompatible-
|
|
78
|
+
// $FlowFixMe[incompatible-type]
|
|
81
79
|
keyAnotherNonNullable,
|
|
82
|
-
)
|
|
83
|
-
// $FlowExpectedError
|
|
80
|
+
) as ExpectedReturnType<QueryVariables, QueryVariablesSubset, NonNullableData>;
|
|
84
81
|
// $FlowFixMe[react-rule-hook]
|
|
85
|
-
// $FlowFixMe[incompatible-
|
|
86
|
-
|
|
82
|
+
// $FlowFixMe[incompatible-type]
|
|
83
|
+
usePaginationFragment(
|
|
87
84
|
refetchableFragmentInput,
|
|
88
|
-
// $FlowFixMe[incompatible-
|
|
85
|
+
// $FlowFixMe[incompatible-type]
|
|
89
86
|
keyAnotherNullable,
|
|
90
|
-
)
|
|
87
|
+
) as ExpectedReturnType<QueryVariables, QueryVariables, NonNullableData>;
|
|
91
88
|
|
|
92
|
-
// $FlowExpectedError: Key should not be a user provided object
|
|
93
89
|
// $FlowFixMe[react-rule-hook]
|
|
94
|
-
// $FlowFixMe[
|
|
90
|
+
// $FlowFixMe[incompatible-type] Key should not be a user provided object
|
|
95
91
|
usePaginationFragment(refetchableFragmentInput, {abc: 123});
|
|
96
92
|
|
|
97
|
-
// $FlowExpectedError: Key should not be an empty object
|
|
98
93
|
// $FlowFixMe[react-rule-hook]
|
|
99
|
-
// $FlowFixMe[
|
|
94
|
+
// $FlowFixMe[incompatible-type] Key should not be an empty object
|
|
100
95
|
usePaginationFragment(refetchableFragmentInput, {});
|
|
101
96
|
|
|
102
|
-
// $FlowExpectedError: Key should be the `<name>$key` type from generated flow
|
|
103
97
|
// $FlowFixMe[react-rule-hook]
|
|
104
|
-
// $FlowFixMe[
|
|
98
|
+
// $FlowFixMe[incompatible-type] Key should be the `<name>$key` type from generated flow
|
|
105
99
|
usePaginationFragment(refetchableFragmentInput, fragmentData);
|
|
106
100
|
|
|
107
101
|
// Refetch function options:
|
|
@@ -113,12 +107,12 @@ const {refetch} = usePaginationFragment(
|
|
|
113
107
|
refetchableFragmentInput,
|
|
114
108
|
keyNonNullable,
|
|
115
109
|
);
|
|
116
|
-
// $FlowExpectedError: internal option
|
|
110
|
+
// $FlowExpectedError[incompatible-type] : internal option
|
|
117
111
|
refetch(variables, {
|
|
118
112
|
__environment: environment,
|
|
119
113
|
});
|
|
120
114
|
|
|
121
|
-
// $FlowExpectedError: doesn't exist
|
|
115
|
+
// $FlowExpectedError[incompatible-type] : doesn't exist
|
|
122
116
|
refetch(variables, {
|
|
123
117
|
NON_EXIST: 'NON_EXIST',
|
|
124
118
|
});
|
|
@@ -135,17 +129,17 @@ const {loadNext} = usePaginationFragment(
|
|
|
135
129
|
// Accepts extraVariables
|
|
136
130
|
loadNext(10, {
|
|
137
131
|
// $FlowFixMe[prop-missing]
|
|
138
|
-
// $FlowFixMe[incompatible-
|
|
132
|
+
// $FlowFixMe[incompatible-type]
|
|
139
133
|
UNSTABLE_extraVariables: extraVariables,
|
|
140
134
|
});
|
|
141
135
|
|
|
142
136
|
// $FlowFixMe[prop-missing]
|
|
143
137
|
loadNext(10, {
|
|
144
|
-
// $FlowExpectedError: doesn't accept variables not available in the Flow type
|
|
138
|
+
// $FlowExpectedError[incompatible-type] : doesn't accept variables not available in the Flow type
|
|
145
139
|
UNSTABLE_extraVariables: invalidVariables,
|
|
146
140
|
});
|
|
147
141
|
|
|
148
|
-
// $FlowExpectedError: doesn't exist
|
|
142
|
+
// $FlowExpectedError[incompatible-type] : doesn't exist
|
|
149
143
|
loadNext(10, {
|
|
150
144
|
UNSTABLE_foo: invalidVariables,
|
|
151
145
|
});
|
|
@@ -32,69 +32,62 @@ import {
|
|
|
32
32
|
|
|
33
33
|
// Nullability of returned data type is correct
|
|
34
34
|
// $FlowFixMe[prop-missing]
|
|
35
|
-
// $FlowFixMe[incompatible-
|
|
35
|
+
// $FlowFixMe[incompatible-type]
|
|
36
36
|
// $FlowFixMe[incompatible-exact]
|
|
37
37
|
// $FlowFixMe[react-rule-hook]
|
|
38
|
-
|
|
38
|
+
useRefetchableFragment(refetchableFragmentInput, keyNonNullable) as [
|
|
39
39
|
NonNullableData,
|
|
40
40
|
FetchFn<QueryVariablesSubset>,
|
|
41
|
-
]
|
|
41
|
+
];
|
|
42
42
|
|
|
43
43
|
// $FlowFixMe[react-rule-hook]
|
|
44
|
-
|
|
44
|
+
useRefetchableFragment(refetchableFragmentInput, keyNullable) as [
|
|
45
45
|
NullableData,
|
|
46
46
|
FetchFn<QueryVariables>,
|
|
47
|
-
]
|
|
47
|
+
];
|
|
48
48
|
|
|
49
|
-
// $FlowExpectedError: can't cast nullable to non-nullable
|
|
50
49
|
// $FlowFixMe[react-rule-hook]
|
|
51
|
-
// $FlowFixMe[incompatible-cast
|
|
52
|
-
|
|
50
|
+
// $FlowFixMe[incompatible-type] can't cast nullable to non-nullable
|
|
51
|
+
useRefetchableFragment(refetchableFragmentInput, keyNullable) as [
|
|
53
52
|
NonNullableData,
|
|
54
53
|
FetchFn<QueryVariables>,
|
|
55
|
-
]
|
|
54
|
+
];
|
|
56
55
|
|
|
57
|
-
// $FlowExpectedError: refetch requires exact type if key is nullable
|
|
58
56
|
// $FlowFixMe[react-rule-hook]
|
|
59
57
|
// $FlowFixMe[incompatible-exact]
|
|
60
|
-
// $FlowFixMe[
|
|
61
|
-
|
|
58
|
+
// $FlowFixMe[incompatible-type] refetch requires exact type if key is nullable
|
|
59
|
+
useRefetchableFragment(refetchableFragmentInput, keyNullable) as [
|
|
62
60
|
NullableData,
|
|
63
61
|
FetchFn<QueryVariablesSubset>,
|
|
64
|
-
]
|
|
62
|
+
];
|
|
65
63
|
|
|
66
|
-
// $FlowExpectedError: actual type of returned data is correct
|
|
67
64
|
// $FlowFixMe[react-rule-hook]
|
|
68
|
-
// $FlowFixMe[incompatible-
|
|
65
|
+
// $FlowFixMe[incompatible-type]
|
|
69
66
|
// $FlowFixMe[incompatible-exact]
|
|
70
67
|
// $FlowFixMe[prop-missing]
|
|
71
|
-
// $FlowFixMe[incompatible-
|
|
72
|
-
|
|
68
|
+
// $FlowFixMe[incompatible-type] actual type of returned data is correct
|
|
69
|
+
useRefetchableFragment(refetchableFragmentInput, keyAnotherNonNullable) as [
|
|
73
70
|
NonNullableData,
|
|
74
71
|
FetchFn<QueryVariablesSubset>,
|
|
75
|
-
]
|
|
72
|
+
];
|
|
76
73
|
|
|
77
|
-
// $FlowExpectedError - incompatible key types
|
|
78
74
|
// $FlowFixMe[react-rule-hook]
|
|
79
|
-
// $FlowFixMe[incompatible-
|
|
80
|
-
|
|
75
|
+
// $FlowFixMe[incompatible-type]: incompatible key types
|
|
76
|
+
useRefetchableFragment(refetchableFragmentInput, keyAnotherNullable) as [
|
|
81
77
|
NullableData,
|
|
82
78
|
FetchFn<QueryVariables>,
|
|
83
|
-
]
|
|
79
|
+
];
|
|
84
80
|
|
|
85
|
-
// $FlowExpectedError: Key should not be a user provided object
|
|
86
81
|
// $FlowFixMe[react-rule-hook]
|
|
87
|
-
// $FlowFixMe[
|
|
82
|
+
// $FlowFixMe[incompatible-type] Key should not be a user provided object
|
|
88
83
|
useRefetchableFragment(refetchableFragmentInput, {abc: 123});
|
|
89
84
|
|
|
90
|
-
// $FlowExpectedError: Key should not be an empty object
|
|
91
85
|
// $FlowFixMe[react-rule-hook]
|
|
92
|
-
// $FlowFixMe[
|
|
86
|
+
// $FlowFixMe[incompatible-type] Key should not be an empty object
|
|
93
87
|
useRefetchableFragment(refetchableFragmentInput, {});
|
|
94
88
|
|
|
95
|
-
// $FlowExpectedError: Key should be the `<name>$key` type from generated flow
|
|
96
89
|
// $FlowFixMe[react-rule-hook]
|
|
97
|
-
// $FlowFixMe[
|
|
90
|
+
// $FlowFixMe[incompatible-type] Key should be the `<name>$key` type from generated flow
|
|
98
91
|
useRefetchableFragment(refetchableFragmentInput, fragmentData);
|
|
99
92
|
|
|
100
93
|
// Refetch function options:
|
|
@@ -106,12 +99,12 @@ const [, refetch] = useRefetchableFragment(
|
|
|
106
99
|
refetchableFragmentInput,
|
|
107
100
|
keyNonNullable,
|
|
108
101
|
);
|
|
109
|
-
// $FlowExpectedError: internal option
|
|
102
|
+
// $FlowExpectedError[incompatible-type] : internal option
|
|
110
103
|
refetch(variables, {
|
|
111
104
|
__environment: environment,
|
|
112
105
|
});
|
|
113
106
|
|
|
114
|
-
// $FlowExpectedError: doesn't exist
|
|
107
|
+
// $FlowExpectedError[incompatible-type] : doesn't exist
|
|
115
108
|
refetch(variables, {
|
|
116
109
|
NON_EXIST: 'NON_EXIST',
|
|
117
110
|
});
|
|
@@ -42,8 +42,8 @@ export type NonNullableData = {
|
|
|
42
42
|
+count: number,
|
|
43
43
|
};
|
|
44
44
|
export type NullableData = ?NonNullableData;
|
|
45
|
-
export type NonNullablePluralData =
|
|
46
|
-
export type NullablePluralData =
|
|
45
|
+
export type NonNullablePluralData = ReadonlyArray<NonNullableData>;
|
|
46
|
+
export type NullablePluralData = ?ReadonlyArray<NonNullableData>;
|
|
47
47
|
|
|
48
48
|
export type AnotherNonNullableData = {
|
|
49
49
|
+name: ?string,
|
|
@@ -52,9 +52,9 @@ export type AnotherNonNullableData = {
|
|
|
52
52
|
|
|
53
53
|
declare export var keyNonNullable: Example_user$key;
|
|
54
54
|
|
|
55
|
-
declare export var keyNonNullablePlural:
|
|
55
|
+
declare export var keyNonNullablePlural: ReadonlyArray<Example_user$key>;
|
|
56
56
|
|
|
57
|
-
declare export var keyNullablePlural:
|
|
57
|
+
declare export var keyNullablePlural: ?ReadonlyArray<Example_user$key>;
|
|
58
58
|
|
|
59
59
|
declare export var keyNullable: ?Example_user$key;
|
|
60
60
|
|
|
@@ -19,8 +19,8 @@ const {ConnectionInterface, getValueAtPath} = require('relay-runtime');
|
|
|
19
19
|
function getConnectionState(
|
|
20
20
|
direction: Direction,
|
|
21
21
|
fragmentNode: ReaderFragment,
|
|
22
|
-
fragmentData:
|
|
23
|
-
connectionPathInFragmentData:
|
|
22
|
+
fragmentData: unknown,
|
|
23
|
+
connectionPathInFragmentData: ReadonlyArray<string | number>,
|
|
24
24
|
): {
|
|
25
25
|
cursor: ?string,
|
|
26
26
|
hasMore: boolean,
|
|
@@ -45,8 +45,8 @@ export type FragmentResource = FragmentResourceImpl;
|
|
|
45
45
|
type FragmentResourceCache = Cache<
|
|
46
46
|
| {
|
|
47
47
|
kind: 'pending',
|
|
48
|
-
pendingOperations:
|
|
49
|
-
promise: Promise<
|
|
48
|
+
pendingOperations: ReadonlyArray<RequestDescriptor>,
|
|
49
|
+
promise: Promise<unknown>,
|
|
50
50
|
result: FragmentResult,
|
|
51
51
|
}
|
|
52
52
|
| {kind: 'done', result: FragmentResult}
|
|
@@ -63,11 +63,11 @@ interface IMap<K, V> {
|
|
|
63
63
|
set(key: K, value: V): IMap<K, V>;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
type SingularOrPluralSnapshot = Snapshot |
|
|
66
|
+
type SingularOrPluralSnapshot = Snapshot | ReadonlyArray<Snapshot>;
|
|
67
67
|
|
|
68
|
-
opaque type FragmentResult: {data:
|
|
68
|
+
opaque type FragmentResult: {data: unknown, ...} = {
|
|
69
69
|
cacheKey: string,
|
|
70
|
-
data:
|
|
70
|
+
data: unknown,
|
|
71
71
|
isMissingData: boolean,
|
|
72
72
|
snapshot: SingularOrPluralSnapshot | null,
|
|
73
73
|
storeEpoch: number,
|
|
@@ -97,7 +97,7 @@ function hasMissingClientEdges(snapshot: SingularOrPluralSnapshot): boolean {
|
|
|
97
97
|
|
|
98
98
|
function missingLiveResolverFields(
|
|
99
99
|
snapshot: SingularOrPluralSnapshot,
|
|
100
|
-
):
|
|
100
|
+
): ?ReadonlyArray<DataID> {
|
|
101
101
|
if (Array.isArray(snapshot)) {
|
|
102
102
|
return snapshot
|
|
103
103
|
.map(s => s.missingLiveResolverFields)
|
|
@@ -217,7 +217,7 @@ class FragmentResourceImpl {
|
|
|
217
217
|
*/
|
|
218
218
|
read(
|
|
219
219
|
fragmentNode: ReaderFragment,
|
|
220
|
-
fragmentRef:
|
|
220
|
+
fragmentRef: unknown,
|
|
221
221
|
componentDisplayName: string,
|
|
222
222
|
fragmentKey?: string,
|
|
223
223
|
): FragmentResult {
|
|
@@ -237,7 +237,7 @@ class FragmentResourceImpl {
|
|
|
237
237
|
*/
|
|
238
238
|
readWithIdentifier(
|
|
239
239
|
fragmentNode: ReaderFragment,
|
|
240
|
-
fragmentRef:
|
|
240
|
+
fragmentRef: unknown,
|
|
241
241
|
fragmentIdentifier: string,
|
|
242
242
|
componentDisplayName: string,
|
|
243
243
|
fragmentKey?: ?string,
|
|
@@ -307,7 +307,7 @@ class FragmentResourceImpl {
|
|
|
307
307
|
!missingLiveResolverFields(cachedValue.result.snapshot)?.length
|
|
308
308
|
) {
|
|
309
309
|
this._throwOrLogErrorsInSnapshot(
|
|
310
|
-
// $FlowFixMe[incompatible-
|
|
310
|
+
// $FlowFixMe[incompatible-type]
|
|
311
311
|
cachedValue.result.snapshot,
|
|
312
312
|
);
|
|
313
313
|
|
|
@@ -527,7 +527,7 @@ class FragmentResourceImpl {
|
|
|
527
527
|
_performClientEdgeQuery(
|
|
528
528
|
queryResource: QueryResource,
|
|
529
529
|
fragmentNode: ReaderFragment,
|
|
530
|
-
fragmentRef:
|
|
530
|
+
fragmentRef: unknown,
|
|
531
531
|
request: ConcreteRequest,
|
|
532
532
|
clientEdgeDestinationID: DataID,
|
|
533
533
|
): {queryResult: QueryResult, requestDescriptor: RequestDescriptor} {
|
|
@@ -568,7 +568,7 @@ class FragmentResourceImpl {
|
|
|
568
568
|
|
|
569
569
|
readSpec(
|
|
570
570
|
fragmentNodes: {[string]: ReaderFragment, ...},
|
|
571
|
-
fragmentRefs: {[string]:
|
|
571
|
+
fragmentRefs: {[string]: unknown, ...},
|
|
572
572
|
componentDisplayName: string,
|
|
573
573
|
): {[string]: FragmentResult, ...} {
|
|
574
574
|
const result: {[string]: FragmentResult} = {};
|
|
@@ -804,7 +804,7 @@ class FragmentResourceImpl {
|
|
|
804
804
|
fragmentResult: FragmentResult,
|
|
805
805
|
): {
|
|
806
806
|
promise: Promise<void>,
|
|
807
|
-
pendingOperations:
|
|
807
|
+
pendingOperations: ReadonlyArray<RequestDescriptor>,
|
|
808
808
|
} | null {
|
|
809
809
|
const pendingOperationsResult = getPendingOperationsForFragment(
|
|
810
810
|
this._environment,
|
|
@@ -840,7 +840,7 @@ class FragmentResourceImpl {
|
|
|
840
840
|
|
|
841
841
|
_updatePluralSnapshot(
|
|
842
842
|
cacheKey: string,
|
|
843
|
-
baseSnapshots:
|
|
843
|
+
baseSnapshots: ReadonlyArray<Snapshot>,
|
|
844
844
|
latestSnapshot: Snapshot,
|
|
845
845
|
idx: number,
|
|
846
846
|
storeEpoch: number,
|
|
@@ -31,7 +31,7 @@ type RefetchVariables<TVariables, TKey> =
|
|
|
31
31
|
// NOTE: This type ensures that the type of the variables is either:
|
|
32
32
|
// - nullable if the provided ref type is non-nullable
|
|
33
33
|
// - non-nullable if the provided ref type is nullable, and the caller need to provide the full set of variables
|
|
34
|
-
[+key: TKey] extends [+key: {+$fragmentSpreads:
|
|
34
|
+
[+key: TKey] extends [+key: {+$fragmentSpreads: unknown, ...}]
|
|
35
35
|
? Partial<TVariables>
|
|
36
36
|
: TVariables;
|
|
37
37
|
|
|
@@ -49,7 +49,7 @@ type ReturnType<TVariables, TData, TKey> = {
|
|
|
49
49
|
// NOTE: This rtpw ensures that the type of the returned data is either:
|
|
50
50
|
// - nullable if the provided ref type is nullable
|
|
51
51
|
// - non-nullable if the provided ref type is non-nullable
|
|
52
|
-
data: [+key: TKey] extends [+key: {+$fragmentSpreads:
|
|
52
|
+
data: [+key: TKey] extends [+key: {+$fragmentSpreads: unknown, ...}]
|
|
53
53
|
? TData
|
|
54
54
|
: ?TData,
|
|
55
55
|
loadNext: LoadMoreFn<TVariables>,
|
|
@@ -60,10 +60,10 @@ type ReturnType<TVariables, TData, TKey> = {
|
|
|
60
60
|
};
|
|
61
61
|
|
|
62
62
|
hook useBlockingPaginationFragment<
|
|
63
|
-
TFragmentType
|
|
64
|
-
TVariables
|
|
63
|
+
TFragmentType extends FragmentType,
|
|
64
|
+
TVariables extends Variables,
|
|
65
65
|
TData,
|
|
66
|
-
TKey
|
|
66
|
+
TKey extends ?{+$fragmentSpreads: TFragmentType, ...},
|
|
67
67
|
>(
|
|
68
68
|
fragmentInput: RefetchableFragment<TFragmentType, TData, TVariables>,
|
|
69
69
|
parentFragmentRef: TKey,
|
|
@@ -99,7 +99,7 @@ hook useBlockingPaginationFragment<
|
|
|
99
99
|
variables: TVariables,
|
|
100
100
|
},
|
|
101
101
|
{
|
|
102
|
-
+$data:
|
|
102
|
+
+$data: unknown,
|
|
103
103
|
...
|
|
104
104
|
},
|
|
105
105
|
>(fragmentNode, parentFragmentRef, componentDisplayName);
|
|
@@ -143,33 +143,34 @@ hook useBlockingPaginationFragment<
|
|
|
143
143
|
disposeFetchNext();
|
|
144
144
|
disposeFetchPrevious();
|
|
145
145
|
// $FlowFixMe[incompatible-variance]
|
|
146
|
+
// $FlowFixMe[incompatible-type]
|
|
146
147
|
return refetch(variables, {...options, __environment: undefined});
|
|
147
148
|
},
|
|
148
149
|
[disposeFetchNext, disposeFetchPrevious, refetch],
|
|
149
150
|
);
|
|
150
151
|
|
|
151
152
|
return {
|
|
152
|
-
// $FlowFixMe[incompatible-
|
|
153
|
-
// $FlowFixMe[incompatible-
|
|
154
|
-
data:
|
|
155
|
-
loadNext,
|
|
156
|
-
loadPrevious,
|
|
153
|
+
// $FlowFixMe[incompatible-type]
|
|
154
|
+
// $FlowFixMe[incompatible-type]
|
|
155
|
+
data: fragmentData as TData,
|
|
157
156
|
hasNext,
|
|
158
157
|
hasPrevious,
|
|
158
|
+
loadNext,
|
|
159
|
+
loadPrevious,
|
|
159
160
|
refetch: refetchPagination,
|
|
160
161
|
};
|
|
161
162
|
}
|
|
162
163
|
|
|
163
|
-
hook useLoadMore<TVariables
|
|
164
|
+
hook useLoadMore<TVariables extends Variables>(args: {
|
|
164
165
|
disableStoreUpdates: () => void,
|
|
165
166
|
enableStoreUpdates: () => void,
|
|
166
167
|
...$Exact<Omit<UseLoadMoreFunctionArgs, 'observer' | 'onReset'>>,
|
|
167
168
|
}): [LoadMoreFn<TVariables>, boolean, () => void] {
|
|
168
169
|
const {disableStoreUpdates, enableStoreUpdates, ...loadMoreArgs} = args;
|
|
169
|
-
const [requestPromise, setRequestPromise] = useState<null | Promise<
|
|
170
|
+
const [requestPromise, setRequestPromise] = useState<null | Promise<unknown>>(
|
|
170
171
|
null,
|
|
171
172
|
);
|
|
172
|
-
const requestPromiseRef = useRef<null | Promise<
|
|
173
|
+
const requestPromiseRef = useRef<null | Promise<unknown>>(null);
|
|
173
174
|
const promiseResolveRef = useRef<null | (() => void)>(null);
|
|
174
175
|
|
|
175
176
|
const promiseResolve = () => {
|
|
@@ -185,6 +186,15 @@ hook useLoadMore<TVariables: Variables>(args: {
|
|
|
185
186
|
|
|
186
187
|
const observer = {
|
|
187
188
|
complete: promiseResolve,
|
|
189
|
+
// TODO: Handle error; we probably don't want to throw an error
|
|
190
|
+
// and blow away the whole list of items.
|
|
191
|
+
error: promiseResolve,
|
|
192
|
+
// NOTE: Since streaming is disallowed with this hook, this means that the
|
|
193
|
+
// first payload will always contain the entire next page of items,
|
|
194
|
+
// while subsequent paylaods will contain @defer'd payloads.
|
|
195
|
+
// This allows us to unsuspend here, on the first payload, and allow
|
|
196
|
+
// descendant components to suspend on their respective @defer payloads
|
|
197
|
+
next: promiseResolve,
|
|
188
198
|
// NOTE: loadMore is a no-op if a request is already in flight, so we
|
|
189
199
|
// can safely assume that `start` will only be called once while a
|
|
190
200
|
// request is in flight.
|
|
@@ -203,17 +213,6 @@ hook useLoadMore<TVariables: Variables>(args: {
|
|
|
203
213
|
requestPromiseRef.current = promise;
|
|
204
214
|
setRequestPromise(promise);
|
|
205
215
|
},
|
|
206
|
-
|
|
207
|
-
// NOTE: Since streaming is disallowed with this hook, this means that the
|
|
208
|
-
// first payload will always contain the entire next page of items,
|
|
209
|
-
// while subsequent paylaods will contain @defer'd payloads.
|
|
210
|
-
// This allows us to unsuspend here, on the first payload, and allow
|
|
211
|
-
// descendant components to suspend on their respective @defer payloads
|
|
212
|
-
next: promiseResolve,
|
|
213
|
-
|
|
214
|
-
// TODO: Handle error; we probably don't want to throw an error
|
|
215
|
-
// and blow away the whole list of items.
|
|
216
|
-
error: promiseResolve,
|
|
217
216
|
};
|
|
218
217
|
const [loadMore, hasMore, disposeFetch] = useLoadMoreFunction<TVariables>({
|
|
219
218
|
...loadMoreArgs,
|
|
@@ -20,15 +20,15 @@ const {useEffect, useState} = require('react');
|
|
|
20
20
|
const {RelayFeatureFlags, getFragmentIdentifier} = require('relay-runtime');
|
|
21
21
|
const warning = require('warning');
|
|
22
22
|
|
|
23
|
-
type ReturnType<TFragmentData
|
|
23
|
+
type ReturnType<TFragmentData extends unknown> = {
|
|
24
24
|
data: TFragmentData,
|
|
25
25
|
disableStoreUpdates: () => void,
|
|
26
26
|
enableStoreUpdates: () => void,
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
-
hook useFragmentNode<TFragmentData
|
|
29
|
+
hook useFragmentNode<TFragmentData extends unknown>(
|
|
30
30
|
fragmentNode: ReaderFragment,
|
|
31
|
-
fragmentRef:
|
|
31
|
+
fragmentRef: unknown,
|
|
32
32
|
componentDisplayName: string,
|
|
33
33
|
): ReturnType<TFragmentData> {
|
|
34
34
|
const environment = useRelayEnvironment();
|
|
@@ -123,7 +123,7 @@ hook useFragmentNode<TFragmentData: mixed>(
|
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
return {
|
|
126
|
-
// $FlowFixMe[incompatible-
|
|
126
|
+
// $FlowFixMe[incompatible-type]
|
|
127
127
|
data: fragmentResult.data,
|
|
128
128
|
disableStoreUpdates,
|
|
129
129
|
enableStoreUpdates,
|