Class: GraphQL::Client::QueryResult::UnionWrapper
- Inherits:
-
Object
- Object
- GraphQL::Client::QueryResult::UnionWrapper
- Defined in:
- lib/graphql/client/query_result.rb
Instance Method Summary collapse
- #cast(value, errors = nil) ⇒ Object
-
#initialize(possible_types) ⇒ UnionWrapper
constructor
A new instance of UnionWrapper.
- #|(_other) ⇒ Object
Constructor Details
#initialize(possible_types) ⇒ UnionWrapper
Returns a new instance of UnionWrapper.
80 81 82 |
# File 'lib/graphql/client/query_result.rb', line 80 def initialize(possible_types) @possible_types = possible_types end |
Instance Method Details
#cast(value, errors = nil) ⇒ Object
84 85 86 87 88 89 90 91 |
# File 'lib/graphql/client/query_result.rb', line 84 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
93 94 95 96 |
# File 'lib/graphql/client/query_result.rb', line 93 def |(_other) # XXX: How would union merge? self end |