Skip to content

Conversation

@hemanta212
Copy link
Contributor

Fix: splitStatements only splits on RETURN

isComplete() was too aggressive - treated any write keyword (CREATE/MERGE/DELETE) as "complete", causing premature splits that broke variable bindings in chained CREATE clauses.

Bug case

MATCH (alice:User {id: 1}), (bob:User {id: 2})
CREATE (c1:Comment {id: 1, text: "Great post!"})
CREATE (bob)-[:WROTE]->(c1)

Was split into 3 statements - bob and c1 became undefined in subsequent statements, creating orphan nodes.

Change

// Before: split on any write keyword
isComplete := func(s string) bool {
    if strings.Contains(upper, "RETURN") { return true }
    for _, kw := range writeKeywords { // CREATE, MERGE, DELETE...
        if strings.Contains(upper, kw) { return true }
    }
    return false
}

// After: only split on RETURN
isComplete := func(s string) bool {
    return strings.Contains(upper, "RETURN ") || strings.HasSuffix(upper, "RETURN")
}

Starter keywords unchanged (MATCH, CREATE, MERGE, DETACH, OPTIONAL, CALL, UNWIND, FOREACH).

Result

  • MATCH...CREATE...CREATE stays together (no RETURN)
  • ...RETURN x then CREATE/MATCH... splits correctly
  • crud example: 58/58 passing

The splitStatements function incorrectly treated CREATE as a statement
starter keyword. This caused multi-CREATE queries like fixtures to be
split into separate statements, losing MATCH context and creating
orphan nodes with relationships to undefined variables.

Changes:
- Remove CREATE from starterKeywords (it can chain within a statement)
- Change isComplete() to only return true for statements with RETURN
- This keeps chained CREATE clauses together as a single Cypher statement
@hemanta212 hemanta212 marked this pull request as ready for review January 13, 2026 16:39
@rlch
Copy link
Owner

rlch commented Jan 13, 2026

Add tests

@rlch rlch merged commit d0216c6 into rlch:main Jan 13, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants