pub async fn create_node(
        rf: &'a ResolverFacade<'_, RequestCtx>,
        type_name: &str,
        input: impl TryInto<Value>,
        partition_key_opt: Option<&Value>,
        transaction: &'a mut <<<RequestCtx as RequestContext>::DBEndpointType as DatabaseEndpoint>::PoolType as DatabasePool>::TransactionType,
    ) -> Result<Node<RequestCtx>, Error> {
        let mut sg = SuffixGenerator::new();
        let node_var =
            NodeQueryVar::new(Some(type_name.to_string()), "node".to_string(), sg.suffix());
        let result = visit_node_create_mutation_input(
            &node_var,
            input.try_into().map_err(|_e| Error::TypeConversionFailed {
                src: "".to_string(),
                dst: "".to_string(),
            })?,
            &Info::new(type_name.to_string(), rf.info.type_defs()),
            partition_key_opt,
            &mut sg,
            transaction,
            rf.executor.context(),
        )
        .await;
        result
    }
/// Provides an abstracted database node create operation using warpgrapher inputs. This is the
/// recommended way to read data in a database-agnostic way that ensures the event handlers
/// are portable across different databases.
///
/// # Arguments
///
/// * `type_name` - String reference represing name of node type (ex: "User").
/// * `input` - Optional `Value` describing which node to match. Same input structure passed to a READ crud operation (`<Type>QueryInput`).
/// * `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::database::{DatabasePool, Transaction};
/// # use warpgrapher::engine::resolvers::{ResolverFacade, ExecutionResult};
/// # use warpgrapher::engine::value::Value;
/// # use warpgrapher::juniper::BoxFuture;
///
/// fn custom_resolve(mut facade: ResolverFacade<()>) -> BoxFuture<ExecutionResult> {
///     Box::pin(async move {
///         let mut transaction = facade.executor().context().pool().transaction().await?;
///         transaction.begin().await?;
///         let result = ResolverFacade::create_node(&facade, "User", json!({"name": "alice"}), None, &mut transaction).await;
///         if result.is_ok() {
///             transaction.commit().await?;
///         } else {
///             transaction.rollback().await?;
///         }
///         let alice = result?;
///         std::mem::drop(transaction);
///         facade.resolve_node(&alice).await
///     })
/// }
/// ```
Provides an abstracted database node create operation using warpgrapher inputs. This is the
recommended way to read data in a database-agnostic way that ensures the event handlers
are portable across different databases.
Provides an abstracted database node create operation using warpgrapher inputs . This is the recommended way to read data in a database - agnostic way that ensures the event handlers are portable across different databases .
pub async fn create_node(
        rf: &'a ResolverFacade<'_, RequestCtx>,
        type_name: &str,
        input: impl TryInto<Value>,
        partition_key_opt: Option<&Value>,
        transaction: &'a mut <<<RequestCtx as RequestContext>::DBEndpointType as DatabaseEndpoint>::PoolType as DatabasePool>::TransactionType,
    ) -> Result<Node<RequestCtx>, Error> {
        let mut sg = SuffixGenerator::new();
        let node_var =
            NodeQueryVar::new(Some(type_name.to_string()), "node".to_string(), sg.suffix());
        let result = visit_node_create_mutation_input(
            &node_var,
            input.try_into().map_err(|_e| Error::TypeConversionFailed {
                src: "".to_string(),
                dst: "".to_string(),
            })?,
            &Info::new(type_name.to_string(), rf.info.type_defs()),
            partition_key_opt,
            &mut sg,
            transaction,
            rf.executor.context(),
        )
        .await;
        result
    }
pub async fn create_node ( rf : & ' a ResolverFacade < ' _ , RequestCtx > , type_name : & str , input : impl TryInto < Value > , partition_key_opt : Option < & Value > , transaction : & ' a mut < < < RequestCtx as RequestContext > :: DBEndpointType as DatabaseEndpoint > :: PoolType as DatabasePool > :: TransactionType , ) -> Result < Node < RequestCtx > , Error > { let mut sg = SuffixGenerator :: new ( ) ; let node_var = NodeQueryVar :: new ( Some ( type_name . to_string ( ) ) , " " . to_string ( ) , sg . suffix ( ) ) ; let result = visit_node_create_mutation_input ( & node_var , input . try_into ( ) . map_err ( | _e | Error :: TypeConversionFailed { src : " " . to_string ( ) , dst : " " . to_string ( ) , } ) ? , & Info :: new ( type_name . to_string ( ) , rf . info . type_defs ( ) ) , partition_key_opt , & mut sg , transaction , rf . executor . context ( ) , ) . await ; result }
Provides an abstracted database node create operation using warpgrapher inputs.
Provides an abstracted database node create operation using warpgrapher inputs .
rf
&'a ResolverFacade<'_, RequestCtx>
type_name
&str
input
impl TryInto<Value>
partition_key_opt
Option<&Value>
transaction
&'a mut <<<RequestCtx as RequestContext>::DBEndpointType as DatabaseEndpoint>::PoolType as DatabasePool>::TransactionType
rf
&'a ResolverFacade<'_, RequestCtx>
type_name
&str
input
impl TryInto<Value>
partition_key_opt
Option<&Value>
transaction
&'a mut <<<RequestCtx as RequestContext>::DBEndpointType as DatabaseEndpoint>::PoolType as DatabasePool>::TransactionType
examples
None
use serde_json::json;
None
use warpgrapher::error;
None
use warpgrapher::engine::database::{databasepool, transaction};
None
use warpgrapher::engine::resolvers::{resolverfacade, executionresult};
None
use warpgrapher::engine::value::value;
None
use warpgrapher::juniper::boxfuture;
fn custom_resolve(mut facade: ResolverFacade<()>) -> BoxFuture {
Box::pin(async move {
let mut transaction = facade.executor().context().pool().transaction().await?;
transaction.begin().await?;
let result = ResolverFacade::create_node(&facade, "User", json!({"name": "alice"}), None, &mut transaction).await;
if result.is_ok() {
transaction.commit().await?;
} else {
transaction.rollback().await?;
}
let alice = result?;
std::mem::drop(transaction);
facade.resolve_node(&alice).await
})
}
```
fn custom_resolve ( mut facade : ResolverFacade< () > ) - > BoxFuture { Box :: pin ( async move { let mut transaction = facade . executor () . context () . pool () . transaction () . await? ; transaction . begin () . await? ; let result = ResolverFacade :: create_node ( &facade " User " json! ( { " name " : " alice " } ) None &mut transaction ) . await ; if result . is_ok () { transaction . commit () . await? ; } else { transaction . rollback () . await? ; } let alice = result? ; std :: mem :: drop ( transaction ) ; facade . resolve_node ( &alice ) . await } ) } ` ` `