Traverse All the nodes and relationship in cayley

57 views
Skip to first unread message

chaita...@gmail.com

unread,
Aug 16, 2017, 9:49:09 AM8/16/17
to cayley-users
Hi All

I am not able to find any prominent solution to how to traverse the whole cayley graph in a single shot and get as a single json output for all the connected Vertexes and Edges.

Example :
"Ordering" "Uses" "BookMyFlowers" .
"BookMyFlowers" "DependsOn" "10.236.220.154-MySql" .
"BookMyFlowers" "DependsOn" "10.236.220.161-IIS" .
"10.236.220.154-MySql" "RunsOn" "10.236.220.154-LinuxOS" .
"10.236.220.154-MySql" "RunsOn" "10.236.220.161-Windows" .
"10.236.220.154-LinuxOS" "IsMountedOn" "Storage1" .
"10.236.220.161-Windows" "IsMountedOn" "Storage2" .

I have tried below scenario but not getting complete connected Vertexes and Edges details:

var path= g.Morphism().Out("DependsOn")
g.V("BookMyFlowers").FollowRecursive(path).All()

output :

{
"result": [
{
"id": "10.236.220.154-MySql"
},
{
"id": "10.236.220.161-IIS"
}
]
}


Please help me out asap.

Thanks & Regards
Chaitanya

Denys Smirnov

unread,
Aug 16, 2017, 12:07:40 PM8/16/17
to cayley-users, chaita...@gmail.com
Hi Chaitanya,

Please note that this mailing list is abandoned in favor of a new forum: https://discourse.cayley.io/

The quick answer is that you cannot currently traverse the whole tree this way in Gizmo. If you know exactly what are the links after DependsOn, you can Save them for each object.

But there is a better option. We added support for GraphQL dialect to simplify querying of tree-like objects, so you can try using it.

First you need to change dataset a bit, because in RDF predicates should not be a plain text literals (note angle brackets on predicates):

"Ordering" <Uses> "BookMyFlowers" .
"BookMyFlowers" <DependsOn> "10.236.220.154-MySql" .
"BookMyFlowers" <DependsOn> "10.236.220.161-IIS" .
"10.236.220.154-MySql" <RunsOn> "10.236.220.154-LinuxOS" .
"10.236.220.154-MySql" <RunsOn> "10.236.220.161-Windows" .
"10.236.220.154-LinuxOS" <IsMountedOn> "Storage1" .
"10.236.220.161-Windows" <IsMountedOn> "Storage2" .

Next you'll need to get a list of objects with the same query as you mentioned before. Then, you can load fields of these objects via GraphQL:

{nodes(id: ["10.236.220.154-MySql", "10.236.220.161-IIS"]){
  id
  runsOn
: <RunsOn> {
    
id
        mountedOn: <IsMountedOn>
  }
}}

This will return the following:

{
 
"data": {
   
"nodes": [
     
{
       
"id": "10.236.220.154-MySql",
       
"runsOn": [
         
{
           
"id": "10.236.220.154-LinuxOS",
           
"mountedOn": "Storage1"
         
},
         
{
           
"id": "10.236.220.161-Windows",
           
"mountedOn": "Storage2"
         
}
       
]
     
},
     
{
       
"id": "10.236.220.161-IIS",
       
"runsOn": null
     
}
   
]
 
}
}

If you have only one level of DependsOn links, you can also filter nodes directly from GraphQL:

{nodes @rev(DependsOn: "BookMyFlowers"){
  id
  runsOn
: <RunsOn> {
    
id
        mountedOn: <IsMountedOn>
  }
}}

Hope this helps,
Denys

Reply all
Reply to author
Forward
0 new messages