Method: GraphQL::Schema::Argument#prepare_value
- Defined in:
- lib/graphql/schema/argument.rb
#prepare_value(obj, value, context: nil) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Apply the #prepare configuration to value, using methods from obj.
Used by the runtime.
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
# File 'lib/graphql/schema/argument.rb', line 230 def prepare_value(obj, value, context: nil) if type.unwrap.kind.input_object? value = recursively_prepare_input_object(value, type, context) end Schema::Validator.validate!(validators, obj, context, value) if @prepare.nil? value elsif @prepare.is_a?(String) || @prepare.is_a?(Symbol) if obj.nil? # The problem here is, we _used to_ prepare while building variables. # But now we don't have the runtime object there. # # This will have to be called later, when the runtime object _is_ available. value elsif obj.respond_to?(@prepare) obj.public_send(@prepare, value) elsif owner.respond_to?(@prepare) owner.public_send(@prepare, value, context || obj.context) else raise "Invalid prepare for #{@owner.name}.name: #{@prepare.inspect}. "\ "Could not find prepare method #{@prepare} on #{obj.class} or #{owner}." end elsif @prepare.respond_to?(:call) @prepare.call(value, context || obj.context) else raise "Invalid prepare for #{@owner.name}.name: #{@prepare.inspect}" end end |