Nhogs / popoto

Visual query builder for Neo4j graph database
http://popotojs.com
GNU General Public License v3.0
511 stars 70 forks source link

customize node label #94

Open DORGAA opened 1 year ago

DORGAA commented 1 year ago

To provide some context, when Popoto.js generates a query for a node with a specific label, it includes the label as part of the node identifier, which can lead to queries that are not accepted by the Neo4j database. For example, the generated query looks like this:

MATCH (node::test:`Node::test`) RETURN node::test

As mentioned, this query format is not compatible with the Neo4j database. I am wondering if there is a solution or workaround to customize the query and achieve the desired result. Specifically, I would like to generate a query in the following format:

MATCH (n:`Node::test`) RETURN n

or escape variables and labels that contain special characters:

MATCH (`node::test`:`Node::test`) RETURN `node::test`

PS: i can't remove the '::' from nodes This modified query format would allow me to work with the Neo4j database seamlessly.

I would greatly appreciate any guidance or insights you can provide regarding this issue. Thank you in advance for your assistance.

Popotojs commented 1 year ago

The right way to fix it is to update query generation in popoto and escape all variables names to avoid issues with specific characters like : or even with cypher reserved keywords.

But as a workaround for your use case you can override generateInternalLabel function to remove or change : characters You can add the following code before starting popoto in your configuration:

    popoto.graph.node.generateInternalLabel = function (nodeLabel) {
        let label = nodeLabel ? nodeLabel.toLowerCase().replace(/[ :]/g, '') : "n";

        if (label in popoto.graph.node.internalLabels) {
            popoto.graph.node.internalLabels[label] = popoto.graph.node.internalLabels[label] + 1;
            return label + popoto.graph.node.internalLabels[label];
        } else {
            popoto.graph.node.internalLabels[label] = 0;
            return label;
        }
    };

Using this code will generate the following query:

MATCH (nodetest:`Node::test`) RETURN nodetest