def next_child_ordering(cnx, parent_eid, rtype):
    """Return value for the `ordering` attribute of a child freshly appended through
    `rtype` to parent entity with the given eid.
    """
    rql = 'Any MAX(O) WHERE X {rtype} P, P eid %(p)s, X ordering O'
    ordering = cnx.execute(rql.format(rtype=rtype), {'p': parent_eid})[0][0]
    return 1 if ordering is None else ordering + 1
