Execute `_entity` requests in parallel. #431
This commit is contained in:
parent
2ce36b2c69
commit
007b4e74db
|
@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
|
|||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
||||
|
||||
## [2.5.11] - 2021-03-07
|
||||
|
||||
- Execute `_entity` requests in parallel. [#431](https://github.com/async-graphql/async-graphql/issues/431)
|
||||
|
||||
## [2.5.10] - 2021-03-06
|
||||
|
||||
- Add descriptions for the exported Federation SDL.
|
||||
|
|
|
@ -124,14 +124,15 @@ impl<T: ObjectType> ContainerType for QueryRoot<T> {
|
|||
if ctx.schema_env.registry.enable_federation || ctx.schema_env.registry.has_entities() {
|
||||
if ctx.item.node.name.node == "_entities" {
|
||||
let representations: Vec<Any> = ctx.param_value("representations", None)?;
|
||||
let mut res = Vec::new();
|
||||
for item in representations {
|
||||
res.push(
|
||||
self.inner.find_entity(ctx, &item.0).await?.ok_or_else(|| {
|
||||
ServerError::new("Entity not found.").at(ctx.item.pos)
|
||||
})?,
|
||||
);
|
||||
}
|
||||
let res = futures_util::future::try_join_all(representations.iter().map(
|
||||
|item| async move {
|
||||
self.inner
|
||||
.find_entity(ctx, &item.0)
|
||||
.await?
|
||||
.ok_or_else(|| ServerError::new("Entity not found.").at(ctx.item.pos))
|
||||
},
|
||||
))
|
||||
.await?;
|
||||
return Ok(Some(Value::List(res)));
|
||||
} else if ctx.item.node.name.node == "_service" {
|
||||
let ctx_obj = ctx.with_selection_set(&ctx.item.node.selection_set);
|
||||
|
|
Loading…
Reference in New Issue