lib/graph_ql/union.rb in graphql-0.1.0 vs lib/graph_ql/union.rb in graphql-0.2.0
- old
+ new
@@ -1,35 +1,24 @@
class GraphQL::Union
include GraphQL::NonNullWithBang
- attr_reader :name, :possible_types
- def initialize(name, types)
- if types.length < 2
- raise ArgumentError, "Union #{name} must be defined with 2 or more types, not #{types.length}"
- end
-
- non_object_types = types.select {|t| t.kind != GraphQL::TypeKinds::OBJECT}
- if non_object_types.any?
- types_string = non_object_types.map{|t| "#{t.name} #{t.kind}"}.join(", ")
- raise ArgumentError, "Unions can only consist of Object types, but #{name} has non-object types: #{types_string}"
- end
-
+ attr_reader :name, :description, :possible_types
+ def initialize(name, desc, types)
@name = name
+ @description = desc
@possible_types = types
end
- def kind; GraphQL::TypeKinds::UNION; end
-
- def include?(type)
- possible_types.include?(type)
+ def kind
+ GraphQL::TypeKinds::UNION
end
# Find a type in this union for a given object.
# Reimplement if needed
def resolve_type(object)
type_name = object.class.name
possible_types.find {|t| t.name == type_name}
end
def to_s
- "<GraphQL::Union #{name} [#{possible_types.map(&:name).join(", ")}]>"
+ "<GraphQL::Union #{name}>"
end
end