react-relay 20.1.0 → 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.
Files changed (129) hide show
  1. package/ReactRelayContext.js +1 -1
  2. package/ReactRelayContext.js.flow +2 -2
  3. package/ReactRelayFragmentContainer.js.flow +9 -10
  4. package/ReactRelayLocalQueryRenderer.js.flow +11 -3
  5. package/ReactRelayLoggingContext.js.flow +3 -3
  6. package/ReactRelayPaginationContainer.js.flow +32 -25
  7. package/ReactRelayQueryFetcher.js.flow +1 -1
  8. package/ReactRelayQueryRenderer.js.flow +2 -2
  9. package/ReactRelayQueryRendererContext.js.flow +2 -2
  10. package/ReactRelayRefetchContainer.js.flow +18 -15
  11. package/ReactRelayTestMocker.js.flow +10 -10
  12. package/ReactRelayTypes.js.flow +18 -20
  13. package/RelayContext.js.flow +3 -3
  14. package/__flowtests__/ReactRelayFragmentContainer-flowtest.js.flow +11 -11
  15. package/__flowtests__/ReactRelayPaginationContainer-flowtest.js.flow +5 -5
  16. package/__flowtests__/ReactRelayRefetchContainer-flowtest.js.flow +5 -5
  17. package/__flowtests__/RelayModern-flowtest.js.flow +24 -27
  18. package/__flowtests__/RelayModernFlowtest_users.graphql.js.flow +1 -1
  19. package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer.graphql.js.flow +3 -4
  20. package/__flowtests__/__generated__/ReactRelayFragmentContainerFlowtest_viewer2.graphql.js.flow +3 -4
  21. package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtestQuery.graphql.js.flow +9 -10
  22. package/__flowtests__/__generated__/ReactRelayPaginationContainerFlowtest_viewer.graphql.js.flow +4 -5
  23. package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtestQuery.graphql.js.flow +9 -10
  24. package/__flowtests__/__generated__/ReactRelayRefetchContainerFlowtest_viewer.graphql.js.flow +4 -5
  25. package/__flowtests__/__generated__/RelayModernFlowtest_badref.graphql.js.flow +3 -4
  26. package/__flowtests__/__generated__/RelayModernFlowtest_notref.graphql.js.flow +3 -4
  27. package/__flowtests__/__generated__/RelayModernFlowtest_user.graphql.js.flow +3 -4
  28. package/__flowtests__/__generated__/RelayModernFlowtest_users.graphql.js.flow +5 -6
  29. package/buildReactRelayContainer.js.flow +4 -4
  30. package/getRootVariablesForFragments.js.flow +3 -3
  31. package/hooks.js +1 -1
  32. package/hooks.js.flow +23 -8
  33. package/index.js +1 -1
  34. package/index.js.flow +40 -14
  35. package/isRelayEnvironment.js.flow +1 -1
  36. package/jest-react/internalAct.js.flow +1 -1
  37. package/legacy.js +1 -1
  38. package/legacy.js.flow +32 -13
  39. package/lib/ReactRelayFragmentContainer.js +1 -1
  40. package/lib/ReactRelayPaginationContainer.js +8 -8
  41. package/lib/ReactRelayRefetchContainer.js +8 -8
  42. package/lib/ReactRelayTestMocker.js +5 -5
  43. package/lib/hooks.js +18 -8
  44. package/lib/index.js +30 -14
  45. package/lib/legacy.js +26 -13
  46. package/lib/relay-hooks/legacy/useBlockingPaginationFragment.js +5 -5
  47. package/lib/relay-hooks/legacy/useRefetchableFragmentNode.js +34 -34
  48. package/lib/relay-hooks/loadEntryPoint.js +2 -2
  49. package/lib/relay-hooks/loadQuery.js +14 -14
  50. package/lib/relay-hooks/preloadQuery_DEPRECATED.js +10 -10
  51. package/lib/relay-hooks/readFragmentInternal.js +6 -6
  52. package/lib/relay-hooks/rsc/serverFetchQuery.js +20 -0
  53. package/lib/relay-hooks/rsc/serverPreloadQuery.js +31 -0
  54. package/lib/relay-hooks/rsc/serverReadFragment.js +15 -0
  55. package/lib/relay-hooks/rsc/useQueryFromServer.js +62 -0
  56. package/lib/relay-hooks/useFragmentInternal_CURRENT.js +49 -25
  57. package/lib/relay-hooks/useFragmentInternal_EXPERIMENTAL.js +81 -44
  58. package/lib/relay-hooks/useLazyLoadQueryNode.js +32 -19
  59. package/lib/relay-hooks/useMutation.js +6 -14
  60. package/lib/relay-hooks/useMutationAction_EXPERIMENTAL.js +26 -0
  61. package/lib/relay-hooks/usePreloadedQuery.js +52 -47
  62. package/lib/relay-hooks/useQueryLoader.js +2 -2
  63. package/lib/relay-hooks/useQueryLoader_EXPERIMENTAL.js +2 -2
  64. package/lib/relay-hooks/useRefetchableFragmentInternal.js +31 -31
  65. package/lib/rsc-client_EXPERIMENTAL.js +7 -0
  66. package/lib/rsc_EXPERIMENTAL.js +43 -0
  67. package/multi-actor/ActorChange.js.flow +1 -1
  68. package/package.json +3 -2
  69. package/relay-hooks/EntryPointContainer.react.js.flow +6 -6
  70. package/relay-hooks/EntryPointTypes.flow.js.flow +61 -67
  71. package/relay-hooks/LazyLoadEntryPointContainer_DEPRECATED.react.js.flow +23 -21
  72. package/relay-hooks/MatchContainer.js.flow +12 -6
  73. package/relay-hooks/NestedRelayEntryPointBuilderUtils.js.flow +3 -9
  74. package/relay-hooks/QueryResource.js.flow +6 -6
  75. package/relay-hooks/RelayEnvironmentProvider.js.flow +2 -2
  76. package/relay-hooks/__flowtests__/EntryPointTypes/EntryPointElementConfig-flowtest.js.flow +6 -6
  77. package/relay-hooks/__flowtests__/EntryPointTypes/ExtractQueryTypes-flowtest.js.flow +48 -1
  78. package/relay-hooks/__flowtests__/EntryPointTypes/NestedEntrypoints-flowtest.js.flow +9 -9
  79. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_user.graphql.js.flow +3 -4
  80. package/relay-hooks/__flowtests__/__generated__/useFragmentFlowtest_users.graphql.js.flow +5 -6
  81. package/relay-hooks/__flowtests__/useBlockingPaginationFragment-flowtest.js.flow +27 -32
  82. package/relay-hooks/__flowtests__/useFragment-flowtest.js.flow +25 -25
  83. package/relay-hooks/__flowtests__/usePaginationFragment-flowtest.js.flow +26 -32
  84. package/relay-hooks/__flowtests__/useRefetchableFragment-flowtest.js.flow +23 -30
  85. package/relay-hooks/__flowtests__/utils.js.flow +4 -4
  86. package/relay-hooks/getConnectionState.js.flow +4 -4
  87. package/relay-hooks/legacy/FragmentResource.js.flow +13 -13
  88. package/relay-hooks/legacy/useBlockingPaginationFragment.js.flow +24 -25
  89. package/relay-hooks/legacy/useFragmentNode.js.flow +4 -4
  90. package/relay-hooks/legacy/useRefetchableFragmentNode.js.flow +79 -81
  91. package/relay-hooks/loadEntryPoint.js.flow +16 -14
  92. package/relay-hooks/loadQuery.js.flow +18 -18
  93. package/relay-hooks/preloadQuery_DEPRECATED.js.flow +16 -13
  94. package/relay-hooks/prepareEntryPoint_DEPRECATED.js.flow +7 -7
  95. package/relay-hooks/readFragmentInternal.js.flow +9 -9
  96. package/relay-hooks/rsc/serverFetchQuery.js.flow +31 -0
  97. package/relay-hooks/rsc/serverPreloadQuery.js.flow +69 -0
  98. package/relay-hooks/rsc/serverReadFragment.js.flow +33 -0
  99. package/relay-hooks/rsc/useQueryFromServer.js.flow +135 -0
  100. package/relay-hooks/useClientQuery.js.flow +2 -2
  101. package/relay-hooks/useEntryPointLoader.js.flow +11 -11
  102. package/relay-hooks/useFragment.js.flow +7 -7
  103. package/relay-hooks/useFragmentInternal.js.flow +1 -1
  104. package/relay-hooks/useFragmentInternal_CURRENT.js.flow +54 -22
  105. package/relay-hooks/useFragmentInternal_EXPERIMENTAL.js.flow +95 -46
  106. package/relay-hooks/useIsOperationNodeActive.js.flow +1 -1
  107. package/relay-hooks/useIsParentQueryActive.js.flow +1 -1
  108. package/relay-hooks/useLazyLoadQuery.js.flow +10 -3
  109. package/relay-hooks/useLazyLoadQueryNode.js.flow +67 -28
  110. package/relay-hooks/useLoadMoreFunction.js.flow +7 -6
  111. package/relay-hooks/useLoadMoreFunction_EXPERIMENTAL.js.flow +5 -5
  112. package/relay-hooks/useMemoVariables.js.flow +1 -1
  113. package/relay-hooks/useMutation.js.flow +8 -16
  114. package/relay-hooks/useMutationAction_EXPERIMENTAL.js.flow +68 -0
  115. package/relay-hooks/usePaginationFragment.js.flow +15 -11
  116. package/relay-hooks/usePrefetchableForwardPaginationFragment.js.flow +19 -18
  117. package/relay-hooks/usePrefetchableForwardPaginationFragment_EXPERIMENTAL.js.flow +19 -18
  118. package/relay-hooks/usePreloadedQuery.js.flow +119 -85
  119. package/relay-hooks/useQueryLoader.js.flow +27 -23
  120. package/relay-hooks/useQueryLoader_EXPERIMENTAL.js.flow +10 -10
  121. package/relay-hooks/useRefetchableFragment.js.flow +16 -11
  122. package/relay-hooks/useRefetchableFragmentInternal.js.flow +77 -79
  123. package/relay-hooks/useRelayLoggingContext.js.flow +1 -1
  124. package/relay-hooks/useSubscribeToInvalidationState.js.flow +1 -1
  125. package/relay-hooks/useSubscription.js.flow +1 -1
  126. package/rsc-client_EXPERIMENTAL.js +10 -0
  127. package/rsc-client_EXPERIMENTAL.js.flow +23 -0
  128. package/rsc_EXPERIMENTAL.js +10 -0
  129. 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
