use of org.springframework.graphql.execution.BatchLoaderRegistry in project spring-graphql by spring-projects.
the class BatchMappingTestSupport method createGraphQlService.
protected GraphQlService createGraphQlService(CourseController controller) {
BatchLoaderRegistry registry = new DefaultBatchLoaderRegistry();
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.registerBean(CourseController.class, () -> controller);
context.registerBean(BatchLoaderRegistry.class, () -> registry);
context.refresh();
return GraphQlSetup.schemaContent(schema).runtimeWiringForAnnotatedControllers(context).dataLoaders(registry).toGraphQlService();
}
use of org.springframework.graphql.execution.BatchLoaderRegistry in project spring-graphql by spring-projects.
the class AnnotatedControllerConfigurer method registerBatchLoader.
private String registerBatchLoader(MappingInfo info) {
if (!info.isBatchMapping()) {
throw new IllegalArgumentException("Not a @BatchMapping method: " + info);
}
String dataLoaderKey = info.getCoordinates().toString();
BatchLoaderRegistry registry = obtainApplicationContext().getBean(BatchLoaderRegistry.class);
HandlerMethod handlerMethod = info.getHandlerMethod();
BatchLoaderHandlerMethod invocable = new BatchLoaderHandlerMethod(handlerMethod);
Class<?> clazz = handlerMethod.getReturnType().getParameterType();
if (clazz.equals(Flux.class) || Collection.class.isAssignableFrom(clazz)) {
registry.forName(dataLoaderKey).registerBatchLoader(invocable::invokeForIterable);
} else if (clazz.equals(Mono.class) || clazz.equals(Map.class)) {
registry.forName(dataLoaderKey).registerMappedBatchLoader(invocable::invokeForMap);
} else {
throw new IllegalStateException("@BatchMapping method is expected to return " + "Flux<V>, List<V>, Mono<Map<K, V>>, or Map<K, V>: " + handlerMethod);
}
return dataLoaderKey;
}
use of org.springframework.graphql.execution.BatchLoaderRegistry in project spring-graphql by spring-projects.
the class SchemaMappingInvocationTests method graphQlService.
private GraphQlService graphQlService() {
BatchLoaderRegistry registry = new DefaultBatchLoaderRegistry();
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(BookController.class);
context.registerBean(BatchLoaderRegistry.class, () -> registry);
context.refresh();
return GraphQlSetup.schemaResource(BookSource.schema).runtimeWiringForAnnotatedControllers(context).dataLoaders(registry).toGraphQlService();
}
Aggregations