How to label complex edges with graph library?

If you're only trying to create flow-charts, it would be much easier if you use pure tikz without a library. Here's an example from the tikz example site (slightly modified).

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes}
\begin{document}

  \tikzstyle{decision} = [diamond, draw, fill=gray!20, 
  text width=4.5em, text badly centered, node distance=3cm, inner sep=0pt]
  \tikzstyle{block} = [rectangle, draw, fill=gray!15, 
  text width=5em, text centered, rounded corners, minimum height=4em]
  \tikzstyle{altblock} = [rectangle, draw, fill=gray!15, 
    text width=5em, text centered, rounded corners=6pt, minimum height=2em]
  \tikzstyle{line} = [draw, -latex']
  \tikzstyle{cloud} = [draw, ellipse,fill=gray!10, node distance=3cm,
  minimum height=2em]
    \begin{tikzpicture}[node distance = 3cm, auto,scale=0.75,transform shape]
    % Place nodes
    \node [altblock] (init) {initialize};
    \node [cloud, left of=init] (expert) {expert};
    \node [cloud, right of=init] (system) {system};
    \node [decision, below of=init] (identify) {Was successful?};
    \node [block, below of=identify] (evaluate) {evaluate candidate models};
    \node [block, left of=evaluate, node distance=3cm] (update) {update model};
    \node [decision, below of=evaluate] (decide) {is best candidate better?};
    \node [block, below of=decide, node distance=3cm] (stop) {stop};
    % Draw edges
    \path [line] (init) -- (identify);
    \path [line] (identify) -- node[auto] {yes} (evaluate);
    \path [line] (identify) -| node[auto,right] {no} (system);
    \path [line] (evaluate) -- (decide);
    \path [line] (decide) -| node [near start] {yes} (update);
    \path [line] (update) |- (identify);
    \path [line] (decide) -- node {no}(stop);
    \path [line,dashed] (expert) -- (init);
    \path [line,dashed] (system) -- (init);
    %\path [line,dashed] (system) |- (evaluate);
    \end{tikzpicture}


\end{document}

Here's the output for this:

enter image description here


Your problem doesn’t have anything to do with graphs or the library. The to paths are missing their nodes. You need to add \tikztonodes after the target coordinate of the path operatore you want to add the nodes to.

hv path/.style ={to path={-| (\tikztotarget) \tikztonodes}},
vh path/.style ={to path={|- (\tikztotarget) \tikztonodes}},

I also switched to the arrows.meta library (stealth becomes Stealth) since the libraries arrows and arrows.spaced are now depecrated (but still available of course).


Though it seem that a new bug has been introduced which can be seen with

A21 -- [edge label=C] A11 -> A12;

as the edge from A21 to A11 gets an arrow tip even if <- is used anywhere on that graph.

Code

\documentclass[tikz]{standalone}
\usetikzlibrary{arrows.meta,graphs}
\begin{document}
\begin{tikzpicture}[
  >=Stealth,
  font=\sffamily\small,
  every node/.style={align=center},
  hv path/.style ={to path={-| (\tikztotarget) \tikztonodes}},
  vh path/.style ={to path={|- (\tikztotarget) \tikztonodes}},
]

\matrix[column sep=1cm,row sep=1cm] (mymatrix)  {
  \coordinate (A11);       & \node[draw] (A12) {A12}; \\
  \node[draw] (A21) {A21}; & \coordinate (A22);       \\
};

\graph[use existing nodes] {
 A21 -> [edge label=A]A12;
 A21 -> [hv path, near end, edge label'=B] A12;
 A21 -- [edge label=C] A11 -> A12; 
};
\end{tikzpicture}
\end{document}

Output

enter image description here