Skip to content

Commit 21b2099

Browse files
committed
Fix handling of skips from lazy values
1 parent 412e141 commit 21b2099

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

lib/graphql/execution/interpreter/runtime.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,15 @@ def continue_value(path, value, parent_type, field, is_non_null, ast_node, resul
517517
end
518518
continue_value(path, next_value, parent_type, field, is_non_null, ast_node, result_name, selection_result)
519519
elsif GraphQL::Execution::Execute::SKIP == value
520+
# It's possible a lazy was already written here
521+
case selection_result
522+
when Hash
523+
selection_result.delete(result_name)
524+
when Array
525+
selection_result.delete_at(result_name)
526+
else
527+
raise "Invariant: unexpected result class #{selection_result.class} (#{selection_result.inspect})"
528+
end
520529
HALT
521530
else
522531
# What could this actually _be_? Anyhow,

spec/graphql/execution/interpreter_spec.rb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -587,21 +587,19 @@ class Subscription < GraphQL::Schema::Object
587587
lazy_resolve Proc, :call
588588
end
589589

590-
focus
591590
it "skips properly" do
592591
res = LazySkipSchema.execute("{ skip }")
593592
assert_equal({}, res["data"])
594593
refute res.key?("errors")
595-
# This failed on 1.12.10, too
596-
# res = LazySkipSchema.execute("{ lazySkip }")
597-
# pp res
598-
# assert_equal({}, res["data"])
599-
# refute res.key?("errors")
594+
595+
res = LazySkipSchema.execute("{ lazySkip }")
596+
assert_equal({}, res["data"])
597+
refute res.key?("errors")
600598

601599
res = LazySkipSchema.execute("subscription { nothing { nothing } }")
602-
pp res
603600
assert_equal({}, res["data"])
604601
refute res.key?("errors")
602+
# Make sure an update works properly
605603
LazySkipSchema.subscriptions.trigger(:nothing, {}, :nothing_at_all)
606604
key, updates = LazySkipSchema.subscriptions.deliveries.first
607605
assert_equal "nothing_at_all", updates[0]["data"]["nothing"]["nothing"]

0 commit comments

Comments
 (0)