cancel
Showing results for 
Search instead for 
Did you mean: 

Neo4j Cypher Projection Query via py2neo

parthiv3215
Node Clone

I am trying to write a cypher query via py2neo.

#UserList to be passed as array   
params = {}
   params['UserList'] = ['Mason']

    # Cypher Projection
    queCreateGraph = """
                    CALL gds.graph.create.cypher(
                    'Test1',
                    'MATCH (n) WHERE n.name in $UserList OR n:FunctionNode RETURN id(n) AS id, labels(n) AS labels',
                    'MATCH (n)-[r:LikedBy]->(m) WHERE m.name in $UserList RETURN id(n) AS source, id(m) AS target, type(r) AS type')
                    YIELD
                    graphName AS graph, nodeQuery, nodeCount AS nodes, relationshipCount AS rels
                     """
    graph.query(queCreateGraph, params)

I am basically trying to use UserList as a list to pass into the cypher projection but I am getting this error - py2neo.errors.ClientError: [Procedure.ProcedureCallFailed] Failed to invoke procedure gds.graph.create.cypher: Caused by: org.neo4j.exceptions.ParameterNotFoundException: Expected parameter(s): UserList

1 REPLY 1

glilienfield
Ninja
Ninja

Not sure why it is not working, but maybe try these two things to see if you can get it working. 

1. Initialize the map directly

params = {'UserList': ['Mason']}

2. Add parameter using 'with' clause:

    queCreateGraph = """
                    WITH ['Mason'] as UserList
                    CALL gds.graph.create.cypher(
                    'Test1',
                    'MATCH (n) WHERE n.name in UserList OR n:FunctionNode RETURN id(n) AS id, labels(n) AS labels',
                    'MATCH (n)-[r:LikedBy]->(m) WHERE m.name in UserList RETURN id(n) AS source, id(m) AS target, type(r) AS type')
                    YIELD
                    graphName AS graph, nodeQuery, nodeCount AS nodes, relationshipCount AS rels
                     """

 

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.