pub async fn read_rels(
        &mut self,
        src_node_label: &str,
        rel_label: &str,
        input: impl TryInto<Value>,
        partition_key_opt: Option<&Value>,
    ) -> Result<Vec<Rel<RequestCtx>>, Error> {
        let input_value_opt = Some(input.try_into().map_err(|_e| Error::TypeConversionFailed {
            src: "TryInto<Value>".to_string(),
            dst: "Value".to_string(),
        })?);
        let mut sg = SuffixGenerator::new();
        let rel_suffix = sg.suffix();
        let dst_suffix = sg.suffix();
        let src_var = NodeQueryVar::new(
            Some(src_node_label.to_string()),
            "src".to_string(),
            sg.suffix(),
        );
        let dst_var = NodeQueryVar::new(None, "dst".to_string(), dst_suffix);
        let rel_var = RelQueryVar::new(rel_label.to_string(), rel_suffix, src_var, dst_var);
        let info = Info::new(
            src_node_label.to_string()
                + &*((&rel_label.to_string().to_title_case())
                    .split_whitespace()
                    .collect::<String>())
                + "QueryInput",
            self.info.type_defs(),
        );
        let query_fragment = visit_rel_query_input::<RequestCtx>(
            None,
            &rel_var,
            input_value_opt,
            &info,
            partition_key_opt,
            &mut sg,
            &mut self.transaction,
        )
        .await?;

        let results = self
            .transaction
            .read_rels(
                query_fragment,
                &rel_var,
                //Some(p.type_name()),
                None,
                partition_key_opt,
            )
            .await?;

        Ok(results)
    }
/// Provides an abstracted database rel read operation using warpgrapher inputs. This is the
/// recommended way to read relationships in a database-agnostic way that ensures the event handlers
/// are portable across different databases.
///
/// # Arguments
///
/// * `src_node_label` - String reference represing name of node type (ex: "User").
/// * `rel_label` - String reference representing the name of the relationship (ex: "teams").
/// * `input` - `Value` describing the relationship query input.
/// * `partition_key_opt` - Optional `Value` describing the partition key if the underlying database supports it.
///
/// # Examples
///
/// ```rust, no_run
/// # use serde_json::json;
/// # use warpgrapher::Error;
/// # use warpgrapher::engine::events::EventFacade;
/// # use warpgrapher::engine::objects::Rel;
/// # use warpgrapher::engine::value::Value;
/// # use warpgrapher::juniper::BoxFuture;
///
/// fn before_user_read(value: Value, mut ef: EventFacade<()>) -> BoxFuture<Result<Value, Error>> {
///     Box::pin(async move {
///         let rels: Vec<Rel<()>> = ef.read_rels(
///             "User",
///             "teams",
///             json!({
///                 "src": {"name": {"EQ": "alice"}}
///             }),
///             None).await?;
///         Ok(value)
///     })
/// }
/// ```
Provides an abstracted database rel read operation using warpgrapher inputs. This is the
recommended way to read relationships in a database-agnostic way that ensures the event handlers
are portable across different databases.
Provides an abstracted database rel read operation using warpgrapher inputs . This is the recommended way to read relationships in a database - agnostic way that ensures the event handlers are portable across different databases .
pub async fn read_rels(
        &mut self,
        src_node_label: &str,
        rel_label: &str,
        input: impl TryInto<Value>,
        partition_key_opt: Option<&Value>,
    ) -> Result<Vec<Rel<RequestCtx>>, Error> {
        let input_value_opt = Some(input.try_into().map_err(|_e| Error::TypeConversionFailed {
            src: "TryInto<Value>".to_string(),
            dst: "Value".to_string(),
        })?);
        let mut sg = SuffixGenerator::new();
        let rel_suffix = sg.suffix();
        let dst_suffix = sg.suffix();
        let src_var = NodeQueryVar::new(
            Some(src_node_label.to_string()),
            "src".to_string(),
            sg.suffix(),
        );
        let dst_var = NodeQueryVar::new(None, "dst".to_string(), dst_suffix);
        let rel_var = RelQueryVar::new(rel_label.to_string(), rel_suffix, src_var, dst_var);
        let info = Info::new(
            src_node_label.to_string()
                + &*((&rel_label.to_string().to_title_case())
                    .split_whitespace()
                    .collect::<String>())
                + "QueryInput",
            self.info.type_defs(),
        );
        let query_fragment = visit_rel_query_input::<RequestCtx>(
            None,
            &rel_var,
            input_value_opt,
            &info,
            partition_key_opt,
            &mut sg,
            &mut self.transaction,
        )
        .await?;
        let results = self
            .transaction
            .read_rels(
                query_fragment,
                &rel_var,
                //Some(p.type_name()),
                None,
                partition_key_opt,
            )
            .await?;
        Ok(results)
    }
pub async fn read_rels ( & mut self , src_node_label : & str , rel_label : & str , input : impl TryInto < Value > , partition_key_opt : Option < & Value > , ) -> Result < Vec < Rel < RequestCtx > > , Error > { let input_value_opt = Some ( input . try_into ( ) . map_err ( | _e | Error :: TypeConversionFailed { src : " " . to_string ( ) , dst : " " . to_string ( ) , } ) ? ) ; let mut sg = SuffixGenerator :: new ( ) ; let rel_suffix = sg . suffix ( ) ; let dst_suffix = sg . suffix ( ) ; let src_var = NodeQueryVar :: new ( Some ( src_node_label . to_string ( ) ) , " " . to_string ( ) , sg . suffix ( ) , ) ; let dst_var = NodeQueryVar :: new ( None , " " . to_string ( ) , dst_suffix ) ; let rel_var = RelQueryVar :: new ( rel_label . to_string ( ) , rel_suffix , src_var , dst_var ) ; let info = Info :: new ( src_node_label . to_string ( ) + & * ( ( & rel_label . to_string ( ) . to_title_case ( ) ) . split_whitespace ( ) . collect :: < String > ( ) ) + " " , self . info . type_defs ( ) , ) ; let query_fragment = visit_rel_query_input :: < RequestCtx > ( None , & rel_var , input_value_opt , & info , partition_key_opt , & mut sg , & mut self . transaction , ) . await ? ; let results = self . transaction . read_rels ( query_fragment , & rel_var , //Some(p.type_name()), None , partition_key_opt , ) . await ? ; Ok ( results ) }
Provides an abstracted database rel read operation using warpgrapher inputs.
Provides an abstracted database rel read operation using warpgrapher inputs .
&mut self
src_node_label
&str
rel_label
&str
input
impl TryInto<Value>
partition_key_opt
Option<&Value>
&mut self
src_node_label
&str
rel_label
&str
input
impl TryInto<Value>
partition_key_opt
Option<&Value>
examples
None
use serde_json::json;
None
use warpgrapher::error;
None
use warpgrapher::engine::events::eventfacade;
None
use warpgrapher::engine::objects::rel;
None
use warpgrapher::engine::value::value;
None
use warpgrapher::juniper::boxfuture;
fn before_user_read(value: Value, mut ef: EventFacade<()>) -> BoxFuture> {
Box::pin(async move {
let rels: Vec> = ef.read_rels(
"User",
"teams",
json!({
"src": {"name": {"EQ": "alice"}}
}),
None).await?;
Ok(value)
})
}
```
fn before_user_read ( value : Value mut ef : EventFacade< () > ) - > BoxFuture > { Box :: pin ( async move { let rels : Vec > = ef . read_rels ( " User " " teams " json! ( { " src " : { " name " : { " EQ " : " alice " }} } ) None ) . await? ; Ok ( value ) } ) } ` ` `