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.



76
77
78
# File 'lib/graphql/client/query_result.rb', line 76

def initialize(possible_types)
  @possible_types = possible_types
end

Instance Method Details

#cast(value, errors = nil) ⇒ Object



80
81
82
83
84
85
86
87
# File 'lib/graphql/client/query_result.rb', line 80

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



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

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