react-apollo-hooks icon indicating copy to clipboard operation
react-apollo-hooks copied to clipboard

Removing the wrapper Promise in useMutation to enable apollo client stubs

Open kaievns opened this issue 6 years ago • 0 comments

Ohi there,

So, can i ask a favour? I support this apollo mocking library called graphql-mock, which we use quite a bit in our work. It's sort like nock but for apollo. We're trying to migrate from vanilla react-apollo to your amazing react-apollo-hooks, but we've run into a bit of a problem with useMutation, which i hope we could address here.

Basically the way graphql-mock works is that it provides a mock apollo client which resolves queries and mutations immediately, so we could write tests without messing with async await. Here is an example https://github.com/MadRabbit/graphql-mock/blob/master/docs/mutations.md

The problem is though react-apollo-hooks wraps client.mutate queries in a new Promise wrapper, which prevents us from getting those immediate renders.

The funny thing is that client.mutate already returns a Promise, so if we shuffle things a little bit as in this PR, we both can get what we want. Your code will still work the same as before, and we can mess with the client methods unobstructed

kaievns avatar Jul 24 '19 01:07 kaievns