Skip to main content

project_entity

Function project_entity 

Source
pub fn project_entity(
    entity: &Value,
    type_name: &str,
    selections: &[FieldSelection],
    schema: &CompiledSchema,
) -> Value
Expand description

Project an entity-shaped JSONB value into a GraphQL response object, mirroring the query path’s SQL projection exactly.

This is the single, canonical entity projector, shared by the mutation success arm (projecting the returned entity) and the error arm (projecting the error metadata). It is behaviourally equivalent to the SQL query projection (projection_generator::render_field):

  • output key = the selection’s response key (the camelCase GraphQL surface name, honouring aliases),
  • source key = to_snake_case of the field name (the stored JSONB key), with a camelCase fallback for legacy metadata that used the surface casing,
  • single object fields with a sub-selection are recursed (depth-capped at MAX_ENTITY_PROJECTION_DEPTH),
  • list fields, scalar fields, sub-selection-less object fields and over-depth fields pass through their stored value (matching the SQL side’s full-sub-blob fallback),
  • __typename is emitted only where the client selected it.

type_name is the concrete GraphQL object type of entity (resolved by the caller). selections is the result selection set for this level, with inline ... on T fragments preserved; an empty slice means “no field filtering” and returns the stored entity unchanged.