apollo-client
apollo-client copied to clipboard
throw and error/warn when "possibleTypes" are not configured and data requiring them is queried
Please add a throw or a warning when "possibleTypes" are not configured and data requiring them is queried. Currently apollo-client returns empty object which obviously wreaks havoc at runtime.
Resolving this issue should make this common misconfiguration issue easier to identify and resolve: https://github.com/apollographql/apollo-client/issues/6632
@capaj This will be happening in v3.2.0 as part of #6901, thanks to 03930ee144fb4c053f67c6e1fd8d3a35b2a39ee3.
Unfortunately, I think I spoke too soon, since any fragment's type condition could match a given __typename
exactly, without any help from possibleTypes
.
This is a problem for identifying (and warning about) fragments that will never match, since the client doesn't know which types are abstract (and thus require an entry in possibleTypes
) and which types might be concrete (and thus could match exactly). Communicating this information to the client/cache would most likely involve adding information to possibleTypes
anyway, so the warnings wouldn't become useful until you'd already done that work.
I'm open to other ideas about how and when to warn about unmatchable fragments, but I don't think my first idea will work.
I just lost a few hours for the second time until I realized possibleTypes declaration was missing. The first time was a few months ago, an ancient past for my brain...
Users are sending valid queries, and InMemoryCache cannot properly operate without possibleTypes set (hiding server-returned content is a huge bug). Hence it should be made a required config to highlight to users its importance.