SHARE
TWEET

Untitled

a guest Oct 15th, 2019 111 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. @Component
  2. @Internal
  3. @Primary
  4. public class CustomGraphQLInvocation implements GraphQLInvocation {
  5.  
  6.     private final GraphQL graphQL;
  7.     private final GraphQLDataFetchers dataFetchers;
  8.  
  9.     public CustomGraphQLInvocation(GraphQL graphQL, GraphQLDataFetchers dataFetchers) {
  10.         this.graphQL = graphQL;
  11.         this.dataFetchers = dataFetchers;
  12.     }
  13.  
  14.     @Override
  15.     public CompletableFuture<ExecutionResult> invoke(GraphQLInvocationData invocationData, WebRequest webRequest) {
  16.         ExecutionInput.Builder executionInputBuilder = ExecutionInput.newExecutionInput()
  17.           .query(invocationData.getQuery())
  18.           .operationName(invocationData.getOperationName())
  19.           .variables(invocationData.getVariables());
  20.  
  21.         DataLoaderRegistry dataLoaderRegistry = new DataLoaderRegistry();
  22.         DataLoader<String, CountryTO> countryLoader = DataLoader.newDataLoader(dataFetchers.countryBatchLoader());
  23.         dataLoaderRegistry.register("countries", countryLoader);
  24.  
  25.         executionInputBuilder.dataLoaderRegistry(dataLoaderRegistry);
  26.         executionInputBuilder.context(dataLoaderRegistry);
  27.         ExecutionInput executionInput = executionInputBuilder.build();
  28.         return graphQL.executeAsync(executionInput);
  29.     }
  30. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top