@@ -91,7 +91,7 @@ def add_step(
9191 path . each { entrypoint << "/" << _1 }
9292
9393 step = @steps_by_entrypoint [ entrypoint ]
94- next_index = step ? parent_index : @planning_index += 1
94+ next_index = step ? step . index : @planning_index += 1
9595
9696 unless selections . empty?
9797 selections = extract_locale_selections ( location , parent_type , next_index , selections , path , variables )
@@ -110,6 +110,7 @@ def add_step(
110110 resolver : resolver ,
111111 )
112112 else
113+ step . variables . merge! ( variables )
113114 step . selections . concat ( selections )
114115 step
115116 end
@@ -142,7 +143,8 @@ def build_root_entrypoints
142143 # A.2) Partition mutation fields by consecutive location for serial execution.
143144 partitions = [ ]
144145 each_field_in_scope ( parent_type , @request . operation . selections ) do |node |
145- next_location = @supergraph . locations_by_type_and_field [ parent_type . graphql_name ] [ node . name ] . first
146+ locations = @supergraph . locations_by_type_and_field [ parent_type . graphql_name ] [ node . name ] || SUPERGRAPH_LOCATIONS
147+ next_location = locations . first
146148
147149 if partitions . none? || partitions . last . location != next_location
148150 partitions << ScopePartition . new ( location : next_location , selections : [ ] )
@@ -256,7 +258,8 @@ def extract_locale_selections(
256258 fragment_type = node . type ? @supergraph . memoized_schema_types [ node . type . name ] : parent_type
257259 next unless @supergraph . locations_by_type [ fragment_type . graphql_name ] . include? ( current_location )
258260
259- is_same_scope = fragment_type == parent_type
261+ extract_node_directive_variables ( node , locale_variables )
262+ is_same_scope = fragment_type == parent_type && node . directives . empty?
260263 selection_set = is_same_scope ? locale_selections : [ ]
261264 extract_locale_selections ( current_location , fragment_type , parent_index , node . selections , path , locale_variables , selection_set )
262265
@@ -269,14 +272,17 @@ def extract_locale_selections(
269272 fragment = @request . fragment_definitions [ node . name ]
270273 next unless @supergraph . locations_by_type [ fragment . type . name ] . include? ( current_location )
271274
275+ extract_node_directive_variables ( node , locale_variables )
276+ extract_node_directive_variables ( fragment , locale_variables )
272277 requires_typename = true
273278 fragment_type = @supergraph . memoized_schema_types [ fragment . type . name ]
274- is_same_scope = fragment_type == parent_type
279+ directives = [ *fragment . directives , *node . directives ]
280+ is_same_scope = fragment_type == parent_type && directives . empty?
275281 selection_set = is_same_scope ? locale_selections : [ ]
276282 extract_locale_selections ( current_location , fragment_type , parent_index , fragment . selections , path , locale_variables , selection_set )
277283
278284 unless is_same_scope
279- locale_selections << GraphQL ::Language ::Nodes ::InlineFragment . new ( type : fragment . type , selections : selection_set )
285+ locale_selections << GraphQL ::Language ::Nodes ::InlineFragment . new ( type : fragment . type , directives : directives , selections : selection_set )
280286 end
281287
282288 else
@@ -362,13 +368,30 @@ def extract_node_variables(node_with_args, variable_definitions)
362368 extract_node_variables ( argument . value , variable_definitions )
363369 when GraphQL ::Language ::Nodes ::VariableIdentifier
364370 variable_definitions [ argument . value . name ] ||= @request . variable_definitions [ argument . value . name ]
371+ when Array
372+ extract_value_variables ( argument . value , variable_definitions )
365373 end
366374 end
367375
368376 if node_with_args . respond_to? ( :directives )
369- node_with_args . directives . each do |directive |
370- extract_node_variables ( directive , variable_definitions )
371- end
377+ extract_node_directive_variables ( node_with_args , variable_definitions )
378+ end
379+ end
380+
381+ def extract_value_variables ( value , variable_definitions )
382+ case value
383+ when GraphQL ::Language ::Nodes ::InputObject
384+ extract_node_variables ( value , variable_definitions )
385+ when GraphQL ::Language ::Nodes ::VariableIdentifier
386+ variable_definitions [ value . name ] ||= @request . variable_definitions [ value . name ]
387+ when Array
388+ value . each { extract_value_variables ( _1 , variable_definitions ) }
389+ end
390+ end
391+
392+ def extract_node_directive_variables ( node_with_directives , variable_definitions )
393+ node_with_directives . directives . each do |directive |
394+ extract_node_variables ( directive , variable_definitions )
372395 end
373396 end
374397
0 commit comments