Skip to content

Commit 1171c95

Browse files
jimkyndemeyerbbakerman
authored andcommitted
Use type names in PossibleFragmentSpreads message format to make it more readable (was toString() on types which includes typeResolver etc.)
1 parent 31b8cbc commit 1171c95

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

src/main/java/graphql/validation/rules/PossibleFragmentSpreads.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void checkInlineFragment(InlineFragment inlineFragment) {
3434
if (fragType == null || parentType == null) return;
3535
if (!doTypesOverlap(fragType, parentType)) {
3636
String message = String.format("Fragment cannot be spread here as objects of " +
37-
"type %s can never be of type %s", parentType, fragType);
37+
"type %s can never be of type %s", parentType.getName(), fragType.getName());
3838
addError(ValidationErrorType.InvalidFragmentType, inlineFragment.getSourceLocation(), message);
3939

4040
}
@@ -50,7 +50,7 @@ public void checkFragmentSpread(FragmentSpread fragmentSpread) {
5050

5151
if (!doTypesOverlap(typeCondition, parentType)) {
5252
String message = String.format("Fragment %s cannot be spread here as objects of " +
53-
"type %s can never be of type %s", fragmentSpread.getName(), parentType, typeCondition);
53+
"type %s can never be of type %s", fragmentSpread.getName(), parentType.getName(), typeCondition.getName());
5454
addError(ValidationErrorType.InvalidFragmentType, fragmentSpread.getSourceLocation(), message);
5555
}
5656
}

src/test/groovy/graphql/validation/rules/PossibleFragmentSpreadsTest.groovy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ class PossibleFragmentSpreadsTest extends Specification {
179179

180180
then:
181181
errorCollector.getErrors().size() == 1
182+
errorCollector.getErrors().get(0).message == 'Validation error of type InvalidFragmentType: Fragment cannot be spread here as objects of type Cat can never be of type Dog @ \'invalidObjectWithinObjectAnon\''
182183
}
183184

184185
def 'object into not implementing interface'() {
@@ -191,6 +192,7 @@ class PossibleFragmentSpreadsTest extends Specification {
191192

192193
then:
193194
errorCollector.getErrors().size() == 1
195+
errorCollector.getErrors().get(0).message == 'Validation error of type InvalidFragmentType: Fragment humanFragment cannot be spread here as objects of type Pet can never be of type Human @ \'invalidObjectWithinInterface\''
194196
}
195197

196198
def 'object into not containing union'() {

0 commit comments

Comments
 (0)