/// Executes the root selection set of a query.
Executes the root selection set of a query.
Executes the root selection set of a query .
pub fn execute_root_selection_set<'a, R>(
    ctx: &ExecutionContext<'a, R>,
    selection_set: &'a q::SelectionSet,
    initial_value: &Option<q::Value>,
) -> Result<q::Value, Vec<QueryExecutionError>>
where
    R: Resolver,
{
    // Obtain the root Query type and fail if there isn't one
    let query_type = match sast::get_root_query_type(&ctx.schema.document) {
        Some(t) => t,
        None => return Err(vec![QueryExecutionError::NoRootQueryObjectType]),
    };
    // Split the toplevel fields into introspection fields and
    // 'normal' data fields
    let mut data_set = q::SelectionSet {
        span: selection_set.span.clone(),
        items: Vec::new(),
    };
    let mut intro_set = q::SelectionSet {
        span: selection_set.span.clone(),
        items: Vec::new(),
    };
    let ictx = ctx.as_introspection_context();
    let introspection_query_type = sast::get_root_query_type(&ictx.schema.document).unwrap();
    for (_, fields) in collect_fields(ctx.clone(), query_type, selection_set, None) {
        let name = fields[0].name.clone();
        let selections = fields.into_iter().map(|f| q::Selection::Field(f.clone()));
        // See if this is an introspection or data field. We don't worry about
        // nonexistant fields; those will cause an error later when we execute
        // the data_set SelectionSet
        if sast::get_field(introspection_query_type, &name).is_some() {
            intro_set.items.extend(selections)
        } else {
            data_set.items.extend(selections)
        }
    }
    // Execute the root selection set against the root query type
    if data_set.items.is_empty() {
        // Only introspection
        execute_selection_set(&ictx, &intro_set, introspection_query_type, initial_value)
    } else if intro_set.items.is_empty() {
        // Only data
        execute_selection_set(&ctx, &data_set, query_type, initial_value)
    } else {
        // Both introspection and data
        let mut values = execute_selection_set_to_map(&ctx, &data_set, query_type, initial_value)?;
        values.extend(execute_selection_set_to_map(
            &ictx,
            &intro_set,
            introspection_query_type,
            initial_value,
        )?);
        Ok(q::Value::Object(values))
    }
}
pub fn execute_root_selection_set < ' a , R > ( ctx : & ExecutionContext < ' a , R > , selection_set : & ' a q :: SelectionSet , initial_value : & Option < q :: Value > , ) -> Result < q :: Value , Vec < QueryExecutionError > > where R : Resolver , { // Obtain the root Query type and fail if there isn't one let query_type = match sast :: get_root_query_type ( & ctx . schema . document ) { Some ( t ) => t , None => return Err ( vec ! [ QueryExecutionError NoRootQueryObjectType ] ) , } ; // Split the toplevel fields into introspection fields and // 'normal' data fields let mut data_set = q :: SelectionSet { span : selection_set . span . clone ( ) , items : Vec :: new ( ) , } ; let mut intro_set = q :: SelectionSet { span : selection_set . span . clone ( ) , items : Vec :: new ( ) , } ; let ictx = ctx . as_introspection_context ( ) ; let introspection_query_type = sast :: get_root_query_type ( & ictx . schema . document ) . unwrap ( ) ; for ( _ , fields ) in collect_fields ( ctx . clone ( ) , query_type , selection_set , None ) { let name = fields [ 0 ] . name . clone ( ) ; let selections = fields . into_iter ( ) . map ( | f | q :: Selection :: Field ( f . clone ( ) ) ) ; // See if this is an introspection or data field. We don't worry about // nonexistant fields; those will cause an error later when we execute // the data_set SelectionSet if sast :: get_field ( introspection_query_type , & name ) . is_some ( ) { intro_set . items . extend ( selections ) } else { data_set . items . extend ( selections ) } } // Execute the root selection set against the root query type if data_set . items . is_empty ( ) { // Only introspection execute_selection_set ( & ictx , & intro_set , introspection_query_type , initial_value ) } else if intro_set . items . is_empty ( ) { // Only data execute_selection_set ( & ctx , & data_set , query_type , initial_value ) } else { // Both introspection and data let mut values = execute_selection_set_to_map ( & ctx , & data_set , query_type , initial_value ) ? ; values . extend ( execute_selection_set_to_map ( & ictx , & intro_set , introspection_query_type , initial_value , ) ? ) ; Ok ( q :: Value :: Object ( values ) ) } }
Executes the root selection set of a query.
Executes the root selection set of a query .
ctx
&ExecutionContext<'a, R>
selection_set
&'a q::SelectionSet
initial_value
&Option<q::Value>