You can pass the weight as extra parameter like:
graph.setEdge(A, B, { weight });
Then, when using dagre algorithm like dijkstra you can override the weighting function like:
const paths = dagre.graphlib.alg.dijkstra(graph, root, (e) => {
const edge = graph.edge(e);
return edge.weight;
})