graphql-java-kickstart / graphql-java-servlet

Servlet endpoint for GraphQL Java
https://www.graphql-java-kickstart.com/servlet/
Other
223 stars 114 forks source link

Allow customize async running or fully disable library async logic. #563

Open nathanmolinari opened 5 months ago

nathanmolinari commented 5 months ago

Is your feature request related to a problem? Please describe.

I would like to code something like this, if operation is x, then execute in threadpool y. But the library do not give me this flexibility, i can only inform one threadpool that all async tasks will run.

Describe the solution you'd like

I would like that i can set my own HttpRequestHandlerImpl and HttpRequestInvokerImpl where i'm going to code my execution logic with fully flexibility to choose which threadpool i`m going to use to each scenario.

Also change the visibility of methods from HttpRequestInvokerImpl, by doing this, i can code something like

    public class MyHttpRequestInvokerImpl extends HttpRequestInvokerImpl {
        @Override
        public void execute(
                GraphQLInvocationInput invocationInput,
                HttpServletRequest request,
                HttpServletResponse response,
                ListenerHandler listenerHandler) {

            if(someLogic) {
                runAsync(myThreadPool, super.handle(invocationInput, request, response, listenerHandler));
            } else {
                super.execute(...args)
            }
        }

    }

Other option would be to check on HttpRequestInvokerImpl.java#L45 if property graphql.servlet.async.enabled is true. If not the library should not execute tasks async. By doing this, i can fully disable library async logic, and code a customized one.

Describe alternatives you've considered

Before async support (older versions) we coded by ourselves async running. When upgraded the async logic just broke because the library try to run async again when isAsyncSupported() returns true. https://github.com/graphql-java-kickstart/graphql-java-servlet/blob/master/graphql-java-servlet/src/main/java/graphql/kickstart/servlet/HttpRequestInvokerImpl.java#L45