Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/java/graphql/GraphqlErrorHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public static Object locations(List<SourceLocation> locations) {
* @return a value for source location of the error
*/
public static Object location(SourceLocation location) {
if (location == null) {
return null;
}
int line = location.getLine();
int column = location.getColumn();
if (line < 1 || column < 1) {
Expand Down
20 changes: 20 additions & 0 deletions src/test/groovy/graphql/GraphQLErrorTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,26 @@ class GraphQLErrorTest extends Specification {
error.toSpecification() == expectedMap
}

def "toSpecification filters out null error locations"() {
given:
def error = ValidationError.newValidationError()
.validationErrorType(ValidationErrorType.UnknownType)
.sourceLocations([null, mkLocation(333, 1)])
.description("Test ValidationError")
.build()

def expectedMap = [
locations: [
[line: 333, column: 1]
],
message: "Test ValidationError",
extensions: [classification:"ValidationError"]
]

expect:
error.toSpecification() == expectedMap
}

class CustomException extends RuntimeException implements GraphQLError {
private LinkedHashMap<String, String> map

Expand Down
Loading