-
Notifications
You must be signed in to change notification settings - Fork 52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/graphql error handling #80
base: master
Are you sure you want to change the base?
Feature/graphql error handling #80
Conversation
Added GraphQL error handling support. Currently integrated with spring-graphql and working towards supporting more 3rd party implementations of GraphQL in Spring Framework/Boot.
import io.github.wimdeblauwe.errorhandlingspringbootstarter.mapper.HttpStatusMapper; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.context.annotation.Bean; | ||
|
||
public abstract class AbstractErrorHandlingConfiguration { | ||
@Bean | ||
@ConditionalOnMissingBean | ||
public LoggingService loggingService(ErrorHandlingProperties properties) { | ||
return new LoggingService(properties); | ||
public LoggingService loggingService(ErrorHandlingProperties properties, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would rather not have any graphql related classes in this class. It would be better to have a dedicated subclass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Do you want this Configuration class to be a separate type of ServletErrorHandlingConfiguration
specific to GraphQL configuration? Would there be a requirement to mark it as optional? Such way in properties with @ConditionalOnProperty(value = "error.handling.graphql.enabled", matchIfMissing = false)
?
@@ -27,6 +32,20 @@ public void logException(ApiErrorResponse errorResponse, Throwable exception) { | |||
} | |||
} | |||
|
|||
public void logException(GraphQLError graphQLError, Throwable exception) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer a separate GraphQlLoggingService
class. Common code could be moved into an abstract super class, or to helper components.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can extract the common logic into an AbstractLoggingService class. Then, each of the concrete implementations for REST and GraphQL can declare it's custom logic for logException
method depending on the context. Is this what you had in mind?
import org.springframework.http.HttpStatusCode; | ||
|
||
public abstract class AbstractGraphqlExceptionHandler implements GraphqlExceptionHandler { | ||
protected final HttpStatusMapper httpStatusMapper; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess these can be private
since there are the getter methods anyway?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can mark them as private, yes. I also mostly used the specialized "get...(Throwable exception)" methods.
import java.util.stream.Collectors; | ||
import java.util.stream.StreamSupport; | ||
|
||
public class GqlConstraintViolationExceptionHandler extends AbstractGraphqlExceptionHandler { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lots of duplication with ConstraintViolationApiExceptionHandler
. We should find a way to avoid that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes here it is a fact, indeed. How would you propose to tackle this? We have multiple options:
- Static Utils class to handle ConstraintViolationException -> ApiErrorResponse
- Bean helper class that translates ConstraintViolationException -> ApiErrorResponse (this increases extensibility)
- Specialized method (+ it's dependencies) in the super class to handle this specific behavior
@@ -0,0 +1,51 @@ | |||
package io.github.wimdeblauwe.errorhandlingspringbootstarter.handler; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can put all GraphQL related handlers in a graphql
sub-package?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you want the Gql handlers to be under the root package or under root/handler sub-package?
Thank you for this PR. Nice that you have so many tests added! In general, I'd like the graphql parts to be a little more separate, so using different packages. Maybe you can add a proposal as a comment here first before you start moving things around? |
Hi, I have used both the error-handling-starter and recently started using GraphQl, so I have a two comments.
|
Hello @ooraini, Those are some good points, but my arguments on using them:
|
Added GraphQL error handling support. Currently integrated with spring-graphql and working towards supporting more 3rd party implementations of GraphQL in Spring Framework/Boot.
Supports minimum version 1.2.2 of spring-graphql.
Features I was not able to implement or not yet supported: