Enum warpgrapher::client::Client[][src]

pub enum Client<RequestCtx: RequestContext> {
    Http {
        endpoint: String,
        headers: HeaderMap,
    },
    Local {
        engine: Box<Engine<RequestCtx>>,
        metadata: Option<HashMap<String, String>>,
    },
}

A Warpgrapher GraphQL client

The Client provides a set of CRUD operations that will automatically generate GraphQL queries that conform to the wargrapher API

Examples


let client = Client::<()>::new_with_http("http://localhost:5000/graphql", None).unwrap();

Variants

Http

Fields of Http

endpoint: Stringheaders: HeaderMap
Local

Fields of Local

engine: Box<Engine<RequestCtx>>metadata: Option<HashMap<String, String>>

Implementations

impl<RequestCtx: RequestContext> Client<RequestCtx>[src]

pub fn new_with_http(
    endpoint: &str,
    headers_opt: Option<HashMap<&str, &str>>
) -> Result<Client<RequestCtx>, Error>
[src]

Takes the URL of a Warpgrapher service endpoint and returns a new [‘Client’] initialized to query that endpoint. The type parameters are only relevant for a local instance of the Warpgrapher engine, not for a remote HTTP client, so pass () for both type parameters, as shown in the example below.

Examples


let mut client = Client::<()>::new_with_http("http://localhost:5000/graphql", None).unwrap();

pub fn new_with_engine(
    engine: Engine<RequestCtx>,
    metadata: Option<HashMap<String, String>>
) -> Client<RequestCtx>
[src]

Takes a Warpgrapher engine and returns a new [‘Client’] initialized to query that engine. The type parameter is the RequestContext used by the engine.

Examples


let c = Configuration::new(1, Vec::new(), Vec::new());
let endpoint = NoDatabaseEndpoint {};
let engine = Engine::new(c, endpoint.pool().await?).build()?;

let mut client = Client::<()>::new_with_engine(engine, None);

pub async fn graphql(
    &mut self,
    query: &str,
    partition_key: Option<&str>,
    input: Option<&Value>,
    result_field_opt: Option<&str>
) -> Result<Value, Error>
[src]

Executes a graphql query

Arguments

  • query - text of the query statement, parameterized to avoid query injection attacks
  • partition_key - used to scope a query to a Cosmos DB partition. In future, when Neo4J is supported, it is anticipated that the partition_key will be used to select among Neo4J fabric shards.
  • input - a serde_json::Value, specifically a Value::Object, containing the arguments to the graph query
  • result_field - an optional name of a field under ‘data’ that holds the GraphQL response. If present, the object with name result_field under data will be returned. If None, the data object will be returned.

Return

A serde_json::Value containing the query response

Errors

Examples


let mut client = Client::<()>::new_with_http("http://localhost:5000/graphql", None).unwrap();

let query = "query { Project { id name } }";
let results = client.graphql("query { Project { id name } }", Some("1234"), None,
    Some("Project")).await;

pub async fn create_node(
    &mut self,
    type_name: &str,
    shape: &str,
    partition_key: Option<&str>,
    input: &Value
) -> Result<Value, Error>
[src]

Creates a node

Arguments

  • type_name - the name of the Type for which to create a node
  • shape - the GraphQL query shape, meaning the selection of objects and properties to be returned in the query result
  • partition_key - the partition_key is used to scope a query to a Cosmos DB partition. In future, when Neo4J is supported, it is anticipated that the partition_key will be used to select among Neo4J fabric shards.
  • input - a serde_json::Value, specifically a Value::Object, containing the arguments to the graph query

Return

A serde_json::Value containing the query response

Errors

Returns an Error of the following kinds:

Examples


let mut client = Client::<()>::new_with_http("http://localhost:5000/graphql", None).unwrap();

let projects = client.create_node("Project", "id name description", Some("1234"),
    &json!({"name": "TodoApp", "description": "Action list tracking application"})).await;

pub async fn create_rel(
    &mut self,
    type_name: &str,
    rel_name: &str,
    shape: &str,
    partition_key: Option<&str>,
    match_input: &Value,
    create_input: &Value
) -> Result<Value, Error>
[src]

Creates one or more relationships

Arguments

  • type_name - the name of the Type for which to create a relationship
  • rel_name - the name of the Relationship to create
  • shape - the GraphQL query shape, meaning the selection of objects and properties to be returned in the query result
  • partition_key - the partition_key is used to scope a query to a Cosmos DB partition. In future, when Neo4J is supported, it is anticipated that the partition_key will be used to select among Neo4J fabric shards.
  • match_input - a serde_json::Value, specifically a Value::Object, containing the arguments to the graph query to select the node(s) on which to create the relationship
  • create_input - a serde_json::Value, specifically a Value::Object, containing the arguments to the graph query to use in creating the relationship

