def test_06_delete_keeps_node_if_other_edges_exist(neo4j_graph_store: Neo4jGraphStore):
    """
    Test that only the specified relationship is removed,
    and the subject/object are deleted only if they have no other edges.
    """
    store = neo4j_graph_store
    # Insert two edges: X->REL->Y and X->OTHER->Z
    store.upsert_triplet("X", "REL", "Y")
    store.upsert_triplet("X", "OTHER", "Z")

    # Delete the first relationship
    store.delete("X", "REL", "Y")

    # 'Y' should be gone if no other edges, but X must remain (it still has an edge to Z).
    # Confirm X->OTHER->Z still exists
    results_x = store.get("X")
    assert len(results_x) == 1
    assert results_x[0] == ["OTHER", "Z"]

    # 'Y' should have 0 edges
    results_y = store.get("Y")
    assert len(results_y) == 0

    Test that only the specified relationship is removed,
    and the subject/object are deleted only if they have no other edges.
    
llama-index-integrations/graph_stores/llama-index-graph-stores-neo4j/tests/test_graph_stores_neo4j.py