Cache typePolicy read() function - returning undefined vs null

I am mocking a local field (@client) in some storybook stories, and discovered that when I was returning undefined from the read() function I defined in the cache for the Query typePolicy, the useQuery hook started returning loading = true. But when I changed read() to return null, loading was set to false.

This leads me to assume that returning undefined from read() is signalling that the element “can not be found” by the read() logic, while returning null means that the element is found, but is “empty”.

Is this documented anywhere? And if not, should I perhaps raise an issue on github for this behavior to be documented where relevant? e.g:

Yeah, I think your observation pretty much sums it up. This might be something we should add to the docs - could you please open an issue, or even a PR, on this?

1 Like

Thanks for taking the time to answer =)

I was on my way to making an issue, but when trying to make a minimal repro, I was unable to reproduce the effect… So to avoid making noise on github I will leave it here in the forums in case others should have the same issue and discover this post. I have no solution to offer though (I even tested downgrading to the version of apollo-client we were using). It might have been some weird interaction with the MockedProvder from @apollo/client/testing too.