Skip to content

Commit

Permalink
Better type inference for {Query,Subscription,Mutation}.propTypes.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamn committed Aug 28, 2020
1 parent 1a601d8 commit ab5a4f0
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 42 deletions.
38 changes: 20 additions & 18 deletions src/react/components/Mutation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,24 @@ export function Mutation<TData = any, TVariables = OperationVariables>(
return props.children ? props.children(runMutation, result) : null;
}

export namespace Mutation {
export const propTypes = {
mutation: PropTypes.object.isRequired,
variables: PropTypes.object,
optimisticResponse: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
refetchQueries: PropTypes.oneOfType([
PropTypes.arrayOf(
PropTypes.oneOfType([PropTypes.string, PropTypes.object])
),
PropTypes.func
]),
awaitRefetchQueries: PropTypes.bool,
update: PropTypes.func,
children: PropTypes.func.isRequired,
onCompleted: PropTypes.func,
onError: PropTypes.func,
fetchPolicy: PropTypes.string
};
export interface Mutation<TData, TVariables> {
propTypes: PropTypes.InferProps<MutationComponentOptions<TData, TVariables>>;
}

Mutation.propTypes = {
mutation: PropTypes.object.isRequired,
variables: PropTypes.object,
optimisticResponse: PropTypes.oneOfType([PropTypes.object, PropTypes.func]),
refetchQueries: PropTypes.oneOfType([
PropTypes.arrayOf(
PropTypes.oneOfType([PropTypes.string, PropTypes.object])
),
PropTypes.func
]),
awaitRefetchQueries: PropTypes.bool,
update: PropTypes.func,
children: PropTypes.func.isRequired,
onCompleted: PropTypes.func,
onError: PropTypes.func,
fetchPolicy: PropTypes.string
};
32 changes: 17 additions & 15 deletions src/react/components/Query.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,21 @@ export function Query<TData = any, TVariables = OperationVariables>(
return children && result ? children(result) : null;
}

export namespace Query {
export const propTypes = {
client: PropTypes.object,
children: PropTypes.func.isRequired,
fetchPolicy: PropTypes.string,
notifyOnNetworkStatusChange: PropTypes.bool,
onCompleted: PropTypes.func,
onError: PropTypes.func,
pollInterval: PropTypes.number,
query: PropTypes.object.isRequired,
variables: PropTypes.object,
ssr: PropTypes.bool,
partialRefetch: PropTypes.bool,
returnPartialData: PropTypes.bool
};
export interface Query<TData, TVariables> {
propTypes: PropTypes.InferProps<QueryComponentOptions<TData, TVariables>>;
}

Query.propTypes = {
client: PropTypes.object,
children: PropTypes.func.isRequired,
fetchPolicy: PropTypes.string,
notifyOnNetworkStatusChange: PropTypes.bool,
onCompleted: PropTypes.func,
onError: PropTypes.func,
pollInterval: PropTypes.number,
query: PropTypes.object.isRequired,
variables: PropTypes.object,
ssr: PropTypes.bool,
partialRefetch: PropTypes.bool,
returnPartialData: PropTypes.bool
};
20 changes: 11 additions & 9 deletions src/react/components/Subscription.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ export function Subscription<TData = any, TVariables = OperationVariables>(
return props.children && result ? props.children(result) : null;
}

export namespace Subscription {
export const propTypes = {
subscription: PropTypes.object.isRequired,
variables: PropTypes.object,
children: PropTypes.func,
onSubscriptionData: PropTypes.func,
onSubscriptionComplete: PropTypes.func,
shouldResubscribe: PropTypes.oneOfType([PropTypes.func, PropTypes.bool])
};
export interface Subscription<TData, TVariables> {
propTypes: PropTypes.InferProps<SubscriptionComponentOptions<TData, TVariables>>;
}

Subscription.propTypes = {
subscription: PropTypes.object.isRequired,
variables: PropTypes.object,
children: PropTypes.func,
onSubscriptionData: PropTypes.func,
onSubscriptionComplete: PropTypes.func,
shouldResubscribe: PropTypes.oneOfType([PropTypes.func, PropTypes.bool])
};

0 comments on commit ab5a4f0

Please sign in to comment.