diff --git a/lib/graphql/schema/wrapper.rb b/lib/graphql/schema/wrapper.rb index 2ad16fc139..8fd49e1961 100644 --- a/lib/graphql/schema/wrapper.rb +++ b/lib/graphql/schema/wrapper.rb @@ -25,6 +25,10 @@ def freeze def ==(other) self.class == other.class && of_type == other.of_type end + + def deconstruct_keys(_keys) + { of_type: of_type } + end end end end diff --git a/spec/graphql/schema/list_spec.rb b/spec/graphql/schema/list_spec.rb index 747eeb1795..090da6e65e 100644 --- a/spec/graphql/schema/list_spec.rb +++ b/spec/graphql/schema/list_spec.rb @@ -215,4 +215,33 @@ class Query < GraphQL::Schema::Object assert_equal 3, res["errors"][0]["extensions"]["problems"].count end end + + describe "pattern matching" do + it "matches the of_type" do + assert case list_type + in { of_type: of_type } + true + else + false + end + end + + it "matches nested list" do + nested = GraphQL::Schema::List.new(GraphQL::Schema::List.new(Jazz::Musician)) + inner_type = case nested + in { of_type: { of_type: t } } + t + end + assert_equal Jazz::Musician, inner_type + end + + it "does not match missing keys" do + assert case list_type + in { z: } + false + else + true + end + end + end end diff --git a/spec/graphql/schema/non_null_spec.rb b/spec/graphql/schema/non_null_spec.rb index 5435853d0e..49764daa5b 100644 --- a/spec/graphql/schema/non_null_spec.rb +++ b/spec/graphql/schema/non_null_spec.rb @@ -86,4 +86,33 @@ class Query < GraphQL::Schema::Object assert_equal [nil], res["data"]["__type"]["fields"].map { |f| f["description"] } end end + + describe "pattern matching" do + it "matches the of_type" do + assert case non_null_type + in { of_type: of_type } + true + else + false + end + end + + it "matches nested list" do + nested = GraphQL::Schema::NonNull.new(GraphQL::Schema::NonNull.new(Jazz::Musician)) + inner_type = case nested + in { of_type: { of_type: t } } + t + end + assert_equal Jazz::Musician, inner_type + end + + it "does not match missing keys" do + assert case non_null_type + in { z: } + false + else + true + end + end + end end