@@ -448,9 +448,14 @@ def evaluate_selection(result_name, field_ast_nodes_or_ast_node, owner_object, o
448448 total_args_count = field_defn . arguments ( context ) . size
449449 if total_args_count == 0
450450 resolved_arguments = GraphQL ::Execution ::Interpreter ::Arguments ::EMPTY
451- evaluate_selection_with_args ( resolved_arguments , field_defn , ast_node , field_ast_nodes , owner_type , object , is_eager_field , result_name , selections_result , parent_object , return_type , return_type_non_null )
451+ if field_defn . extras . size == 0
452+ evaluate_selection_with_resolved_keyword_args (
453+ NO_ARGS , resolved_arguments , field_defn , ast_node , field_ast_nodes , owner_type , object , is_eager_field , result_name , selections_result , parent_object , return_type , return_type_non_null
454+ )
455+ else
456+ evaluate_selection_with_args ( resolved_arguments , field_defn , ast_node , field_ast_nodes , owner_type , object , is_eager_field , result_name , selections_result , parent_object , return_type , return_type_non_null )
457+ end
452458 else
453- # TODO remove all arguments(...) usages?
454459 @query . arguments_cache . dataload_for ( ast_node , field_defn , object ) do |resolved_arguments |
455460 evaluate_selection_with_args ( resolved_arguments , field_defn , ast_node , field_ast_nodes , owner_type , object , is_eager_field , result_name , selections_result , parent_object , return_type , return_type_non_null )
456461 end
@@ -464,9 +469,13 @@ def evaluate_selection_with_args(arguments, field_defn, ast_node, field_ast_node
464469 next
465470 end
466471
467- kwarg_arguments = if resolved_arguments . empty? && field_defn . extras . empty?
468- # We can avoid allocating the `{ Symbol => Object }` hash in this case
469- NO_ARGS
472+ kwarg_arguments = if field_defn . extras . empty?
473+ if resolved_arguments . empty?
474+ # We can avoid allocating the `{ Symbol => Object }` hash in this case
475+ NO_ARGS
476+ else
477+ resolved_arguments . keyword_arguments
478+ end
470479 else
471480 # Bundle up the extras, then make a new arguments instance
472481 # that includes the extras, too.
@@ -505,60 +514,65 @@ def evaluate_selection_with_args(arguments, field_defn, ast_node, field_ast_node
505514 resolved_arguments . keyword_arguments
506515 end
507516
508- st = get_current_runtime_state
509- st . current_field = field_defn
510- st . current_object = object
511- st . current_arguments = resolved_arguments
512- st . current_result_name = result_name
513- st . current_result = selection_result
514- # Optimize for the case that field is selected only once
515- if field_ast_nodes . nil? || field_ast_nodes . size == 1
516- next_selections = ast_node . selections
517- directives = ast_node . directives
518- else
519- next_selections = [ ]
520- directives = [ ]
521- field_ast_nodes . each { |f |
522- next_selections . concat ( f . selections )
523- directives . concat ( f . directives )
524- }
525- end
526-
527- field_result = call_method_on_directives ( :resolve , object , directives ) do
528- # Actually call the field resolver and capture the result
529- app_result = begin
530- query . current_trace . execute_field ( field : field_defn , ast_node : ast_node , query : query , object : object , arguments : kwarg_arguments ) do
531- field_defn . resolve ( object , kwarg_arguments , context )
532- end
533- rescue GraphQL ::ExecutionError => err
534- err
535- rescue StandardError => err
536- begin
537- query . handle_or_reraise ( err )
538- rescue GraphQL ::ExecutionError => ex_err
539- ex_err
540- end
517+ evaluate_selection_with_resolved_keyword_args ( kwarg_arguments , resolved_arguments , field_defn , ast_node , field_ast_nodes , owner_type , object , is_eager_field , result_name , selection_result , parent_object , return_type , return_type_non_null )
518+ end
519+ end
520+
521+ def evaluate_selection_with_resolved_keyword_args ( kwarg_arguments , resolved_arguments , field_defn , ast_node , field_ast_nodes , owner_type , object , is_eager_field , result_name , selection_result , parent_object , return_type , return_type_non_null ) # rubocop:disable Metrics/ParameterLists
522+ st = get_current_runtime_state
523+ st . current_field = field_defn
524+ st . current_object = object
525+ st . current_arguments = resolved_arguments
526+ st . current_result_name = result_name
527+ st . current_result = selection_result
528+ # Optimize for the case that field is selected only once
529+ if field_ast_nodes . nil? || field_ast_nodes . size == 1
530+ next_selections = ast_node . selections
531+ directives = ast_node . directives
532+ else
533+ next_selections = [ ]
534+ directives = [ ]
535+ field_ast_nodes . each { |f |
536+ next_selections . concat ( f . selections )
537+ directives . concat ( f . directives )
538+ }
539+ end
540+
541+ field_result = call_method_on_directives ( :resolve , object , directives ) do
542+ # Actually call the field resolver and capture the result
543+ app_result = begin
544+ query . current_trace . execute_field ( field : field_defn , ast_node : ast_node , query : query , object : object , arguments : kwarg_arguments ) do
545+ field_defn . resolve ( object , kwarg_arguments , context )
541546 end
542- after_lazy ( app_result , owner : owner_type , field : field_defn , ast_node : ast_node , owner_object : object , arguments : resolved_arguments , result_name : result_name , result : selection_result ) do |inner_result |
543- continue_value = continue_value ( inner_result , owner_type , field_defn , return_type . non_null? , ast_node , result_name , selection_result )
544- if HALT != continue_value
545- continue_field ( continue_value , owner_type , field_defn , return_type , ast_node , next_selections , false , object , resolved_arguments , result_name , selection_result )
546- end
547+ rescue GraphQL ::ExecutionError => err
548+ err
549+ rescue StandardError => err
550+ begin
551+ query . handle_or_reraise ( err )
552+ rescue GraphQL ::ExecutionError => ex_err
553+ ex_err
547554 end
548555 end
549-
550- # If this field is a root mutation field, immediately resolve
551- # all of its child fields before moving on to the next root mutation field.
552- # (Subselections of this mutation will still be resolved level-by-level.)
553- if is_eager_field
554- Interpreter ::Resolve . resolve_all ( [ field_result ] , @dataloader )
555- else
556- # Return this from `after_lazy` because it might be another lazy that needs to be resolved
557- field_result
556+ after_lazy ( app_result , owner : owner_type , field : field_defn , ast_node : ast_node , owner_object : object , arguments : resolved_arguments , result_name : result_name , result : selection_result ) do |inner_result |
557+ continue_value = continue_value ( inner_result , owner_type , field_defn , return_type_non_null , ast_node , result_name , selection_result )
558+ if HALT != continue_value
559+ continue_field ( continue_value , owner_type , field_defn , return_type , ast_node , next_selections , false , object , resolved_arguments , result_name , selection_result )
560+ end
558561 end
559562 end
563+
564+ # If this field is a root mutation field, immediately resolve
565+ # all of its child fields before moving on to the next root mutation field.
566+ # (Subselections of this mutation will still be resolved level-by-level.)
567+ if is_eager_field
568+ Interpreter ::Resolve . resolve_all ( [ field_result ] , @dataloader )
569+ else
570+ # Return this from `after_lazy` because it might be another lazy that needs to be resolved
571+ field_result
572+ end
560573 end
561574
575+
562576 def dead_result? ( selection_result )
563577 selection_result . graphql_dead # || ((parent = selection_result.graphql_parent) && parent.graphql_dead)
564578 end
0 commit comments