pub struct EventFacade<'a, RequestCtx> where
    RequestCtx: RequestContext
{ /* private fields */ }
Expand description

Provides a simplified interface to utility operations inside an event handler.

Implementations

Returns the context of the GraphQL request which in turn contains the application-defined request context.

Returns the context of the GraphQL request which in turn contains the application-defined request context.

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)
    })
}

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 - Optional Value 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)
    })
}

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)
    })
}

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)
    })
}

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)
    })
}

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)
    })
}

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 input
  • options - 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)
    })
}

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 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 _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)
    })
}

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 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 _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

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more