|
3 | 3 |
|
4 | 4 | from ...error import GraphQLError |
5 | 5 | from ...language import ( |
| 6 | + DirectiveNode, |
6 | 7 | FieldNode, |
7 | 8 | FragmentDefinitionNode, |
8 | 9 | FragmentSpreadNode, |
9 | 10 | InlineFragmentNode, |
10 | | - ObjectFieldNode, |
11 | | - ObjectValueNode, |
12 | 11 | SelectionSetNode, |
| 12 | + ValueNode, |
13 | 13 | print_ast, |
14 | 14 | ) |
15 | 15 | from ...type import ( |
@@ -551,7 +551,7 @@ def find_conflict( |
551 | 551 | ) |
552 | 552 |
|
553 | 553 | # Two field calls must have the same arguments. |
554 | | - if stringify_arguments(node1) != stringify_arguments(node2): |
| 554 | + if not same_arguments(node1, node2): |
555 | 555 | return (response_name, "they have differing arguments"), [node1], [node2] |
556 | 556 |
|
557 | 557 | if type1 and type2 and do_types_conflict(type1, type2): |
@@ -582,14 +582,34 @@ def find_conflict( |
582 | 582 | return None # no conflict |
583 | 583 |
|
584 | 584 |
|
585 | | -def stringify_arguments(field_node: FieldNode) -> str: |
586 | | - input_object_with_args = ObjectValueNode( |
587 | | - fields=tuple( |
588 | | - ObjectFieldNode(name=arg_node.name, value=arg_node.value) |
589 | | - for arg_node in field_node.arguments |
590 | | - ) |
591 | | - ) |
592 | | - return print_ast(sort_value_node(input_object_with_args)) |
| 585 | +def same_arguments( |
| 586 | + node1: Union[FieldNode, DirectiveNode], node2: Union[FieldNode, DirectiveNode] |
| 587 | +) -> bool: |
| 588 | + args1 = node1.arguments |
| 589 | + args2 = node2.arguments |
| 590 | + |
| 591 | + if not args1: |
| 592 | + return not args2 |
| 593 | + |
| 594 | + if not args2: |
| 595 | + return False |
| 596 | + |
| 597 | + if len(args1) != len(args2): |
| 598 | + return False # pragma: no cover |
| 599 | + |
| 600 | + values2 = {arg.name.value: arg.value for arg in args2} |
| 601 | + |
| 602 | + for arg1 in args1: |
| 603 | + value1 = arg1.value |
| 604 | + value2 = values2.get(arg1.name.value) |
| 605 | + if value2 is None or stringify_value(value1) != stringify_value(value2): |
| 606 | + return False |
| 607 | + |
| 608 | + return True |
| 609 | + |
| 610 | + |
| 611 | +def stringify_value(value: ValueNode) -> str: |
| 612 | + return print_ast(sort_value_node(value)) |
593 | 613 |
|
594 | 614 |
|
595 | 615 | def do_types_conflict(type1: GraphQLOutputType, type2: GraphQLOutputType) -> bool: |
|
0 commit comments