I am brand new to Gremlin and am using gremlin-python to traverse my graph. The graph is made up of many clusters or sub-graphs which are intra-connected, and not inter-connected with any other cluster in the graph.
A simple example of this is a graph with 5 nodes and 3 edges:
Customer_1is connected toCreditCard_Awith1_HasCreditCard_AedgeCustomer_2is connected toCreditCard_Bwith2_HasCreditCard_BedgeCustomer_3is connected toCreditCard_Awith3_HasCreditCard_Aedge
I want a query that will return a sub-graph object of all nodes and edges connected (in or out) to the queried node. I can then store this sub-graph as a variable and then run different traversals on it to calculate different things.
This query would need to be recursive as these clusters could be made up of nodes which are many (inward or outward) hops away from each other. There are also many different types of nodes and edges, and they all must be returned.
For example:
- If I specified
Customer_1in the query, the resulting sub-graph would containCustomer_1,Customer_3,CreditCardA,1_HasCreditCard_A, and3_HasCreditCard_A. - If I specififed
Customer_2, the returned sub-graph would consist ofCustomer_2,CreditCard_B,2_HasCreditCard_B. - If I queried
Customer_3, the exact same subgraph object as returned from theCustomer_1query would be returned.
I have used both Neo4J with Cypher and Dgraph with GraphQL and found this task quite easy in these two langauges, but am struggling a bit more with understanding gremlin.
EDIT:
From, this question, the selected answer should achieve what I want, but without specifying the edge type by changing .both('created') to just .both().
However, the loop syntax: .loop{true}{true} is invalid in Python of course. Is this loop function available in gremlin-python? I cannot find anything.
EDIT 2:
I have tried this and it seems to be working as expected, I think.
g.V(node_id).repeat(bothE().otherV().simplePath()).emit()
Is this a valid solution to what I am looking for? Is it also possible to include the queried node in this result?