Skip to content
This repository was archived by the owner on Dec 19, 2023. It is now read-only.
This repository was archived by the owner on Dec 19, 2023. It is now read-only.

Why does GraphQLErrorFromExceptionHandler remove information from incoming errors? #310

@Sam-Kruglov

Description

@Sam-Kruglov

I found there this code:

protected List<GraphQLError> filterGraphQLErrors(List<GraphQLError> errors) {
  return errors.stream().map(this::transform).flatMap(Collection::stream).collect(Collectors.toList());
}
private Collection<GraphQLError> transform(GraphQLError error) {
  return extractException(error).map(this::transform)
      .orElse(singletonList(new GenericGraphQLError(error.getMessage())));
}
private Optional<Throwable> extractException(GraphQLError error) {
...
}

This is really confusing to me, as why would I spend effort building up GraphQLError if it's just going to be discarted here? Here is some context:

I created my own DataFetcherExceptionHandler in order to catch some exceptions like IllegalArgumentException, MyServiceException and add an error code inside extensions.errorCode. (btw, I could not find a better way of integrating it other than creating a Spring Bean of new AsyncExecutionStrategy(dataFetcherExceptionHandler) )

Then, I ran the code and I see that I only have the contents of GenericGraphQLError returned to the client. I can see that this class (GraphQLErrorFromExceptionHandler) takes MyCustomGraphQLError, tries to convert it into a Throwable and then back to GraphQLError but without considering any fields I populated (except for the message).

I see, that DefaultGraphQLErrorHandler doesn't do that. I added this property graphql.servlet.exception-handlers-enabled: true because I wanted to use @ExceptionHandler annotations, but that didn't work for me (#309).

Anyway, this is just to understand, why would you want to strip so much information from the errors?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions