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 execute_query(
&mut self,
query: String,
params: HashMap<String, Value>
) -> Result<QueryResult, Error>
pub async fn execute_query(
&mut self,
query: String,
params: HashMap<String, Value>
) -> Result<QueryResult, Error>
Provides a direct database query operation. This is recommended when it is necessary to bypass the event handlers that will be triggered from a standard warpgrapher query.
Arguments
query
- String of the query to execute.params
- HashMap<String, Value> dictionary of parameters to pass to the query.
Examples
fn before_user_read(value: Value, mut ef: EventFacade<()>) -> BoxFuture<Result<Value, Error>> {
Box::pin(async move {
let query = "MATCH (u:User) WHERE u.id IN $user_ids SET u.active = true RETURN u".to_string();
let mut params = HashMap::new();
if let Value::Map(hm) = &value {
if let Value::Map(m) = hm.get("MATCH").unwrap() {
if let Value::Map(i) = m.get("id").unwrap() {
if let Value::Array(a) = i.get("IN").unwrap() {
params.insert("user_ids".to_string(), Value::Array(a.clone()));
};
};
};
};
ef.execute_query(
query,
params,
).await?;
Ok(value)
})
}
sourcepub async fn read_nodes(
&mut self,
type_name: &str,
input: impl TryInto<Value>,
options: Options
) -> Result<Vec<Node<RequestCtx>>, Error>
pub async fn read_nodes(
&mut self,
type_name: &str,
input: impl TryInto<Value>,
options: Options
) -> 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
).options
- Optional structure with arguments that affect the behavior of the query
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(), Options::default()).await?;
// modify value before passing it forward ...
Ok(value)
})
}
sourcepub async fn create_node(
&mut self,
type_name: &str,
input: impl TryInto<Value>,
options: Options
) -> Result<Node<RequestCtx>, Error>
pub async fn create_node(
&mut self,
type_name: &str,
input: impl TryInto<Value>,
options: Options
) -> 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.options
- Options affecting how a query is performed, such as sort ordering
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(), Options::default()).await?;
Ok(value)
})
}
sourcepub async fn update_nodes(
&mut self,
type_name: &str,
input: impl TryInto<Value>,
options: Options
) -> Result<Vec<Node<RequestCtx>>, Error>
pub async fn update_nodes(
&mut self,
type_name: &str,
input: impl TryInto<Value>,
options: Options
) -> 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.options
- Optional arguments describing how a query is performed, such as a sort order
Examples
fn before_user_read(value: Value, mut ef: EventFacade<()>) -> BoxFuture<Result<Value, Error>> {
Box::pin(async move {
let new_node = ef.update_nodes(
"User",
json!({
"MATCH": {"name": {"EQ": "alice"}},
"SET": {"name": "eve"}
}),
Options::default()).await?;
Ok(value)
})
}
sourcepub async fn delete_nodes(
&mut self,
type_name: &str,
input: impl TryInto<Value>,
options: Options
) -> Result<i32, Error>
pub async fn delete_nodes(
&mut self,
type_name: &str,
input: impl TryInto<Value>,
options: Options
) -> 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.options
- Optional arguments affecting a query, such as a sort order
Examples
fn before_user_read(value: Value, mut ef: EventFacade<()>) -> BoxFuture<Result<Value, Error>> {
Box::pin(async move {
let new_node = ef.delete_nodes(
"User",
json!({
"MATCH": {"name": {"EQ": "alice"}}
}),
Options::default()).await?;
Ok(value)
})
}
sourcepub async fn read_rels(
&mut self,
src_node_label: &str,
rel_label: &str,
input: impl TryInto<Value>,
options: Options
) -> Result<Vec<Rel<RequestCtx>>, Error>
pub async fn read_rels(
&mut self,
src_node_label: &str,
rel_label: &str,
input: impl TryInto<Value>,
options: Options
) -> 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.options
- Optional arguments affecting a query, such as a sort order
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"}}
}),
Options::default()).await?;
Ok(value)
})
}
sourcepub async fn create_rels(
&mut self,
src_node_label: &str,
rel_label: &str,
input: impl TryInto<Value>,
options: Options
) -> Result<Vec<Rel<RequestCtx>>, Error>
pub async fn create_rels(
&mut self,
src_node_label: &str,
rel_label: &str,
input: impl TryInto<Value>,
options: Options
) -> Result<Vec<Rel<RequestCtx>>, Error>
Provides an abstracted database create operation using warpgrapher inputs. This is the recommended way to create 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 creation inputoptions
- Optional arguments affecting a query, such a sort order
Examples
fn before_user_read(value: Value, mut ef: EventFacade<()>) -> BoxFuture<Result<Value, Error>> {
Box::pin(async move {
let _new_rels = ef.create_rels(
"User",
"teams",
json!({
"MATCH": {"name": {"EQ": "alice"}},
"CREATE": {
"sort_order": 1,
"dst": {
"Team": {
"NEW": {
"name": "project_team_name"
}
}
}
}
}),
Options::default()).await?;
Ok(value)
})
}
sourcepub async fn update_rels(
&mut self,
src_node_label: &str,
rel_label: &str,
input: impl TryInto<Value>,
options: Options
) -> Result<Vec<Rel<RequestCtx>>, Error>
pub async fn update_rels(
&mut self,
src_node_label: &str,
rel_label: &str,
input: impl TryInto<Value>,
options: Options
) -> Result<Vec<Rel<RequestCtx>>, Error>
Provides an abstracted database update operation using warpgrapher inputs. This is the recommended way to update 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 update inputoptions
- Optional arguments affecting a query, such as a sort order
Examples
fn before_user_read(value: Value, mut ef: EventFacade<()>) -> BoxFuture<Result<Value, Error>> {
Box::pin(async move {
let _updated_rels = ef.update_rels(
"User",
"teams",
json!({
"MATCH": {"src": {"name": {"EQ": "alice"}}, "dst": {"name": {"EQ": "project_team_name"}}},
"SET": {"sort_order": 2}
}),
Options::default()).await?;
Ok(value)
})
}
sourcepub async fn delete_rels(
&mut self,
src_node_label: &str,
rel_label: &str,
input: impl TryInto<Value>,
options: Options
) -> Result<i32, Error>
pub async fn delete_rels(
&mut self,
src_node_label: &str,
rel_label: &str,
input: impl TryInto<Value>,
options: Options
) -> Result<i32, Error>
Provides an abstracted database delete operation using warpgrapher inputs. This is the recommended way to delete 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 src node type type (ex: “User”).rel_label
- String reference representing the name of the relationship (ex: “teams”)input
-Value
describing the relationship delete inputoptions
- Optional arguments affecting a query, such as a sort order
Examples
fn before_user_read(value: Value, mut ef: EventFacade<()>) -> BoxFuture<Result<Value, Error>> {
Box::pin(async move {
let _deleted_rel_count = ef.delete_rels(
"User",
"teams",
json!({
"MATCH": {"src": {"Card": {"name": {"EQ": "alice"}}},
"dst": {"Team": {"name": {"EQ": "project_team_name"}}}}
}),
Options::default()).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 · sourcefn borrow_mut(&mut self) -> &mut T
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>,
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