I\'m very new to Prolog. I defined in graph.pl the following graph:

And here\'s
It is checking in a cycle!
I executed the example with the trace. command before hand, and saw, that the program returns to the problem to find the path from a to f after cycling around.
path(a,f) needs path(e,f) to be true, following in short notation we need to be true:
(d,f), (c,f), (b,f), an then (a,f) again.
To resolv the loop you need a mechanism to prevent loop. My first Idea would be to keep a list of node-names and also check, if the list does not include the current X while checking the path.