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.



168
169
170
# File 'lib/graphql/client/query_result.rb', line 168

def initialize(type)
  @type = type
end

Instance Method Details

#cast(value, _errors = nil) ⇒ Object



172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/graphql/client/query_result.rb', line 172

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



190
191
192
193
# File 'lib/graphql/client/query_result.rb', line 190

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