-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changed return type of useMutation when ignoreResult is explicitly set to true to hide unset result #12277
base: main
Are you sure you want to change the base?
Changed return type of useMutation when ignoreResult is explicitly set to true to hide unset result #12277
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@apollo/client": patch | ||
--- | ||
|
||
Changed return type of useMutation when ignoreResult is explicitly set to true to avoid using unset values of the result |
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -2,6 +2,7 @@ import * as React from "rehackt"; | |||||||||||
import type { DocumentNode } from "graphql"; | ||||||||||||
import type { TypedDocumentNode } from "@graphql-typed-document-node/core"; | ||||||||||||
import type { | ||||||||||||
MutationFunction, | ||||||||||||
MutationFunctionOptions, | ||||||||||||
MutationHookOptions, | ||||||||||||
MutationResult, | ||||||||||||
|
@@ -69,6 +70,38 @@ import { useIsomorphicLayoutEffect } from "./internal/useIsomorphicLayoutEffect. | |||||||||||
* @param options - Options to control how the mutation is executed. | ||||||||||||
* @returns A tuple in the form of `[mutate, result]` | ||||||||||||
*/ | ||||||||||||
export function useMutation< | ||||||||||||
TData = any, | ||||||||||||
TVariables = OperationVariables, | ||||||||||||
TContext = DefaultContext, | ||||||||||||
TCache extends ApolloCache<any> = ApolloCache<any>, | ||||||||||||
>( | ||||||||||||
mutation: DocumentNode | TypedDocumentNode<TData, TVariables>, | ||||||||||||
options: { ignoreResults: true } & MutationHookOptions< | ||||||||||||
NoInfer<TData>, | ||||||||||||
NoInfer<TVariables>, | ||||||||||||
TContext, | ||||||||||||
TCache | ||||||||||||
> | ||||||||||||
): [ | ||||||||||||
MutationFunction<TData, TVariables, TContext, TCache>, | ||||||||||||
// result is not reliable when ignoreResults is true | ||||||||||||
Pick<MutationResult<TData>, "reset">, | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like we still return apollo-client/src/react/hooks/useMutation.ts Lines 88 to 92 in eeb5f3c
Can we include those properties here as well? I see no reason not to be able to access them, even if |
||||||||||||
]; | ||||||||||||
export function useMutation< | ||||||||||||
TData = any, | ||||||||||||
TVariables = OperationVariables, | ||||||||||||
TContext = DefaultContext, | ||||||||||||
TCache extends ApolloCache<any> = ApolloCache<any>, | ||||||||||||
>( | ||||||||||||
mutation: DocumentNode | TypedDocumentNode<TData, TVariables>, | ||||||||||||
options?: MutationHookOptions< | ||||||||||||
NoInfer<TData>, | ||||||||||||
NoInfer<TVariables>, | ||||||||||||
TContext, | ||||||||||||
TCache | ||||||||||||
> | ||||||||||||
): MutationTuple<TData, TVariables, TContext, TCache>; | ||||||||||||
export function useMutation< | ||||||||||||
TData = any, | ||||||||||||
TVariables = OperationVariables, | ||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -394,6 +394,8 @@ export declare type MutationFunction< | |
TCache extends ApolloCache<any> = ApolloCache<any>, | ||
> = ( | ||
options?: MutationFunctionOptions<TData, TVariables, TContext, TCache> | ||
// TODO This FetchResult<TData> seems strange here, as opposed to an | ||
// ApolloQueryResult<TData> | ||
) => Promise<FetchResult<MaybeMasked<TData>>>; | ||
|
||
export interface MutationHookOptions< | ||
|
@@ -418,11 +420,7 @@ export type MutationTuple< | |
TContext = DefaultContext, | ||
TCache extends ApolloCache<any> = ApolloCache<any>, | ||
> = [ | ||
mutate: ( | ||
options?: MutationFunctionOptions<TData, TVariables, TContext, TCache> | ||
// TODO This FetchResult<TData> seems strange here, as opposed to an | ||
// ApolloQueryResult<TData> | ||
) => Promise<FetchResult<MaybeMasked<TData>>>, | ||
mutate: MutationFunction<TData, TVariables, TContext, TCache>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💯 I have no idea why this wasn't that way to begin with. Good find! |
||
result: MutationResult<TData>, | ||
]; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update this to check
client
andcalled
as well?