Return

A serde_json::Value containing the query response

Errors

Returns an Error of the following kinds:

Examples


let mut client = Client::<()>::new_with_http("http:://localhost:5000/graphql", None).unwrap();

let proj_issues = client.create_rel("Project",
    "issues",
    "id props { since } src { id name } dst { id name }",
    Some("1234"),
    &json!({"name": "ProjectName"}),
    &json!({"props": {"since": "2000"},
           "dst": {"Feature": {"NEW": {"name": "NewFeature"}}}})
).await;

pub async fn delete_node(
    &mut self,
    type_name: &str,
    partition_key: Option<&str>,
    match_input: Option<&Value>,
    delete_input: Option<&Value>
) -> Result<Value, Error>
[src]

Deletes one or more nodes

Arguments

  • type_name - the name of the Type of the node to delete
  • partition_key - the partition_key is used to scope a query to a Cosmos DB partition. In future, when Neo4J is supported, it is anticipated that the partition_key will be used to select among Neo4J fabric shards.
  • match_input - a serde_json::Value, specifically a Value::Object, containing the arguments to the graph query to select the node(s) on which to create the relationship
  • delete_input - a serde_json::Value, specifically a Value::Object, containing the arguments to the graph query to use in deleting the relationship. By default, all relationships incoming to and outgoing from the node are deleted. The delete input argument allows for extending the delete operation through relationships to destination nodes.

Return

A serde_json::Value containing the query response, a count of the nodes deleted

Errors

Returns an Error of the following kinds:

Examples


let mut client = Client::<()>::new_with_http("http://localhost:5000/graphql", None).unwrap();

let projects = client.delete_node("Project", Some("1234"),
    Some(&json!({"name": "MJOLNIR"})), None).await;

pub async fn delete_rel(
    &mut self,
    type_name: &str,
    rel_name: &str,
    partition_key: Option<&str>,
    match_input: Option<&Value>,
    src_input: Option<&Value>,
    dst_input: Option<&Value>
) -> Result<Value, Error>
[src]

Deletes one or more relationships

Arguments

  • type_name - the name of the Type for which to delete a relationship
  • rel_name - the name of the Relationship to delete
  • partition_key - the partition_key is used to scope a query to a Cosmos DB partition. In future, when Neo4J is supported, it is anticipated that the partition_key will be used to select among Neo4J fabric shards.
  • match_input - a serde_json::Value, specifically a Value::Object, containing the arguments to the graph query to select the relationship(s) to delete
  • src_input - a serde_json::Value, specifically a Value::Object, containing the arguments to the graph query to use in deleting the src node. By default, nodes are not deleted along with a relationship, but this parameter can be used to delete the source of the relationship as well.
  • dst_input - a serde_json::Value, specifically a Value::Object, containing the arguments to the graph query to use in deleting the destination node. By default, nodes are not deleted along with a relationship, but this parameter can be used to delete the destination node of the relationship as well.

Return

A serde_json::Value containing the query response, a count of the relationships deleted

Errors

Returns an Error of the following kinds:

Examples


let mut client = Client::<()>::new_with_http("http:://localhost:5000/graphql", None).unwrap();

let proj_issues = client.delete_rel("Project", "issues",
   Some("1234"),
   Some(&json!({"props": {"since": "2000"}})),
   None,
   Some(&json!({"Bug": {}}))
).await;

pub async fn read_node(
    &mut self,
    type_name: &str,
    shape: &str,
    partition_key: Option<&str>,
    input: Option<&Value>
) -> Result<Value, Error>
[src]

Queries to retrieve one or more nodes

Arguments

  • type_name - the name of the Type to be retrieved
  • shape - the GraphQL query shape, meaning the selection of objects and properties to be returned in the query result
  • partition_key - the partition_key is used to scope a query to a Cosmos DB partition. In future, when Neo4J is supported, it is anticipated that the partition_key will be used to select among Neo4J fabric shards.
  • input - a serde_json::Value, specifically a Value::Object, containing the arguments to the graph query

Return

A Value containing the query response

Errors

Returns an Error of the following kinds:

Examples


let mut client = Client::<()>::new_with_http("http://localhost:5000/graphql", None).unwrap();

let projects = client.read_node("Project", "id name description", Some("1234"),
    None).await;

pub async fn read_rel(
    &mut self,
    type_name: &str,
    rel_name: &str,
    shape: &str,
    partition_key: Option<&str>,
    input: Option<&Value>
) -> Result<Value, Error>
[src]

