10
10
FragmentDefinitionNode ,
11
11
FragmentSpreadNode ,
12
12
InlineFragmentNode ,
13
- ObjectFieldNode ,
14
- ObjectValueNode ,
15
13
SelectionSetNode ,
14
+ ValueNode ,
16
15
print_ast ,
17
16
)
18
17
from ...type import (
@@ -558,7 +557,7 @@ def find_conflict(
558
557
)
559
558
560
559
# Two field calls must have the same arguments.
561
- if stringify_arguments (node1 ) != stringify_arguments ( node2 ):
560
+ if not same_arguments (node1 , node2 ):
562
561
return (response_name , "they have differing arguments" ), [node1 ], [node2 ]
563
562
564
563
directives1 = node1 .directives
@@ -598,14 +597,34 @@ def find_conflict(
598
597
return None # no conflict
599
598
600
599
601
- def stringify_arguments (field_node : Union [FieldNode , DirectiveNode ]) -> str :
602
- input_object_with_args = ObjectValueNode (
603
- fields = tuple (
604
- ObjectFieldNode (name = arg_node .name , value = arg_node .value )
605
- for arg_node in field_node .arguments
606
- )
607
- )
608
- return print_ast (sort_value_node (input_object_with_args ))
600
+ def same_arguments (
601
+ node1 : Union [FieldNode , DirectiveNode ], node2 : Union [FieldNode , DirectiveNode ]
602
+ ) -> bool :
603
+ args1 = node1 .arguments
604
+ args2 = node2 .arguments
605
+
606
+ if args1 is None or len (args1 ) == 0 :
607
+ return args2 is None or len (args2 ) == 0
608
+
609
+ if args2 is None or len (args2 ) == 0 :
610
+ return False
611
+
612
+ if len (args1 ) != len (args2 ):
613
+ return False
614
+
615
+ values2 = {arg .name .value : arg .value for arg in args2 }
616
+
617
+ for arg1 in args1 :
618
+ value1 = arg1 .value
619
+ value2 = values2 .get (arg1 .name .value )
620
+ if value2 is None or stringify_value (value1 ) != stringify_value (value2 ):
621
+ return False
622
+
623
+ return True
624
+
625
+
626
+ def stringify_value (value : ValueNode ) -> str :
627
+ return print_ast (sort_value_node (value ))
609
628
610
629
611
630
def get_stream_directive (
@@ -627,7 +646,7 @@ def same_streams(
627
646
return True
628
647
if stream1 and stream2 :
629
648
# check if both fields have equivalent streams
630
- return stringify_arguments (stream1 ) == stringify_arguments ( stream2 )
649
+ return same_arguments (stream1 , stream2 )
631
650
# fields have a mix of stream and no stream
632
651
return False
633
652
0 commit comments