How to create a graph with variable length relationships in gds library?

Hello,

I am trying to calculate the node embeddings for a graph containing variable-length relationships between nodes. However, when I try to create the graph with the following code,

MATCH (t)<-[ad:rel*]-(a)  
WITH gds.graph.project('testGraph', t, a, {sourceNodeLabels:labels(a),targetNodeLabels:labels(t), relationshipType:type(ad) }, {undirectedRelationshipTypes: ['*']}) AS g 
RETURN g.graphName AS graph, g.nodeCount AS nodes, g.relationshipCount AS rels

I am getting "Type mismatch: expected Relationship but was List". I tried using UNWIND and relationships() methods. Below is the code I tried

MATCH path = (t)<-[ad:rel*]-(a:Label)  
WITH t, a, relationships(path) AS rels
WITH gds.graph.project('testGraph', t, a, {sourceNodeLabels:labels(a), targetNodeLabels:labels(t), relationshipType:type(rels[0])}, {undirectedRelationshipTypes: ['*']}) AS g 
RETURN g.graphName AS graph, g.nodeCount AS nodes, g.relationshipCount AS rels

MATCH (t)<-[ad:rel*]-(a:labels)  
UNWIND ad AS singleRel
WITH t, a, singleRel
WITH gds.graph.project('testGraph', t, a, {sourceNodeLabels:labels(a), targetNodeLabels:labels(t), relationshipType:type(singleRel)}, {undirectedRelationshipTypes: ['*']}) AS g 
RETURN g.graphName AS graph, g.nodeCount AS nodes, g.relationshipCount AS rels

Using both approaches will result in a relationship between nodes that currently do not exist. Can you please suggest how to create the graph with variable-length relationships using cypher projection in the GDS library?

Thanks in advance.

Hello,
I can see, you always use t and a as source and target node of the gds.graph.project query.
Using UNWIND ad AS singleRel looks good. How about using WITH gds.graph.project('testGraph', startNode(singleRel), endNode(singleRel), ...?

If (t)<-[ad:rel*]-(a) is the graph you want to study, why not simply do:

MATCH (t)<-[ad:rel]-(a)  
WITH gds.graph.project('testGraph', t, a, {sourceNodeLabels:labels(a),targetNodeLabels:labels(t), relationshipType:type(ad) }, {undirectedRelationshipTypes: ['*']}) AS g 
RETURN g.graphName AS graph, g.nodeCount AS nodes, g.relationshipCount AS rels

To project your graph "the way it is, with its variable length paths"?

Or did you mean to collapse the path (t)<-[ad:rel*]-(a) into something like:

MATCH p=(t)-[ad:link*]->(a) 
WITH t,a,length(p) as distance....

There is also a collapse path algorithm/other path computations you can do after you have projected the graph.

Thanks @florentin_dorre. This is working.