Unverified Commit 574a966b authored by Vasili Novikov's avatar Vasili Novikov
Browse files

Allow creating Edge items via the create_item API

parent 7fed938b
Showing with 17 additions and 15 deletions
+17 -15
......@@ -84,14 +84,6 @@ pub fn create_item_tx(
cli: &CliOptions,
database_key: &DatabaseKey,
) -> Result<String> {
if schema::is_edge(&item._type) {
return Err(Error {
code: StatusCode::BAD_REQUEST,
msg: "Cannot create edges via item addition API. Use create_edge or similar APIs \
in order to also create _source, _target bindings"
.to_string(),
});
};
let id: String = if let Some(id) = &item.id {
id.to_string()
} else {
......@@ -607,6 +599,23 @@ mod tests {
};
}
#[test]
/// Test creating an item that has type="Edge"
fn test_create_edge_item() {
let mut conn = new_conn();
let cli = command_line_interface::tests::test_cli();
let db_key = DatabaseKey::from("".to_string()).unwrap();
let tx = conn.transaction().unwrap();
let mut schema = database_api::get_schema(&tx).unwrap();
let edge_item = json!({
"type": "Edge",
});
let edge_item: CreateItem = serde_json::from_value(edge_item).unwrap();
// Creating raw "Edge" items should be successful.
// (It is also the way how Memri clients push edge information to the Pod.)
create_item_tx(&tx, &mut schema, edge_item, "", &cli, &db_key).unwrap();
}
#[test]
fn test_edge_search() {
let mut conn = new_conn();
......
......@@ -89,13 +89,6 @@ fn validate_property_name_syntax(property: &str) -> Result<()> {
}
}
/// Returns whether an item type is an "Edge".
/// Currently, only literally "Edge" item type is an edge. This implementation is UNSTABLE.
/// See `docs/HTTP_API.md` for details.
pub fn is_edge(item_type: &str) -> bool {
item_type == "Edge"
}
/// All item properties should be of this format
pub fn validate_property_name(property: &str) -> Result<()> {
if let Err(err) = validate_property_name_syntax(property) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment