Cypher query parameter problem

I am trying to pass on the parameter to the cypher query in a function but it is not returning the results as expected. First error was ClientError: {code: Neo.ClientError.Statement.ParameterMissing} {message: Expected parameter(s): x} I checked it on another forum where I also had to pass the parameter along with query run session I did so and error disappeared but still it didn't get the results as expected and returned the empty nodes.

In the graph db the nodes are connected with 4 types of relationships with an ids.

This is what I have tried so far:

def get_objects(x):
    query = ''' MATCH (p)-[r]->(a) where r.id = $x RETURN p.id; ''' 
    resultNodes = session.run(query, x = x)
    df = DataFrame(resultNodes)
    print(df)
    return df

def find_max_1():
    authors,terms,venues,papers=0,0,0,0
    authors=get_objects(1).max()
    terms=get_objects(2).max()
    venues=get_objects(3).max()
    papers=get_objects(4).max()
    return authors,terms,venues,papers

def main():
    
    m = m=find_max_1()
    

if __name__ == "__main__":
    
    main()

and the output is:

Empty DataFrame
Columns: []
Index: []
Empty DataFrame
Columns: []
Index: []
Empty DataFrame
Columns: []
Index: []
Empty DataFrame
Columns: []
Index: []

I also checked giving the absolute value as ''' MATCH (p)-[r]->(a) where r.id = '1' RETURN p.id ''' into the function, it worked fine but there is a problem when i pass it through the function?

Any kind of help in right direction would be appreciated.

Thanks in advance.

Hello @mumarhafiz and welcome to the Neo4j community :slight_smile:

In your example, you passed a String:

MATCH (p)-[r]->(a) where r.id = '1' RETURN p.id

So you should write:

query = "MATCH (p)-[r]->(a) where r.id = toString($x) RETURN p.id;"

or

query = "MATCH (p)-[r]->(a) where r.id = $x RETURN p.id;" 
resultNodes = session.run(query, x=str(x))

Moreover, do you have an id parameter on your nodes and relations or do you want to use the Neo4j internal ID? If it's the Neo4j internal ID, you should have a look at id().

Regards,
Cobra

Thanks for your response. Meanwhile I tried the other way and convert the parameter to string separately and then passed to cypher statement. It worked in my scenario, but this is clean and efficient.

And yes, I have the id parameter on each of the nodes and also for the relations.

Thanks for your help.