Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

customize node label #94

Open
DORGAA opened this issue Jun 29, 2023 · 1 comment
Open

customize node label #94

DORGAA opened this issue Jun 29, 2023 · 1 comment

Comments

@DORGAA
Copy link

DORGAA commented Jun 29, 2023

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
Copy link
Collaborator

Popotojs commented Jul 1, 2023

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

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

No branches or pull requests

2 participants