From 79a3672729f5d839f50f2acf571d3e432bbb1ae8 Mon Sep 17 00:00:00 2001 From: Andrey Novikov Date: Thu, 25 Jan 2024 18:55:52 +0900 Subject: [PATCH] Add test to reproduce bug report #42 --- spec/graphql/query_spec.rb | 21 +++++++++++++++++++++ spec/integrations/rails_spec.rb | 1 - spec/support/graphql_schema.rb | 25 +++++++++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 spec/graphql/query_spec.rb diff --git a/spec/graphql/query_spec.rb b/spec/graphql/query_spec.rb new file mode 100644 index 0000000..18bfcbb --- /dev/null +++ b/spec/graphql/query_spec.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +RSpec.describe "Query without subscriptions" do + subject { BroadcastSchema.execute(query: query) } + + let(:query) do + <<~GRAPHQL.strip + query SomeQuery { strategy { id classType } } + GRAPHQL + end + + it "works" do + expect(subject["data"]).to eq( + "strategy" => { + "id" => "2134", + "classType" => "strategy", + "__typename": "Strategy", + }, + ) + end +end diff --git a/spec/integrations/rails_spec.rb b/spec/integrations/rails_spec.rb index da79df7..d81dcc3 100644 --- a/spec/integrations/rails_spec.rb +++ b/spec/integrations/rails_spec.rb @@ -14,7 +14,6 @@ def self.root require "anycable-rails" # Load server to trigger load hooks -require "action_cable/server" require "action_cable/server/base" # Only for anycable-rails <1.3.0 unless defined?(::AnyCable::Rails::Connection) diff --git a/spec/support/graphql_schema.rb b/spec/support/graphql_schema.rb index ee946b1..e84af1c 100644 --- a/spec/support/graphql_schema.rb +++ b/spec/support/graphql_schema.rb @@ -42,9 +42,33 @@ def default_resolver end end +class BaseObject < GraphQL::Schema::Object + field :class_type, String, null: false + + def class_type + object.class.name.camelize(:lower) + end +end + +class StrategyType < BaseObject + field :id, ID, null: false +end + +class QueryType < GraphQL::Schema::Object + field :strategy, StrategyType + + def strategy + { + id: 2134, + class_type: "strategy", + } + end +end + class AnycableSchema < GraphQL::Schema use GraphQL::AnyCable + query QueryType subscription SubscriptionType end @@ -78,4 +102,5 @@ class BroadcastSchema < GraphQL::Schema use GraphQL::AnyCable, broadcast: true, default_broadcastable: true subscription Broadcastable::SubscriptionType + query QueryType end