Sha256: e56e2d48b32cd5a4d373f6985ae544d2a5b48ef6516079d68df9b50697c2afb5

Contents?: true

Size: 1.43 KB

Versions: 12

Compression:

Stored size: 1.43 KB

Contents

module GraphQL
  # A Union is is a collection of object types which may appear in the same place.
  #
  # The members of a union are declared with `possible_types`.
  #
  # @example A union of object types
  #   MediaUnion = GraphQL::UnionType.define do
  #     name "Media"
  #     description "Media objects which you can enjoy"
  #     possible_types [AudioType, ImageType, VideoType]
  #   end
  #
  # A union itself has no fields; only its members have fields.
  # So, when you query, you must use fragment spreads to access fields.
  #
  # @example Querying for fields on union members
  #  {
  #    searchMedia(name: "Jens Lekman") {
  #      ... on Audio { name, duration }
  #      ... on Image { name, height, width }
  #      ... on Video { name, length, quality }
  #    }
  #  }
  #
  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

12 entries across 12 versions & 1 rubygems

Version Path
graphql-0.19.0 lib/graphql/union_type.rb
graphql-0.18.15 lib/graphql/union_type.rb
graphql-0.18.14 lib/graphql/union_type.rb
graphql-0.18.13 lib/graphql/union_type.rb
graphql-0.18.12 lib/graphql/union_type.rb
graphql-0.18.11 lib/graphql/union_type.rb
graphql-0.18.10 lib/graphql/union_type.rb
graphql-0.18.9 lib/graphql/union_type.rb
graphql-0.18.8 lib/graphql/union_type.rb
graphql-0.18.7 lib/graphql/union_type.rb
graphql-0.18.6 lib/graphql/union_type.rb
graphql-0.18.5 lib/graphql/union_type.rb