-
Notifications
You must be signed in to change notification settings - Fork 111
Description
Upstream graphql-java NonNullableFieldWasNullError.java returns null for locations & extensions.
According to GraphQL spec, locations must be non null if rendered:
If an error can be associated to a particular point in the requested GraphQL document, it should contain an entry with the key locations with a list of locations, where each location is a map with the keys line and column, both positive numbers starting from 1 which describe the beginning of an associated syntax element.
The simplest fix for this would be to apply @JsonInclude.NON_NULL to the getLocations() getter on the NonNullableFieldWasNullError upstream but that project has no dependency upon Jackson.
In lieu of doing that a decorator for NonNullableFieldWasNullError which can be swapped in by the DefaultGraphQLErrorHandler would solve the isue.
I had opened the issue in the upstream project but closed as it is a rendering issue. See graphql-java/graphql-java#940
Suggested decorator:
public class RenderableNonNullableFieldWasNullError implements GraphQLError {
private final NonNullableFieldWasNullError delegate;
public RenderableNonNullableFieldWasNullError(NonNullableFieldWasNullError nonNullableFieldWasNullError) {
this.delegate = nonNullableFieldWasNullError;
}
@Override
public String getMessage() {
return delegate.getMessage();
}
@Override
@JsonInclude(JsonInclude.Include.NON_NULL)
public List<SourceLocation> getLocations() {
return delegate.getLocations();
}
@Override
public ErrorType getErrorType() {
return delegate.getErrorType();
}
@Override
public List<Object> getPath() {
return delegate.getPath();
}
@Override
public Map<String, Object> toSpecification() {
return delegate.toSpecification();
}
@Override
@JsonInclude(JsonInclude.Include.NON_NULL)
public Map<String, Object> getExtensions() {
return delegate.getExtensions();
}
}