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.

Promise callback of Mutate function not being called

See original GitHub issue

Describe the bug When using a Mutate function with the PUT verb, the callback of the mutation promise is not called

To Reproduce Minimal Code example to reproduce

    {(update, { loading, error }) => {
    return (
        style={{ width: "100px", height: "100px" }}
        onClick={() => {
            id: 1,
            title: "foo",
            body: "bar",
            userId: 1
            }).then(() => console.log("Then called"));

There are no throw errors and loading turns from false -> true -> false indicating an operation took place.

Not sure if the operation is being aborted early for some reason, or is throwing an error that is not being caught by the Mutate function.

NOTE: You can use the .finally method on the promise but it is unclear if this is intended behavior in the docs

Expected behavior According to the docs, “Each mutation returns a promise…”, which to me indicates that I should be allowed to use the .then function on the returned promise.

Screenshots N/A

Desktop (please complete the following information):

  • OS: Windows 10 1803
  • Browser: Firefox
  • Version: 66.0.5 (64-bit)

Additional Note Even the docs are using the .then function on the mutate function so I believe this is definitely a bug See here

onClick={() => delete( => dispatch('DELETED'))}

Also a side note, delete is a reserved word in JS and that line will result in a compile error

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

fabien0102commented, May 16, 2019

Indeed the error is not correctly propagated in Mutate (, the trick is to add a .catch statement. In your snippet you just have a 404 error for example. I’ve spotted this bug yesterday during my useMutate implementation but you was quicker than me for reporting 😉

Good catch for the example in the documentation 😅 using delete is quite stupid ^^

fabien0102commented, May 16, 2019

Time to add a new unit test! Thanks for the feedback 💯

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mutations in Apollo Client - Apollo GraphQL Docs
A callback function that's called when your mutation successfully completes with zero errors (or if errorPolicy is ignore and partial data is returned)....
Read more >
javascript - Why is my variable unaltered after I modify it inside ...
That function is clearly not executed immediately; it is being assigned or passed as an argument. That is what we call a callback....
Read more >
Testing-library: avoid these mistakes in async tests
In our test, when we are calling render with await , JavaScript implicitly wraps the result into a promise and waits for it...
Read more >
Mutations | TanStack Query Docs
When returning a promise in any of the callback functions it will first be ... the component that triggers the mutation might not...
Read more >
Testing Asynchronous Behavior - Vue Test Utils
The following examples shows how to test a method that makes an API call. ... the promise callback has been executed by the...
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 Post

No results found

github_iconTop Related Hashnode Post

No results found