create the graph for given cypher input
u
usman alebe
CREATE
(u1:User {name: 'Alice', age: 30, location: 'New York'}),
(u2:User {name: 'Bob', age: 25, location: 'Los Angeles'}),
(u3:User {name: 'Charlie', age: 28, location: 'Chicago'}),
(u4:User {name: 'Diana', age: 22, location: 'Miami'});
// Create Posts
CREATE
(p1:Post {content: 'Hello World!', likes: 5}),
(p2:Post {content: 'Graph databases are amazing!', likes: 10}),
(p3:Post {content: 'Learning Cypher!', likes: 15});
// Create Relationships
CREATE
(u1)-[:FRIENDS_WITH]->(u2),
(u1)-[:POSTED]->(p2),
(u2)-[:POSTED]->(p3);
Gregory King
I'm guessing what you're asking here is why your CREATE relationships aren't linking up the nodes you CREATEd immediately before?
What's happening here is each of your CREATEs is terminated with a semi-colon, making them three independent Cypher statements . Variable scope is isolated across those three separate statements, so that last CREATE can't see the node variables and is instead creating new unlabelled nodes.
If you remove the semi-colons, as below, you will likely end up with what you were intending:
CREATE
(u1:User {name: 'Alice', age: 30, location: 'New York'}),
(u2:User {name: 'Bob', age: 25, location: 'Los Angeles'}),
(u3:User {name: 'Charlie', age: 28, location: 'Chicago'}),
(u4:User {name: 'Diana', age: 22, location: 'Miami'})
// Create Posts
CREATE
(p1:Post {content: 'Hello World!', likes: 5}),
(p2:Post {content: 'Graph databases are amazing!', likes: 10}),
(p3:Post {content: 'Learning Cypher!', likes: 15})
// Create Relationships
CREATE
(u1)-[:FRIENDS_WITH]->(u2),
(u1)-[:POSTED]->(p2),
(u2)-[:POSTED]->(p3);