How to return created node in cypher query?

create (role:ROLE {slug:"abc1"})

with role

match (permission:PERMISSION)

where permission.name IN ['create']

merge (role)-[:HAS_PERMISSION]->(permission)

RETURN role;

With above query I am trying to create role and its relationship with permission. The query returns role in above case but if i make array empty in where condition, it creates role but does not return it. Please refer below query for the same.

create (role:ROLE {slug:"abc1"})

with role

match (permission:PERMISSION)

where permission.name IN []

merge (role)-[:HAS_PERMISSION]->(permission)

RETURN role;

I need to return created role node in both the cases. Need help here.

Thanks in advanced.

hey thanks it worked. The only thing which needs to be changed is the position of with statement.

create (role:ROLE {slug:"abc1"})

with role

call {

match (permission:PERMISSION)

where permission.name IN

merge (role)-[:HAS_PERMISSION]->(permission)

}

RETURN role

Try this:

create (role:ROLE {slug:"abc1"})

call {

with role

match (permission:PERMISSION)

where permission.name IN ['create']

merge (role)-[:HAS_PERMISSION]->(permission)

}
RETURN role

True, you need a with between a create and a call. You should also need the with in the call subquery to make the ‘role’ node available within the call subquery. Your merge will create a new node otherwise.