Sha256: c07fe46317fd348fd74ff5cbbf7e63be5a0181d1402312d97e70a683da83730b
Contents?: true
Size: 1.92 KB
Versions: 7
Compression:
Stored size: 1.92 KB
Contents
require "spec_helper" describe GraphQL::UnionType do let(:type_1) { OpenStruct.new(kind: GraphQL::TypeKinds::OBJECT)} let(:type_2) { OpenStruct.new(kind: GraphQL::TypeKinds::OBJECT)} let(:type_3) { OpenStruct.new(kind: GraphQL::TypeKinds::SCALAR)} let(:union) { types = [type_1, type_2] GraphQL::UnionType.define { name("MyUnion") description("Some items") possible_types(types) } } it "has a name" do assert_equal("MyUnion", union.name) end it "infers type from an object" do assert_equal(CheeseType, DairyProductUnion.resolve_type(CHEESES[1], OpenStruct.new(schema: DummySchema))) end it '#include? returns true if type in in possible_types' do assert union.include?(type_1) end it '#include? returns false if type is not in possible_types' do assert_equal(false, union.include?(type_3)) end describe "list of union type" do describe "fragment spreads" do let(:result) { DummySchema.execute(query_string) } let(:query_string) {%| { allDairy { __typename ... milkFields ... cheeseFields } } fragment milkFields on Milk { id source origin flavors } fragment cheeseFields on Cheese { id source origin flavor } |} it "resolves the right fragment on the right item" do all_dairy = result["data"]["allDairy"] cheeses = all_dairy.first(3) cheeses.each do |cheese| assert_equal "Cheese", cheese["__typename"] assert_equal ["__typename", "id", "source", "origin", "flavor"], cheese.keys end milks = all_dairy.last(1) milks.each do |milk| assert_equal "Milk", milk["__typename"] assert_equal ["__typename", "id", "source", "origin", "flavors"], milk.keys end end end end end
Version data entries
7 entries across 7 versions & 1 rubygems