Enum warpgrapher::client::Client
source · [−]pub enum Client<RequestCtx: RequestContext> {
Http {
endpoint: String,
headers: HeaderMap,
},
Local {
engine: Box<Engine<RequestCtx>>,
metadata: Option<HashMap<String, String>>,
},
}
Expand description
Variants
Http
Local
Implementations
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();
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);
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
underdata
will be returned. IfNone
, thedata
object will be returned.
Return
A serde_json::Value
containing the query response
Errors
ClientRequestFailed
- if the HTTP response is a non-OKPayloadNotFound
- if the JSON response body is not a valid GraphQL response
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;
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:
ClientRequestFailed
- if the HTTP response is a non-OKPayloadNotFound
- if the JSON response body is not a valid GraphQL response
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;
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:
ClientRequestFailed
- if the HTTP response is a non-OKPayloadNotFound
- if the JSON response body is not a valid GraphQL response
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;
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:
ClientRequestFailed
- if the HTTP response is a non-OKPayloadNotFound
- if the JSON response body is not a valid GraphQL response
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;
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:
ClientRequestFailed
- if the HTTP response is a non-OKPayloadNotFound
- if the JSON response body is not a valid GraphQL response
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;
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:
ClientRequestFailed
- if the HTTP response is a non-OKPayloadNotFound
- if the JSON response body is not a valid GraphQL response
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;
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:
ClientRequestFailed
- if the HTTP response is a non-OKPayloadNotFound
- if the JSON response body is not a valid GraphQL response
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;
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:
ClientRequestFailed
- if the HTTP response is a non-OKPayloadNotFound
- if the JSON response body is not a valid GraphQL response
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;
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:
ClientRequestFailed
- if the HTTP response is a non-OKPayloadNotFound
- if the JSON response body is not a valid GraphQL response
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
Auto Trait Implementations
impl<RequestCtx> RefUnwindSafe for Client<RequestCtx> where
RequestCtx: RefUnwindSafe,
<<RequestCtx as RequestContext>::DBEndpointType as DatabaseEndpoint>::PoolType: RefUnwindSafe,
impl<RequestCtx> UnwindSafe for Client<RequestCtx> where
RequestCtx: RefUnwindSafe,
<<RequestCtx as RequestContext>::DBEndpointType as DatabaseEndpoint>::PoolType: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
pub fn vzip(self) -> V
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