Skip to content

Commit 2334451

Browse files
committed
verlappingFieldsCanBeMergedRule: simplify argument comparison
Replicates graphql/graphql-js@5caff03
1 parent 6765215 commit 2334451

File tree

1 file changed

+12
-22
lines changed

1 file changed

+12
-22
lines changed

src/graphql/validation/rules/overlapping_fields_can_be_merged.py

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
from itertools import chain
2-
from typing import Any, Collection, Dict, List, Optional, Tuple, Union, cast
2+
from typing import Any, Dict, List, Optional, Tuple, Union, cast
33

44
from ...error import GraphQLError
55
from ...language import (
6-
ArgumentNode,
76
FieldNode,
87
FragmentDefinitionNode,
98
FragmentSpreadNode,
109
InlineFragmentNode,
10+
ObjectFieldNode,
11+
ObjectValueNode,
1112
SelectionSetNode,
12-
ValueNode,
1313
print_ast,
1414
)
1515
from ...type import (
@@ -551,7 +551,7 @@ def find_conflict(
551551
)
552552

553553
# Two field calls must have the same arguments.
554-
if not same_arguments(node1.arguments or [], node2.arguments or []):
554+
if stringify_arguments(node1) != stringify_arguments(node2):
555555
return (response_name, "they have differing arguments"), [node1], [node2]
556556

557557
if type1 and type2 and do_types_conflict(type1, type2):
@@ -582,24 +582,14 @@ def find_conflict(
582582
return None # no conflict
583583

584584

585-
def same_arguments(
586-
arguments1: Collection[ArgumentNode], arguments2: Collection[ArgumentNode]
587-
) -> bool:
588-
if len(arguments1) != len(arguments2):
589-
return False
590-
for argument1 in arguments1:
591-
for argument2 in arguments2:
592-
if argument2.name.value == argument1.name.value:
593-
if stringify_value(argument1.value) != stringify_value(argument2.value):
594-
return False
595-
break
596-
else:
597-
return False
598-
return True
599-
600-
601-
def stringify_value(value: ValueNode) -> str:
602-
return print_ast(sort_value_node(value))
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))
603593

604594

605595
def do_types_conflict(type1: GraphQLOutputType, type2: GraphQLOutputType) -> bool:

0 commit comments

Comments
 (0)