我正在建立基于Java的graphQl App,并发现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 并全部打印在同一流中