Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/graphql/schema/wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
29 changes: 29 additions & 0 deletions spec/graphql/schema/list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
29 changes: 29 additions & 0 deletions spec/graphql/schema/non_null_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading