Class: GraphQL::Client::Schema::UnionType

Inherits:
Module
  • Object
show all
Includes:
BaseType
Defined in:
lib/graphql/client/schema/union_type.rb

Instance Attribute Summary

Attributes included from BaseType

#schema_module, #type

Instance Method Summary collapse

Methods included from BaseType

#cast, #to_list_type, #to_non_null_type

Constructor Details

#initialize(type) ⇒ UnionType

Returns a new instance of UnionType.



11
12
13
14
15
16
17
# File 'lib/graphql/client/schema/union_type.rb', line 11

def initialize(type)
  unless type.is_a?(GraphQL::UnionType)
    raise "expected type to be a GraphQL::UnionType, but was #{type.class}"
  end

  @type = type
end

Instance Method Details

#define_class(definition, ast_nodes) ⇒ Object



23
24
25
26
27
28
29
# File 'lib/graphql/client/schema/union_type.rb', line 23

def define_class(definition, ast_nodes)
  possible_type_names = definition.client.schema.possible_types(type).map(&:graphql_name)
  possible_types = possible_type_names.map { |concrete_type_name|
    schema_module.get_class(concrete_type_name).define_class(definition, ast_nodes)
  }
  new(possible_types)
end

#new(types) ⇒ Object



19
20
21
# File 'lib/graphql/client/schema/union_type.rb', line 19

def new(types)
  PossibleTypes.new(type, types)
end