- (useFragment(
43
+ useFragment(
44
44
  userFragment,
45
- (Any: useFragmentFlowtest_user$key),
46
- ): useFragmentFlowtest_user$data);
47
- (useFragment(
45
+ Any as useFragmentFlowtest_user$key,
46
+ ) as useFragmentFlowtest_user$data;
47
+ useFragment(
48
48
  userFragment,
49
- (Any: ?useFragmentFlowtest_user$key),
50
- ): ?useFragmentFlowtest_user$data);
51
- (useFragment(
49
+ Any as ?useFragmentFlowtest_user$key,
50
+ ) as ?useFragmentFlowtest_user$data;
51
+ useFragment(
52
52
  usersFragment,
53
- (Any: useFragmentFlowtest_users$key),
54
- ): useFragmentFlowtest_users$data);
55
- (useFragment(
53
+ Any as useFragmentFlowtest_users$key,
54
+ ) as useFragmentFlowtest_users$data;
55
+ useFragment(
56
56
  usersFragment,
57
- (Any: ?useFragmentFlowtest_users$key),
58
- ): ?useFragmentFlowtest_users$data);
57
+ Any as ?useFragmentFlowtest_users$key,
58
+ ) as ?useFragmentFlowtest_users$data;
59
59
 
60
- // $FlowExpectedError: can't cast nullable to non-nullable
61
- (useFragment(
60
+ // $FlowExpectedError[incompatible-type] : can't cast nullable to non-nullable
61
+ useFragment(
62
62
  userFragment,
63
- (Any: ?useFragmentFlowtest_user$key),
64
- ): useFragmentFlowtest_user$data);
65
- // $FlowExpectedError: can't cast nullable plural to non-nullable plural
66
- (useFragment(
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
- (Any: ?useFragmentFlowtest_users$key),
69
- ): useFragmentFlowtest_users$data);
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, (Any: useFragmentFlowtest_user$data));
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: Variables,
34
- TLoadMoreVariables: Variables,
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-cast]
51
+ // $FlowFixMe[incompatible-type]
52
52
  // $FlowFixMe[incompatible-exact]
