Class: GraphQL::Client::QueryResult::UnionWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/graphql/client/query_result.rb

Instance Method Summary collapse

Constructor Details

#initialize(possible_types) ⇒ UnionWrapper

Returns a new instance of UnionWrapper.



81
82
83
# File 'lib/graphql/client/query_result.rb', line 81

def initialize(possible_types)
  @possible_types = possible_types
end

Instance Method Details

#cast(value, errors = nil) ⇒ Object



85
86
87
88
89
90
91
92
# File 'lib/graphql/client/query_result.rb', line 85

def cast(value, errors = nil)
  typename = value && value["__typename"]
  if wrapper = @possible_types[typename]
    wrapper.cast(value, errors)
  else
    raise TypeError, "expected union value to be #{@possible_types.keys.join(", ")}, but was #{typename}"
  end
end

#|(_other) ⇒ Object



94
95
96
97
# File 'lib/graphql/client/query_result.rb', line 94

def |(_other)
  # XXX: How would union merge?
  self
end