apollo-feature-requests icon indicating copy to clipboard operation
apollo-feature-requests copied to clipboard

Add `MockedResponse` -> `newData` to docs

Open wild-lotus opened this issue 5 years ago • 1 comments

I just realised that when providing a MockedResponse to MockedProvider, you can provide a newData key in the MockedResponse. This seems to be an alternative to the result key. I have found no documentation about it.

My request here is to add this newData to MockedProvider docs.

On top of that, if you could leave here a brief explanation of the differences between newData and result for the meantime, I would appreciate.

wild-lotus avatar Jan 10 '20 12:01 wild-lotus

I'd also like some info about this newData - could you find something out @CarlosGines ? Or can someone else give more info? Thanks!

stuartjbrown avatar Jul 05 '22 11:07 stuartjbrown

I've seen this addition requested here and on other websites and people have been requesting it for years. I just want to say it's super inconvenient that it hasn't been added to the docs yet. So far, all I can gather about newData is that it's a function run to get maybe data for successive calls but not the first one? I have no idea how it's different from result being a function.

artium-ryanh avatar Feb 10 '23 15:02 artium-ryanh

Hi @artium-ryanh @stuartjbrown @CarlosGines 👋🏻 newData lets users control the mocked response result dynamically in case they want to test scenarios with responses that can't be statically defined. Here's an SO thread showing a real-world usage. And here's a blog post by @jkettmann that goes into some depth about how they used newData for mutation testing. I agree this should be in the docs - not sure when the maintainers will get to it but I hope this info is enough to go on for now. And if you're interested in submitting a PR we'd definitely be interested in reviewing it!

bignimbus avatar Feb 16 '23 19:02 bignimbus

@bignimbus It does help, thank you! I was able to figure that out with experimentation and I'm glad to know this post can be a resource for people searching for the same thing I was. I'd consider drafting a PR, but I'm not sure where I would make it. Can you link me to the docs repo?

artium-ryanh avatar Feb 16 '23 22:02 artium-ryanh

@artium-ryanh awesome 🚀 I think this file would probably be a good place to start: https://github.com/apollographql/apollo-client/blob/main/docs/source/development-testing/testing.mdx

bignimbus avatar Feb 17 '23 02:02 bignimbus