Skip to content

Commit 23012ad

Browse files
authored
Merge pull request #3886 from RafeArnold/handle-null-error-locations
filter out null error location in toSpecification
2 parents 1662f0a + a918e60 commit 23012ad

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/main/java/graphql/GraphqlErrorHelper.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ public static Object locations(List<SourceLocation> locations) {
6565
* @return a value for source location of the error
6666
*/
6767
public static Object location(SourceLocation location) {
68+
if (location == null) {
69+
return null;
70+
}
6871
int line = location.getLine();
6972
int column = location.getColumn();
7073
if (line < 1 || column < 1) {

src/test/groovy/graphql/GraphQLErrorTest.groovy

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,26 @@ class GraphQLErrorTest extends Specification {
9494
error.toSpecification() == expectedMap
9595
}
9696

97+
def "toSpecification filters out null error locations"() {
98+
given:
99+
def error = ValidationError.newValidationError()
100+
.validationErrorType(ValidationErrorType.UnknownType)
101+
.sourceLocations([null, mkLocation(333, 1)])
102+
.description("Test ValidationError")
103+
.build()
104+
105+
def expectedMap = [
106+
locations: [
107+
[line: 333, column: 1]
108+
],
109+
message: "Test ValidationError",
110+
extensions: [classification:"ValidationError"]
111+
]
112+
113+
expect:
114+
error.toSpecification() == expectedMap
115+
}
116+
97117
class CustomException extends RuntimeException implements GraphQLError {
98118
private LinkedHashMap<String, String> map
99119

0 commit comments

Comments
 (0)