Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions libs/@local/graph/api/src/rest/data_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::collections::{HashMap, HashSet};

use axum::{
Extension, Router,
response::Response,
routing::{post, put},
};
use error_stack::{Report, ResultExt as _};
Expand Down Expand Up @@ -46,6 +45,7 @@ use type_system::{
};
use utoipa::{OpenApi, ToSchema};

use super::status::BoxedResponse;
use crate::rest::{
AuthenticatedUserHeader, OpenApiQuery, QueryLogger, RestApiStore,
json::Json,
Expand Down Expand Up @@ -170,7 +170,7 @@ async fn create_data_type<S>(
temporal_client: Extension<Option<Arc<TemporalClient>>>,
domain_validator: Extension<DomainValidator>,
body: Json<CreateDataTypeRequest>,
) -> Result<Json<ListOrValue<DataTypeMetadata>>, Response>
) -> Result<Json<ListOrValue<DataTypeMetadata>>, BoxedResponse>
where
S: StorePool + Send + Sync,
for<'pool> S::Store<'pool>: RestApiStore,
Expand Down Expand Up @@ -207,7 +207,7 @@ where
conversions: conversions.clone(),
})
})
.collect::<Result<Vec<_>, Response>>()?,
.collect::<Result<Vec<_>, BoxedResponse>>()?,
)
.await
.map_err(report_to_response)?;
Expand Down Expand Up @@ -256,7 +256,7 @@ async fn load_external_data_type<S>(
temporal_client: Extension<Option<Arc<TemporalClient>>>,
domain_validator: Extension<DomainValidator>,
Json(request): Json<LoadExternalDataTypeRequest>,
) -> Result<Json<DataTypeMetadata>, Response>
) -> Result<Json<DataTypeMetadata>, BoxedResponse>
where
S: StorePool + Send + Sync,
for<'pool> S::Store<'pool>: RestApiStore,
Expand Down Expand Up @@ -343,7 +343,7 @@ async fn query_data_types<S>(
temporal_client: Extension<Option<Arc<TemporalClient>>>,
mut query_logger: Option<Extension<QueryLogger>>,
Json(request): Json<serde_json::Value>,
) -> Result<Json<QueryDataTypesResponse>, Response>
) -> Result<Json<QueryDataTypesResponse>, BoxedResponse>
where
S: StorePool + Send + Sync,
{
Expand Down Expand Up @@ -407,7 +407,7 @@ async fn query_data_type_subgraph<S>(
temporal_client: Extension<Option<Arc<TemporalClient>>>,
mut query_logger: Option<Extension<QueryLogger>>,
Json(request): Json<serde_json::Value>,
) -> Result<Json<QueryDataTypeSubgraphResponse>, Response>
) -> Result<Json<QueryDataTypeSubgraphResponse>, BoxedResponse>
where
S: StorePool + Send + Sync,
{
Expand Down Expand Up @@ -465,7 +465,7 @@ async fn find_data_type_conversion_targets<S>(
store_pool: Extension<Arc<S>>,
temporal_client: Extension<Option<Arc<TemporalClient>>>,
Json(request): Json<FindDataTypeConversionTargetsParams>,
) -> Result<Json<FindDataTypeConversionTargetsResponse>, Response>
) -> Result<Json<FindDataTypeConversionTargetsResponse>, BoxedResponse>
where
S: StorePool + Send + Sync,
{
Expand Down Expand Up @@ -510,7 +510,7 @@ async fn update_data_type<S>(
store_pool: Extension<Arc<S>>,
temporal_client: Extension<Option<Arc<TemporalClient>>>,
body: Json<UpdateDataTypeRequest>,
) -> Result<Json<DataTypeMetadata>, Response>
) -> Result<Json<DataTypeMetadata>, BoxedResponse>
where
S: StorePool + Send + Sync,
{
Expand Down Expand Up @@ -565,7 +565,7 @@ async fn update_data_types<S>(
store_pool: Extension<Arc<S>>,
temporal_client: Extension<Option<Arc<TemporalClient>>>,
bodies: Json<Vec<UpdateDataTypeRequest>>,
) -> Result<Json<Vec<DataTypeMetadata>>, Response>
) -> Result<Json<Vec<DataTypeMetadata>>, BoxedResponse>
where
S: StorePool + Send + Sync,
{
Expand Down Expand Up @@ -594,7 +594,7 @@ where
})
},
)
.collect::<Result<Vec<_>, Response>>()?;
.collect::<Result<Vec<_>, BoxedResponse>>()?;
store
.update_data_types(actor_id, params)
.await
Expand Down Expand Up @@ -622,7 +622,7 @@ async fn update_data_type_embeddings<S>(
store_pool: Extension<Arc<S>>,
temporal_client: Extension<Option<Arc<TemporalClient>>>,
Json(body): Json<serde_json::Value>,
) -> Result<(), Response>
) -> Result<(), BoxedResponse>
where
S: StorePool + Send + Sync,
{
Expand Down Expand Up @@ -665,7 +665,7 @@ async fn archive_data_type<S>(
store_pool: Extension<Arc<S>>,
temporal_client: Extension<Option<Arc<TemporalClient>>>,
Json(body): Json<serde_json::Value>,
) -> Result<Json<OntologyTemporalMetadata>, Response>
) -> Result<Json<OntologyTemporalMetadata>, BoxedResponse>
where
S: StorePool + Send + Sync,
{
Expand Down Expand Up @@ -717,7 +717,7 @@ async fn unarchive_data_type<S>(
store_pool: Extension<Arc<S>>,
temporal_client: Extension<Option<Arc<TemporalClient>>>,
Json(body): Json<serde_json::Value>,
) -> Result<Json<OntologyTemporalMetadata>, Response>
) -> Result<Json<OntologyTemporalMetadata>, BoxedResponse>
where
S: StorePool + Send + Sync,
{
Expand Down Expand Up @@ -766,7 +766,7 @@ async fn has_permission_for_data_types<S>(
temporal_client: Extension<Option<Arc<TemporalClient>>>,
store_pool: Extension<Arc<S>>,
Json(params): Json<HasPermissionForDataTypesParams<'static>>,
) -> Result<Json<HashSet<VersionedUrl>>, Response>
) -> Result<Json<HashSet<VersionedUrl>>, BoxedResponse>
where
S: StorePool + Send + Sync,
for<'p> S::Store<'p>: DataTypeStore,
Expand Down
24 changes: 12 additions & 12 deletions libs/@local/graph/api/src/rest/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use alloc::sync::Arc;
use std::collections::HashMap;

