Skip to content

Commit 8c54d02

Browse files
committed
server: Resolve subgraph names in a blocking task
1 parent dc82611 commit 8c54d02

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

server/http/src/service.rs

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -191,28 +191,26 @@ where
191191
subgraph_name: String,
192192
request: Request<Body>,
193193
) -> GraphQLServiceResult {
194-
let subgraph_id = SubgraphName::new(subgraph_name.as_str())
195-
.map_err(|()| {
196-
GraphQLServerError::ClientError(format!(
197-
"Invalid subgraph name {:?}",
198-
subgraph_name
199-
))
200-
})
201-
.and_then(|subgraph_name| {
202-
self.store
203-
.resolve_subgraph_name_to_id(subgraph_name)
204-
.map_err(|e| {
205-
GraphQLServerError::InternalError(format!(
206-
"Error resolving subgraph name: {}",
207-
e
208-
))
209-
})
210-
})
211-
.and_then(|subgraph_id_opt| {
212-
subgraph_id_opt.ok_or(GraphQLServerError::ClientError(
213-
"Subgraph name not found".to_owned(),
214-
))
215-
})?;
194+
let subgraph_name = SubgraphName::new(subgraph_name.as_str()).map_err(|()| {
195+
GraphQLServerError::ClientError(format!("Invalid subgraph name {:?}", subgraph_name))
196+
})?;
197+
198+
let store = self.store.cheap_clone();
199+
let subgraph_id =
200+
tokio::task::spawn_blocking(move || store.resolve_subgraph_name_to_id(subgraph_name))
201+
.await
202+
.unwrap() // Propagate panics.
203+
.map_err(|e| {
204+
GraphQLServerError::InternalError(format!(
205+
"Error resolving subgraph name: {}",
206+
e
207+
))
208+
})
209+
.and_then(|subgraph_id_opt| {
210+
subgraph_id_opt.ok_or(GraphQLServerError::ClientError(
211+
"Subgraph name not found".to_owned(),
212+
))
213+
})?;
216214

217215
self.handle_graphql_query(subgraph_id, request.into_body())
218216
.await

0 commit comments

Comments
 (0)