Skip to content

Commit f8d6c26

Browse files
committed
fix(typescript): parametrize update option of useMutation hook
1 parent 1417ebb commit f8d6c26

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/index.d.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
OperationVariables,
99
QueryOptions,
1010
} from 'apollo-client';
11+
import { DataProxy } from 'apollo-cache';
1112
import { DocumentNode, ExecutionResult } from 'graphql';
1213
import * as React from 'react';
1314

@@ -52,10 +53,22 @@ export function useQuery<TData = any, TVariables = OperationVariables>(
5253
): Promise<ApolloQueryResult<TData>>;
5354
};
5455

56+
// We have to redefine MutationUpdaterFn and `update` option of `useMutation`
57+
// hook because we want them to use our custom parametrized version
58+
// of `FetchResult` type. Please look at
59+
// https://github.com/trojanowski/react-apollo-hooks/issues/25
60+
export type MutationUpdaterFn<
61+
T = {
62+
[key: string]: any;
63+
}
64+
> = (proxy: DataProxy, mutationResult: FetchResult<T>) => void;
65+
5566
type MutationHookOptions<T, TVariables> = Omit<
5667
MutationOptions<T, TVariables>,
57-
'mutation'
58-
>;
68+
'mutation' | 'update'
69+
> & {
70+
update?: MutationUpdaterFn<T>;
71+
};
5972

6073
export function useMutation<T, TVariables = OperationVariables>(
6174
mutation: DocumentNode,

0 commit comments

Comments
 (0)