Skip to content

Commit

Permalink
Codemod $Shape to Partial in Relay files, suppressing errors
Browse files Browse the repository at this point in the history
Reviewed By: SamChou19815

Differential Revision: D44976718

fbshipit-source-id: 1bb01ae431c7cef5f3a9b0f3f6d420b12bc397dc
  • Loading branch information
gkz authored and facebook-github-bot committed Apr 17, 2023
1 parent b4099fc commit f0dbef2
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 14 deletions.
11 changes: 8 additions & 3 deletions packages/react-relay/ReactRelayQueryRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ class ReactRelayQueryRenderer extends React.Component<Props, State> {

this._maybeHiddenOrFastRefresh = false;

// $FlowFixMe[incompatible-type]
this.state = {
prevPropsEnvironment: props.environment,
prevPropsVariables: props.variables,
Expand All @@ -149,7 +150,7 @@ class ReactRelayQueryRenderer extends React.Component<Props, State> {
static getDerivedStateFromProps(
nextProps: Props,
prevState: State,
): $Shape<State> | null {
): Partial<State> | null {
if (
prevState.prevQuery !== nextProps.query ||
prevState.prevPropsEnvironment !== nextProps.environment ||
Expand All @@ -175,6 +176,7 @@ class ReactRelayQueryRenderer extends React.Component<Props, State> {
const {requestCacheKey, queryFetcher} = newState;
if (requestCacheKey != null && requestCache[requestCacheKey] != null) {
if (RelayFeatureFlags.ENABLE_QUERY_RENDERER_SET_STATE_PREVENTION) {
// $FlowFixMe[incompatible-use]
const fetchResult = queryFetcher.getFetchResult();
if (fetchResult != null) {
const snapshot = fetchResult.snapshot ?? null;
Expand All @@ -188,15 +190,18 @@ class ReactRelayQueryRenderer extends React.Component<Props, State> {
newState.renderProps = getRenderProps(
error,
snapshot,
// $FlowFixMe[incompatible-call]
queryFetcher,
prevState.retryCallbacks,
);
newState.snapshot = snapshot;
newState.requestCacheKey = null;
} else {
// $FlowFixMe[incompatible-use]
queryFetcher.setOnDataChange(this._handleDataChange);
}
} else {
// $FlowFixMe[incompatible-use]
queryFetcher.setOnDataChange(this._handleDataChange);
}
}
Expand Down Expand Up @@ -366,7 +371,7 @@ function getRequestCacheKey(
function resetQueryStateForUpdate(
props: Props,
prevState: State,
): $Shape<State> {
): Partial<State> {
const {query} = props;

const prevSelectionReferences =
Expand Down Expand Up @@ -403,7 +408,7 @@ function fetchQueryAndComputeStateFromProps(
queryFetcher: ReactRelayQueryFetcher,
retryCallbacks: RetryCallbacks,
requestCacheKey: ?string,
): $Shape<State> {
): Partial<State> {
const {environment, query, variables, cacheConfig} = props;
const genericEnvironment = (environment: IEnvironment);
if (query) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,10 @@ function prepareEntryPoint<
}
const preloadProps = entryPoint.getPreloadProps(entryPointParams);
const {queries, entryPoints, extraProps} = preloadProps;
const preloadedQueries: $Shape<TPreloadedQueries> = {};
const preloadedEntryPoints: $Shape<TPreloadedEntryPoints> = {};
// $FlowFixMe[incompatible-type]
const preloadedQueries: Partial<TPreloadedQueries> = {};
// $FlowFixMe[incompatible-type]
const preloadedEntryPoints: Partial<TPreloadedEntryPoints> = {};
if (queries != null) {
const queriesPropNames = Object.keys(queries);
queriesPropNames.forEach(queryPropName => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ type ExpectedReturnType<
/* eslint-disable react-hooks/rules-of-hooks */

// Nullability of returned data type is correct
// $FlowFixMe[prop-missing]
// $FlowFixMe[incompatible-cast]
(useBlockingPaginationFragment(
refetchableFragmentInput,
keyNonNullable,
Expand Down Expand Up @@ -112,9 +114,12 @@ const {loadNext} = useBlockingPaginationFragment(
);
// Accepts extraVariables
loadNext(10, {
// $FlowFixMe[prop-missing]
// $FlowFixMe[incompatible-call]
UNSTABLE_extraVariables: extraVariables,
});

// $FlowFixMe[prop-missing]
loadNext(10, {
// $FlowExpectedError: doesn't accept variables not available in the Flow type
UNSTABLE_extraVariables: invalidVariables,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ type ExpectedReturnType<
/* eslint-disable react-hooks/rules-of-hooks */

// Nullability of returned data type is correct
// $FlowFixMe[prop-missing]
// $FlowFixMe[incompatible-cast]
(usePaginationFragment(
refetchableFragmentInput,
keyNonNullable,
Expand Down Expand Up @@ -113,9 +115,12 @@ const {loadNext} = usePaginationFragment(
);
// Accepts extraVariables
loadNext(10, {
// $FlowFixMe[prop-missing]
// $FlowFixMe[incompatible-call]
UNSTABLE_extraVariables: extraVariables,
});

// $FlowFixMe[prop-missing]
loadNext(10, {
// $FlowExpectedError: doesn't accept variables not available in the Flow type
UNSTABLE_extraVariables: invalidVariables,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import {
/* eslint-disable react-hooks/rules-of-hooks */

// Nullability of returned data type is correct
// $FlowFixMe[prop-missing]
// $FlowFixMe[incompatible-cast]
(useRefetchableFragment(refetchableFragmentInput, keyNonNullable): [
NonNullableData,
FetchFn<QueryVariablesSubset>,
Expand Down
6 changes: 4 additions & 2 deletions packages/react-relay/relay-hooks/loadEntryPoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ function loadEntryPoint<
}
const preloadProps = entryPoint.getPreloadProps(entryPointParams);
const {queries, entryPoints, extraProps} = preloadProps;
const preloadedQueries: $Shape<TPreloadedQueries> = {};
const preloadedEntryPoints: $Shape<TPreloadedEntryPoints> = {};
// $FlowFixMe[incompatible-type]
const preloadedQueries: Partial<TPreloadedQueries> = {};
// $FlowFixMe[incompatible-type]
const preloadedEntryPoints: Partial<TPreloadedEntryPoints> = {};
if (queries != null) {
const queriesPropNames = Object.keys(queries);
queriesPropNames.forEach(queryPropName => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,10 @@ function prepareEntryPoint<
}
const preloadProps = entryPoint.getPreloadProps(entryPointParams);
const {queries, entryPoints} = preloadProps;
const preloadedQueries: $Shape<TPreloadedQueries> = {};
const preloadedEntryPoints: $Shape<TPreloadedEntryPoints> = {};
// $FlowFixMe[incompatible-type]
const preloadedQueries: Partial<TPreloadedQueries> = {};
// $FlowFixMe[incompatible-type]
const preloadedEntryPoints: Partial<TPreloadedEntryPoints> = {};
if (queries != null) {
const queriesPropNames = Object.keys(queries);
queriesPropNames.forEach(queryPropName => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type RefetchVariables<TVariables, TKey> =
// - non-nullable if the provided ref type is nullable, and the caller need to provide the full set of variables
// prettier-ignore
$Call<
& (<TFragmentType>( { +$fragmentSpreads: TFragmentType, ... }) => $Shape<TVariables>)
& (<TFragmentType>( { +$fragmentSpreads: TFragmentType, ... }) => Partial<TVariables>)
& (<TFragmentType>(?{ +$fragmentSpreads: TFragmentType, ... }) => TVariables),
TKey,
>;
Expand Down Expand Up @@ -157,6 +157,7 @@ function useBlockingPaginationFragment<
(variables: TVariables, options: void | Options) => {
disposeFetchNext();
disposeFetchPrevious();
// $FlowFixMe[incompatible-variance]
return refetch(variables, {...options, __environment: undefined});
},
[disposeFetchNext, disposeFetchPrevious, refetch],
Expand Down
4 changes: 2 additions & 2 deletions packages/react-relay/relay-hooks/useLoadMoreFunction.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export type LoadMoreFn<TVariables: Variables> = (
count: number,
options?: {
onComplete?: (Error | null) => void,
UNSTABLE_extraVariables?: $Shape<TVariables>,
UNSTABLE_extraVariables?: Partial<TVariables>,
},
) => Disposable;

Expand Down Expand Up @@ -125,7 +125,7 @@ function useLoadMoreFunction<TVariables: Variables>(
(
count: number,
options: void | {
UNSTABLE_extraVariables?: $Shape<TVariables>,
UNSTABLE_extraVariables?: Partial<TVariables>,
onComplete?: (Error | null) => void,
},
) => {
Expand Down
3 changes: 2 additions & 1 deletion packages/react-relay/relay-hooks/useRefetchableFragment.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type RefetchVariables<TVariables, TKey> =
// - non-nullable if the provided ref type is non-nullable
// prettier-ignore
$Call<
& (<TFragmentType>( { +$fragmentSpreads: TFragmentType, ... }) => $Shape<TVariables>)
& (<TFragmentType>( { +$fragmentSpreads: TFragmentType, ... }) => Partial<TVariables>)
& (<TFragmentType>(?{ +$fragmentSpreads: TFragmentType, ... }) => TVariables),
TKey,
>;
Expand Down Expand Up @@ -100,6 +100,7 @@ function useRefetchableFragment_LEGACY<

// $FlowFixMe[incompatible-return]
// $FlowFixMe[prop-missing]
// $FlowFixMe[incompatible-variance]
return [fragmentData, refetch];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ type RefetchFnExact<TQuery: OperationType, TOptions = Options> = RefetchFnBase<
type RefetchFnInexact<
TQuery: OperationType,
TOptions = Options,
> = RefetchFnBase<$Shape<VariablesOf<TQuery>>, TOptions>;
> = RefetchFnBase<Partial<VariablesOf<TQuery>>, TOptions>;

type Action =
| {
Expand Down

0 comments on commit f0dbef2

Please sign in to comment.