Queries for one or more relationships

Arguments

  • type_name - the name of the Type for the source node in the relationship
  • rel_name - the name of the Relationship to find
  • shape - the GraphQL query shape, meaning the selection of objects and properties to be returned in the query result
  • partition_key - the partition_key is used to scope a query to a Cosmos DB partition. In future, when Neo4J is supported, it is anticipated that the partition_key will be used to select among Neo4J fabric shards.
  • input - a serde_json::Value, specifically a Value::Object, containing the arguments to the graph query to select the relationship(s) to return

Return

A serde_json::Value containing the query response

Errors

Returns an Error of the following kinds:

Examples


let mut client = Client::<()>::new_with_http("http:://localhost:5000/graphql", None).unwrap();

let proj_issues = client.read_rel("Project", "issues", "id props { since }",
    Some("1234"), Some(&json!({"props": {"since": "2000"}}))).await;

pub async fn update_node(
    &mut self,
    type_name: &str,
    shape: &str,
    partition_key: Option<&str>,
    match_input: Option<&Value>,
    update_input: &Value
) -> Result<Value, Error>
[src]

Updates one or more nodes

Arguments

  • type_name - the name of the Type to be updated
  • shape - the GraphQL query shape, meaning the selection of objects and properties to be returned in the query result
  • partition_key - the partition_key is used to scope a query to a Cosmos DB partition. In future, when Neo4J is supported, it is anticipated that the partition_key will be used to select among Neo4J fabric shards.
  • match_input - a serde_json::Value, specifically a Value::Object, containing the arguments to the graph query used to select the set of nodes to update
  • update_input - a serde_json::Value, specifically a Value::Object, containing the arugments to the graph query used to change the properties of the nodes being updated

Return

A serde_json::Value containing the query response

Errors

Returns an Error of the following kinds:

Examples


    let mut client = Client::<()>::new_with_http("http://localhost:5000/graphql", None).unwrap();

    let projects = client.update_node("Project", "id name status", Some("1234"),
        Some(&json!({"name": "TodoApp"})), &json!({"status": "ACTIVE"})).await;

pub async fn update_rel(
    &mut self,
    type_name: &str,
    rel_name: &str,
    shape: &str,
    partition_key: Option<&str>,
    match_input: Option<&Value>,
    update_input: &Value
) -> Result<Value, Error>
[src]

Updates one or more relationships

Arguments

  • type_name - the name of the Type for the source node in the relationship(s) to update
  • rel_name - the name of the Relationship to find and update
  • shape - the GraphQL query shape, meaning the selection of objects and properties to be returned in the query result
  • partition_key - the partition_key is used to scope a query to a Cosmos DB partition. In future, when Neo4J is supported, it is anticipated that the partition_key will be used to select among Neo4J fabric shards.
  • match_input - a serde_json::Value, specifically a Value::Object, containing the arguments to the graph query used to select the set of relationships to update
  • update_input - a serde_json::Value, specifically a Value::Object, containing the arguments to the graph query used to change the properties of the items being updated

Return

A serde_json::Value containing the query response

Errors

Returns an Error of the following kinds:

Examples


let mut client = Client::<()>::new_with_http("http:://localhost:5000/graphql", None).unwrap();

let proj_issues = client.update_rel("Project", "issues",
    "id props {since} src {id name} dst {id name}",
    Some("1234"),
    Some(&json!({"props": {"since": "2000"}})),
    &json!({"props": {"since": "2010"}})
).await;

Trait Implementations

impl<RequestCtx: Clone + RequestContext> Clone for Client<RequestCtx>[src]

impl<RequestCtx: Debug + RequestContext> Debug for Client<RequestCtx>[src]

impl<R> Display for Client<R> where
    R: RequestContext
[src]

Auto Trait Implementations

impl<RequestCtx> RefUnwindSafe for Client<RequestCtx> where
    RequestCtx: RefUnwindSafe,
    <<RequestCtx as RequestContext>::DBEndpointType as DatabaseEndpoint>::PoolType: RefUnwindSafe

impl<RequestCtx> Send for Client<RequestCtx>

impl<RequestCtx> Sync for Client<RequestCtx>

impl<RequestCtx> Unpin for Client<RequestCtx>

impl<RequestCtx> UnwindSafe for Client<RequestCtx> where
    RequestCtx: RefUnwindSafe,
    <<RequestCtx as RequestContext>::DBEndpointType as DatabaseEndpoint>::PoolType: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T> Instrument for T[src]

impl<T> Instrument for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,