Skip to content

Commit 1549663

Browse files
committed
Add parse_type tests
1 parent 70bc3a0 commit 1549663

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed

spec/graphql/schema/member/build_type_spec.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,52 @@
22
require "spec_helper"
33

44
describe GraphQL::Schema::Member::BuildType do
5+
describe ".parse_type" do
6+
it "resolves a string type from a string" do
7+
assert_equal GraphQL::Types::String, GraphQL::Schema::Member::BuildType.parse_type("String", null: true)
8+
end
9+
10+
it "resolves an integer type from a string" do
11+
assert_equal GraphQL::Types::Int, GraphQL::Schema::Member::BuildType.parse_type("Integer", null: true)
12+
end
13+
14+
it "resolves a float type from a string" do
15+
assert_equal GraphQL::Types::Float, GraphQL::Schema::Member::BuildType.parse_type("Float", null: true)
16+
end
17+
18+
it "resolves a boolean type from a string" do
19+
assert_equal GraphQL::Types::Boolean, GraphQL::Schema::Member::BuildType.parse_type("Boolean", null: true)
20+
end
21+
22+
it "resolves an interface type from a string" do
23+
assert_equal Jazz::BaseInterface, GraphQL::Schema::Member::BuildType.parse_type("Jazz::BaseInterface", null: true)
24+
end
25+
26+
it "resolves an object type from a class" do
27+
assert_equal Jazz::BaseObject, GraphQL::Schema::Member::BuildType.parse_type(Jazz::BaseObject, null: true)
28+
end
29+
30+
it "resolves an object type from a string" do
31+
assert_equal Jazz::BaseObject, GraphQL::Schema::Member::BuildType.parse_type("Jazz::BaseObject", null: true)
32+
end
33+
34+
it "resolves a nested object type from a string" do
35+
assert_equal Jazz::Introspection::NestedType, GraphQL::Schema::Member::BuildType.parse_type("Jazz::Introspection::NestedType", null: true)
36+
end
37+
38+
it "resolves a deeply nested object type from a string" do
39+
assert_equal Jazz::Introspection::NestedType::DeeplyNestedType, GraphQL::Schema::Member::BuildType.parse_type("Jazz::Introspection::NestedType::DeeplyNestedType", null: true)
40+
end
41+
42+
it "resolves a list type from an array of classes" do
43+
assert_instance_of GraphQL::Schema::List, GraphQL::Schema::Member::BuildType.parse_type([Jazz::BaseObject], null: true)
44+
end
45+
46+
it "resolves a list type from an array of strings" do
47+
assert_instance_of GraphQL::Schema::List, GraphQL::Schema::Member::BuildType.parse_type(["Jazz::BaseObject"], null: true)
48+
end
49+
end
50+
551
describe ".to_type_name" do
652
it "works with lists and non-nulls" do
753
t = Class.new(GraphQL::Schema::Object) do

spec/support/jazz.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,18 @@ def name
637637
end
638638
end
639639

640+
class NestedType < GraphQL::Introspection::TypeType
641+
def name
642+
object.name.upcase
643+
end
644+
645+
class DeeplyNestedType < GraphQL::Introspection::TypeType
646+
def name
647+
object.name.upcase
648+
end
649+
end
650+
end
651+
640652
class SchemaType < GraphQL::Introspection::SchemaType
641653
graphql_name "__Schema"
642654

0 commit comments

Comments
 (0)