Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[Validation] Un-interleave overlapping field messages
  • Loading branch information
syrusakbary committed Apr 9, 2016
commit 062a6af33ad91da03641d4b34a740446c691b7fd
19 changes: 12 additions & 7 deletions graphql/core/validation/rules/overlapping_fields_can_be_merged.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def find_conflict(self, response_name, pair1, pair2):
if name1 != name2:
return (
(response_name, '{} and {} are different fields'.format(name1, name2)),
(ast1, ast2)
[ast1],
[ast2]
)

type1 = def1 and def1.type
Expand All @@ -60,19 +61,22 @@ def find_conflict(self, response_name, pair1, pair2):
if type1 and type2 and not self.same_type(type1, type2):
return (
(response_name, 'they return differing types {} and {}'.format(type1, type2)),
(ast1, ast2)
[ast1],
[ast2]
)

if not self.same_arguments(ast1.arguments, ast2.arguments):
return (
(response_name, 'they have differing arguments'),
(ast1, ast2)
[ast1],
[ast2]
)

if not self.same_directives(ast1.directives, ast2.directives):
return (
(response_name, 'they have differing directives'),
(ast1, ast2)
[ast1],
[ast2]
)

selection_set1 = ast1.selection_set
Expand All @@ -98,7 +102,8 @@ def find_conflict(self, response_name, pair1, pair2):
if conflicts:
return (
(response_name, [conflict[0] for conflict in conflicts]),
tuple(itertools.chain((ast1, ast2), *[conflict[1] for conflict in conflicts]))
tuple(itertools.chain([ast1], *[conflict[1] for conflict in conflicts])),
tuple(itertools.chain([ast2], *[conflict[2] for conflict in conflicts]))
)

def leave_SelectionSet(self, node, key, parent, path, ancestors):
Expand All @@ -110,8 +115,8 @@ def leave_SelectionSet(self, node, key, parent, path, ancestors):
conflicts = self.find_conflicts(field_map)
if conflicts:
return [
GraphQLError(self.fields_conflict_message(reason_name, reason), list(fields)) for
(reason_name, reason), fields in conflicts
GraphQLError(self.fields_conflict_message(reason_name, reason), list(fields1)+list(fields2)) for
(reason_name, reason), fields1, fields2 in conflicts
]

@staticmethod
Expand Down
14 changes: 7 additions & 7 deletions tests/core_validation/test_overlapping_fields_can_be_merged.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def test_deep_conflict():
''', [
fields_conflict(
'field', [('x', 'a and b are different fields')],
L(3, 9), L(6, 9), L(4, 13), L(7, 13))
L(3, 9), L(4, 13), L(6, 9), L(7, 13))
], sort_list=False)


Expand All @@ -224,7 +224,7 @@ def test_deep_conflict_with_multiple_issues():
''', [
fields_conflict(
'field', [('x', 'a and b are different fields'), ('y', 'c and d are different fields')],
L(3, 9), L(7, 9), L(4, 13), L(8, 13), L(5, 13), L(9, 13)
L(3, 9), L(4, 13), L(5, 13), L(7, 9), L(8, 13), L(9, 13)
)
], sort_list=False)

Expand All @@ -246,7 +246,7 @@ def test_very_deep_conflict():
''', [
fields_conflict(
'field', [['deepField', [['x', 'a and b are different fields']]]],
L(3, 9), L(8, 9), L(4, 13), L(9, 13), L(5, 17), L(10, 17)
L(3, 9), L(4, 13), L(5, 17), L(8, 9), L(9, 13), L(10, 17)
)
], sort_list=False)

Expand All @@ -271,7 +271,7 @@ def test_reports_deep_conflict_to_nearest_common_ancestor():
''', [
fields_conflict(
'deepField', [('x', 'a and b are different fields')],
L(4, 13), L(7, 13), L(5, 17), L(8, 17)
L(4, 13), L(5, 17), L(7, 13), L(8, 17)
)
], sort_list=False)

Expand Down Expand Up @@ -378,9 +378,9 @@ def test_compares_deep_types_including_list():
''', [
fields_conflict(
'edges', [['node', [['id', 'id and name are different fields']]]],
L(14, 9), L(5, 13),
L(15, 13), L(6, 17),
L(16, 17), L(7, 21),
L(14, 9), L(15, 13),
L(16, 17), L(5, 13),
L(6, 17), L(7, 21),
)
], sort_list=False)

Expand Down