53
53
  // $FlowFixMe[react-rule-hook]
54
- (usePaginationFragment(
54
+ usePaginationFragment(
55
55
  refetchableFragmentInput,
56
56
  keyNonNullable,
57
- ): ExpectedReturnType<QueryVariablesSubset, QueryVariables, NonNullableData>);
57
+ ) as ExpectedReturnType<QueryVariablesSubset, QueryVariables, NonNullableData>;
58
58
 
59
59
  // $FlowFixMe[react-rule-hook]
60
- (usePaginationFragment(
60
+ usePaginationFragment(
61
61
  refetchableFragmentInput,
62
62
  keyNullable,
63
- ): ExpectedReturnType<QueryVariables, QueryVariables, NullableData>);
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
- (usePaginationFragment(
66
+ // $FlowFixMe[incompatible-type] can't cast nullable to non-nullable
67
+ usePaginationFragment(
69
68
  refetchableFragmentInput,
70
69
  keyNullable,
71
- ): ExpectedReturnType<QueryVariables, QueryVariables, NonNullableData>);
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-cast]
78
- (usePaginationFragment(
75
+ // $FlowFixMe[incompatible-type] actual type of returned data is correct
76
+ usePaginationFragment(
79
77
  refetchableFragmentInput,
80
- // $FlowFixMe[incompatible-call]
78
+ // $FlowFixMe[incompatible-type]
81
79
  keyAnotherNonNullable,
82
- ): ExpectedReturnType<QueryVariables, QueryVariablesSubset, NonNullableData>);
83
- // $FlowExpectedError
80
+ ) as ExpectedReturnType<QueryVariables, QueryVariablesSubset, NonNullableData>;
84
81
  // $FlowFixMe[react-rule-hook]
85
- // $FlowFixMe[incompatible-cast]
86
- (usePaginationFragment(
82
+ // $FlowFixMe[incompatible-type]
83
+ usePaginationFragment(
87
84
  refetchableFragmentInput,
88
- // $FlowFixMe[incompatible-call]
85
+ // $FlowFixMe[incompatible-type]
89
86
  keyAnotherNullable,
90
- ): ExpectedReturnType<QueryVariables, QueryVariables, NonNullableData>);
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[prop-missing]
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[prop-missing]
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[prop-missing]
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-call]
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-cast]
35
+ // $FlowFixMe[incompatible-type]
36
36
  // $FlowFixMe[incompatible-exact]
