Mike-Gibson / mock-apollo-client

Helps unit test components which use the Apollo Client.
MIT License
117 stars 15 forks source link

How can I make a request handler for client side/ cache queries? #19

Closed davidcolatti closed 4 years ago

davidcolatti commented 4 years ago

The documentation isn't very clear about this and I've been attempting this for a while.

Mike-Gibson commented 4 years ago

Hi, Is this with version 0.x (Apollo 2) or 1.x (Apollo 3) of mock Apollo client?

The behaviour of client side directives and how they are passed down to a link changed between Apollo client 2 and 3 which means mock Apollo client support is different between the two versions.

davidcolatti commented 4 years ago

Yes, this is for Apollo 3..

I just resolved my issue thought looking at your tests. :)

I had a full client directive query and I resolved it using the resolver.

Mike-Gibson commented 4 years ago

Ah, great news. Glad you've got it working.

Maybe I'll add a bit to the readme outlining how it works, as it's come up a few times now.

davidcolatti commented 4 years ago

That would definitely be helpful! Thanks for your work though! Way better than the Apollo MockedProvider..

miguelrincon commented 2 years ago

For folks coming here from Google, this is the line that helped me.

You can pass either resolvers or cache typePolicies to createMockClient to tell the client to use these your mocks.