Skip to content

Commit 3caa3e0

Browse files
committed
Improve validation error message when field names conflict
Related GraphQL-js commit: graphql/graphql-js@6103d2d
1 parent 547949b commit 3caa3e0

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

graphql/validation/rules/overlapping_fields_can_be_merged.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,11 @@ def collect_field_asts_and_defs(self, parent_type, selection_set, visited_fragme
257257

258258
@classmethod
259259
def fields_conflict_message(cls, reason_name, reason):
260-
return 'Fields "{}" conflict because {}'.format(reason_name, cls.reason_message(reason))
260+
return (
261+
'Fields "{}" conflict because {}. '
262+
'Use different aliases on the fields to fetch both if this was '
263+
'intentional.'
264+
).format(reason_name, cls.reason_message(reason))
261265

262266
@classmethod
263267
def reason_message(cls, reason):

graphql/validation/tests/test_overlapping_fields_can_be_merged.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,3 +635,13 @@ def test_ignores_unknown_types():
635635
}
636636
}
637637
''')
638+
639+
640+
def test_error_message_contains_hint_for_alias_conflict():
641+
error = OverlappingFieldsCanBeMerged.fields_conflict_message('x', 'a and b are different fields')
642+
hint = (
643+
'Fields "x" conflict because a and b are different fields. '
644+
'Use different aliases on the fields to fetch both '
645+
'if this was intentional.'
646+
)
647+
assert error == hint

0 commit comments

Comments
 (0)