Skip to content

Commit 1856cea

Browse files
committed
feat: add conversion parameters that skip validation
1 parent daacece commit 1856cea

2 files changed

Lines changed: 59 additions & 10 deletions

File tree

  • libs/@local/graph/api/src/rest/entity/query
  • tests/graph/benches/manual_queries/entity_queries

libs/@local/graph/api/src/rest/entity/query/request.rs

Lines changed: 57 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,20 +188,21 @@ pub struct QueryEntitiesRequest<'q, 's, 'p> {
188188
}
189189

190190
impl<'q, 'p> QueryEntitiesRequest<'q, '_, 'p> {
191-
/// # Errors
191+
/// Convert this request into [`QueryEntitiesParams`] with the given [`ApiConfig`] and resolved
192+
/// limit.
192193
///
193-
/// Returns [`LimitExceededError`] if the requested limit exceeds the configured maximum in
194-
/// [`ApiConfig::query_entity_limit`].
195-
pub fn into_params(
194+
/// Does not validate that the resolved limit does not exceed [`ApiConfig::query_entity_limit`].
195+
pub fn into_params_unchecked(
196196
self,
197197
config: ApiConfig,
198-
) -> Result<QueryEntitiesParams<'q>, Report<LimitExceededError>>
198+
limit: Option<usize>,
199+
) -> QueryEntitiesParams<'q>
199200
where
200201
'p: 'q,
201202
{
202-
let limit = resolve_limit(self.limit, config.query_entity_limit)?;
203+
let limit = limit.or(self.limit).unwrap_or(config.query_entity_limit);
203204

204-
Ok(QueryEntitiesParams {
205+
QueryEntitiesParams {
205206
filter: self.filter,
206207
sorting: EntityQuerySorting {
207208
paths: generate_sorting_paths(self.sorting_paths, &self.temporal_axes),
@@ -219,7 +220,26 @@ impl<'q, 'p> QueryEntitiesRequest<'q, '_, 'p> {
219220
include_type_ids: self.include_type_ids,
220221
include_type_titles: self.include_type_titles,
221222
include_permissions: self.include_permissions,
222-
})
223+
}
224+
}
225+
226+
/// Convert this request into [`QueryEntitiesParams`] with the given [`ApiConfig`] and resolved
227+
/// limit.
228+
///
229+
/// # Errors
230+
///
231+
/// Returns [`LimitExceededError`] if the requested limit exceeds the configured maximum in
232+
/// [`ApiConfig::query_entity_limit`].
233+
pub fn into_params(
234+
self,
235+
config: ApiConfig,
236+
) -> Result<QueryEntitiesParams<'q>, Report<LimitExceededError>>
237+
where
238+
'p: 'q,
239+
{
240+
let limit = resolve_limit(self.limit, config.query_entity_limit)?;
241+
242+
Ok(self.into_params_unchecked(config, Some(limit)))
223243
}
224244
}
225245

@@ -286,6 +306,35 @@ impl<'q, 's, 'p> QueryEntitySubgraphRequest<'q, 's, 'p> {
286306
}
287307
}
288308

309+
/// Convert the request into traversal parameters. Skipping validation.
310+
#[must_use]
311+
pub fn into_traversal_params_unchecked(self, config: ApiConfig) -> QueryEntitySubgraphParams<'q>
312+
where
313+
'p: 'q,
314+
{
315+
let (request, params) = self.into_parts();
316+
let request = request.into_params_unchecked(config, None);
317+
318+
match params {
319+
SubgraphTraversalParams::Paths { traversal_paths } => {
320+
QueryEntitySubgraphParams::Paths {
321+
traversal_paths,
322+
request,
323+
}
324+
}
325+
SubgraphTraversalParams::ResolveDepths {
326+
traversal_paths,
327+
graph_resolve_depths,
328+
} => QueryEntitySubgraphParams::ResolveDepths {
329+
traversal_paths,
330+
graph_resolve_depths,
331+
request,
332+
},
333+
}
334+
}
335+
336+
/// Convert the request into traversal parameters.
337+
///
289338
/// # Errors
290339
///
291340
/// Returns [`QueryEntitySubgraphError`] if:

tests/graph/benches/manual_queries/entity_queries/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ where
341341
request.actor_id,
342342
request
343343
.request
344-
.into_params(config)
344+
.into_params_unchecked(config, None)
345345
.expect("limit should not exceed configured maximum"),
346346
)
347347
.await
@@ -353,7 +353,7 @@ where
353353
request.actor_id,
354354
request
355355
.request
356-
.into_traversal_params(config)
356+
.into_traversal_params_unchecked(config)
357357
.expect("limit should not exceed configured maximum"),
358358
)
359359
.await

0 commit comments

Comments
 (0)