pub struct ResultProjector { /* private fields */ }Expand description
Result projector - high-level result transformation.
Implementations§
Source§impl ResultProjector
impl ResultProjector
Sourcepub fn new(fields: Vec<String>) -> Self
pub fn new(fields: Vec<String>) -> Self
Create new result projector from field names (no aliases).
Sourcepub const fn with_mappings(fields: Vec<FieldMapping>) -> Self
pub const fn with_mappings(fields: Vec<FieldMapping>) -> Self
Create new result projector with field mappings (supports aliases).
Sourcepub fn with_typename(self, typename: impl Into<String>) -> Self
pub fn with_typename(self, typename: impl Into<String>) -> Self
Set __typename to include in all projected objects.
Per GraphQL spec §2.7, __typename returns the name of the object type.
This should be called when the client requests __typename in the selection set.
Sourcepub fn project_results(
&self,
results: &[JsonbValue],
is_list: bool,
) -> Result<JsonValue>
pub fn project_results( &self, results: &[JsonbValue], is_list: bool, ) -> Result<JsonValue>
Sourcepub fn wrap_in_data_envelope(result: JsonValue, query_name: &str) -> JsonValue
pub fn wrap_in_data_envelope(result: JsonValue, query_name: &str) -> JsonValue
Sourcepub fn add_typename_only(
&self,
projected_data: &JsonbValue,
typename: &str,
) -> Result<JsonValue>
pub fn add_typename_only( &self, projected_data: &JsonbValue, typename: &str, ) -> Result<JsonValue>
Add __typename field to SQL-projected data.
For data that has already been projected at the SQL level, we only need to add
the __typename field in Rust. This is much faster than projecting all fields
since the SQL already filtered to only requested fields.
§Arguments
projected_data- JSONB data already projected by SQLtypename- GraphQL type name to add
§Returns
New JSONB value with __typename field added
§Example
let projector = ResultProjector::new(vec!["id".to_string(), "name".to_string()]);
// Database already returned only: { "id": "123", "name": "Alice" }
let result = projector.add_typename_only(
&JsonbValue::new(json!({ "id": "123", "name": "Alice" })),
"User"
).unwrap();
// Result: { "id": "123", "name": "Alice", "__typename": "User" }
assert_eq!(result["__typename"], "User");§Errors
Returns FraiseQLError::Validation if the projected data contains a
list element that is not a JSON object, making __typename injection impossible.
Sourcepub fn wrap_error(error: &FraiseQLError) -> JsonValue
pub fn wrap_error(error: &FraiseQLError) -> JsonValue
Auto Trait Implementations§
impl Freeze for ResultProjector
impl RefUnwindSafe for ResultProjector
impl Send for ResultProjector
impl Sync for ResultProjector
impl Unpin for ResultProjector
impl UnsafeUnpin for ResultProjector
impl UnwindSafe for ResultProjector
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more