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

Weird behaviour with graphql-mock

Open kaievns opened this issue 6 years ago • 0 comments

Hey Daniel, how are you?

Firstly, thank you for an epic library and releasing us from the shackles of the Query components!

Secondly, i'm having a bit of a drama trying to make your awesome library to work with my awesome graphql-mock library, and i was wondering if you could shed some light for me why this happens?

The way graphql-mock works is that it creates a wrapped appolo-client instance that allows to specify exact responses for specific queries/mutation/variables combination. Think nock but for apollo graphql. It works perfectly with react-apollo and we've been using it for almost a year now. but there is a problem with useQuery i'm seeing

so basically when i render the same component that uses useQuery in several test cases, each next test case somehow feeds the previous case data back. I'm seeing a history that looks like this:

beforeEach reset client
test case 1 setup mocks
render/assert works fine

beforeEach reset client
test case 2 setup different mocks
render -> renders the test case 1 mocks and explodes

now i know what you might think, the mock client is messed up, but i've tracked the client data flow back and fourth, and again it works fine with react-apollo, but something weird starts to happen when i start using useQuery. each case works fine in isolation, but when i start run several of them in a succession, it starts throwing weird errors.

any chance you could look at it? i've stashed everything in a PR, added console.logs and isolated the test case for you. it breaks down essentially over here on the second test case https://github.com/MadRabbit/graphql-mock/pull/22/files#diff-a86d2aa137c6728b2bf9a60bccd88855R93

kaievns avatar May 27 '19 02:05 kaievns