我的Dataloader创建代码:-
public DataLoaderRegistry buildDataLoaders(){
return new DataLoaderRegistry().register("books",DataLoader.newDataLoader(userBatchLoader));
}
BatchLoader<String, Book> userBatchLoader = new BatchLoader<String, Book>() {
@Override
public CompletionStage<List<Book>> load(List<String> isbnList) {
return CompletableFuture.supplyAsync(() -> {
return bookManager.loadBookByISBN(isbnList);
});
}
};
在上下文中添加为
的数据加载器ExecutionResult executionResult=graphQLService.getGraphQL().execute(ExecutionInput.newExecutionInput()
.query(graphQLQuery)
.context(graphQLService.buildDataLoaders())
.build());
用于加载数据的Datafetcher代码
DataLoaderRegistry loaders = environment.getContext();
List<String> list=new ArrayList<String>();
list.add(environment.getArgument("id"));
return (Book)loaders.getDataLoader("books").load(list).get();
请求无法解决,日志中没有错误,但是似乎系统进入了无限循环,因为即使几分钟后请求也没有结束。