cypher-builder icon indicating copy to clipboard operation
cypher-builder copied to clipboard

Define labels in pattern instead of relying on Node/Relationship variables

Open angrykoala opened this issue 1 year ago • 1 comments

Instead of relying on withoutLabels and withoutProperty, labels used in a Pattern should be defined in the pattern, instead of the Cypher.Node and Cypher.Relationship types.

There are 2 alternatives for achieving this:

Option 1: Using a chained command pattern, similar to current solution

new Cypher.Pattern({ variable: movie, labels: ["Movie"] })
    .related()
    .withDirection("left")
    .withLength("*")
    .to({ labels: ["Actor"] })
    .withProperties({
        name: new Cypher.Param("Keanu"),
    });

Option 1.5: Same as before but with labels in a method

new Cypher.Pattern(movie)
    .withLabels("Movie")
    .related()
    .withDirection("left")
    .withLength("*")
    .to()
    .withLabels(["Actor"])
    .withProperties({
        name: new Cypher.Param("Keanu"),
    });

Option 2: Use objects chained with related and to

new Cypher.Pattern({
    variable: movie,
    labels: ["Movie"],
})
    .related({
        direction: "left",
        length: "*",
    })
    .to({
        labels: ["Actor"],
        properties: {
            name: new Cypher.Param("Keanu"),
        },
    });

Regardless of the option to be implemented, the Cypher.Node and Cypher.Relationship types should be maintained as sugar syntax, but every possible pattern should be possible to produce with plain variables.

The following methods should be deprecated:

  • withoutLabels
  • withoutVariable
  • withoutType
  • (optionally) getVariables

Related Discussion: https://github.com/neo4j/cypher-builder/discussions/293

angrykoala avatar Feb 15 '24 16:02 angrykoala

This also requires hasLabel and hasType methods to be available in variables

angrykoala avatar Feb 22 '24 16:02 angrykoala