graphql - 如何使解析器异步运行
问题描述
我正在设置基于 java 的 graphQl 应用程序并发现 graphql-java-tools 确实很方便解决问题,虽然它非常简单使用 graphql-java 使字段解析器异步我找不到使用 graphql-java-tools 的方法
我试过了
@Bean
public ExecutionStrategy executionStrategy() {
return new AsyncExecutionStrategy();
}
我在这里使用解析器进行测试
@Component
public class VideoResolver implements GraphQLResolver<Video> {
public Episode getEpisode(Video video){
Episode result = new Episode();
result.setTitle("episodeTitle");
result.setUuid("EpisodeUuid");
result.setBrand("episodeBrand");
try {
Thread.sleep(2000L);
System.out.println(Thread.currentThread().getName());
} catch (InterruptedException e) {
e.printStackTrace();
}
return result;
}
public List<Images> getImages(Video video){
Images image = new Images();
image.setFileName("Image FileName1");
List<Images> imageList = new ArrayList<>();
imageList.add(image);
try {
Thread.sleep(2000L);
System.out.println(Thread.currentThread().getName());
} catch (InterruptedException e) {
System.out.println("Exxxxxxxxxx");
}
return imageList;
}
}
假设这应该在大约 2 秒内运行并打印两个不同的流,但不需要 4 并且打印它都在同一个流中
解决方案
推荐阅读
- python - 如何在 Python 中将字典拆分为迭代器对象
- asp.net-mvc - TempData 在发布到 Azure 时不起作用
- vba - VBA:将一个集合附加到另一个集合上,例如 VB.NET 中的“.AddRange”
- cassandra - 为什么即使指定了主键,Cassandra 也不允许对没有二级索引的列进行查询/过滤
- macros - 如何为所有数值变量设置缺失值
- docker - Docker:如何获取现有容器的完整容器 ID?
- atom-editor - Atom 编辑器中的 Atom Beautify 包快捷方式/热键不起作用
- sql-server - SQL 删除查询。100000 行要删除
- moodle-api - Moodle API 可选返回值
- javascript - 在我的 Chrome 扩展程序中,Thumbs.db 是什么,我可以删除它吗?