def _build_execution_route(self) -> dict[tuple[UUID, UUID], list[Optional[UUID]]]:
        """Construct an execution route for the DAG.

        Maps a tuple of a producer node id with a entity definition id to a consumer node id.

        If the entity is sent to a destination, the route is set to None, this stops the entity
        from being routed further.
        """
        route_map = {}
        for node in self.dag.nodes:
            if node.type == NodeType.entity:
                edge_inwards = self.dag.get_edges_to_node(node.id)

                # Get the producer node
                producer = edge_inwards[0].from_node_id

                edges_outwards = self.dag.get_edges_from_node(node.id)

                # Check if all outgoing edges go to destination nodes
                if edges_outwards:
                    all_destinations = True
                    for edge in edges_outwards:
                        consumer_node = self.dag.get_node(edge.to_node_id)
                        if consumer_node.type != NodeType.destination:
                            all_destinations = False
                            break

                    if all_destinations:
                        # If all outgoing edges go to destinations, stop routing
                        route_map[(producer, node.entity_definition_id)] = None
                    elif len(edges_outwards) == 1:
                        # If there's only one outgoing edge and it's not to a destination,
                        # route to that node
                        route_map[(producer, node.entity_definition_id)] = edges_outwards[
                            0
                        ].to_node_id
                    else:
                        # If there are multiple outgoing edges and not all go to destinations,
                        # this is an invalid configuration
                        raise ValueError(
                            f"Entity node {node.id} has multiple outbound edges "
                            "to non-destination nodes."
                        )
                else:
                    # No outgoing edges, this is a terminal node
                    route_map[(producer, node.entity_definition_id)] = None

        return route_map
Construct an execution route for the DAG.

        Maps a tuple of a producer node id with a entity definition id to a consumer node id.

        If the entity is sent to a destination, the route is set to None, this stops the entity
        from being routed further.
        
backend/airweave/platform/sync/router.py