-
Notifications
You must be signed in to change notification settings - Fork 2k
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
fix(gateway): pass null required fields correctly to resolvers #4157
fix(gateway): pass null required fields correctly to resolvers #4157
Conversation
… into prevent-null-from-expanding-into-objects
@trevor-scheer this was another bug I had noticed when working with nested |
b5a418a
to
56a5661
Compare
@trevor-scheer can you take a look at this when you get a chance? This fixes an issue where the resolver parent type can sometimes break the contract as specified by the schema (e.g. certain non-nullable fields appear as null in the parent type passed to the resolver). This can cause some nasty bugs in production since it breaks type safety. |
Hey @jakeblaxon, thank you for patience (and effort!) on this. This looks good to me. If you don't mind pushing up a few comments that explain the conditions that we're handling differently that would be much appreciated. Explaining the edges will be helpful for us in the future 🙂 |
…thub.com/jakeblaxon/apollo-server into prevent-null-from-expanding-into-objects
…into prevent-null-from-expanding-into-objects
@trevor-scheer sounds good! I actually just found what I think is a more simple fix for this. I left a comment above to explain the check as well. Can you take another look and let me know what you think? |
@jakeblaxon in digging in a bit more deeply to understand this change, I found that your test passes even if I revert the change. Are you aware of that? This is not to say the change is necessarily wrong, but if it's correct then I think the test may be missing the point. Maybe we need to reconsider the testing path? Let me know your thoughts! |
@trevor-scheer That's interesting. The test fails for me, even with the latest pull from main. Did you make sure to run |
Thanks @jakeblaxon, my mistake on that and all is well! This is good to go. Thanks again 🥳 |
…ographql/apollo-server#4157) This commit fixes a bug in the Apollo Gateway, where certain subfields that were null in the parent object that is passed to resolvers were getting expanded into objects that contained all null subfields. Apollo-Orig-Commit-AS: apollographql/apollo-server@eeaeaf0
This fixes a bug in the Apollo Gateway, where certain subfields that were null in the parent object that is passed to resolvers were getting expanded into objects that contained all null subfields.
Scenario
When service
B
requires a field from serviceA
, if that field isnull
in serviceA
, it would be passed toB
's resolver expanded as an object with all null subfields.For example, if
B
required the fieldmovie
from serviceA
in its resolver, and the value in serviceA
looks like the following:the
actor
object, being the parent, would be passed toB
's resolver as the following:This can cause unexpected errors in the resolver logic, since the resolver may assume that the
title
andyear
fields will never be null (as per the graphQL schema).This fix prevents this expansion, so that the
actor
object passed toB
's resolver remains the same, i.e. theactor.movie
field is null.