Skip to content

Commit 062a6af

Browse files
committed
[Validation] Un-interleave overlapping field messages
Related GraphQL-js commit https://github.com/graphql/graphql-js/tree/228215a704e9d7f67078fc2652eafa6b6e22026f
1 parent 8de6087 commit 062a6af

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

graphql/core/validation/rules/overlapping_fields_can_be_merged.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ def find_conflict(self, response_name, pair1, pair2):
5151
if name1 != name2:
5252
return (
5353
(response_name, '{} and {} are different fields'.format(name1, name2)),
54-
(ast1, ast2)
54+
[ast1],
55+
[ast2]
5556
)
5657

5758
type1 = def1 and def1.type
@@ -60,19 +61,22 @@ def find_conflict(self, response_name, pair1, pair2):
6061
if type1 and type2 and not self.same_type(type1, type2):
6162
return (
6263
(response_name, 'they return differing types {} and {}'.format(type1, type2)),
63-
(ast1, ast2)
64+
[ast1],
65+
[ast2]
6466
)
6567

6668
if not self.same_arguments(ast1.arguments, ast2.arguments):
6769
return (
6870
(response_name, 'they have differing arguments'),
69-
(ast1, ast2)
71+
[ast1],
72+
[ast2]
7073
)
7174

7275
if not self.same_directives(ast1.directives, ast2.directives):
7376
return (
7477
(response_name, 'they have differing directives'),
75-
(ast1, ast2)
78+
[ast1],
79+
[ast2]
7680
)
7781

7882
selection_set1 = ast1.selection_set
@@ -98,7 +102,8 @@ def find_conflict(self, response_name, pair1, pair2):
98102
if conflicts:
99103
return (
100104
(response_name, [conflict[0] for conflict in conflicts]),
101-
tuple(itertools.chain((ast1, ast2), *[conflict[1] for conflict in conflicts]))
105+
tuple(itertools.chain([ast1], *[conflict[1] for conflict in conflicts])),
106+
tuple(itertools.chain([ast2], *[conflict[2] for conflict in conflicts]))
102107
)
103108

104109
def leave_SelectionSet(self, node, key, parent, path, ancestors):
@@ -110,8 +115,8 @@ def leave_SelectionSet(self, node, key, parent, path, ancestors):
110115
conflicts = self.find_conflicts(field_map)
111116
if conflicts:
112117
return [
113-
GraphQLError(self.fields_conflict_message(reason_name, reason), list(fields)) for
114-
(reason_name, reason), fields in conflicts
118+
GraphQLError(self.fields_conflict_message(reason_name, reason), list(fields1)+list(fields2)) for
119+
(reason_name, reason), fields1, fields2 in conflicts
115120
]
116121

117122
@staticmethod

tests/core_validation/test_overlapping_fields_can_be_merged.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def test_deep_conflict():
205205
''', [
206206
fields_conflict(
207207
'field', [('x', 'a and b are different fields')],
208-
L(3, 9), L(6, 9), L(4, 13), L(7, 13))
208+
L(3, 9), L(4, 13), L(6, 9), L(7, 13))
209209
], sort_list=False)
210210

211211

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

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

@@ -271,7 +271,7 @@ def test_reports_deep_conflict_to_nearest_common_ancestor():
271271
''', [
272272
fields_conflict(
273273
'deepField', [('x', 'a and b are different fields')],
274-
L(4, 13), L(7, 13), L(5, 17), L(8, 17)
274+
L(4, 13), L(5, 17), L(7, 13), L(8, 17)
275275
)
276276
], sort_list=False)
277277

@@ -378,9 +378,9 @@ def test_compares_deep_types_including_list():
378378
''', [
379379
fields_conflict(
380380
'edges', [['node', [['id', 'id and name are different fields']]]],
381-
L(14, 9), L(5, 13),
382-
L(15, 13), L(6, 17),
383-
L(16, 17), L(7, 21),
381+
L(14, 9), L(15, 13),
382+
L(16, 17), L(5, 13),
383+
L(6, 17), L(7, 21),
384384
)
385385
], sort_list=False)
386386

0 commit comments

Comments
 (0)