@@ -215,9 +215,20 @@ def find_conflicts_within(response_keys)
215215 end
216216
217217 if all_same
218- # All fields are identical in signature — just compare first two
219- if f0 . node . selections . size > 0 || fields [ 1 ] . node . selections . size > 0
220- find_conflict ( key , f0 , fields [ 1 ] )
218+ # All fields share a signature, so they can only conflict on
219+ # sub-selections. Deduplicate by AST node identity — fields from
220+ # the same node always have identical sub-selections.
221+ unique_nodes = fields . uniq { |f | f . node . object_id }
222+ i = 0
223+ while i < unique_nodes . size
224+ j = i + 1
225+ while j < unique_nodes . size
226+ if unique_nodes [ i ] . node . selections . size > 0 || unique_nodes [ j ] . node . selections . size > 0
227+ find_conflict ( key , unique_nodes [ i ] , unique_nodes [ j ] )
228+ end
229+ j += 1
230+ end
231+ i += 1
221232 end
222233 else
223234 groups = fields . group_by { |f | field_signature ( f ) }
@@ -232,11 +243,22 @@ def find_conflicts_within(response_keys)
232243 gj += 1
233244 end
234245
235- # Within same group, only check first pair for sub-selection conflicts
246+ # Within same group, deduplicate by AST node and compare all
247+ # pairs for sub-selection conflicts
236248 group = unique_groups [ gi ]
237-
238- if group . size >= 2 && ( group [ 0 ] . node . selections . size > 0 || group [ 1 ] . node . selections . size > 0 )
239- find_conflict ( key , group [ 0 ] , group [ 1 ] )
249+ if group . size >= 2
250+ unique_in_group = group . uniq { |f | f . node . object_id }
251+ ui = 0
252+ while ui < unique_in_group . size
253+ uj = ui + 1
254+ while uj < unique_in_group . size
255+ if unique_in_group [ ui ] . node . selections . size > 0 || unique_in_group [ uj ] . node . selections . size > 0
256+ find_conflict ( key , unique_in_group [ ui ] , unique_in_group [ uj ] )
257+ end
258+ uj += 1
259+ end
260+ ui += 1
261+ end
240262 end
241263
242264 gi += 1
0 commit comments