def delete_subgraph(tx, subgraph):
    """ Delete data in a remote :class:`.Graph` based on a local
    :class:`.Subgraph`.

    :param tx:
    :param subgraph:
    :return:
    """
    graph = tx.graph
    node_identities = []
    for relationship in subgraph.relationships:
        if relationship.graph is graph:
            graph.relationship_cache.update(relationship.identity, None)
            relationship.graph = None
            relationship.identity = None
    for node in subgraph.nodes:
        if node.graph is graph:
            graph.node_cache.update(node.identity, None)
            node_identities.append(node.identity)
            node.graph = None
            node.identity = None
    list(tx.run('MATCH (_) WHERE id(_) IN $x DETACH DELETE _', x=
        node_identities))