use axum::{Extension, Router, response::Response, routing::post};
use axum::{Extension, Router, routing::post};
use error_stack::{Report, ResultExt as _};
use hash_graph_authorization::policies::principal::actor::AuthenticatedActor;
use hash_graph_postgres_store::store::error::{EntityDoesNotExist, RaceConditionOnUpdate};
Expand Down Expand Up @@ -75,7 +75,7 @@ use type_system::{
};
use utoipa::{OpenApi, ToSchema};

use super::InteractiveHeader;
use super::{InteractiveHeader, status::BoxedResponse};
pub use crate::rest::entity_query_request::{
EntityQuery, EntityQueryOptions, QueryEntitiesRequest, QueryEntitySubgraphRequest,
};
Expand Down Expand Up @@ -255,7 +255,7 @@ async fn create_entity<S>(
store_pool: Extension<Arc<S>>,
temporal_client: Extension<Option<Arc<TemporalClient>>>,
Json(body): Json<serde_json::Value>,
) -> Result<Json<Entity>, Response>
) -> Result<Json<Entity>, BoxedResponse>
where
S: StorePool + Send + Sync,
{
Expand Down Expand Up @@ -296,7 +296,7 @@ async fn create_entities<S>(
store_pool: Extension<Arc<S>>,
temporal_client: Extension<Option<Arc<TemporalClient>>>,
Json(body): Json<serde_json::Value>,
) -> Result<Json<Vec<Entity>>, Response>
) -> Result<Json<Vec<Entity>>, BoxedResponse>
where
S: StorePool + Send + Sync,
{
Expand Down Expand Up @@ -338,7 +338,7 @@ async fn validate_entity<S>(
temporal_client: Extension<Option<Arc<TemporalClient>>>,
mut query_logger: Option<Extension<QueryLogger>>,
Json(body): Json<serde_json::Value>,
) -> Result<Json<HashMap<usize, EntityValidationReport>>, Response>
) -> Result<Json<HashMap<usize, EntityValidationReport>>, BoxedResponse>
where
S: StorePool + Send + Sync,
{
Expand Down Expand Up @@ -385,7 +385,7 @@ async fn has_permission_for_entities<S>(
temporal_client: Extension<Option<Arc<TemporalClient>>>,
store_pool: Extension<Arc<S>>,
Json(params): Json<HasPermissionForEntitiesParams<'static>>,
) -> Result<Json<HashMap<EntityId, Vec<EntityEditionId>>>, Response>
) -> Result<Json<HashMap<EntityId, Vec<EntityEditionId>>>, BoxedResponse>
where
S: StorePool + Send + Sync,
for<'p> S::Store<'p>: EntityStore,
Expand Down Expand Up @@ -429,7 +429,7 @@ async fn query_entities<S>(
temporal_client: Extension<Option<Arc<TemporalClient>>>,
mut query_logger: Option<Extension<QueryLogger>>,
Json(request): Json<Box<RawJsonvalue>>,
) -> Result<Json<QueryEntitiesResponse<'static>>, Response>
) -> Result<Json<QueryEntitiesResponse<'static>>, BoxedResponse>
where
S: StorePool + Send + Sync,
{
Expand Down Expand Up @@ -546,7 +546,7 @@ async fn query_entity_subgraph<S>(
temporal_client: Extension<Option<Arc<TemporalClient>>>,
mut query_logger: Option<Extension<QueryLogger>>,
Json(request): Json<serde_json::Value>,
) -> Result<Json<QueryEntitySubgraphResponse<'static>>, Response>
) -> Result<Json<QueryEntitySubgraphResponse<'static>>, BoxedResponse>
where
S: StorePool + Send + Sync,
{
Expand Down Expand Up @@ -629,7 +629,7 @@ async fn count_entities<S>(
temporal_client: Extension<Option<Arc<TemporalClient>>>,
mut query_logger: Option<Extension<QueryLogger>>,
Json(request): Json<serde_json::Value>,
) -> Result<Json<usize>, Response>
) -> Result<Json<usize>, BoxedResponse>
where
S: StorePool + Send + Sync,
{
Expand Down Expand Up @@ -680,7 +680,7 @@ async fn patch_entity<S>(
store_pool: Extension<Arc<S>>,
temporal_client: Extension<Option<Arc<TemporalClient>>>,
Json(params): Json<PatchEntityParams>,
) -> Result<Json<Entity>, Response>
) -> Result<Json<Entity>, BoxedResponse>
where
S: StorePool + Send + Sync,
{
Expand Down Expand Up @@ -725,7 +725,7 @@ async fn update_entity_embeddings<S>(
store_pool: Extension<Arc<S>>,
temporal_client: Extension<Option<Arc<TemporalClient>>>,
Json(body): Json<serde_json::Value>,
) -> Result<(), Response>
) -> Result<(), BoxedResponse>
where
S: StorePool + Send + Sync,
{
Expand Down Expand Up @@ -768,7 +768,7 @@ async fn diff_entity<S>(
temporal_client: Extension<Option<Arc<TemporalClient>>>,
mut query_logger: Option<Extension<QueryLogger>>,
Json(params): Json<DiffEntityParams>,
) -> Result<Json<DiffEntityResult<'static>>, Response>
) -> Result<Json<DiffEntityResult<'static>>, BoxedResponse>
where
S: StorePool + Send + Sync,
{
Expand Down
13 changes: 7 additions & 6 deletions libs/@local/graph/api/src/rest/entity_query_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use core::{cmp, ops::Range};

use axum::{
Json,
response::{Html, IntoResponse as _, Response},
response::{Html, IntoResponse as _},
};
use hash_graph_store::{
entity::{
Expand Down Expand Up @@ -64,6 +64,8 @@ use serde_json::value::RawValue as RawJsonValue;
use type_system::knowledge::Entity;
use utoipa::ToSchema;

use super::status::BoxedResponse;

#[tracing::instrument(level = "info", skip_all)]
fn generate_sorting_paths(
paths: Option<Vec<EntityQuerySortingRecord<'_>>>,
Expand Down Expand Up @@ -282,7 +284,7 @@ fn issues_to_response(
source: &str,
mut spans: &SpanTable<Span>,
options: CompilationOptions,
) -> Response {
) -> BoxedResponse {
let status_code = match severity {
Severity::Bug | Severity::Fatal => StatusCode::INTERNAL_SERVER_ERROR,
Severity::Error => StatusCode::BAD_REQUEST,
Expand All @@ -306,15 +308,15 @@ fn issues_to_response(
};

*response.status_mut() = status_code;
response
response.into()
}

fn failure_to_response(
failure: Failure<HashQLDiagnosticCategory, SpanId>,
source: &str,
spans: &SpanTable<Span>,
options: CompilationOptions,
) -> Response {
) -> BoxedResponse {
// Find the highest diagnostic level
let severity = cmp::max(
failure
Expand Down Expand Up @@ -445,12 +447,11 @@ impl<'q> EntityQuery<'q> {
/// # Errors
///
/// Returns an error if the HashQL query cannot be compiled.
#[expect(clippy::result_large_err, reason = "precompiled response")]
pub(crate) fn compile(
self,
heap: &'q Heap,
options: CompilationOptions,
) -> Result<Filter<'q, Entity>, Response> {
) -> Result<Filter<'q, Entity>, BoxedResponse> {
match self {
EntityQuery::Filter { filter } => Ok(filter),
EntityQuery::Query { query } => {
Expand Down
Loading
Loading