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

Custom implementation of GraphQLErrorHandler no longer supported? #379

Closed
pstarritt-evooq opened this issue Apr 2, 2020 · 2 comments · Fixed by #380
Closed

Custom implementation of GraphQLErrorHandler no longer supported? #379

pstarritt-evooq opened this issue Apr 2, 2020 · 2 comments · Fixed by #380
Labels
Milestone

Comments

@pstarritt-evooq
Copy link

pstarritt-evooq commented Apr 2, 2020

Hi,

Previously you could bring your own implementation of GraphQLErrorHandler.

Now, this is always set to the DefaultGraphQLErrorHandler.

The correct custom implementation is still created and injected into the objectmapper etc.
But when the GraphQLErrorStartupListener executes onApplicationEvent, the injected ErrorHandlerSupplier (with the correct custom implementation variable at this point) is always overridden with the exception handlers (org.springframework.web.bind.annotation.ExceptionHandler) or the DefaultGraphQLErrorHandler.

This is done in GraphQLErrorStartupListener -> GraphQLErrorHandlerFactory -> override implementation.

Done in following PR:
#305

E.g.

@Component
public class CustomGraphQLErrorHandler implements GraphQLErrorHandler 

Is this a feature to no longer support bring your own GraphQLErrorHandler?

@oliemansm oliemansm added the bug label Apr 3, 2020
@oliemansm
Copy link
Member

oliemansm commented Apr 3, 2020

Hi, this is not intended behavior. We welcome PRs to fix stuff like this in case you have time :)

@neerajsu
Copy link

The issue is because GraphQLObjectMapper being overriden. So for those still on 7.0.1, just create the following bean in any configuration class and you should be good to go.

The custom exception handler in this code snippet is GraphQLExceptionHandler. Rest of them are library classes. The Exception handler should be exposed as a Bean or a Component.

    @Bean
    public GraphQLObjectMapper graphQLObjectMapper(ObjectProvider<ObjectMapperProvider> objectMapperProviderObjectProvider, GraphQLExceptionHandler graphQLExceptionHandler, @Autowired(required = false) GraphQLServletObjectMapperConfigurer objectMapperConfigurer) {
        GraphQLObjectMapper.Builder builder = newBuilder();

        builder.withGraphQLErrorHandler(new ErrorHandlerSupplier(graphQLExceptionHandler));

        ObjectMapperProvider objectMapperProvider = objectMapperProviderObjectProvider.getIfAvailable();

        if (objectMapperProvider != null) {
            builder.withObjectMapperProvider(objectMapperProvider);
        } else if (objectMapperConfigurer != null) {
            builder.withObjectMapperConfigurer(objectMapperConfigurer);
        }
        return builder.build();
    }

Someone should add this to the documentation just in case people are not stuck trying to troubleshoot a problem that they didn't cause.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
3 participants