Method: GraphQL::Schema::Member::HasArguments#coerce_arguments
- Defined in:
- lib/graphql/schema/member/has_arguments.rb
#coerce_arguments(parent_object, values, context) {|Interpreter::Arguments, Execution::Lazy<Interpreter::Arguments>| ... } ⇒ Interpreter::Arguments, Execution::Lazy<Interpreter::Arguments>
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.
If given a block, it will eventually yield the loaded args to the block.
If no block is given, it will immediately dataload (but might return a Lazy).
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
# File 'lib/graphql/schema/member/has_arguments.rb', line 259 def coerce_arguments(parent_object, values, context, &block) # Cache this hash to avoid re-merging it arg_defns = context.types.arguments(self) total_args_count = arg_defns.size finished_args = nil prepare_finished_args = -> { if total_args_count == 0 finished_args = GraphQL::Execution::Interpreter::Arguments::EMPTY if block_given? block.call(finished_args) end else argument_values = {} resolved_args_count = 0 raised_error = false arg_defns.each do |arg_defn| context.dataloader.append_job do begin arg_defn.coerce_into_values(parent_object, values, context, argument_values) rescue GraphQL::ExecutionError, GraphQL::UnauthorizedError => err raised_error = true finished_args = err if block_given? block.call(finished_args) end end resolved_args_count += 1 if resolved_args_count == total_args_count && !raised_error finished_args = context.schema.after_any_lazies(argument_values.values) { GraphQL::Execution::Interpreter::Arguments.new( argument_values: argument_values, ) } if block_given? block.call(finished_args) end end end end end } if block_given? prepare_finished_args.call nil else # This API returns eagerly, gotta run it now context.dataloader.run_isolated(&prepare_finished_args) finished_args end end |