apollo-client icon indicating copy to clipboard operation
apollo-client copied to clipboard

throw and error/warn when "possibleTypes" are not configured and data requiring them is queried

Open capaj opened this issue 3 years ago • 4 comments

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 avatar Aug 28 '20 10:08 capaj

@capaj This will be happening in v3.2.0 as part of #6901, thanks to 03930ee144fb4c053f67c6e1fd8d3a35b2a39ee3.

benjamn avatar Aug 28 '20 14:08 benjamn

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.

benjamn avatar Sep 10 '20 18:09 benjamn

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...

batamire avatar Apr 08 '21 07:04 batamire

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.

mrclay avatar Sep 18 '22 12:09 mrclay