question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

There was a undescribed "Breaking change" in useMutation hook

See original GitHub issue

Since this commit there was a “breaking change” in the useMutation hook.

Intended outcome: When doing the following code:

const { errors } = await doMutation()

errors was filled if there was an error from the API

Actual outcome: Error is now thrown instead of returned.

How to reproduce the issue:

// Make sure this mutation returns a error
const { errors } = await doMutation()

// Errors wont be called since 
console.log(errors)

Versions Everything after 3.4.0

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:1
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
jembachcommented, Dec 9, 2021

Hi @TriPSs,

I’m having the same problem. It is in my opinion an unexpected behavior because when i can get an error returned i expect that it does not throw an error. In addition it isn’t documented:

Currently my solution looks like this:


class ApolloCatchError implements ApolloQueryResult<undefined> {
  data = undefined;

  loading = false;

  networkStatus = NetworkStatus.error;

  errors = [];

  constructor(public error: ApolloError) {}
}

  async function fetchUser() {
    return gqlClient
      .query<QueryCurrentUserData, QueryCurrentUserVariables>({
        query: QUERY_CURRENT_USER,
        fetchPolicy: 'network-only',
      })
      .catch((error: ApolloError) => new ApolloCatchError(error));
  }

This is a typesafe solution providing the same result as @TriPSs and me expect

1reaction
TriPSscommented, Nov 18, 2021

Yea, if the line where it now throws the error would return it just like it does a couple of lines above it the behaviour would be how it was.

Currently we have it this was in a lot of places, so if this behaviour won’t work anymore we would have to refractor all off those and add empty try catches to it otherwise our error reporting tool will send un needed messages.

Read more comments on GitHub >

github_iconTop Results From Across the Web

The useMutation hook | Lift-off IV: Mutations
Inside the TrackCard component, we'll start off by calling the hook. It takes in the mutation we set up earlier, INCREMENT_TRACK_VIEWS , as...
Read more >
Relay with hook useMutation get error: Invalid hook call. ...
I'm trying to commit a relay mutation of using the useMutation hook, but got the error: Error: Invalid hook call. Hooks can only...
Read more >
react-apollo-hooks | Yarn - Package Manager
BREAKING CHANGES · useMutation returns tuple with result instead of just returning a mutating function · now Apollo Client >= 2.6.0 is required...
Read more >
[Solved] Running a mutation from an event handler
It IS inside of a function. I've tried instead of { } in const { setDomain } = useMutation . What am I...
Read more >
apollo/client
Implement useFragment_experimental hook, which represents a lightweight live ... whose addition in #8699 was a breaking change (starting in Apollo Client ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found