Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing the wrapper Promise in useMutation to enable apollo client stubs #199

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kaievns
Copy link

@kaievns kaievns commented Jul 24, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant