Skip to content

Commit 18a20ce

Browse files
committed
Log all filtered graphql errors.
1 parent 3e88dc0 commit 18a20ce

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/main/java/graphql/servlet/GraphQLServlet.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.fasterxml.jackson.databind.ObjectMapper;
2222
import com.fasterxml.jackson.databind.RuntimeJsonMappingException;
2323
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
24+
import graphql.ExceptionWhileDataFetching;
2425
import graphql.ExecutionResult;
2526
import graphql.GraphQL;
2627
import graphql.GraphQLError;
@@ -306,6 +307,12 @@ private Map<String, Object> createResultFromDataAndErrors(Object data, List<Grap
306307
if (clientErrors.size() < errors.size()) {
307308
// Some errors were filtered out to hide implementation - put a generic error in place.
308309
clientErrors.add(new GenericGraphQLError("Internal Server Error(s) while executing query"));
310+
311+
errors.stream()
312+
.filter(error -> !isClientError(error))
313+
.forEach(error -> {
314+
log.error("Error executing query ({}): {}", error.getClass().getSimpleName(), error.getMessage());
315+
});
309316
}
310317
result.put("errors", clientErrors);
311318
}
@@ -318,9 +325,13 @@ private boolean errorsPresent(List<GraphQLError> errors) {
318325
}
319326

320327
protected List<GraphQLError> filterGraphQLErrors(List<GraphQLError> errors) {
321-
return errors.stream().
322-
filter(error -> error instanceof InvalidSyntaxError || error instanceof ValidationError).
323-
collect(Collectors.toList());
328+
return errors.stream()
329+
.filter(this::isClientError)
330+
.collect(Collectors.toList());
331+
}
332+
333+
protected boolean isClientError(GraphQLError error) {
334+
return error instanceof InvalidSyntaxError || error instanceof ValidationError;
324335
}
325336

326337
private <T> void runListeners(List<T> listeners, Consumer<? super T> action) {

0 commit comments

Comments
 (0)