GraphQL#execute 运行 是否在同一线程上执行所有 DataFetcher?异步行为是否委托给 DataFetcher 实现?

Does the GraphQL#execute run all DataFetchers on the same thread? Is the asynchronous behaviour delegated to the DataFetcher implementation?

如果我的所有 Data Fetcher 都直接返回 POJO 而不是 CompletableFuture,那么整个 GraphQL 执行会在同一个线程上发生吗?

是的。根据我从源代码中看到的,如果所有数据提取器只有 return POJO,整个执行将在同一个线程上执行。

要将数据提取器配置为 运行 并行,您必须使用支持异步处理的 ExecutionStrategy。查询使用的默认值 (AsyncExecutionStrategy) 支持,而变异 (AsyncSerialExecutionStrategy) 不支持。

数据获取器还必须使用 CompletableFuture.supplyAsync() return 一个 CompletableFuture。请注意 graphql-java 提供了一个名为 AsyncDataFetcher 的方便的数据获取器,它可以将普通的同步数据获取器包装到异步数据获取器:

DataFetcher asyncDataFetcher = AsyncDataFetcher.async(fooDataFetcher);