Fix returning [Type, false] from resolve_type #4412
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
#4130 fixed returning
[Type, nil]
from a union'sresolve_type
, but it caused a regression for literalfalse
values.Schema#resolve_type
had anif resolved_value
conditional would be false forfalse
values causing it always return a single value (theresolve_type
).The runtime's
resolve_type
method would then always return the tuple version (in non-lazy cases):[type, value]
. However, sinceSchema#resolve_type
was only returning a single value, the resolved value would be lost resulting in[type, nil]
being passed on.The fix is to remove the
if resolved_value
conditional entirely and always return the two-value tuple ensuring the original resolved value is correctly passed along.Note: the runtime still has a branch to check if the
resolve_type
value is a tuple or not. The only case where this won't be true is for lazy resolved types.The call stack is a bit confusing, so here's all the relevant code in call order:
Schema#resolve_type
graphql-ruby/lib/graphql/schema.rb
Lines 802 to 806 in 42b3413
Runtime#resolve_type
graphql-ruby/lib/graphql/execution/interpreter/runtime.rb
Line 992 in 42b3413
Runtime#continue_field
graphql-ruby/lib/graphql/execution/interpreter/runtime.rb
Lines 725 to 730 in 42b3413
cc @IDolgirev