Now that we are somewhat familiar with the two shortest path commands,
the shortest path, or a single path and
the all shortest paths command or multiple shortest paths, we're going to use
that in a little bit of a creative way to return the diameter of the graph.
And if you remember from a previous lecture,
the definition of the diameter of the graph
is actually the longest continuous path between two nodes in the graph.
So by using the shortest path command, but returning all possible shortest paths,
we're actually going to get the longest path included in those results returned.
Now, if we look carefully at this script,
it is a little different than our previous scripts.
In this case our match command is matching all nodes of type MyNode.
We'll assign those to the variable end.
We're also matching the all nodes of type MyNode and assigning that to variable m.
So these matches are the same.
But we want to place a constraint such that the nodes in n are not
the same as the nodes in m, and
then we want to find all of the shortest paths between unique nodes in n and m.
And return the names of those nodes as well as the length of that resulting path.
And the trick is to use the command order by.
And so for those of you who are familiar already with SQL query language,
you'll recognize order by.
You'll also recognize the descend command.
So if we order the resulting paths by their length in descending order,
and only return 1, that path should actually be the longest path.
And that's equal to the diameter of the graph.