How to identify if a cycle connection exist

Hi,
I want to identify the cycle connection among the nodes while drawing links. I want to pass a custom data to that link because of which cycle is identified. Is this possible??

So you want to allow your users to draw new links that may form a cycle, yes?

In general, you will not want to limit link validation but instead just implement a “LinkDrawn” DiagramEvent listener which optionally sets some properties on the new link’s data object. Are you just asking about how to find out if the new, now existing, link is part of a cycle?

If I am drawing a link from one Node to Another, While Drawing that Link I want to know if it’s creating a cycle among the node.
for eg (Nodes A, B, C are present I draw Link from A-B, B-C, While Drawing link from C-A it should trigger me that the link is forming a cycle connection. )
And Yes I have implemented the linkDrawn listener but I am unable to identify the cycle

      $(go.Diagram, "myDiagramDiv", {
        "linkingTool.portTargeted": function(node, port, tempNode, tempPort, toEnd) {
          var tool = myDiagram.toolManager.linkingTool;
          console.log(tool.isValidCycle(tool.isForwards ? tool.originalFromNode : tool.originalToNode, node))
        },
        "LinkDrawn": function(e) {
          var link = e.subject;
          var diag = e.diagram;
          var tool = diag.toolManager.linkingTool;
          diag.validCycle = go.Diagram.CycleNotDirected;
          console.log(link.toString() + " " + tool.isValidCycle(link.fromNode, link.toNode, link));
          diag.validCycle = go.Diagram.CycleAll;
        }
      })

During the linking operation:

After the link has been created, but before the transaction is complete:
https://gojs.net/latest/intro/events.html#LinkDrawn