pub struct ProjectionMapper {
pub fields: Vec<FieldMapping>,
pub typename: Option<String>,
pub federation_mode: bool,
}Expand description
Projection mapper - maps JSONB fields to GraphQL selection set.
Fields§
§fields: Vec<FieldMapping>Fields to project (with optional aliases).
typename: Option<String>Optional __typename value to add to each object.
federation_mode: boolWhen true, __typename is injected unconditionally regardless of selection set.
Used by federation _entities resolver where the gateway always expects __typename.
Implementations§
Source§impl ProjectionMapper
impl ProjectionMapper
Sourcepub fn new(fields: Vec<String>) -> Self
pub fn new(fields: Vec<String>) -> Self
Create new projection mapper 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 projection mapper with field mappings (supports aliases).
Sourcepub fn with_declared_scalars(
self,
schema: &CompiledSchema,
entity_type: &str,
) -> Self
pub fn with_declared_scalars( self, schema: &CompiledSchema, entity_type: &str, ) -> Self
Mark every mapping whose field entity_type declares as a scalar
(#1192), so the JSON-text recovery in FieldMapping::declared_scalar
does not fire on a String whose characters happen to be JSON.
Lookup is by the mapping’s output name — the GraphQL field name, which
is what a type definition carries — falling back to source for a
mapping built from a stored key. A field the schema does not describe
stays unmarked: this narrows the recovery to what is positively known,
and never widens it.
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 projected objects.
Sourcepub const fn with_federation_mode(self, enabled: bool) -> Self
pub const fn with_federation_mode(self, enabled: bool) -> Self
Enable federation mode: __typename is always injected regardless of selection set.
Sourcepub fn project(&self, jsonb: &JsonbValue) -> Result<JsonValue>
pub fn project(&self, jsonb: &JsonbValue) -> Result<JsonValue>
Sourcepub fn project_json_object(
&self,
map: &Map<String, JsonValue>,
) -> Result<JsonValue>
pub fn project_json_object( &self, map: &Map<String, JsonValue>, ) -> Result<JsonValue>
Project object fields from JSON object.
Maps source keys to output keys according to the configured FieldMappings,
injects __typename when configured, and recursively projects nested objects
and arrays.
§Errors
Returns error if nested value projection fails.