Sha256: eeb93781e6aa385d719d3b5a1f0ba91a8f951e32882fa7c8af3e01acca7b2c2f

Contents?: true

Size: 939 Bytes

Versions: 8

Compression:

Stored size: 939 Bytes

Contents

module GraphQL
  # 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 UnionType < GraphQL::BaseType
    include GraphQL::BaseType::HasPossibleTypes
    accepts_definitions :possible_types, :resolve_type

    def kind
      GraphQL::TypeKinds::UNION
    end

    def include?(child_type_defn)
      possible_types.include?(child_type_defn)
    end

    def possible_types=(new_possible_types)
      @clean_possible_types = nil
      @dirty_possible_types = new_possible_types
    end

    def possible_types
      @clean_possible_types ||= begin
        ensure_defined
        @dirty_possible_types.map { |type| GraphQL::BaseType.resolve_related_type(type) }
      rescue
        @dirty_possible_types
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
graphql-0.18.4 lib/graphql/union_type.rb
graphql-0.18.3 lib/graphql/union_type.rb
graphql-0.18.2 lib/graphql/union_type.rb
graphql-0.18.1 lib/graphql/union_type.rb
graphql-0.18.0 lib/graphql/union_type.rb
graphql-0.17.2 lib/graphql/union_type.rb
graphql-0.17.1 lib/graphql/union_type.rb
graphql-0.17.0 lib/graphql/union_type.rb