Visualize data as graph

I want to visualize all relations/entities that a certain entity type is linked with, how can we write such a query ? Using typedb 3.3, I want relations with say configurable hops for eg I have a user with id 123 and want to visualize all relationships that this user has with all other entities and the role that this user plays in them.
From there I can traverse and find 2nd degree or 3rd relations.

Here’s something to get you started. It should get you all hops through relations (but not through attributes). It should also get you the attributes of each of the nodes involved.
You just need to change the first line ({ $x isa book, has isbn "9780008627843"; } ). The rest should work for any database.

match
{ $x isa book, has isbn "9780008627843"; } # Change this line.
 or
 { $x isa $_; $x iid 0x0000000000000000000000;  }; # Fool type-inference in-case 'book' isn't a relation, doesn't play any roles. or doesn't own any attributes.
match 
# This will fail if $x doesn't play any roles, but you'll notice.
{ $x links ($r1: $y); } or { $y links ($r1: $x); }; # First half-hop
match 
{ $y links ($r2: $z); } or { $z links ($r2: $y); } or # Second-half hop.
{ $r2 is $r1; $y is $z; }; # Stops at 1 hop 
# ...
# Add more to go further.
match
{ $x has $attr; } or { $y has $attr; } or {$z has $attr; }; # Bit of a blow-up.

I would have liked to have written a function for this, but there’s no way to label the argument & return types