-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
query returns null data when there is missing field and fetchPolicy is cache-first #4267
Comments
apollo-client works only with graphql servers that actually adhere to the graphql specification. It clearly states:
Your graphql server does not adhere to the specification. Instead of returning per spec
you are returning
So the behavior of apollo-client is undefined. |
Thank you for replying @danilobuerger. If that's the case, why Apollo cache the resulting data at all, but fail to return it in the promise? That's very confusing for us since I can still retrieve the results directly from cache. Also, if that's to be considered some sort of erroneous behavior, Apollo could provide some extra logs/warnings stating that to guide us into the expected way. |
As I wrote: the behaviour of Apollo is undefined, if your server does not behave as per spec. |
Could we have some sort of explicit warning or error messaging saying that there was some issue parsing the data instead of silently returning undefined? It's quite common to have this sort of bug in the api especially when the data object is large so having a useful error message will go along way in terms of dev experience. |
Intended outcome:
When using
client.query()
the resultingdata
is always null whenever fetchPolicy is set tocache-first
and there are missing fields from the projected result. For instance, if we're supposed to query an user like:user { uuid email picture }
and for some reason the server does not return field picture, then result will be:In my particular case, my backend never serializes null values. Since user's
picture
and many other fields are optional (nullable), we constantly face this problem.I've also noticed we'll get a Missing field picture warning on the console. In addition, the user data will be cached and I can retrieve at
client.cache.data.data
. However, not directly from the promise result.Finally, If we change the fetchPolicy to
no-cache
, the problem does not happen and we can also access the resulting data.Actual outcome:
data
should not be null since the result is valid. In case of missing fieldpicture
, the user data should successfully returnuuid
andemail
fields. An example would be:How to reproduce the issue:
Please, see query above.
Versions
The text was updated successfully, but these errors were encountered: