Skip to content

Commit 31b8cbc

Browse files
jimkyndemeyerbbakerman
authored andcommitted
Added source location of where a type was used incorrectly
1 parent e9e8c63 commit 31b8cbc

4 files changed

Lines changed: 10 additions & 8 deletions

File tree

src/main/java/graphql/schema/idl/SchemaGenerator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ private <T extends GraphQLOutputType> T buildOutputType(BuildContext buildCtx, T
307307
outputType = buildScalar(buildCtx, (ScalarTypeDefinition) typeDefinition);
308308
} else {
309309
// typeDefinition is not a valid output type
310-
throw new NotAnOutputTypeError(typeDefinition);
310+
throw new NotAnOutputTypeError(rawType, typeDefinition);
311311
}
312312

313313
buildCtx.put(outputType);
@@ -340,7 +340,7 @@ private GraphQLInputType buildInputType(BuildContext buildCtx, Type rawType) {
340340
inputType = buildScalar(buildCtx, (ScalarTypeDefinition) typeDefinition);
341341
} else {
342342
// typeDefinition is not a valid InputType
343-
throw new NotAnInputTypeError(typeDefinition);
343+
throw new NotAnInputTypeError(rawType, typeDefinition);
344344
}
345345

346346
buildCtx.put(inputType);
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package graphql.schema.idl.errors;
22

3+
import graphql.language.Type;
34
import graphql.language.TypeDefinition;
45

56
import static java.lang.String.format;
67

78
public class NotAnInputTypeError extends BaseError {
89

9-
public NotAnInputTypeError(TypeDefinition typeDefinition) {
10-
super(typeDefinition, format("expected InputType, but found %s type %s", typeDefinition.getName(), lineCol(typeDefinition)));
10+
public NotAnInputTypeError(Type rawType, TypeDefinition typeDefinition) {
11+
super(rawType, format("The type '%s' %s is not an input type, but was used as an input type %s", typeDefinition.getName(), lineCol(typeDefinition), lineCol(rawType)));
1112
}
1213
}
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
package graphql.schema.idl.errors;
22

3+
import graphql.language.Type;
34
import graphql.language.TypeDefinition;
45

56
import static java.lang.String.format;
67

78
public class NotAnOutputTypeError extends BaseError {
89

9-
public NotAnOutputTypeError(TypeDefinition typeDefinition) {
10-
super(typeDefinition, format("expected OutputType, but found %s type %s", typeDefinition.getName(), lineCol(typeDefinition)));
10+
public NotAnOutputTypeError(Type rawType, TypeDefinition typeDefinition) {
11+
super(rawType, format("The type '%s' %s is not an output type, but was used to declare the output type of a field %s", typeDefinition.getName(), lineCol(typeDefinition), lineCol(rawType)));
1112
}
1213
}

src/test/groovy/graphql/schema/idl/SchemaGeneratorTest.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ class SchemaGeneratorTest extends Specification {
634634

635635
then:
636636
def err = thrown(NotAnInputTypeError.class)
637-
err.message == "expected InputType, but found CharacterInput type [@11:13]"
637+
err.message == "The type 'CharacterInput' [@11:13] is not an input type, but was used as an input type [@7:42]"
638638
}
639639

640640
def "InputType used as type should throw appropriate error #425"() {
@@ -659,7 +659,7 @@ class SchemaGeneratorTest extends Specification {
659659

660660
then:
661661
def err = thrown(NotAnOutputTypeError.class)
662-
err.message == "expected OutputType, but found CharacterInput type [@11:13]"
662+
err.message == "The type 'CharacterInput' [@11:13] is not an output type, but was used to declare the output type of a field [@7:32]"
663663
}
664664

665665
def "schema with subscription"() {

0 commit comments

Comments
 (0)