Created
September 27, 2019 07:04
-
-
Save kijanowski/e281fcbb89daceef1f2d8f4da3a3f8b8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Component | |
| @Internal | |
| @Primary | |
| public class CustomGraphQLInvocation implements GraphQLInvocation { | |
| private final GraphQL graphQL; | |
| private final GraphQLDataFetchers dataFetchers; | |
| public CustomGraphQLInvocation(GraphQL graphQL, GraphQLDataFetchers dataFetchers) { | |
| this.graphQL = graphQL; | |
| this.dataFetchers = dataFetchers; | |
| } | |
| @Override | |
| public CompletableFuture<ExecutionResult> invoke(GraphQLInvocationData invocationData, WebRequest webRequest) { | |
| ExecutionInput.Builder executionInputBuilder = ExecutionInput.newExecutionInput() | |
| .query(invocationData.getQuery()) | |
| .operationName(invocationData.getOperationName()) | |
| .variables(invocationData.getVariables()); | |
| DataLoaderRegistry dataLoaderRegistry = new DataLoaderRegistry(); | |
| DataLoader<String, CountryTO> countryLoader = DataLoader.newDataLoader(dataFetchers.countryBatchLoader()); | |
| dataLoaderRegistry.register("countries", countryLoader); | |
| executionInputBuilder.dataLoaderRegistry(dataLoaderRegistry); | |
| executionInputBuilder.context(dataLoaderRegistry); | |
| ExecutionInput executionInput = executionInputBuilder.build(); | |
| return graphQL.executeAsync(executionInput); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment