Class: GraphQL::Client::QueryResult::ScalarWrapper

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

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ ScalarWrapper

Returns a new instance of ScalarWrapper.



114
115
116
# File 'lib/graphql/client/query_result.rb', line 114

def initialize(type)
  @type = type
end

Instance Method Details

#cast(value, _errors = nil) ⇒ Object



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/graphql/client/query_result.rb', line 118

def cast(value, _errors = nil)
  if value.is_a? Array
    value.map { |item|
      if @type.respond_to?(:coerce_isolated_input)
        @type.coerce_isolated_input(item)
      else
        @type.coerce_input(item)
      end
    }
  else
    if @type.respond_to?(:coerce_isolated_input)
      @type.coerce_isolated_input(value)
    else
      @type.coerce_input(value)
    end
  end
end

#|(_other) ⇒ Object



136
137
138
139
# File 'lib/graphql/client/query_result.rb', line 136

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