You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
graphql-java removed BatchedExecutionStrategy and @Batched annotation. In order to build with newer versions of graphql-java, yet still support batching and preserve backwards-compatibility as much as possible, SPQR must reimplement batching via DataLoader (the only currently supported batching strategy in graphql-java).
To make use of the new implementation:
Replace graphql.execution.batched.Batched with io.leangen.graphql.annotations.Batched (same @Batched, different package)
Configure DataLoaderRegistry either:
a. usingGraphQLRuntime.newGraphQL instead of GraphQL.newGraphQL
b. manually, using the generated BatchLoaderWithContext instances
Examples:
a)
//No changes in the business logic, apart from the new annotation packagepublicclassUserService {
@Batched@GraphQLQuery//Can also return List<Education>, but async fetching is preferredpublicCompletionStage<List<Education>> education(@GraphQLContextList<User> users) {
... //Batch-resolve the educations for all users
}
}
//ExecutableSchema contains the schema and the batch loadersExecutableSchemaexecutableSchema = newGraphQLSchemaGenerator()
.withOperationsFromSingleton(newUserService());
.generateExecutable();
GraphQLgraphQL = GraphQLRuntime.newGraphQL(executableSchema).build();
//Execute queries as normal, no DataLoader setup neededExecutionResultresult = graphQL.execute("{users {education {startYear}}}");
b)
ExecutableSchemaexecutableSchema = newGraphQLSchemaGenerator()
.withOperationsFromSingleton(newUserService());
.generateExecutable();
GraphQLgraphQL = GraphQL.newGraphQL(executableSchema.getSchema()).build();
//Get the generated BatchLoaderWithContext instances and setup DataLoader manuallyDataLoaderRegistryregistry = newDataLoaderRegistry();
executableSchema.getBatchLoaders().forEach((loaderName, batchLoader) -> {
//Configure DataLoaderOptions etc as neededregistry.register(loaderName, DataLoader.newDataLoader(batchLoader));
});
ExecutionResultresult = graphQL.execute(ExecutionInput.newExecutionInput()
.query("{users {education {startYear}}}")
.dataLoaderRegistry(registry) //Make sure to use the registry
.build());
The text was updated successfully, but these errors were encountered:
graphql-java removed
BatchedExecutionStrategy
and@Batched
annotation. In order to build with newer versions of graphql-java, yet still support batching and preserve backwards-compatibility as much as possible, SPQR must reimplement batching via DataLoader (the only currently supported batching strategy in graphql-java).To make use of the new implementation:
graphql.execution.batched.Batched
withio.leangen.graphql.annotations.Batched
(same@Batched
, different package)DataLoaderRegistry
either:a. using
GraphQLRuntime.newGraphQL
instead ofGraphQL.newGraphQL
b. manually, using the generated
BatchLoaderWithContext
instancesExamples:
a)
b)
The text was updated successfully, but these errors were encountered: