Skip to content
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

warning on undefined from field in readField #8499

Closed
willrax opened this issue Jul 15, 2021 · 2 comments · Fixed by #8508
Closed

warning on undefined from field in readField #8499

willrax opened this issue Jul 15, 2021 · 2 comments · Fixed by #8508

Comments

@willrax
Copy link

willrax commented Jul 15, 2021

Hi 👋

In our app we make heavy use of the readField function to for client fields on our schema. When we're using these fields we often send in a reference or object as the second argument to the function. What we find though is that in some more complicated functions that it's possible for the reference or object to be undefined. This is often due to the relationship / reference we pass in having no data when we request it from the our graph.

Unfortunately, this introduces the possibility for a bug because we're now reading a field from the original object rather than the reference. In some cases where the the original object has the same field you won’t even know you’re running into an issue or that you're working off the wrong data.

It's difficult to catch this is happening until you really dig in to the readField function and add lots of logging.

In reading the code for the readField function I noticed that the function checks for undefined. I think a more robust solution could check for the presence of the from argument rather than the presence of a value. That way we could throw an error or a warning that the reference or object is undefined.

How to reproduce the issue:
Working on a reproduction now and I'll update.

@benjamn
Copy link
Member

benjamn commented Jul 16, 2021

Fix incoming: #8508

@benjamn
Copy link
Member

benjamn commented Jul 28, 2021

@willrax This should be fixed in @apollo/client@3.4.0 (just released). Please try updating with npm i @apollo/client@next when you have a chance!

@hwillson hwillson removed this from the MM-2021-07 milestone Jul 29, 2021
@hwillson hwillson closed this as completed Aug 3, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.