Struct warpgrapher::engine::events::EventFacade
source · [−]pub struct EventFacade<'a, RequestCtx> where
RequestCtx: RequestContext, { /* private fields */ }
Expand description
Provides a simplified interface to utility operations inside an event handler.
Implementations
sourceimpl<'a, RequestCtx> EventFacade<'a, RequestCtx> where
RequestCtx: RequestContext,
impl<'a, RequestCtx> EventFacade<'a, RequestCtx> where
RequestCtx: RequestContext,
sourcepub fn op(&self) -> &CrudOperation
pub fn op(&self) -> &CrudOperation
Returns the context of the GraphQL request which in turn contains the application-defined request context.
sourcepub fn context(&self) -> &'a GraphQLContext<RequestCtx>
pub fn context(&self) -> &'a GraphQLContext<RequestCtx>
Returns the context of the GraphQL request which in turn contains the application-defined request context.
sourcepub async fn read_nodes(
&mut self,
type_name: &str,
input: impl TryInto<Value>,
partition_key_opt: Option<&Value>
) -> Result<Vec<Node<RequestCtx>>, Error>
pub async fn read_nodes(
&mut self,
type_name: &str,
input: impl TryInto<Value>,
partition_key_opt: Option<&Value>
) -> Result<Vec<Node<RequestCtx>>, Error>
Provides an abstracted database read 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
- OptionalValue
describing which node to match. Same input structure passed to a READ crud operation (<Type>QueryInput
).partition_key_opt
- OptionalValue
describing the partition key if the underlying database supports it.
Examples
fn before_user_read(value: Value, mut ef: EventFacade<()>) -> BoxFuture<Result<Value, Error>> {
Box::pin(async move {
let nodes_to_be_read = ef.read_nodes("User", value.clone(), None).await?;
// modify value before passing it forward ...
Ok(value)
})
}
sourcepub async fn create_node(
&mut self,
type_name: &str,
input: impl TryInto<Value>,
partition_key_opt: Option<&Value>
) -> Result<Node<RequestCtx>, Error>
pub async fn create_node(
&mut self,
type_name: &str,
input: impl TryInto<Value>,
partition_key_opt: Option<&Value>
) -> Result<Node<RequestCtx>, Error>
Provides an abstracted database create operation using warpgrapher inputs. This is the recommended way to create nodes 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
-Value
describing the node to create.partition_key_opt
- OptionalValue
describing the partition key if the underlying database supports it.
Examples
fn before_user_read(value: Value, mut ef: EventFacade<()>) -> BoxFuture<Result<Value, Error>> {
Box::pin(async move {
let new_node = ef.create_node("Team", value.clone(), None).await?;
Ok(value)
})
}
sourcepub async fn update_node(
&mut self,
type_name: &str,
input: impl TryInto<Value>,
partition_key_opt: Option<&Value>
) -> Result<Vec<Node<RequestCtx>>, Error>
pub async fn update_node(
&mut self,
type_name: &str,
input: impl TryInto<Value>,
partition_key_opt: Option<&Value>
) -> Result<Vec<Node<RequestCtx>>, Error>
Provides an abstracted database update operation using warpgrapher inputs. This is the recommended way to create nodes 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
-Value
describing the node to update.partition_key_opt
- OptionalValue
describing the partition key if the underlying database supports it.
Examples
fn before_user_read(value: Value, mut ef: EventFacade<()>) -> BoxFuture<Result<Value, Error>> {
Box::pin(async move {
let new_node = ef.update_node(
"User",
json!({
"MATCH": {"name": {"EQ": "alice"}},
"SET": {"name": "eve"}
}),
None).await?;
Ok(value)
})
}
sourcepub async fn delete_node(
&mut self,
type_name: &str,
input: impl TryInto<Value>,
partition_key_opt: Option<&Value>
) -> Result<i32, Error>
pub async fn delete_node(
&mut self,
type_name: &str,
input: impl TryInto<Value>,
partition_key_opt: Option<&Value>
) -> Result<i32, Error>
Provides an abstracted database delete operation using warpgrapher inputs. This is the recommended way to create nodes 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
-Value
describing the node to update.partition_key_opt
- OptionalValue
describing the partition key if the underlying database supports it.
Examples
fn before_user_read(value: Value, mut ef: EventFacade<()>) -> BoxFuture<Result<Value, Error>> {
Box::pin(async move {
let new_node = ef.delete_node(
"User",
json!({
"MATCH": {"name": {"EQ": "alice"}}
}),
None).await?;
Ok(value)
})
}
sourcepub 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>
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>
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
- OptionalValue
describing the partition key if the underlying database supports it.
Examples
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)
})
}
Auto Trait Implementations
impl<'a, RequestCtx> !RefUnwindSafe for EventFacade<'a, RequestCtx>
impl<'a, RequestCtx> Send for EventFacade<'a, RequestCtx>
impl<'a, RequestCtx> Sync for EventFacade<'a, RequestCtx>
impl<'a, RequestCtx> Unpin for EventFacade<'a, RequestCtx>
impl<'a, RequestCtx> !UnwindSafe for EventFacade<'a, RequestCtx>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
pub fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more