cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Calling the gds.graph.create.cypher in .NET Core Neo4j Client

In raw format, i have a query like the following:

CALL gds.graph.create.cypher(
        "{graph_name}",
        'MATCH (p:Post)-[:ACCOUNT_POST]->(a:Account) WHERE p.CreatedAt>="{start_date}" and p.CreatedAt<"{end_date}" RETURN distinct id(a) as id',
        'MATCH (p1:Post)-[:ACCOUNT_POST]->(a1:Account) match(p2:Post)-[:ACCOUNT_POST]->(a2:Account) match(p2)-[:POST_RETWEET|:POST_QUOTE]->(p1) WHERE and p1.CreatedAt>="{start_date}" and p1.CreatedAt<"{end_date}" and p2.CreatedAt>="{start_date}" and p2.CreatedAt<"{end_date}"  RETURN id(a1) as target, id(a2) as source',
        {validateRelationships: false})

I want to use the neo4j .Net Core client for querying the db but was not able to find such a solution other than typing a raw query.

As you can see from the following link, it seems it is inappropriate to use raw query in most cases.

I wanted to ask the community to get a solution with this before giving up and typing the entire query as a raw Cypher query.

I also found a solution like the following, although I'm not sure how to implement it to my own query:

1 REPLY 1

Hey @taylangezici1

The problem you face is that the Call command on Neo4jClient is for calling procedures, but isn't tailored for any specific cases.

The GDS ones would be specific cases, and it doesn't cater for that. If you want the results you could do something like:

var results = (await client.Cypher.Call(@"
            gds.graph.create.cypher(
                ""TestGraph3"",
                'MATCH (p:Post)-[:ACCOUNT_POST]->(a:Account) WHERE p.counter > 2 RETURN distinct id(a) as id',
                'MATCH (p1:Post)-[:ACCOUNT_POST]->(a1:Account) match(p2:Post)-[:ACCOUNT_POST]->(a2:Account) match(p2)-[:POST_RETWEET|:POST_QUOTE]->(p1) WHERE p1.counter>=2 RETURN id(a1) as target, id(a2) as source',
                { validateRelationships: false})"
            )
            .Yield("nodeQuery, relationshipQuery, graphName, nodeCount, relationshipCount, createMillis")
            .Return((nodeQuery, relationshipQuery, graphName, nodeCount, relationshipCount, createMillis) =>
           new CreateGraphResults {
                NodeQuery = nodeQuery.As<string>(),
                RelationshipQuery = relationshipQuery.As<string>(),
                GraphName = graphName.As<string>(),
                NodeCount = nodeCount.As<int>(),
                RelationshipCount = relationshipCount.As<int>(),
                CreateMs = createMillis.As<int>()
           }).ResultsAsync).Single();

public class CreateGraphResults {
    public string NodeQuery { get; set; }
    public string RelationshipQuery { get; set; }
    public string GraphName { get; set; }

    public int NodeCount { get; set; }
    public int RelationshipCount { get; set; }
    public int CreateMs { get; set; }
}

But you're still largely writing it in a 'string'.

You could take that whole thing and write an extension on the top of the client to do GDS things - What I would think is that GDS isn't typically used from an application pov, so I don't know how useful it would be