diff --git a/lib/graphql/subscriptions/anycable_subscriptions.rb b/lib/graphql/subscriptions/anycable_subscriptions.rb index 4d9aca3..5f2ee7f 100644 --- a/lib/graphql/subscriptions/anycable_subscriptions.rb +++ b/lib/graphql/subscriptions/anycable_subscriptions.rb @@ -140,7 +140,7 @@ def write_subscription(query, events) query_string: query.query_string, variables: query.provided_variables.to_json, context: @serializer.dump(context.to_h), - operation_name: query.operation_name, + operation_name: query.operation_name.to_s, events: events.map { |e| [e.topic, e.fingerprint] }.to_h.to_json, } diff --git a/spec/graphql/anycable_spec.rb b/spec/graphql/anycable_spec.rb index 8510ebd..123f08a 100644 --- a/spec/graphql/anycable_spec.rb +++ b/spec/graphql/anycable_spec.rb @@ -89,6 +89,28 @@ end end + context "with empty operation name" do + subject do + AnycableSchema.execute( + query: query, + context: { channel: channel, subscription_id: subscription_id }, + variables: {}, + operation_name: nil, + ) + end + + let(:query) do + <<~GRAPHQL + subscription { productUpdated { id } } + GRAPHQL + end + + it "subscribes channel to stream updates from GraphQL subscription" do + subject + expect(channel).to have_received(:stream_from).with("graphql-subscriptions:#{fingerprint}") + end + end + describe ".delete_channel_subscriptions" do before do GraphQL::AnyCable.config.use_client_provided_uniq_id = false