GithubHelp home page GithubHelp logo

Comments (2)

logaretm avatar logaretm commented on June 12, 2024 1

Possible but not recommended as you might cause value skipping setting the reactive values on the useMutation returns, which could be acceptable if the only way you use useMutation is via the execute function.

So the dirty way is to introduce a custom fetch plugin that throws, something similar to fetch default plugin which you can use as a baseline but make sure to throw the error. I'm not going to offer code guidance there since I don't like recommending this hack.

Another way that I recommend, is to compose useMutation with a custom one:

export function useThrowingMutation(query) {
  const mutation = useMutation(query);

  mutation.execute = function executeWithThrow(...args) {
     const { data, errors } = await execute(...args);
     if (error) {
       throw error;
    }

    return { data };
  }
}

This is simpler and should work well and you can use it for all of your mutations.

Internally this is hard to offer out of the box because villus uses a pipeline of plugins system, so if one crashes it is a big deal and causes integrity concerns to the GraphQL result.

from villus.

Laurensvdmaas avatar Laurensvdmaas commented on June 12, 2024

I understand, thanks for your answer!

from villus.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.