we’ll commonly see No more mocked responses for the query in the console output but have been unable to distill them down to something minimal
Usually this happens as a result of __typename
being omitted in the test (e.g. by using addTypename={false}
in MockedProvider
). Any chance you could post a small snippet of one of these failing tests? I might be able to spot something there, but not sure. Its at least a clue that the query is being transformed by the Apollo Client instance in a way your test didn’t expect.
some tests now fail because of code directly modifying the response data. What we’re confused about is that this does not appear to apply to network results, only cache results?
To be honest, I’m not sure the historical reason for allowing that. Perhaps its an oversight? This one unfortunately predates my time on the team, so I’m not sure why the network request would be mutable. I know we do this for the cache because its really easy to introduce bugs this way. Mutable updates to the cache aren’t broadcasted, so its easy to get into weird inconsistencies. I agree though, its odd we don’t do this for the network response as well.
We’d strongly recommend moving away from mutability if you can in areas that the client allows you to. We do a lot of internal caching and work that relies on referential equality, so mutating values could introduce weird side effects. Totally understand this is a difficult ask and a big effort, so for now I’d just say that areas where you’re mutating data, pay attention to make sure there aren’t weird bugs as a result of it.
Invariants (and perhaps other error types?) just console.error’ing and no longer showing up on the error object
Unfortunately this is another one that predates my time on the team. My best guess is that some of the invariants were moved to warnings 1) due to feedback and 2) because the client could better handle instances where cache writes were incomplete. The client will execute a network fetch in the case that a missing field is encountered to ensure it can fulfill the query in that case.
How are we meant to check for error/loading/data
Your example looks fine to me. Are there cases where you’re seeing something unexpected such as loading: false
and no data? Unless you’re using an errorPolicy
of ignore
, this would seem odd to me.
This has been done due to some combination of trying to make tests happy and TypeScript errors
Perhaps a code sample would be useful? I do know that unfortunately our TS types for useQuery
are a tad lacking in v3. We don’t use unions on the result, so the TS type will show TData | undefined
even after you’ve checked error
and loading
. This is something we have on the roadmap that we’d like to address soon so that data
is more akin to what you’d see at runtime, which is that it should never be undefined
if loading
is false
and you don’t have errors (unless you modify the errorPolicy
to ignore
).
Does this sound like the issue your’e seeing?