Skip to content

Commit

Permalink
fix: when triggers with input object and null as input value
Browse files Browse the repository at this point in the history
  • Loading branch information
LanceRabbit committed Oct 4, 2024
1 parent cfd5c95 commit 6a3e5d3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/graphql/subscriptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ def broadcastable?(query_str, **query_options)
def normalize_arguments(event_name, arg_owner, args, context)
case arg_owner
when GraphQL::Schema::Field, Class
return args if args.nil?

if arg_owner.is_a?(Class) && !arg_owner.kind.input_object?
# it's a type, but not an input object
return args
Expand Down
17 changes: 17 additions & 0 deletions spec/graphql/subscriptions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1143,5 +1143,22 @@ class Schema < GraphQL::Schema
assert_equal(':mySubscription:input:innerInput:', write_subscription_events[0].topic)
assert_equal(':mySubscription:input:innerInput:', execute_all_events[0].topic)
end

it 'correctly generates subscription topics when triggering with nil as input value' do
query_str = <<-GRAPHQL
subscription ($input: OuterInput) {
mySubscription (input: $input) {
fullName
}
}
GRAPHQL

schema.execute(query_str, variables: { 'input' => nil })

schema.subscriptions.trigger(:mySubscription, { 'input' => nil }, nil)

assert_equal(':mySubscription:input:', write_subscription_events[0].topic)
assert_equal(':mySubscription:input:', execute_all_events[0].topic)
end
end
end

0 comments on commit 6a3e5d3

Please sign in to comment.