37
37
  // $FlowFixMe[react-rule-hook]
38
- (useRefetchableFragment(refetchableFragmentInput, keyNonNullable): [
38
+ useRefetchableFragment(refetchableFragmentInput, keyNonNullable) as [
39
39
  NonNullableData,
40
40
  FetchFn<QueryVariablesSubset>,
41
- ]);
41
+ ];
42
42
 
43
43
  // $FlowFixMe[react-rule-hook]
44
- (useRefetchableFragment(refetchableFragmentInput, keyNullable): [
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
- (useRefetchableFragment(refetchableFragmentInput, keyNullable): [
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[prop-missing]
61
- (useRefetchableFragment(refetchableFragmentInput, keyNullable): [
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-call]
65
+ // $FlowFixMe[incompatible-type]
69
66
  // $FlowFixMe[incompatible-exact]
70
67
  // $FlowFixMe[prop-missing]
71
- // $FlowFixMe[incompatible-cast]
72
- (useRefetchableFragment(refetchableFragmentInput, keyAnotherNonNullable): [
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-call]
80
- (useRefetchableFragment(refetchableFragmentInput, keyAnotherNullable): [
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[prop-missing]
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[prop-missing]
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[prop-missing]
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 = $ReadOnlyArray<NonNullableData>;
46
- export type NullablePluralData = ?$ReadOnlyArray<NonNullableData>;
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: $ReadOnlyArray<Example_user$key>;
55
+ declare export var keyNonNullablePlural: ReadonlyArray<Example_user$key>;
56
56
 
57
- declare export var keyNullablePlural: ?$ReadOnlyArray<Example_user$key>;
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: mixed,
23
- connectionPathInFragmentData: $ReadOnlyArray<string | number>,
22
+ fragmentData: unknown,
23
+ connectionPathInFragmentData: ReadonlyArray<string | number>,
24
24
  ): {
25
25
  cursor: ?string,
26
26
  hasMore: boolean,
@@ -73,8 +73,8 @@ function getConnectionState(
73
73
 
74
74
  const cursor =
75
75
  direction === 'forward'
76
- ? pageInfo[END_CURSOR] ?? null
77
- : pageInfo[START_CURSOR] ?? null;
76
+ ? (pageInfo[END_CURSOR] ?? null)
77
+ : (pageInfo[START_CURSOR] ?? null);
78
78
  invariant(
79
79
  cursor === null || typeof cursor === 'string',
80
80
  'Relay: Expected page info for connection in fragment `%s` to have a ' +
@@ -45,8 +45,8 @@ export type FragmentResource = FragmentResourceImpl;
45
45
  type FragmentResourceCache = Cache<
46
46
  | {
47
47
  kind: 'pending',
48
- pendingOperations: $ReadOnlyArray<RequestDescriptor>,
49
- promise: Promise<mixed>,
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 | $ReadOnlyArray<Snapshot>;
66
+ type SingularOrPluralSnapshot = Snapshot | ReadonlyArray<Snapshot>;
67
67
 
68
- opaque type FragmentResult: {data: mixed, ...} = {
68
+ opaque type FragmentResult: {data: unknown, ...} = {
69
69
  cacheKey: string,
70
- data: mixed,
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
- ): ?$ReadOnlyArray<DataID> {
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: mixed,
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: mixed,
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-call]
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: mixed,
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]: mixed, ...},
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: $ReadOnlyArray<RequestDescriptor>,
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: $ReadOnlyArray<Snapshot>,
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: mixed, ...}]
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: mixed, ...}]
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: FragmentType,
64
- TVariables: Variables,
63
+ TFragmentType extends FragmentType,
64
+ TVariables extends Variables,
65
65
  TData,
66
- TKey: ?{+$fragmentSpreads: TFragmentType, ...},
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: mixed,
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-cast]
153
- // $FlowFixMe[incompatible-return]
154
- data: (fragmentData: TData),
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: Variables>(args: {
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<mixed>>(
170
+ const [requestPromise, setRequestPromise] = useState<null | Promise<unknown>>(
170
171
  null,
171
172
  );
172
- const requestPromiseRef = useRef<null | Promise<mixed>>(null);
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: mixed> = {
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: mixed>(
29
+ hook useFragmentNode<TFragmentData extends unknown>(
30
30
  fragmentNode: ReaderFragment,
31
- fragmentRef: mixed,
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-return]
126
+ // $FlowFixMe[incompatible-type]
127
127
  data: fragmentResult.data,
128
128
  disableStoreUpdates,
129
129
  enableStoreUpdates,