useMutation diffs between client v2 and v3

Hello,

I’m migrating from apollo-client@v2 to @apollo/client@v3

I have a rather large codebase where we used to do something like this:

const [mutate, {loading}] = useMutation(...)
const handleClick = () => {
    const res = await mutate()
    if (res.errors?.length > 0) {
         // do something
         return 
    }

   // do something else
}

As far as I understand from your documentation , “The mutate function returns a promise that fulfills with your mutation result.”, and from reading the code, it looks like the data returned when awaiting the mutate function should be the same as the data in the object returned from the useMutation (2nd element of the returned tuple).

However, from the typings, the mutate function only seems to expose data, context and extensions (not errors nor error)

What should I understand from this ? Are the types wrong ? Or do you expect people to only use the onError callback to handle ApolloErrors ?

Best

@Maxime_Vast errors should be available. useMutation returns a MutationTuple:

MutationTuple defines a Promise of type FetchResult as the result from the execute function:

FetchResult extends the graphql-js ExecutionResult type:

The ExecutionResult type has errors:

Thanks for your anwser,

I’m using 3.5.10 and typescript only sees return values from FetchResult