Sha256: ecdbbcb59f1bf426d6fa03dc570156dad9b160cb6a9036184994f3c8f8a7086f

Contents?: true

Size: 1.15 KB

Versions: 1

Compression:

Stored size: 1.15 KB

Contents

# A collection of {ObjectType}s
#
# @example a union of types
#
#   PetUnion = GraphQL::UnionType.define do
#     name "Pet"
#     description "Animals that live in your house"
#     possible_types [DogType, CatType, FishType]
#   end
#
class GraphQL::UnionType
  include GraphQL::DefinitionHelpers::NonNullWithBang
  include GraphQL::DefinitionHelpers::DefinedByConfig
  attr_accessor :name, :description, :possible_types

  class DefinitionConfig
    extend GraphQL::DefinitionHelpers::Definable
    attr_definable :name, :description, :possible_types

    def to_instance
      object = GraphQL::UnionType.new
      object.name = name
      object.description = description
      object.possible_types = possible_types
      object
    end
  end

  def initialize(name = nil, desc = nil, types = nil)
    @name = name
    @description = desc
    @possible_types = types
    name && warn("Initializing with .new is deprecated, use .define instead! (see #{self})")
  end

  def kind
    GraphQL::TypeKinds::UNION
  end

  # @see {InterfaceType#resolve_type}
  def resolve_type(object)
    type_name = object.class.name
    possible_types.find {|t| t.name == type_name}
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
graphql-0.5.0 lib/graph_ql/union_type.rb