def predecessors_query(var_name, node_id, node_label, edge_label,
    predecessor_label=None):
    """Generate query for getting the ids of all the predecessors of a node.

    Parameters
    ----------
    var_name
        Name of the variable corresponding to the node to match
    node_id
        Id of the node to match
    node_label
        Label of the node to match
    edge_label
        Label of the edge to match
    predecessor_label
        Label of the predecessors we want to find. node_label if None.
    """
    if predecessor_label is None:
        predecessor_label = node_label
    query = "OPTIONAL MATCH (pred:{})-[:{}]-> (n:{} {{id : '{}'}})\n".format(
        predecessor_label, edge_label, node_label, node_id
        ) + 'RETURN pred.id as pred'
    return query
