@@ -89,21 +89,26 @@ def build_document(origin_sets_by_operation, operation_name = nil, operation_dir
8989 doc = String . new ( QUERY_OP ) # << resolver fulfillment always uses query
9090
9191 if operation_name
92- doc << " #{ operation_name } "
92+ doc << " " << operation_name
9393 origin_sets_by_operation . each_key do |op |
94- doc << "_#{ op . step } "
94+ doc << "_" << op . step . to_s
9595 end
9696 end
9797
9898 if variable_defs . any?
99- doc << "(#{ variable_defs . map { |k , v | "$#{ k } :#{ v } " } . join ( "," ) } )"
99+ doc << "("
100+ variable_defs . each_with_index do |( k , v ) , i |
101+ doc << "," unless i . zero?
102+ doc << "$" << k << ":" << v
103+ end
104+ doc << ")"
100105 end
101106
102107 if operation_directives
103- doc << " #{ operation_directives } "
108+ doc << " " << operation_directives << " "
104109 end
105110
106- doc << "{ #{ query_fields . join ( " " ) } }"
111+ doc << "{ " << query_fields . join ( " " ) << " }"
107112
108113 return doc , variable_defs . keys . tap do |names |
109114 names . reject! { @variables . key? ( _1 ) }
@@ -132,7 +137,7 @@ def merge_results!(origin_sets_by_operation, raw_result)
132137 def extract_errors! ( origin_sets_by_operation , errors )
133138 ops = origin_sets_by_operation . keys
134139 origin_sets = origin_sets_by_operation . values
135- pathed_errors_by_op_index_and_object_id = { }
140+ pathed_errors_by_op_index_and_object_id = Hash . new { | h , k | h [ k ] = { } }
136141
137142 errors_result = errors . each_with_object ( [ ] ) do |err , memo |
138143 err . delete ( "locations" )
@@ -151,8 +156,8 @@ def extract_errors!(origin_sets_by_operation, errors)
151156 end
152157
153158 if origin_obj
154- by_op_index = pathed_errors_by_op_index_and_object_id [ result_alias [ 1 ] . to_i ] ||= { }
155- by_object_id = by_op_index [ origin_obj . object_id ] ||= [ ]
159+ pathed_errors_by_op_index = pathed_errors_by_op_index_and_object_id [ result_alias [ 1 ] . to_i ]
160+ by_object_id = pathed_errors_by_op_index [ origin_obj . object_id ] ||= [ ]
156161 by_object_id << err
157162 next
158163 end
@@ -162,9 +167,9 @@ def extract_errors!(origin_sets_by_operation, errors)
162167 memo << err
163168 end
164169
165- if pathed_errors_by_op_index_and_object_id . any ?
170+ unless pathed_errors_by_op_index_and_object_id . empty ?
166171 pathed_errors_by_op_index_and_object_id . each do |op_index , pathed_errors_by_object_id |
167- repath_errors! ( pathed_errors_by_object_id , ops . dig ( op_index , " path" ) )
172+ repath_errors! ( pathed_errors_by_object_id , ops [ op_index ] . path )
168173 errors_result . push ( *pathed_errors_by_object_id . each_value )
169174 end
170175 end
@@ -180,7 +185,7 @@ def repath_errors!(pathed_errors_by_object_id, forward_path, current_path=[], ro
180185 current_path . push ( forward_path . shift )
181186 scope = root [ current_path . last ]
182187
183- if forward_path . any ? && scope . is_a? ( Array )
188+ if ! forward_path . empty ? && scope . is_a? ( Array )
184189 scope . each_with_index do |element , index |
185190 inner_elements = element . is_a? ( Array ) ? element . flatten : [ element ]
186191 inner_elements . each do |inner_element |
@@ -190,7 +195,7 @@ def repath_errors!(pathed_errors_by_object_id, forward_path, current_path=[], ro
190195 end
191196 end
192197
193- elsif forward_path . any ?
198+ elsif ! forward_path . empty ?
194199 repath_errors! ( pathed_errors_by_object_id , forward_path , current_path , scope )
195200
196201 elsif scope . is_a? ( Array )
0 commit comments