spring-graphql icon indicating copy to clipboard operation
spring-graphql copied to clipboard

Make it easier to configure `ExecutionStrategy`

Open gli-chwy opened this issue 2 years ago • 4 comments

org.springframework.graphql.execution.ExceptionResolversExceptionHandler is package private, and it's not exposed as a Bean. Clearly it's designed that way.

I'm trying to extend graphql.execution.AsyncExecutionStrategy and override

@Override
protected CompletableFuture<ExecutionResult> completeValueForEnum(ExecutionContext executionContext, ExecutionStrategyParameters parameters, GraphQLEnumType enumType, Object result) 
{
}

to ignore unknown enum values in a class called IgnoreUnknownEnumValueExecutionStrategy. But the difficulty, without duplicating ExceptionResolversExceptionHandler, is I could not inject the ExceptionResolversExceptionHandler instance (which is hidden within the framework) into my IgnoreUnknownEnumValueExecutionStrategy bean.

Please advise if my use case and question is legitimate. Thanks.

gli-chwy avatar Oct 02 '23 18:10 gli-chwy

I think this is the same case as #552. There we provided the static factory method DataFetcherExceptionResolver#createExceptionHandler to create the ExceptionResolversExceptionHandler instance.

We could try to take this a step further by facilitating the registration of execution strategies with the the DataFetcherExceptionHandler that we create. Something like this on GraphQlSource.Builder:

Builder configureExecutionStrategies(BiConsumer<GraphQL.Builder, DataFetcherExceptionHandler> configurer);

Or perhaps even a dedicated ExecutionStrategyFactory to create an ExecutionStrategy given a DataFetcherExceptionHandler. Although something like that could belong in GraphQL Java too.

rstoyanchev avatar Oct 13 '23 15:10 rstoyanchev

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

spring-projects-issues avatar Oct 20 '23 15:10 spring-projects-issues

Thank you @rstoyanchev for your response. I'll update our version to take advantage of DataFetcherExceptionResolver#createExceptionHandler since it is currently at 1.0.3. You can decide on the further refinement you mentioned.

gli-chwy avatar Oct 25 '23 18:10 gli-chwy

I'll update the title to reflect the actual goal to make it easier to configure a custom ExecutionStrategy. We need to consider whether to make a change here, or to request an enhancement in GraphQL Java's GraphQL.Builder. I'll leave this open for the time being.

rstoyanchev avatar Oct 27 '23 10:10 rstoyanchev

On further thought, a callback on GraphQlSource.Builder limits the ability to declare an ExecutionStrategy as a Spring bean while at the same time there isn't much of a drawback to create DataFetcherExceptionHandler via DataFetcherExceptionResolver#createExceptionHandler. It's mostly about making it easier to discover.

I'm turning this into a documentation issue. I'll update the Javadoc and reference docs to make it easy to find.

rstoyanchev avatar May 18 '24 11:05 rstoyanchev

Fixed via aa1ee77867aee19bedef1f7eb5451fe46fc1c5e4

github-actions[bot] avatar May 20 '24 07:05 github-actions[bot]