@classmethod
def _map_graph(api, defn, path_processor):
    """travel the graph from this element down until we either stop or locate
        a cycle.  each visit occurs within the scope of a root element, forming
        multiple trees as we flatten the graph out.
        """
    api._instrument_read_method(defn, path_processor)
    if defn.create != None or defn.update != None:
        api._instrument_write_or_create_method(defn, path_processor)
    if defn.delete != None:
        api._instrument_delete_method(defn, path_processor)
    for action in defn.actions:
        api._instrument_action(defn, path_processor, action)
    for c_name, c_defn, c_index in defn.collections:
        api._instrument_collection(defn, path_processor.for_child(c_name),
            c_name, c_index)
        api._map_graph(c_defn, path_processor.for_collection(c_name, c_index))
    for s_name, s_defn in defn.scalars:
        api._map_graph(s_defn, path_processor.for_child(s_name))
